📄 dcf_parser_cmd.c
字号:
{
if((++uLength) >MAX_COMMAND_NAME_LENGTH)
{
trace("DRVTEST: the input command name is too long.\n");
*pszName = 0;
return DRVTEST_ERROR;
}
*pszName++ = *p++;
}
}
*pszName = 0;
//pszStr = p;
if(pWordOrigin == pszName)
{
return DRVTEST_ERROR;
}
else
{
return DRVTEST_OK;
}
}
/****************************************************************************/
/* FUNCTION: cnxt_drvtest_get_cmd_ID */
/* */
/* DESCRIPTION: find given command in command table and return an index */
/* */
/* INPUTS: pszStr - pointer to the start of the input command */
/* pCmdTable - pointer to the command table */
/* uMinID - the ID of the command in command table you want to */
/* start searching from */
/* uMaxID - the ID of the command in command table you want to */
/* end searching to */
/* OUTPUTS: uCmdID - the found command ID in command table */
/* */
/* RETURNS: DRVTEST_OK -get name ID successfully */
/* DRVTEST_ERROR - get name ID failed */
/* */
/* NOTES: */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/****************************************************************************/
CNXT_DRVTEST_STATUS cnxt_drvtest_get_cmd_ID(
u_int8 *pszStr,
CNXT_DRVTEST_CMD* pCmdTable,
u_int32 uMinID,
u_int32 uMaxID,
u_int32 *uCmdID)
{
u_int8 *p = pszStr;
u_int8 szWord[MAX_COMMAND_NAME_LENGTH];
u_int32 i = uMinID;
if(p == NULL || pCmdTable == NULL)
{
return DRVTEST_ERROR;
}
if (!cnxt_drvtest_get_cmd_name(p, szWord))
{
while ((i<=uMaxID) && (pCmdTable+i)->szFormat[0])
{
u_int8 szOperator[MAX_COMMAND_NAME_LENGTH];
u_int8 *pOp = (pCmdTable+i)->szFormat;
if(!cnxt_drvtest_get_cmd_name(pOp, szOperator))
{
if (!cnxt_stricmp((char*)szWord, (char*)szOperator))
//if (!strcmp((char*)szWord, (char*)szOperator))
{
*uCmdID = i;
return DRVTEST_OK;
}
else
{
i++;
}
}
else
{
//trace("Can not get the format name.\n");
return DRVTEST_ERROR;
}
}
trace("DRVTEST: \"%s\" is not a valid command!\n", szWord);
return DRVTEST_ERROR;
}
else
{
trace("DRVTEST: Can not get the input command name.\n");
return DRVTEST_ERROR;
}
}
/****************************************************************************/
/* FUNCTION: cnxt_drvtest_get_cmd_para */
/* */
/* DESCRIPTION: get the parameters from the iuput command according to */
/* the command format */
/* */
/* INPUTS: pszStr - pointer to the start of the input command */
/* pszFmt - pointer to the start of the command format in */
/* command table */
/* uParaNum - the anticipated parameter number */
/* */
/* OUTPUTS: variable argument,use to store the parameter wanted */
/* */
/* RETURNS: DRVTEST_OK -get name parameter successfully */
/* DRVTEST_ERROR - get name parameter failed */
/* */
/* NOTES: */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/****************************************************************************/
CNXT_DRVTEST_STATUS cnxt_drvtest_get_cmd_para(
u_int8 uParaNum,
u_int8 *pszStr,
u_int8 *pszFmt, ...)
{
va_list args;
u_int8 *p = pszStr;
u_int8 doneArgs = 0;
u_int32 *pCurArg = 0;
u_int8 *pCurArgC, *pOriArgC;
u_int8 format[MAX_COMMAND_FORMAT_LENGTH];
u_int8 *pFormat = format;
if(p == NULL || pszFmt == NULL)
{
return DRVTEST_ERROR;
}
/*copy to local string, skip the '<' & '>'*/
while (*pszFmt)
{
/*
if (*pszFmt == '<')
{
pszFmt++;
continue;
}
else if (*pszFmt == '>')
{
pszFmt++;
continue;
}
*/
*pFormat++ = *pszFmt++;
}
*pFormat = 0;
/*reset pointer*/
pFormat = format;
va_start(args, pszFmt);
while (*pFormat)
{
/*skip leading spaces */
while (*p && *p <= ' ')
{
p++;
}
if (*pFormat <= ' ')
{
pFormat++;
continue;
}
/*find a parameter*/
if (*pFormat == '%')
{
pFormat++;
if (!*pFormat)
{
break;
}
switch (*pFormat)
{
case 'X':
case 'x':
case 'D':
case 'd':
{
pCurArg = va_arg(args, u_int32*);
if(pCurArg == NULL)
{
goto Error;
}
if (Str2Int(&p, pCurArg))
{
doneArgs++;
}
else
{
goto Error;
}
break;
}
case 'F':
case 'f':
{
break;
}
case 'C':
case 'c':
{
if (!ISDIGITORALPHA(p))
{
goto Error;
}
pCurArgC = va_arg(args, u_int8*);
if(pCurArg == NULL)
{
goto Error;
}
*pCurArgC = *p++;
doneArgs++;
break;
}
case 'S':
case 's':
{
pCurArgC = va_arg(args, u_int8*);
if(pCurArgC == NULL)
{
goto Error;
}
pOriArgC = pCurArgC;
/*skip leading spaces */
while (*p && *p <= ' ')
{
p++;
}
while (ISDIGITORALPHA(p))
{
*pCurArgC++ = *p++;
}
*pCurArgC = 0;
if (pCurArgC != pOriArgC)
{
doneArgs++;
}
else
{
goto Error;
}
break;
}
}
}
else
{ /*Exact sequence*/
if ( !*p || ((*p != *pFormat) && ((*p & ~0x20)!= (*pFormat & ~0x20)) ) )
{
goto Error;
}
else
{
p++;
}
}
pFormat++;
}
Error:
va_end(args);
//pszStr = p;
if(doneArgs != uParaNum)
{
trace("DRVTEST: The input parameters are error!\n ");
return DRVTEST_ERROR;
}
else
{
return DRVTEST_OK;
}
}
/*main task of the driver test module*/
static void drvtest_main_task(void * param)
{
u_int8 *p;
u_int32 uCmdID;
while(1)
{
memset(input_cmd, 0 ,MAX_COMMAND_INPUT_LENGTH);
if(cnxt_drvtest_get_cmd(input_cmd))
{
trace("DRVTEST: get command error!\n");
continue;
}
p = input_cmd;
RemoveCMDLeadingSpaces(p);
if(cnxt_drvtest_get_cmd_ID(p, cmd_format_table, 0, -1, &uCmdID))
{
//trace("get command ID error!\n");
continue;
}
(*(cmd_callback_table+uCmdID))(p, (cmd_format_table+uCmdID)->szFormat);
}
}
/****************************************************************************/
/* FUNCTION: cnxt_drvtest_get_id_from_str */
/* */
/* DESCRIPTION: get the ID of a inputed string parameter in a specified */
/* array */
/* */
/* INPUTS: pszInputStr - pointer to the string parameter in input command */
/* pszArray - pointer to the array in which find the inputed */
/* string parameter */
/* OUTPUTS: uID - the found ID of the input string */
/* */
/* RETURNS: DRVTEST_OK -find ID successfully */
/* DRVTEST_ERROR - find ID failed */
/* */
/* NOTES: */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/****************************************************************************/
CNXT_DRVTEST_STATUS cnxt_drvtest_get_id_from_str(
u_int8 *pszInputStr,
CNXT_DRVTEST_INPUT_STR *pszArray,
u_int8 *uID)
{
u_int8 uIndex = 0;
while ((pszArray + uIndex)->szPara[0])
{
if (!cnxt_stricmp((char*)pszInputStr, (char*)((pszArray + uIndex)->szPara)))
//if (!strcmp((char*)pszInputStr, (char*)((pszArray + uIndex)->szPara)))
{
*uID = uIndex;
return DRVTEST_OK;
}
uIndex++;
}
return DRVTEST_ERROR;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -