⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmd_parse.c

📁 cmd line like! cmd line like!
💻 C
📖 第 1 页 / 共 2 页
字号:
			i = 0;
		}
		
		if(bc->pnext->cmd[0]!=bc->cmd[0]){
			if(i == 0)	printf_0("\r-\n  ");
			else{
				printf_0("\n-\n  ");
				i = 0;
			}
		}
		
		bc = bc->pnext;
	}
	
	if ( i != 0 ) {
		printf_0("\n");
	}
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
static void
cmdProcess(
	UINT8 *cmd,
	UINT32 repeating
)
{
	cmd_t *bc = pcmds;
	UINT32 idx = 0;
	UINT32 copy = 0;

	/*
	 * Strip the white space from the command.
	 */
	while ( cmd[idx] != '\0' ) {
		if ( (cmd[idx] != ' ') &&
			 (cmd[idx] != '\t') &&
			 (cmd[idx] != '\r') &&
			 (cmd[idx] != '\n') ) {
			break;
		}
		idx++;
	}

	if ( idx > 0 ) {
		/* Reached a non-white space character, compact the string */
		while ( cmd[idx] != '\0' ) {
			cmd[copy++] = cmd[idx++];
		}
		cmd[copy] = '\0';
	}

	/*
	 * Index points to the end of the string, move backwards.
	 */
	idx = strlen(cmd);

	while ( idx > 0 ) {
		idx--;
		if ( (cmd[idx] == ' ') || 
			 (cmd[idx] == '\t') ||
			 (cmd[idx] == '\r') ||
			 (cmd[idx] == '\n') ) {
			cmd[idx] = '\0';
		}
		else {
			break;
		}
	}

	/*
	 * Find the command.
	 */
	idx = 0;

	while ( cmd[idx] != '\0' ) {
		if ( (cmd[idx] == ' ') ||
			 (cmd[idx] == '\t') ||
			 (cmd[idx] == '\r') ||
			 (cmd[idx] == '\n') ) {
			break;
		}
		idx++;
	}
	cmd[idx] = '\0';
	while ( bc ) {
		if ( strcmp(bc->cmd, cmd) == 0 ) {
			(bc->phandler)(cmd + idx + 1);
			return;
		}
		bc = bc->pnext;
	}
	
	bc = &cmdList;	/* machao@20060808 */
	if ( strcmp(bc->cmd, cmd) == 0 ) {
		(bc->phandler)(cmd + idx + 1);
		return;
	}
	
	printf_0("command '%s' not found, try 'help'\n", cmd);
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
static UINT32
cmdIdxIncrease(
	UINT32 *pcmdIdx
)
{
	UINT32 localIdx;
	UINT32 ret = 0;

	localIdx = *pcmdIdx;
	localIdx++;
	if ( localIdx == CMD_HISTORIES ) {
		localIdx = 0;
		ret = 1;
	}
	*pcmdIdx = localIdx;

	return ret;
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
static UINT32
cmdFlushCopy(
	UINT32 cursorPos,
	UINT8 *pcmdBuf,
	UINT8 *pcmdSrc,
	UINT32 cmdLen
)
{
	if ( cursorPos > 0 ) {
		for ( ; cursorPos > 0; cursorPos-- ) {
			printf_0("\b \b");
			buffer[cursorPos] = '\0';
		}
	}
	memcpy(pcmdBuf, pcmdSrc, cmdLen);

	return 0;
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
void
cmdMonitor(
	void
)
{
	UINT8 c;
	UINT32 repeating;
	UINT32 histDownArw;
	static UINT32 upArrowCnt;

	c = (UINT8)getch();
	
	if ( !logIn ) {
		if ( c == '\r' ) {
			logIn = TRUE;
			printf_0("\n\ncmd>");
		}
	}
	else 
	{
		switch ( c ) {
		case '\b':
		case '\x7f':
			if ( pos > 0 ) {
				printf_0("\b \b");
				pos--;
			}
			buffer[pos] = '\0';
			break;

		case '\r':  /* Process the command. */
			printf_0("\n");
			if ( pos ) {
				/*
				 * Do not place the same last command into the history if the same.
				 */
				if ( strcmp((UINT8 *)histBuf[histIns], buffer) ) {
					if ( cmdIdxIncrease(&histIns) == 1 ) {
						histInsWrap = 1;
					}
					memcpy(histBuf[histIns], buffer, CMD_BUF_SIZE);
					histPos[histIns] = pos;
				}
				histOutput = histIns;
				histOutputWrap = 0;
				upArrowCnt = 0;
				repeating = FALSE;
			} 
			if ( pos ) {
				cmdProcess(buffer, repeating);
				pos = 0;
				memset(buffer, 0, CMD_BUF_SIZE);
				printf_0("\n");
			}
			printf_0("cmd>");
			break;

		case '[': /* Non ASCII characters, arrow. */
		case 0xe0:
			c = (UINT8)getch();
			switch ( c ) {
			case 'A': /* Key: up arrow */
			case 'H':
				if ( histOutputWrap == 1 ) {
					if ( histOutput == histIns ) {
						break;
					}
				}
				if ( histInsWrap == 0 ) {
					if ( histOutput == 0 ) {
						break;
					}
				}
				upArrowCnt++;
				cmdFlushCopy(
					pos,
					buffer,
					(UINT8 *)histBuf[histOutput],
					histPos[histOutput]
				);
				pos = histPos[histOutput];
				buffer[pos + 1] = '\0';
				printf_0(buffer);
				if ( histInsWrap == 1 ) {
					if ( histOutput == 0 ) {
						histOutput = CMD_HISTORIES - 1;
						histOutputWrap = 1;
					}
					else {
						histOutput--;
					}
				}
				else {
					if ( histOutput != 0 ) {
						/* Note that when wrap around does not occur, the least
						 * of index is 1 because it is the first one to be
						 * written.
						 */
						histOutput--;
					}
					/* Nothing to do with histOutput == 0,
					 * because there is no more commands.
					 */
				}
				break;

			case 'B': /* Key: down arrow */
			case 'P':
				if ( upArrowCnt <= 1 ) {
					break;
				}
				upArrowCnt--;
				cmdIdxIncrease(&histOutput);
				histDownArw = histOutput;
				cmdIdxIncrease(&histDownArw);
				cmdFlushCopy(
					pos,
					buffer,
					(UINT8 *)histBuf[histDownArw],
					histPos[histDownArw]
				);
				pos = histPos[histDownArw];
				buffer[pos + 1] = '\0';
				printf_0(buffer);
				break;

			case 'C': /* Key: right arrow */
			case 'M':
				break;
			case 'D': /* Key: left arrow */
			case 'K':
				break;
			default:
				break;
			}
			break;

		default:
			if ( (pos < (CMD_BUF_SIZE - 1)) && (c >= ' ') && (c <= 'z') ) {
				buffer[pos++] = c;
				buffer[pos] = '\0';
				printf_0(buffer + pos - 1);
			}
			if ( c == '\x7e' ) {
				buffer[pos++] = c;
				buffer[pos] = '\0';
				printf_0(buffer + pos - 1);
			}
			break;
		}
	} /* else of if !logged_in */
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
void
cmdRegister(
	cmd_t *bc
)
{
	cmd_t *prev;
	cmd_t *curr;

	bc->pnext = NULL;
	if ( pcmds == NULL ) {
		pcmds = bc;
	}
	else {
		prev = NULL;
		curr = pcmds;
		while ( curr ) {
			/* The list is sorted by alphabetic order. */
			if ( strcmp(bc->cmd, curr->cmd) <= 0 ) {
				bc->pnext = curr;
				if ( prev ) {
					prev->pnext = bc;
				}
				else {
					pcmds = bc;
				}
				return;
			}
			prev = curr;
			curr = curr->pnext;
		}

		/* Last on the list. */

		prev->pnext = bc;
	} /* else boot_commands */
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
void
cmdInit(
	void
)
{
	cmdDscInit();
	cmdGfxInit();
	cmdFileInit();
	cmdGameInit();
	cmdMiscInit();
	cmdAudioInit();
	cmdVideoInit();
	cmdFlashInit();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -