📄 exparser.c
字号:
/************************************************************************
* Name : exparser.c *
* *
* Written : Ronen Golan *
* *
* Abstract : This file contains the routines of the template parser *
************************************************************************/
/***************************** #include ***************************/
#include "exparser.h"
#include "exos.h"
#ifdef EX_GET_COMMAND_LINE_STRUCT
/***********************************************************************
* Name : ExGetCommandLineStruct
* Parses string into known CommandLineStruct struct
* It assumes the string token has the format:
*
* "/[CommandFromList][SuffixNumber]:[Argument]
* "-[CommandFromList][SuffixNumber]:[Argument]
*
* Parameters:
* curArgv - The string needed to be parsed.
* pCommandList - Pointer to the command list.(array of strings)
* Outputs:
* cmdLine->fSlash - EXTRUE : If The string starts with '/' or '-' char
* EXFALSE : Otherwise.
* cmdLine->bCommandNumber - The number of the command from the command list
* cmdLine->pCommand - Pointer to the command start (After the '/' or '-')
* cmdLine->pCommandUpper - NULL always (we don't need it actually).
* cmdLine->bCommandLen - Returns the command length in bytes
* cmdLine->fSuffix - There is a suffix after the command
* cmdLine->bSuffix - The suffix value
* cmdLine->pArg - Pointer to the argument
* cmdLine->bArgLen - Argument length
***********************************************************************/
void EXAPI ExGetCommandLineStruct(EXCHAR* curArgv,CommandLineStruct* cmdLine, EXCHAR** pCommandList)
{
EXCHAR* p = curArgv;
EXCHAR* pEnd = curArgv + ExStrLen( curArgv );
EXBYTE bCommandNumber = 0;
EXBYTE bListLen;
EXWORD iCommand;
/*** Initialization ***/
cmdLine->fSlash = EXFALSE;
cmdLine->bCommandNumber = 0xFF;
cmdLine->pCommand = EXNULL;
cmdLine->pCommandUpper = EXNULL;
cmdLine->bCommandLen = 0;
cmdLine->fSuffix = EXFALSE;
cmdLine->bSuffix = 0;
cmdLine->pArg = EXNULL;
cmdLine->bArgLen = 0;
/*** If '/' or '-' char appears in string => cmdLine->fSlash is true else false ***/
if( *p == EX_SLASH_PREFIX || *p == EX_SLASH_MINUS )
{
p++;
cmdLine->fSlash = EXTRUE;
}
/* pointer to command */
if( p < pEnd )
{
/*** Set pointer cmdLine->pCommand to be the command start ***/
/*** (After the '/' or '-') ***/
cmdLine->pCommand = (EXCHAR*)p;
/*** If no slash was found => cmdLine->bCommandLen is all the line ***/
if(!cmdLine->fSlash)
{
cmdLine->bCommandLen = (EXBYTE)ExStrLen(p);
}
}
/*** Find the length of the command => The length until ':' sigb ***/
for(;p+cmdLine->bCommandLen<pEnd ;cmdLine->bCommandLen++)
{
if(*(p+cmdLine->bCommandLen)==COLON)
{
p++; /*** Pass the colon (':') sign ***/
break;
}
}
/*** Advance the pointer after colon sign ***/
p += cmdLine->bCommandLen;
/* arg */
if (p<pEnd)
{
/*** Pointer to argument after the colon ***/
cmdLine->pArg = (EXCHAR*)p;
/*** Length of the argument after colon ***/
cmdLine->bArgLen = (EXBYTE)ExStrLen(p);
}
/*** Runs over all commands and see if you find it in the command list ***/
for (iCommand=0;ExMemCmp((EXCHAR*)pCommandList[iCommand],LAST_COMMAND,ExStrLen(LAST_COMMAND))!=0;iCommand++)
{
/*** The length of the comand ***/
bListLen = (EXBYTE)ExStrLen(pCommandList[iCommand]);
/*** Check if the length is equal or different by 1 ***/
/*** (because of the partition number) ***/
if (bListLen<=cmdLine->bCommandLen && bListLen+1>=cmdLine->bCommandLen)
{
EXBYTE b;
/*** Compare the string that the parser found with ***/
/*** one of the strings in the command list ***/
for (b=0;b<bListLen;b++)
{
if (ExToupper(pCommandList[iCommand][b]) != ExToupper(cmdLine->pCommand[b]))
break;
}
if (b==bListLen)
{ /*** command was found ***/
if(bListLen+1==cmdLine->bCommandLen)
{ /*** If we have suffix number after the command => Update suffix fields ***/
if(cmdLine->pCommand[bListLen] < END_LIST || cmdLine->pCommand[bListLen] > '9' )
{
bCommandNumber++;
continue;
}
/*** Raise the suffix flag ***/
cmdLine->fSuffix = EXTRUE;
/*** Return the suffix number ***/
cmdLine->bSuffix = (EXBYTE)( cmdLine->pCommand[bListLen] - '0' );
}
cmdLine->bCommandNumber = bCommandNumber;
return;
}
}
bCommandNumber++;
} /* For loop over commands */
}
/***********************************************************************
* Name : ParseCommandLine
* Parses a command line string
* It assumes the string token has the format:
*
* "/[CommandFromList][SuffixNumber]:[Argument]
* "-[CommandFromList][SuffixNumber]:[Argument]
*
* Parameters:
* commandNumber - The command number (Argc)
* exUtilCommands - Pointer to the command list.(array of strings)
*
* Outputs:
* cmdLineRecord->fSlash - EXTRUE : If The string starts with '/' or '-' char
* EXFALSE : Otherwise.
* cmdLineRecord->bCommandNumber - The number of the command from the command list
* cmdLineRecord->pCommand - Pointer to the command start (After the '/' or '-')
* cmdLineRecord->pCommandUpper - NULL always (we don't need it actually).
* cmdLineRecord->bCommandLen - Returns the command length in bytes
* cmdLineRecord->fSuffix - There is a suffix after the command
* cmdLineRecord->bSuffix - The suffix value
* cmdLineRecord->pArg - Pointer to the argument
* cmdLineRecord->bArgLen - Argument length
***********************************************************************/
ExStatus EXAPI ParseCommandLine( CommandLineStruct* cmdLineRecord, EXBYTE commandNumber, EXCHAR **exUtilCommands )
{
ExStatus Err;
ExDevice cmlDev;
void* curCommand;
/*** Open a command line device ***/
if( ( Err = OpenCmdLineDevice( &cmlDev ) ) != EX_OK )
return Err;
/*** Read the command line Device ***/
Err = ReadCmdLineDevice( &cmlDev, commandNumber, &curCommand );
if( Err != EX_OK )
return Err;
/*** Get the command line struct ***/
ExGetCommandLineStruct( (EXCHAR*)curCommand, cmdLineRecord, exUtilCommands) ;
/*** Close the Command Line device ***/
CloseCmdLineDevice( &cmlDev );
return EX_OK;
}
#endif /* EX_GET_COMMAND_LINE_STRUCT */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -