1
0
mirror of https://github.com/NevermindZZT/letter-shell.git synced 2025-01-21 10:02:54 +08:00

增加 参数自动转换最大参数限制

修复 对错误命令使用help时会引起异常的问题
This commit is contained in:
Letter 2020-11-29 14:32:48 +08:00
parent 8392f6c859
commit 38b8c7795f
6 changed files with 119 additions and 16 deletions

View File

@ -1,8 +1,8 @@
# letter shell 3.0 # letter shell 3.0
![version](https://img.shields.io/badge/version-3.0.5-brightgreen.svg) ![version](https://img.shields.io/badge/version-3.0.6-brightgreen.svg)
![standard](https://img.shields.io/badge/standard-c99-brightgreen.svg) ![standard](https://img.shields.io/badge/standard-c99-brightgreen.svg)
![build](https://img.shields.io/badge/build-2020.08.23-brightgreen.svg) ![build](https://img.shields.io/badge/build-2020.11.29-brightgreen.svg)
![license](https://img.shields.io/badge/license-MIT-brightgreen.svg) ![license](https://img.shields.io/badge/license-MIT-brightgreen.svg)
一个功能强大的嵌入式shell 一个功能强大的嵌入式shell

View File

@ -86,7 +86,7 @@
/** /**
* @brief shell命令参数最大数量 * @brief shell命令参数最大数量
* 8使 * 16使
*/ */
#define SHELL_PARAMETER_MAX_NUMBER 8 #define SHELL_PARAMETER_MAX_NUMBER 8

View File

@ -1597,11 +1597,18 @@ void shellHelp(int argc, char *argv[])
argv[1], argv[1],
shell->commandList.base, shell->commandList.base,
0); 0);
shellWriteString(shell, shellText[SHELL_TEXT_HELP_HEADER]); if (command)
shellWriteString(shell, shellGetCommandName(command)); {
shellWriteString(shell, "\r\n"); shellWriteString(shell, shellText[SHELL_TEXT_HELP_HEADER]);
shellWriteString(shell, shellGetCommandDesc(command)); shellWriteString(shell, shellGetCommandName(command));
shellWriteString(shell, "\r\n"); shellWriteString(shell, "\r\n");
shellWriteString(shell, shellGetCommandDesc(command));
shellWriteString(shell, "\r\n");
}
else
{
shellWriteString(shell, shellText[SHELL_TEXT_CMD_NOT_FOUND]);
}
} }
} }
SHELL_EXPORT_CMD( SHELL_EXPORT_CMD(

View File

@ -14,7 +14,7 @@
#include "shell_cfg.h" #include "shell_cfg.h"
#define SHELL_VERSION "3.0.5" /**< 版本号 */ #define SHELL_VERSION "3.0.6" /**< 版本号 */
/** /**

View File

@ -24,12 +24,12 @@ extern int shellGetVarValue(Shell *shell, ShellCommand *command);
* @brief * @brief
* *
* @param string * @param string
* @return NUM_Type * @return ShellNumType
*/ */
static NUM_Type shellExtNumType(char *string) static ShellNumType shellExtNumType(char *string)
{ {
char *p = string; char *p = string;
NUM_Type type = NUM_TYPE_INT; ShellNumType type = NUM_TYPE_DEC;
if ((*p == '0') && ((*(p + 1) == 'x') || (*(p + 1) == 'X'))) if ((*p == '0') && ((*(p + 1) == 'x') || (*(p + 1) == 'X')))
{ {
@ -174,7 +174,7 @@ static char* shellExtParseString(char *string)
*/ */
static unsigned int shellExtParseNumber(char *string) static unsigned int shellExtParseNumber(char *string)
{ {
NUM_Type type = NUM_TYPE_INT; ShellNumType type = NUM_TYPE_DEC;
char radix = 10; char radix = 10;
char *p = string; char *p = string;
char offset = 0; char offset = 0;
@ -301,7 +301,7 @@ unsigned int shellExtParsePara(Shell *shell, char *string)
*/ */
int shellExtRun(Shell *shell, ShellCommand *command, int argc, char *argv[]) int shellExtRun(Shell *shell, ShellCommand *command, int argc, char *argv[])
{ {
unsigned int params[8] = {0}; unsigned int params[SHELL_PARAMETER_MAX_NUMBER] = {0};
int paramNum = command->attr.attrs.paramNum > (argc - 1) ? int paramNum = command->attr.attrs.paramNum > (argc - 1) ?
command->attr.attrs.paramNum : (argc - 1); command->attr.attrs.paramNum : (argc - 1);
for (int i = 0; i < argc - 1; i++) for (int i = 0; i < argc - 1; i++)
@ -310,39 +310,135 @@ int shellExtRun(Shell *shell, ShellCommand *command, int argc, char *argv[])
} }
switch (paramNum) switch (paramNum)
{ {
#if SHELL_PARAMETER_MAX_NUMBER >= 1
case 0: case 0:
return command->data.cmd.function(); return command->data.cmd.function();
// break; // break;
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 1 */
#if SHELL_PARAMETER_MAX_NUMBER >= 2
case 1: case 1:
return command->data.cmd.function(params[0]); return command->data.cmd.function(params[0]);
// break; // break;
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 2 */
#if SHELL_PARAMETER_MAX_NUMBER >= 3
case 2: case 2:
return command->data.cmd.function(params[0], params[1]); return command->data.cmd.function(params[0], params[1]);
// break; // break;
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 3 */
#if SHELL_PARAMETER_MAX_NUMBER >= 4
case 3: case 3:
return command->data.cmd.function(params[0], params[1], return command->data.cmd.function(params[0], params[1],
params[2]); params[2]);
// break; // break;
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 4 */
#if SHELL_PARAMETER_MAX_NUMBER >= 5
case 4: case 4:
return command->data.cmd.function(params[0], params[1], return command->data.cmd.function(params[0], params[1],
params[2], params[3]); params[2], params[3]);
// break; // break;
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 5 */
#if SHELL_PARAMETER_MAX_NUMBER >= 6
case 5: case 5:
return command->data.cmd.function(params[0], params[1], return command->data.cmd.function(params[0], params[1],
params[2], params[3], params[2], params[3],
params[4]); params[4]);
// break; // break;
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 6 */
#if SHELL_PARAMETER_MAX_NUMBER >= 7
case 6: case 6:
return command->data.cmd.function(params[0], params[1], return command->data.cmd.function(params[0], params[1],
params[2], params[3], params[2], params[3],
params[4], params[5]); params[4], params[5]);
// break; // break;
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 7 */
#if SHELL_PARAMETER_MAX_NUMBER >= 8
case 7: case 7:
return command->data.cmd.function(params[0], params[1], return command->data.cmd.function(params[0], params[1],
params[2], params[3], params[2], params[3],
params[4], params[5], params[4], params[5],
params[6]); params[6]);
// break; // break;
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 8 */
#if SHELL_PARAMETER_MAX_NUMBER >= 9
case 8:
return command->data.cmd.function(params[0], params[1],
params[2], params[3],
params[4], params[5],
params[6], params[7]);
// break;
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 9 */
#if SHELL_PARAMETER_MAX_NUMBER >= 10
case 9:
return command->data.cmd.function(params[0], params[1],
params[2], params[3],
params[4], params[5],
params[6], params[7],
params[8]);
// break;
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 10 */
#if SHELL_PARAMETER_MAX_NUMBER >= 11
case 10:
return command->data.cmd.function(params[0], params[1],
params[2], params[3],
params[4], params[5],
params[6], params[7],
params[8], params[9]);
// break;
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 11 */
#if SHELL_PARAMETER_MAX_NUMBER >= 12
case 11:
return command->data.cmd.function(params[0], params[1],
params[2], params[3],
params[4], params[5],
params[6], params[7],
params[8], params[9],
params[10]);
// break;
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 12 */
#if SHELL_PARAMETER_MAX_NUMBER >= 13
case 12:
return command->data.cmd.function(params[0], params[1],
params[2], params[3],
params[4], params[5],
params[6], params[7],
params[8], params[9],
params[10], params[11]);
// break;
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 13 */
#if SHELL_PARAMETER_MAX_NUMBER >= 14
case 13:
return command->data.cmd.function(params[0], params[1],
params[2], params[3],
params[4], params[5],
params[6], params[7],
params[8], params[9],
params[10], params[11],
params[12]);
// break;
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 14 */
#if SHELL_PARAMETER_MAX_NUMBER >= 15
case 14:
return command->data.cmd.function(params[0], params[1],
params[2], params[3],
params[4], params[5],
params[6], params[7],
params[8], params[9],
params[10], params[11],
params[12], params[13]);
// break;
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 15 */
#if SHELL_PARAMETER_MAX_NUMBER >= 16
case 15:
return command->data.cmd.function(params[0], params[1],
params[2], params[3],
params[4], params[5],
params[6], params[7],
params[8], params[9],
params[10], params[11],
params[12], params[13],
params[14]);
// break;
#endif /** SHELL_PARAMETER_MAX_NUMBER >= 16 */
default: default:
return -1; return -1;
// break; // break;

View File

@ -20,12 +20,12 @@
*/ */
typedef enum typedef enum
{ {
NUM_TYPE_INT, /**< 十进制整型 */ NUM_TYPE_DEC, /**< 十进制整型 */
NUM_TYPE_BIN, /**< 二进制整型 */ NUM_TYPE_BIN, /**< 二进制整型 */
NUM_TYPE_OCT, /**< 八进制整型 */ NUM_TYPE_OCT, /**< 八进制整型 */
NUM_TYPE_HEX, /**< 十六进制整型 */ NUM_TYPE_HEX, /**< 十六进制整型 */
NUM_TYPE_FLOAT /**< 浮点型 */ NUM_TYPE_FLOAT /**< 浮点型 */
} NUM_Type; } ShellNumType;
unsigned int shellExtParsePara(Shell *shell, char *string); unsigned int shellExtParsePara(Shell *shell, char *string);
int shellExtRun(Shell *shell, ShellCommand *command, int argc, char *argv[]); int shellExtRun(Shell *shell, ShellCommand *command, int argc, char *argv[]);