Update msh.c

This commit is contained in:
roamboy 2014-01-13 15:56:20 +08:00
parent 849130da2c
commit 1df4c1b962
1 changed files with 25 additions and 26 deletions

View File

@ -253,39 +253,38 @@ int msh_exec(char* cmd, rt_size_t length)
{ {
int argc; int argc;
char *argv[RT_FINSH_ARG_MAX]; char *argv[RT_FINSH_ARG_MAX];
int cmd0_size = 0;
int cmd0_size = 0;
cmd_function_t cmd_func; cmd_function_t cmd_func;
while(*cmd == ' ') while(*cmd == ' ')
{ {
cmd++; cmd++;
length--; length--;
} }
while ((cmd[cmd0_size] != ' ' && cmd[cmd0_size] != '\t') && cmd0_size < length) while ((cmd[cmd0_size] != ' ' && cmd[cmd0_size] != '\t') && cmd0_size < length)
cmd0_size ++; cmd0_size ++;
/* try to get built-in command */ /* try to get built-in command */
if (cmd0_size == 0) return -1; if (cmd0_size == 0) return -1;
cmd_func = msh_get_cmd(cmd, cmd0_size); cmd_func = msh_get_cmd(cmd, cmd0_size);
if (cmd_func == RT_NULL) if (cmd_func == RT_NULL)
{ {
#ifdef RT_USING_MODULE #ifdef RT_USING_MODULE
msh_exec_module(cmd, length); msh_exec_module(cmd, length);
#else #else
argv[0] = cmd; argv[0] = cmd;
while(*cmd != ' ') while(*cmd != ' ')
{ {
if (*cmd == 0) break; if (*cmd == 0) break;
cmd++; cmd++;
} }
if (*cmd == ' ') *cmd = 0; if (*cmd == ' ') *cmd = 0;
rt_kprintf("%s: command not found.\n", argv[0]); rt_kprintf("%s: command not found.\n", argv[0]);
#endif #endif
return -1; return -1;
} }
/* split arguments */ /* split arguments */
memset(argv, 0x00, sizeof(argv)); memset(argv, 0x00, sizeof(argv));
argc = msh_split(cmd, length, argv); argc = msh_split(cmd, length, argv);
if (argc == 0) return -1; if (argc == 0) return -1;