Re: [U-Boot] [RFC] exposing finding a command for subcommands

2008-09-23 Thread Wolfgang Denk
Dear Kumar Gala,

In message <[EMAIL PROTECTED]> you wrote:
> How about something like this for exposing the command table code for
> subcommands.  I'll follow this up with an example of usage based on the
> bootm subcommand patch

Looks good to me. Just a question:

> -cmd_tbl_t *find_cmd (const char *cmd)
> +cmd_tbl_t *__find_cmd (const char *cmd, cmd_tbl_t *table, int table_len)

That means we would export __find_cmd() to other functions? We
shouldn't do that - "__" names are reserved.

> +#define U_BOOT_CMD_INIT(name,maxargs,rep,cmd,usage,help) \
> +{#name, maxargs, rep, cmd, usage, help}
> +

I think "INIT" is not a good name here. To me it sounds like a macro
to use just once. How about "ENTRY" or "MKENT" or something like this?

Best regards,

Wolfgang Denk

-- 
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: [EMAIL PROTECTED]
"Open the pod bay doors, HAL."- Dave Bowman, 2001
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [RFC] exposing finding a command for subcommands

2008-09-23 Thread Kumar Gala
Here's an example of how we sould use this.  Obviously the code after the
if (cmd) would change.

- k

diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 3a20ad2..64e7571 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -377,10 +377,23 @@ static int bootm_load_os(image_info_t os, ulong 
*load_end, int boot_progress)
return 0;
 }

+cmd_tbl_t cmd_bootm_sub[] = {
+   U_BOOT_CMD_INIT(start, CFG_MAXARGS, 1, BOOTM_STATE_START, "", ""),
+   U_BOOT_CMD_INIT(loados, CFG_MAXARGS, 1, BOOTM_STATE_LOADOS, "", ""),
+   U_BOOT_CMD_INIT(ramdisk, CFG_MAXARGS, 1, BOOTM_STATE_RAMDISK, "", ""),
+};
+
+
 int do_bootm_subcommand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
int ret = 0;
int state;
+   cmd_tbl_t *cmd;
+
+   cmd = __find_cmd(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
+
+   if (cmd)
+   printf("%s %d\n", cmd->name, cmd->cmd);

/* start */
if (strcmp(argv[1], "start") == 0) {
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [RFC] exposing finding a command for subcommands

2008-09-23 Thread Kumar Gala
How about something like this for exposing the command table code for
subcommands.  I'll follow this up with an example of usage based on the
bootm subcommand patch

- k

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

diff --git a/common/command.c b/common/command.c
index aca57b2..d8e1495 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 (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(cmd, &__u_boot_cmd_start, len);
+}
+
 #ifdef CONFIG_AUTO_COMPLETE

 int var_complete(int argc, char *argv[], char last_char, int maxv, char 
*cmdv[])
diff --git a/include/command.h b/include/command.h
index f92383d..03d340c 100644
--- a/include/command.h
+++ b/include/command.h
@@ -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 (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_INIT(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_INIT(name,maxargs,rep,cmd,usage,help) \
+{#name, maxargs, rep, cmd, usage}
+
 #endif /* CFG_LONGHELP */

 #endif /* __COMMAND_H */
-- 
1.5.5.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot