From 849130da2c7128d88a1b5516cf1b955461718601 Mon Sep 17 00:00:00 2001 From: roamboy <0yfj0@163.com> Date: Mon, 13 Jan 2014 15:52:23 +0800 Subject: [PATCH 1/3] Update msh.c fix msh_exec(char* cmd, rt_size_t length) bug --- components/finsh/msh.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/components/finsh/msh.c b/components/finsh/msh.c index 8da80fad5..98c34c1de 100644 --- a/components/finsh/msh.c +++ b/components/finsh/msh.c @@ -257,16 +257,29 @@ int msh_exec(char* cmd, rt_size_t length) int cmd0_size = 0; cmd_function_t cmd_func; + while(*cmd == ' ') + { + cmd++; + length--; + } while ((cmd[cmd0_size] != ' ' && cmd[cmd0_size] != '\t') && cmd0_size < length) cmd0_size ++; - + /* try to get built-in command */ + if (cmd0_size == 0) return -1; cmd_func = msh_get_cmd(cmd, cmd0_size); if (cmd_func == RT_NULL) { #ifdef RT_USING_MODULE msh_exec_module(cmd, length); #else + argv[0] = cmd; + while(*cmd != ' ') + { + if (*cmd == 0) break; + cmd++; + } + if (*cmd == ' ') *cmd = 0; rt_kprintf("%s: command not found.\n", argv[0]); #endif return -1; From 1df4c1b9629269a4e5374f44873026b122eeb0ab Mon Sep 17 00:00:00 2001 From: roamboy <0yfj0@163.com> Date: Mon, 13 Jan 2014 15:56:20 +0800 Subject: [PATCH 2/3] Update msh.c --- components/finsh/msh.c | 51 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/components/finsh/msh.c b/components/finsh/msh.c index 98c34c1de..8d2a51e92 100644 --- a/components/finsh/msh.c +++ b/components/finsh/msh.c @@ -253,39 +253,38 @@ int msh_exec(char* cmd, rt_size_t length) { int argc; char *argv[RT_FINSH_ARG_MAX]; - - int cmd0_size = 0; + int cmd0_size = 0; cmd_function_t cmd_func; - while(*cmd == ' ') - { - cmd++; - length--; - } - while ((cmd[cmd0_size] != ' ' && cmd[cmd0_size] != '\t') && cmd0_size < length) - cmd0_size ++; + while(*cmd == ' ') + { + cmd++; + length--; + } + while ((cmd[cmd0_size] != ' ' && cmd[cmd0_size] != '\t') && cmd0_size < length) + cmd0_size ++; - /* try to get built-in command */ - if (cmd0_size == 0) return -1; - cmd_func = msh_get_cmd(cmd, cmd0_size); - if (cmd_func == RT_NULL) - { + /* try to get built-in command */ + if (cmd0_size == 0) return -1; + cmd_func = msh_get_cmd(cmd, cmd0_size); + if (cmd_func == RT_NULL) + { #ifdef RT_USING_MODULE - msh_exec_module(cmd, length); + msh_exec_module(cmd, length); #else - argv[0] = cmd; - while(*cmd != ' ') - { - if (*cmd == 0) break; - cmd++; - } - if (*cmd == ' ') *cmd = 0; - rt_kprintf("%s: command not found.\n", argv[0]); + argv[0] = cmd; + while(*cmd != ' ') + { + if (*cmd == 0) break; + cmd++; + } + if (*cmd == ' ') *cmd = 0; + rt_kprintf("%s: command not found.\n", argv[0]); #endif - return -1; - } + return -1; + } - /* split arguments */ + /* split arguments */ memset(argv, 0x00, sizeof(argv)); argc = msh_split(cmd, length, argv); if (argc == 0) return -1; From 1c8693c87eb4636df0edeb0dfeb36551df6f5e75 Mon Sep 17 00:00:00 2001 From: roamboy <0yfj0@163.com> Date: Mon, 13 Jan 2014 15:57:13 +0800 Subject: [PATCH 3/3] Update msh.c --- components/finsh/msh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/finsh/msh.c b/components/finsh/msh.c index 8d2a51e92..35ebb4b55 100644 --- a/components/finsh/msh.c +++ b/components/finsh/msh.c @@ -276,7 +276,7 @@ int msh_exec(char* cmd, rt_size_t length) while(*cmd != ' ') { if (*cmd == 0) break; - cmd++; + cmd++; } if (*cmd == ' ') *cmd = 0; rt_kprintf("%s: command not found.\n", argv[0]);