summaryrefslogtreecommitdiffstats
path: root/common/command.c
diff options
context:
space:
mode:
authorsascha <sascha@nomad.localdomain>2007-10-19 13:06:45 +0200
committersascha <sascha@nomad.localdomain>2007-10-19 13:06:45 +0200
commit8ed683dddb84e1daf4ce73463d98fe4787d40bef (patch)
tree70dc26f337b0c3d79b68277217b846891c9a75fe /common/command.c
parentf1020bd2d508c150fea98ab79b8ca7458ccb4a13 (diff)
downloadbarebox-8ed683dddb84e1daf4ce73463d98fe4787d40bef.tar.gz
barebox-8ed683dddb84e1daf4ce73463d98fe4787d40bef.tar.xz
- Insert commands sorted into the command list. This is useful
for commands added via modules. - Let command aliases show up in help text
Diffstat (limited to 'common/command.c')
-rw-r--r--common/command.c75
1 files changed, 36 insertions, 39 deletions
diff --git a/common/command.c b/common/command.c
index 40ac8de981..fdd7444e6d 100644
--- a/common/command.c
+++ b/common/command.c
@@ -119,32 +119,17 @@ EXPORT_SYMBOL(u_boot_cmd_usage);
*/
static int do_help (cmd_tbl_t * cmdtp, int argc, char *argv[])
{
- if (argc == 1) { /*show list of commands */
- int cmd_items = &__u_boot_cmd_end -
- &__u_boot_cmd_start; /* pointer arith! */
- int i;
-
- /* No need to sort the command list. The linker already did
- * this for us.
- */
- cmdtp = &__u_boot_cmd_start;
- for (i = 0; i < cmd_items; i++) {
- /* print short help (usage) */
-
- /* allow user abort */
- if (ctrlc ())
- return 1;
+ if (argc == 1) { /* show list of commands */
+ for_each_command(cmdtp) {
if (!cmdtp->usage)
continue;
printf("%10s - %s\n", cmdtp->name, cmdtp->usage);
- cmdtp++;
}
return 0;
}
- /*
- * command help (long version)
- */
- if ((cmdtp = find_cmd (argv[1])) != NULL) {
+
+ /* command help (long version) */
+ if ((cmdtp = find_cmd(argv[1])) != NULL) {
u_boot_cmd_usage(cmdtp);
return 0;
} else {
@@ -173,7 +158,13 @@ U_BOOT_CMD_START(help)
U_BOOT_CMD_HELP(cmd_help_help)
U_BOOT_CMD_END
-#ifdef CONFIG_MODULES
+static int compare(struct list_head *a, struct list_head *b)
+{
+ char *na = list_entry(a, cmd_tbl_t, list)->name;
+ char *nb = list_entry(b, cmd_tbl_t, list)->name;
+
+ return strcmp(na, nb);
+}
int register_command(cmd_tbl_t *cmd)
{
@@ -183,17 +174,37 @@ int register_command(cmd_tbl_t *cmd)
* with a module.
*/
- printf("register command %s\n", cmd->name);
+ debug("register command %s\n", cmd->name);
/*
* Would be nice to have some kind of list_add_sort
* to keep the command list in order
*/
- list_add_tail(&cmd->list, &command_list);
+ list_add_sort(&cmd->list, &command_list, compare);
+
+ if (cmd->aliases) {
+ char **aliases = cmd->aliases;
+ while(*aliases) {
+ char *usage = "alias for ";
+ cmd_tbl_t *c = xzalloc(sizeof(cmd_tbl_t));
+
+ memcpy(c, cmd, sizeof(cmd_tbl_t));
+
+ c->name = *aliases;
+ c->usage = xmalloc(strlen(usage) + strlen(cmd->name) + 1);
+ sprintf(c->usage, "%s%s", usage, cmd->name);
+
+ c->aliases = NULL;
+
+ register_command(c);
+
+ aliases++;
+ }
+ }
return 0;
}
-#endif
+EXPORT_SYMBOL(register_command);
/*
* find command table entry for a command
@@ -216,20 +227,6 @@ cmd_tbl_t *find_cmd (const char *cmd)
cmdtp_temp = cmdtp; /* abbreviated command ? */
n_found++;
}
-
- if (cmdtp->aliases) {
- char **aliases = cmdtp->aliases;
- while(*aliases) {
- if (strncmp (cmd, *aliases, len) == 0) {
- if (len == strlen (cmdtp->name))
- return cmdtp; /* full match */
-
- cmdtp_temp = cmdtp; /* abbreviated command ? */
- n_found++;
- }
- aliases++;
- }
- }
}
if (n_found == 1) { /* exactly one match */
@@ -252,7 +249,7 @@ static int init_command_list(void)
for (cmdtp = &__u_boot_cmd_start;
cmdtp != &__u_boot_cmd_end;
cmdtp++)
- list_add_tail(&cmdtp->list, &command_list);
+ register_command(cmdtp);
return 0;
}