Commit b799cb4c0eebb0762e91e9653d8b9cc9a98440e3
Committed by
Wolfgang Denk
1 parent
f7e51b2750
Exists in
master
and in
54 other branches
Expose command table search for sub-commands
Sub-command can benefit from using the same table and search functions that top level commands have. Expose this functionality by refactoring find_cmd() and introducing find_cmd_tbl() that sub-command processing can call. Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Showing 2 changed files with 17 additions and 4 deletions Side-by-side Diff
common/command.c
... | ... | @@ -341,10 +341,10 @@ |
341 | 341 | /*************************************************************************** |
342 | 342 | * find command table entry for a command |
343 | 343 | */ |
344 | -cmd_tbl_t *find_cmd (const char *cmd) | |
344 | +cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len) | |
345 | 345 | { |
346 | 346 | cmd_tbl_t *cmdtp; |
347 | - cmd_tbl_t *cmdtp_temp = &__u_boot_cmd_start; /*Init value */ | |
347 | + cmd_tbl_t *cmdtp_temp = table; /*Init value */ | |
348 | 348 | const char *p; |
349 | 349 | int len; |
350 | 350 | int n_found = 0; |
... | ... | @@ -355,8 +355,8 @@ |
355 | 355 | */ |
356 | 356 | len = ((p = strchr(cmd, '.')) == NULL) ? strlen (cmd) : (p - cmd); |
357 | 357 | |
358 | - for (cmdtp = &__u_boot_cmd_start; | |
359 | - cmdtp != &__u_boot_cmd_end; | |
358 | + for (cmdtp = table; | |
359 | + cmdtp != table + table_len; | |
360 | 360 | cmdtp++) { |
361 | 361 | if (strncmp (cmd, cmdtp->name, len) == 0) { |
362 | 362 | if (len == strlen (cmdtp->name)) |
... | ... | @@ -371,6 +371,12 @@ |
371 | 371 | } |
372 | 372 | |
373 | 373 | return NULL; /* not found or ambiguous command */ |
374 | +} | |
375 | + | |
376 | +cmd_tbl_t *find_cmd (const char *cmd) | |
377 | +{ | |
378 | + int len = &__u_boot_cmd_end - &__u_boot_cmd_start; | |
379 | + return find_cmd_tbl(cmd, &__u_boot_cmd_start, len); | |
374 | 380 | } |
375 | 381 | |
376 | 382 | #ifdef CONFIG_AUTO_COMPLETE |
include/command.h
... | ... | @@ -62,6 +62,7 @@ |
62 | 62 | |
63 | 63 | /* common/command.c */ |
64 | 64 | cmd_tbl_t *find_cmd(const char *cmd); |
65 | +cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len); | |
65 | 66 | |
66 | 67 | #ifdef CONFIG_AUTO_COMPLETE |
67 | 68 | extern void install_auto_complete(void); |
68 | 69 | |
... | ... | @@ -102,10 +103,16 @@ |
102 | 103 | #define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \ |
103 | 104 | cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage, help} |
104 | 105 | |
106 | +#define U_BOOT_CMD_MKENT(name,maxargs,rep,cmd,usage,help) \ | |
107 | +{#name, maxargs, rep, cmd, usage, help} | |
108 | + | |
105 | 109 | #else /* no long help info */ |
106 | 110 | |
107 | 111 | #define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \ |
108 | 112 | cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage} |
113 | + | |
114 | +#define U_BOOT_CMD_MKENT(name,maxargs,rep,cmd,usage,help) \ | |
115 | +{#name, maxargs, rep, cmd, usage} | |
109 | 116 | |
110 | 117 | #endif /* CFG_LONGHELP */ |
111 | 118 |