static const CLI_Definition_List_Item_t *pxCommand = NULL;\r
portBASE_TYPE xReturn = pdTRUE;\r
const int8_t *pcRegisteredCommandString;\r
+size_t xCommandStringLength;\r
\r
/* Note: This function is not re-entrant. It must not be called from more\r
thank one task. */\r
for( pxCommand = &xRegisteredCommands; pxCommand != NULL; pxCommand = pxCommand->pxNext )\r
{\r
pcRegisteredCommandString = pxCommand->pxCommandLineDefinition->pcCommand;\r
- if( strncmp( ( const char * ) pcCommandInput, ( const char * ) pcRegisteredCommandString, strlen( ( const char * ) pcRegisteredCommandString ) ) == 0 )\r
+ xCommandStringLength = strlen( ( const char * ) pcRegisteredCommandString );\r
+\r
+ /* To ensure the string lengths match exactly, so as not to pick up \r
+ a sub-string of a longer command, check the byte after the expected\r
+ end of the string is either the end of the string or a space before\r
+ a parameter. */\r
+ if( ( pcCommandInput[ xCommandStringLength ] == ' ' ) || ( pcCommandInput[ xCommandStringLength ] == 0x00 ) )\r
{\r
- /* The command has been found. Check it has the expected\r
- number of parameters. If cExpectedNumberOfParameters is -1,\r
- then there could be a variable number of parameters and no\r
- check is made. */\r
- if( pxCommand->pxCommandLineDefinition->cExpectedNumberOfParameters >= 0 )\r
+ if( strncmp( ( const char * ) pcCommandInput, ( const char * ) pcRegisteredCommandString, xCommandStringLength ) == 0 )\r
{\r
- if( prvGetNumberOfParameters( pcCommandInput ) != pxCommand->pxCommandLineDefinition->cExpectedNumberOfParameters )\r
+ /* The command has been found. Check it has the expected\r
+ number of parameters. If cExpectedNumberOfParameters is -1,\r
+ then there could be a variable number of parameters and no\r
+ check is made. */\r
+ if( pxCommand->pxCommandLineDefinition->cExpectedNumberOfParameters >= 0 )\r
{\r
- xReturn = pdFALSE;\r
+ if( prvGetNumberOfParameters( pcCommandInput ) != pxCommand->pxCommandLineDefinition->cExpectedNumberOfParameters )\r
+ {\r
+ xReturn = pdFALSE;\r
+ }\r
}\r
- }\r
\r
- break;\r
+ break;\r
+ }\r
}\r
}\r
}\r
pcCommandString++;\r
}\r
\r
+ /* If the command string ended with spaces, then there will have been too\r
+ many parameters counted. */\r
+ if( xLastCharacterWasSpace == pdTRUE )\r
+ {\r
+ cParameters--;\r
+ }\r
+\r
/* The value returned is one less than the number of space delimited words,\r
as the first word should be the command itself. */\r
return cParameters;\r