📄 parselib.c
字号:
/******************************************************************************
Copyright (c) 2006 by RockOS.
All rights reserved.
This software is supported by the Rock Software Workroom only.
Any bugs please contact the author with e-mail or QQ:
E-mail : baobaoba520@yahoo.com.cn
QQ : 59681888
*******************************************************************************
File name : parselib.c
Description : parse command line library for RockOS' shell.
:
:
Auther : sunxinqiu
History :
2006-3-15 first release.
******************************************************************************/
#include "os.h"
/******************************************************************************
Function : STATUS parseCmdLine()
Params : cmdLine - command line get from shell prompt.
: cmdName - the command name parsed from cmdLine.
: argc - total argument count for this command.
: argv - the arguments list for this command.
:
Return : OS_SUCCESS for parsing successfully, or OS_FAIL.
Description : parse the command line before executing the proper shell command
: function.
******************************************************************************/
STATUS parseCmdLine (char * cmdLine,
char * cmdName,
int * argc,
char * argv[])
{
BOOL parsingKey;
BOOL parsingString;
int n;
char ch;
int length;
* argc = 0;
cmdName[0] = 0;
argv[0] = NULL;
/* skip the leading spaces & TABs. */
length = 0;
ch = cmdLine[0];
if (ch == '\0')
{
/* null command line. */
return OS_SUCCESS;
}
else
{
while ((ch == ' ')||(ch == '\t'))
{
length++;
ch = cmdLine[length];
if (ch == '\0')
{
return OS_SUCCESS;
}
}
}
/* start parse command, argv[0] first. */
n = 0;
argv[0] = &cmdLine[length];
parsingKey = OS_TRUE;
parsingString = OS_FALSE;
while (ch != '\0')
{
switch (ch)
{
case ' ': /* 0x20, space */
case '\t': /* 0x09, TAB */
case ',': /* 0x2c, comma (,) */
if (parsingKey != OS_TRUE)
{
/* skip this separator char*/
;
}
else if (parsingString == OS_TRUE)
{
;
}
else
{
parsingKey = OS_FALSE;
cmdLine[length] = '\0';
n++;
}
break;
case '\"': /* 0x22, double quotation (") */
if ((parsingKey == OS_TRUE)&&(parsingString == OS_FALSE))
{
/* error: double quotation occurs in a key word or argument. */
OS_printf("parseCmdLine(): doule quotation can't be used as a seperator!!!\n");
return OS_FAIL;
}
else if ((parsingKey == OS_FALSE)&&(parsingString == OS_FALSE))
{
/* a string argument begins here. */
parsingKey = OS_TRUE;
parsingString = OS_TRUE;
argv[n] = &cmdLine[length];
}
else if ((parsingKey == OS_TRUE)&&(parsingString == OS_TRUE))
{
/* a string argument ends here. */
parsingKey = OS_FALSE;
parsingString = OS_FALSE;
cmdLine[length] = '\0';
}
else
{
/* error: double quotation occurs leading a command line.*/
OS_printf("");
return OS_FAIL;
}
break;
default:
if (parsingString != OS_TRUE)
{
if (parsingKey != OS_TRUE)
{
argv[n] = &cmdLine[length];
parsingKey = OS_TRUE;
}
}
break;
}
length++;
ch = cmdLine[length];
}
* argc = n + 1;
strcpy (&cmdName[0], argv[0]);
return OS_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -