Skip to contentSkip to conversation

Expose command table search for sub-commands

PATCH New Kumar Gala 2 participants 3 messages Sep 23, 2008 – Oct 15, 2008

lore
Share & tools
lore

Kumar Gala

author
#0 lore raw

PATCH 1/1 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.

---
 common/command.c  |   14 ++++++++++----
 include/command.h |    7 +++++++
 2 files changed, 17 insertions(+), 4 deletions(-)
common/command.c +10 -4
index aca57b2..fc9d79c 100644
@@ -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[])
include/command.h +7 -0
index f92383d..78feea5 100644
@@ -62,6 +62,7 @@ extern cmd_tbl_t  __u_boot_cmd_end;
 
 /* common/command.c */
 cmd_tbl_t *find_cmd(const char *cmd);
+cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len);
 
 #ifdef CONFIG_AUTO_COMPLETE
 extern void install_auto_complete(void);
@@ -102,11 +103,17 @@ extern int cmd_get_data_size(char* arg, int default_size);
 #define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
 cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage, help}
 
+#define U_BOOT_CMD_MKENT(name,maxargs,rep,cmd,usage,help) \
+{#name, maxargs, rep, cmd, usage, help}
+
 #else	/* no long help info */
 
 #define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
 cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage}
 
+#define U_BOOT_CMD_MKENT(name,maxargs,rep,cmd,usage,help) \
+{#name, maxargs, rep, cmd, usage}
+
 #endif	/* CFG_LONGHELP */
 
 #endif	/* __COMMAND_H */
Signature · 1 line
1.5.5.1
author
#1 lore raw

PATCH 1/1 Expose command table search for sub-commands

Quoted 11 lines · Kumar Gala

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.

---
common/command.c | 14 ++++++++++----
include/command.h | 7 +++++++

2 files changed, 17 insertions(+), 4 deletions(-)

Wolfgang,

how about applying this to next?

- k

#2 lore raw

PATCH 1/1 Expose command table search for sub-commands

In reply to Kumar Gala

Dear Kumar Gala,

Quoted 10 lines · In message <[email protected]> you…

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.

---
 common/command.c  |   14 ++++++++++----
 include/command.h |    7 +++++++
 2 files changed, 17 insertions(+), 4 deletions(-)

Applied to "next" branch. Thanks.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
All easy problems have already been solved.