consolidate command calling in execute_command
Signed-off-by: Sascha Hauer <sha@pengutronix.de>
This commit is contained in:
parent
2dc2132f0e
commit
ef7ff70ca4
|
@ -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)
|
||||
{
|
||||
/*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue