diff options
-rw-r--r-- | common/command.c | 19 | ||||
-rw-r--r-- | common/hush.c | 18 | ||||
-rw-r--r-- | common/parser.c | 19 | ||||
-rw-r--r-- | include/command.h | 1 |
4 files changed, 22 insertions, 35 deletions
diff --git a/common/command.c b/common/command.c index accaffa4be..24c2e2407f 100644 --- a/common/command.c +++ b/common/command.c @@ -91,6 +91,25 @@ static int compare(struct list_head *a, struct list_head *b) return strcmp(na, nb); } +int execute_command(int argc, char **argv) +{ + cmd_tbl_t *cmdtp; + + /* Look up command in command table */ + if ((cmdtp = find_cmd(argv[0]))) { + /* found - check max args */ + if (argc > cmdtp->maxargs) { + u_boot_cmd_usage(cmdtp); + return -1; + } + /* OK - call function to do the command */ + return cmdtp->cmd(cmdtp, argc, argv); + } else { + printf ("Unknown command '%s' - try 'help'\n", argv[0]); + return -1; /* give up after bad command */ + } +} + int register_command(cmd_tbl_t *cmd) { /* diff --git a/common/hush.c b/common/hush.c index 0ad5977218..5ff695beb7 100644 --- a/common/hush.c +++ b/common/hush.c @@ -513,7 +513,6 @@ static int run_pipe_real(struct pipe *pi) int i; int nextin; struct child_prog *child; - cmd_tbl_t *cmdtp; char *p; char *path; int ret; @@ -589,23 +588,8 @@ static int run_pipe_real(struct pipe *pi) free(path); return ret; } - /* Look up command in command table */ - if ((cmdtp = find_cmd(child->argv[i]))) { - int rcode; - - /* found - check max args */ - if ((child->argc - i) > cmdtp->maxargs) { - printf ("Usage:\n%s\n", cmdtp->usage); - return -1; - } - /* OK - call function to do the command */ - rcode = cmdtp->cmd(cmdtp, child->argc-i, &child->argv[i]); - return rcode; - } else { - printf ("Unknown command '%s' - try 'help'\n", child->argv[i]); - return -1; /* give up after bad command */ - } + return execute_command(child->argc - i, &child->argv[i]); } return -1; } diff --git a/common/parser.c b/common/parser.c index c43d7ca176..97e354bae9 100644 --- a/common/parser.c +++ b/common/parser.c @@ -176,7 +176,6 @@ static void process_macros (const char *input, char *output) int run_command (const char *cmd, int flag) { - cmd_tbl_t *cmdtp; char cmdbuf[CONFIG_CBSIZE]; /* working copy of cmd */ char *token; /* start of token in cmdbuf */ char *sep; /* end of token (separator) in cmdbuf */ @@ -251,23 +250,7 @@ int run_command (const char *cmd, int flag) continue; } - /* Look up command in command table */ - if ((cmdtp = find_cmd(argv[0])) == NULL) { - printf ("Unknown command '%s' - try 'help'\n", argv[0]); - rc = -1; /* give up after bad command */ - continue; - } - - /* found - check max args */ - if (argc > cmdtp->maxargs) { - printf ("Usage:\n%s\n", cmdtp->usage); - rc = -1; - continue; - } - - /* OK - call function to do the command */ - if ((cmdtp->cmd) (cmdtp, argc, argv) != 0) - rc = -1; + rc = execute_command(argc, argv); } return rc; diff --git a/include/command.h b/include/command.h index fa9acc879f..b2a1a9cbf6 100644 --- a/include/command.h +++ b/include/command.h @@ -71,6 +71,7 @@ extern cmd_tbl_t __u_boot_cmd_end; /* common/command.c */ cmd_tbl_t *find_cmd(const char *cmd); +int execute_command(int argc, char **argv); void u_boot_cmd_usage(cmd_tbl_t *cmdtp); /* |