From ef7ff70ca445f380548fe17f488dc6428aa1efc5 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 17 Oct 2009 12:01:14 +0200 Subject: consolidate command calling in execute_command Signed-off-by: Sascha Hauer --- common/command.c | 19 +++++++++++++++++++ common/hush.c | 18 +----------------- common/parser.c | 19 +------------------ 3 files changed, 21 insertions(+), 35 deletions(-) (limited to 'common') 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; -- cgit v1.2.3