rename CFG_ macros to CONFIG_SYS
[oweals/u-boot.git] / common / command.c
index af2f8cbf7b8c163e74dc8530d89c50f67dc82665..a4a978c5fdc676249bc6f73c7e639acfc1b9dc72 100644 (file)
@@ -38,7 +38,7 @@ do_version (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
 U_BOOT_CMD(
        version,        1,              1,      do_version,
-       "version - print monitor version\n",
+       "version - print monitor version\n",
        NULL
 );
 
@@ -70,15 +70,15 @@ do_echo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 }
 
 U_BOOT_CMD(
-       echo,   CFG_MAXARGS,    1,      do_echo,
-       "echo    - echo args to console\n",
-       "[args..]\n"
+       echo,   CONFIG_SYS_MAXARGS,     1,      do_echo,
+       "echo    - echo args to console\n",
+       "[args..]\n"
        "    - echo args to console; \\c suppresses newline\n"
 );
 
 #endif
 
-#ifdef CFG_HUSH_PARSER
+#ifdef CONFIG_SYS_HUSH_PARSER
 
 int
 do_test (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
@@ -196,17 +196,15 @@ do_test (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
        expr = !expr;
 
-#if 0
-       printf(": returns %d\n", expr);
-#endif
+       debug (": returns %d\n", expr);
 
        return expr;
 }
 
 U_BOOT_CMD(
-       test,   CFG_MAXARGS,    1,      do_test,
-       "test    - minimal test like /bin/sh\n",
-       "[args..]\n"
+       test,   CONFIG_SYS_MAXARGS,     1,      do_test,
+       "test    - minimal test like /bin/sh\n",
+       "[args..]\n"
        "    - test functionality\n"
 );
 
@@ -224,7 +222,7 @@ do_exit (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
 U_BOOT_CMD(
        exit,   2,      1,      do_exit,
-       "exit    - exit script\n",
+       "exit    - exit script\n",
        "    - exit functionality\n"
 );
 
@@ -288,7 +286,7 @@ int do_help (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
         */
        for (i = 1; i < argc; ++i) {
                if ((cmdtp = find_cmd (argv[i])) != NULL) {
-#ifdef CFG_LONGHELP
+#ifdef CONFIG_SYS_LONGHELP
                        /* found - print (long) help info */
                        puts (cmdtp->name);
                        putc (' ');
@@ -302,7 +300,7 @@ int do_help (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 #else  /* no long help available */
                        if (cmdtp->usage)
                                puts (cmdtp->usage);
-#endif /* CFG_LONGHELP */
+#endif /* CONFIG_SYS_LONGHELP */
                } else {
                        printf ("Unknown command '%s' - try 'help'"
                                " without arguments for list of all"
@@ -316,37 +314,37 @@ int do_help (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 
 
 U_BOOT_CMD(
-       help,   CFG_MAXARGS,    1,      do_help,
-       "help    - print online help\n",
-       "[command ...]\n"
-       "    - show help information (for 'command')\n"
-       "'help' prints online help for the monitor commands.\n\n"
-       "Without arguments, it prints a short usage message for all commands.\n\n"
-       "To get detailed help information for specific commands you can type\n"
+       help,   CONFIG_SYS_MAXARGS,     1,      do_help,
+       "help    - print online help\n",
+       "[command ...]\n"
+       "    - show help information (for 'command')\n"
+       "'help' prints online help for the monitor commands.\n\n"
+       "Without arguments, it prints a short usage message for all commands.\n\n"
+       "To get detailed help information for specific commands you can type\n"
   "'help' with one or more command names as arguments.\n"
 );
 
 /* This do not ust the U_BOOT_CMD macro as ? can't be used in symbol names */
-#ifdef  CFG_LONGHELP
+#ifdef  CONFIG_SYS_LONGHELP
 cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {
-       "?",    CFG_MAXARGS,    1,      do_help,
-       "?       - alias for 'help'\n",
+       "?",    CONFIG_SYS_MAXARGS,     1,      do_help,
+       "?       - alias for 'help'\n",
        NULL
 };
 #else
 cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {
-       "?",    CFG_MAXARGS,    1,      do_help,
-       "?       - alias for 'help'\n"
+       "?",    CONFIG_SYS_MAXARGS,     1,      do_help,
+       "?       - alias for 'help'\n"
 };
-#endif /* CFG_LONGHELP */
+#endif /* CONFIG_SYS_LONGHELP */
 
 /***************************************************************************
  * 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;
@@ -357,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))
@@ -375,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[])
@@ -498,7 +502,7 @@ static int make_argv(char *s, int argvsz, char *argv[])
                while ((*s == ' ') || (*s == '\t'))
                        ++s;
 
-               if (*s == '\0')         /* end of s, no more args       */
+               if (*s == '\0') /* end of s, no more args       */
                        break;
 
                argv[argc++] = s;       /* begin of argument string     */
@@ -566,12 +570,12 @@ static int find_common_prefix(char *argv[])
        return len;
 }
 
-static char tmp_buf[CFG_CBSIZE];       /* copy of console I/O buffer   */
+static char tmp_buf[CONFIG_SYS_CBSIZE];        /* copy of console I/O buffer   */
 
 int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp)
 {
        int n = *np, col = *colp;
-       char *argv[CFG_MAXARGS + 1];            /* NULL terminated      */
+       char *argv[CONFIG_SYS_MAXARGS + 1];             /* NULL terminated      */
        char *cmdv[20];
        char *s, *t;
        const char *sep;
@@ -579,7 +583,7 @@ int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp)
        int cnt;
        char last_char;
 
-       if (strcmp(prompt, CFG_PROMPT) != 0)
+       if (strcmp(prompt, CONFIG_SYS_PROMPT) != 0)
                return 0;       /* not in normal console */
 
        cnt = strlen(buf);
@@ -627,7 +631,7 @@ int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp)
        if (s != NULL) {
                k = len + seplen;
                /* make sure it fits */
-               if (n + k >= CFG_CBSIZE - 2) {
+               if (n + k >= CONFIG_SYS_CBSIZE - 2) {
                        putc('\a');
                        return 1;
                }
@@ -656,3 +660,27 @@ int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp)
 }
 
 #endif
+
+#ifdef CMD_DATA_SIZE
+int cmd_get_data_size(char* arg, int default_size)
+{
+       /* Check for a size specification .b, .w or .l.
+        */
+       int len = strlen(arg);
+       if (len > 2 && arg[len-2] == '.') {
+               switch(arg[len-1]) {
+               case 'b':
+                       return 1;
+               case 'w':
+                       return 2;
+               case 'l':
+                       return 4;
+               case 's':
+                       return -2;
+               default:
+                       return -1;
+               }
+       }
+       return default_size;
+}
+#endif