summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <sha@pengutronix.de>2009-10-17 12:01:14 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2009-10-19 10:18:51 +0200
commitef7ff70ca445f380548fe17f488dc6428aa1efc5 (patch)
tree1a672d375d001ff844d979e79dbe93ec3c92e8e5
parent2dc2132f0e3c707a86fe332fd94b1c05b137dfe7 (diff)
downloadbarebox-ef7ff70ca445f380548fe17f488dc6428aa1efc5.tar.gz
barebox-ef7ff70ca445f380548fe17f488dc6428aa1efc5.tar.xz
consolidate command calling in execute_command
Signed-off-by: Sascha Hauer <sha@pengutronix.de>
-rw-r--r--common/command.c19
-rw-r--r--common/hush.c18
-rw-r--r--common/parser.c19
-rw-r--r--include/command.h1
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);
/*