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

Merge pull request #168 from NevermindZZT/shell3.1

修复 命令表方式编译问题
This commit is contained in:
Letter 2023-10-14 12:25:36 +08:00 committed by GitHub
commit 6a0bfa5ca2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 76 additions and 23 deletions

View File

@ -10,6 +10,7 @@ add_executable(LetterShell
../../src/shell.c
../../src/shell_companion.c
../../src/shell_ext.c
../../src/shell_cmd_list.c
../../extensions/fs_support/shell_fs.c
../../extensions/log/log.c
../../extensions/telnet/telnetd.c

View File

@ -316,3 +316,16 @@ SHELL_EXPORT_CMD_SIGN(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC
paramParserTest, shellParamParserTest, test function signature and param parser, iLTestStruct;s);
#endif /** SHELL_USING_FUNC_SIGNATURE == 1 */
int paramTest(int argc, char *argv[])
{
int i;
printf("argc = %d\r\n", argc);
for (i = 0; i < argc; i++)
{
printf("argv[%d] = %s\r\n", i, argv[i]);
}
return 0;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
paramTest, paramTest, test param);

View File

@ -143,6 +143,17 @@ static const char *shellText[] =
};
unsigned char pairedChars[][2] = {
{'\"', '\"'},
// {'[', ']'},
// {'(', ')'},
// {'{', '}'},
// {'<', '>'},
// {'\'', '\''},
// {'`', '`'},
};
/**
* @brief shell对象表
*/
@ -900,8 +911,9 @@ void shellDeleteByte(Shell *shell, signed char direction)
*/
static void shellParserParam(Shell *shell)
{
unsigned char quotes = 0;
unsigned char record = 1;
unsigned char pairedLeft[16] = {0};
unsigned char pariedCount = 0;
for (short i = 0; i < SHELL_PARAMETER_MAX_NUMBER; i++)
{
@ -911,33 +923,44 @@ static void shellParserParam(Shell *shell)
shell->parser.paramCount = 0;
for (unsigned short i = 0; i < shell->parser.length; i++)
{
if (quotes != 0
|| (shell->parser.buffer[i] != ' '
&& shell->parser.buffer[i] != 0))
{
if (shell->parser.buffer[i] == '\"')
if (pariedCount == 0) {
if (shell->parser.buffer[i] != ' '
&& record == 1
&& shell->parser.paramCount < SHELL_PARAMETER_MAX_NUMBER)
{
quotes = quotes ? 0 : 1;
}
if (record == 1)
{
if (shell->parser.paramCount < SHELL_PARAMETER_MAX_NUMBER)
{
shell->parser.param[shell->parser.paramCount++] =
&(shell->parser.buffer[i]);
}
shell->parser.param[shell->parser.paramCount++] =
&(shell->parser.buffer[i]);
record = 0;
}
if (shell->parser.buffer[i] == '\\'
&& shell->parser.buffer[i + 1] != 0)
else if (shell->parser.buffer[i] == ' ' && record == 0)
{
i++;
shell->parser.buffer[i] = 0;
record = 1;
continue;
}
}
else
for (unsigned char j = 0; j < sizeof(pairedChars) / 2; j++)
{
shell->parser.buffer[i] = 0;
record = 1;
if (pariedCount > 0
&& shell->parser.buffer[i] == pairedChars[j][1]
&& pairedLeft[pariedCount - 1] == pairedChars[j][0])
{
--pariedCount;
break;
}
else if (shell->parser.buffer[i] == pairedChars[j][0])
{
pairedLeft[pariedCount++] = pairedChars[j][0];
pariedCount &= 0x0F;
break;
}
}
if (shell->parser.buffer[i] == '\\'
&& shell->parser.buffer[i + 1] != 0)
{
i++;
}
}
}

View File

@ -14,7 +14,7 @@
#include "shell_cfg.h"
#define SHELL_VERSION "3.2.0" /**< 版本号 */
#define SHELL_VERSION "3.2.1" /**< 版本号 */
/**
@ -359,13 +359,16 @@
#endif /** SHELL_USING_FUNC_SIGNATURE == 1 */
#define SHELL_EXPORT_CMD(_attr, _name, _func, _desc)
#if SHELL_USING_FUNC_SIGNATURE == 1
#define SHELL_EXPORT_CMD_SIGN(_attr, _name, _func, _desc, _sign)
#endif /** SHELL_USING_FUNC_SIGNATURE == 1 */
#define SHELL_EXPORT_CMD_AGENCY(_attr, _name, _func, _desc, ...)
#define SHELL_EXPORT_VAR(_attr, _name, _value, _desc)
#define SHELL_EXPORT_USER(_attr, _name, _password, _desc)
#define SHELL_EXPORT_KEY(_attr, _value, _func, _desc)
#define SHELL_EXPORT_KEY_AGENCY(_attr, _name, _func, _desc, ...)
#if SHELL_USING_FUNC_SIGNATURE == 1
#define SHELL_EXPORT_PARAM_PARSER(_attr, _type, _func)
#define SHELL_EXPORT_PARAM_PARSER(_attr, _type, _parser, _cleaner)
#endif /** SHELL_USING_FUNC_SIGNATURE == 1 */
#endif /** SHELL_USING_CMD_EXPORT == 1 */

View File

@ -324,6 +324,7 @@ static unsigned int shellExtParseVar(Shell *shell, char *var)
*
* @param shell shell对象
* @param string
* @param type
* @param result
*
* @return int 0 --1
@ -410,6 +411,15 @@ int shellExtParsePara(Shell *shell, char *string, char *type, unsigned int *resu
#if SHELL_USING_FUNC_SIGNATURE == 1
/**
* @brief
*
* @param shell shell
* @param type
* @param param
*
* @return int 0 -1
*/
int shellExtCleanerPara(Shell *shell, char *type, unsigned int param)
{
if (type == NULL)

View File

@ -28,6 +28,9 @@ typedef enum
} ShellNumType;
int shellExtParsePara(Shell *shell, char *string, char *type, unsigned int *result);
#if SHELL_USING_FUNC_SIGNATURE == 1
int shellExtCleanerPara(Shell *shell, char *type, unsigned int param);
#endif /** SHELL_USING_FUNC_SIGNATURE == 1 */
int shellExtRun(Shell *shell, ShellCommand *command, int argc, char *argv[]);
#endif