mirror of
https://github.com/NevermindZZT/letter-shell.git
synced 2025-01-21 10:02:54 +08:00
优化 变量作为参数时, 如果变量不存在, 命令直接返回; 命令组子命令允许返回值打印
This commit is contained in:
parent
0ce0255194
commit
03432e824c
@ -1,8 +1,8 @@
|
||||
# letter shell 3.x
|
||||
|
||||
![version](https://img.shields.io/badge/version-3.2.2-brightgreen.svg)
|
||||
![version](https://img.shields.io/badge/version-3.2.4-brightgreen.svg)
|
||||
![standard](https://img.shields.io/badge/standard-c99-brightgreen.svg)
|
||||
![build](https://img.shields.io/badge/build-2023.10.25-brightgreen.svg)
|
||||
![build](https://img.shields.io/badge/build-2024.07.31-brightgreen.svg)
|
||||
![license](https://img.shields.io/badge/license-MIT-brightgreen.svg)
|
||||
|
||||
一个功能强大的嵌入式shell
|
||||
|
@ -47,7 +47,7 @@
|
||||
*/
|
||||
#define SHELL_CMD_GROUP_ITEM(_type, _name, _func, _desc, ...) \
|
||||
{ \
|
||||
.attr.value = SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(_type)|SHELL_CMD_DISABLE_RETURN, \
|
||||
.attr.value = SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(_type), \
|
||||
.data.cmd.name = #_name, \
|
||||
.data.cmd.function = (int (*)())_func, \
|
||||
.data.cmd.desc = #_desc, \
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
#include "shell_cfg.h"
|
||||
|
||||
#define SHELL_VERSION "3.2.3" /**< 版本号 */
|
||||
#define SHELL_VERSION "3.2.4" /**< 版本号 */
|
||||
|
||||
|
||||
/**
|
||||
|
@ -326,9 +326,11 @@ static size_t shellExtParseNumber(char *string)
|
||||
*
|
||||
* @param shell shell对象
|
||||
* @param var 变量
|
||||
* @return size_t 变量值
|
||||
* @param result 解析结果
|
||||
*
|
||||
* @return int 0 解析成功 --1 解析失败
|
||||
*/
|
||||
static size_t shellExtParseVar(Shell *shell, char *var)
|
||||
static int shellExtParseVar(Shell *shell, char *var, size_t *result)
|
||||
{
|
||||
ShellCommand *command = shellSeekCommand(shell,
|
||||
var + 1,
|
||||
@ -336,11 +338,12 @@ static size_t shellExtParseVar(Shell *shell, char *var)
|
||||
0);
|
||||
if (command)
|
||||
{
|
||||
return shellGetVarValue(shell, command);
|
||||
*result = shellGetVarValue(shell, command);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -371,8 +374,7 @@ int shellExtParsePara(Shell *shell, char *string, char *type, size_t *result)
|
||||
}
|
||||
else if (*string == '$' && *(string + 1))
|
||||
{
|
||||
*result = shellExtParseVar(shell, string);
|
||||
return 0;
|
||||
return shellExtParseVar(shell, string, result);
|
||||
}
|
||||
else if (*string)
|
||||
{
|
||||
@ -385,8 +387,7 @@ int shellExtParsePara(Shell *shell, char *string, char *type, size_t *result)
|
||||
{
|
||||
if (*string == '$' && *(string + 1))
|
||||
{
|
||||
*result = shellExtParseVar(shell, string);
|
||||
return 0;
|
||||
return shellExtParseVar(shell, string, result);
|
||||
}
|
||||
#if SHELL_SUPPORT_ARRAY_PARAM == 1
|
||||
else if (type[0] == '[')
|
||||
|
Loading…
x
Reference in New Issue
Block a user