summaryrefslogtreecommitdiffstats
path: root/common/command.c
diff options
context:
space:
mode:
authorKumar Gala <galak@kernel.crashing.org>2008-09-23 10:05:02 -0500
committerWolfgang Denk <wd@denx.de>2008-10-18 21:54:02 +0200
commitb799cb4c0eebb0762e91e9653d8b9cc9a98440e3 (patch)
tree849320dadf7caf2347e5a33450285f6c0c8f1b47 /common/command.c
parentf7e51b27508446f8cae3927975817137979ad5e8 (diff)
downloadu-boot-b799cb4c0eebb0762e91e9653d8b9cc9a98440e3.tar.gz
u-boot-b799cb4c0eebb0762e91e9653d8b9cc9a98440e3.tar.xz
u-boot-b799cb4c0eebb0762e91e9653d8b9cc9a98440e3.zip
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>
Diffstat (limited to 'common/command.c')
-rw-r--r--common/command.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/common/command.c b/common/command.c
index aca57b26be..fc9d79c7d1 100644
--- a/common/command.c
+++ b/common/command.c
@@ -341,10 +341,10 @@ cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {
/***************************************************************************
* find command table entry for a command
*/
-cmd_tbl_t *find_cmd (const char *cmd)
+cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len)
{
cmd_tbl_t *cmdtp;
- cmd_tbl_t *cmdtp_temp = &__u_boot_cmd_start; /*Init value */
+ cmd_tbl_t *cmdtp_temp = table; /*Init value */
const char *p;
int len;
int n_found = 0;
@@ -355,8 +355,8 @@ cmd_tbl_t *find_cmd (const char *cmd)
*/
len = ((p = strchr(cmd, '.')) == NULL) ? strlen (cmd) : (p - cmd);
- for (cmdtp = &__u_boot_cmd_start;
- cmdtp != &__u_boot_cmd_end;
+ for (cmdtp = table;
+ cmdtp != table + table_len;
cmdtp++) {
if (strncmp (cmd, cmdtp->name, len) == 0) {
if (len == strlen (cmdtp->name))
@@ -373,6 +373,12 @@ cmd_tbl_t *find_cmd (const char *cmd)
return NULL; /* not found or ambiguous command */
}
+cmd_tbl_t *find_cmd (const char *cmd)
+{
+ int len = &__u_boot_cmd_end - &__u_boot_cmd_start;
+ return find_cmd_tbl(cmd, &__u_boot_cmd_start, len);
+}
+
#ifdef CONFIG_AUTO_COMPLETE
int var_complete(int argc, char *argv[], char last_char, int maxv, char *cmdv[])