Allow parser selection to make use of autoconf instead of #ifdefs.

Signed-off-by: Simon Glass <s...@chromium.org>
---
Changes in v4:
- Rebase on current master

Changes in v3: None
Changes in v2: None

 common/main.c  | 87 +++++++++++++++++++++++++++-------------------------------
 include/hush.h |  2 --
 2 files changed, 41 insertions(+), 48 deletions(-)

diff --git a/common/main.c b/common/main.c
index fc55e06..b09bfb4 100644
--- a/common/main.c
+++ b/common/main.c
@@ -382,12 +382,10 @@ static void process_boot_delay(void)
 
 void main_loop(void)
 {
-#ifndef CONFIG_SYS_HUSH_PARSER
        static char lastcommand[CONFIG_SYS_CBSIZE] = { 0, };
        int len;
        int rc = 1;
        int flag;
-#endif
 #ifdef CONFIG_PREBOOT
        char *p;
 #endif
@@ -444,12 +442,11 @@ void main_loop(void)
        /*
         * Main Loop for Monitor Command Processing
         */
-#ifdef CONFIG_SYS_HUSH_PARSER
-       parse_file_outer();
-       /* This point is never reached */
-       for (;;);
-#else
-       for (;;) {
+       if (autoconf_sys_hush_parser()) {
+               parse_file_outer();
+               /* This point is never reached */
+               for (;;);
+       } else {
                if (autoconf_boot_retry_time() && rc >= 0) {
                        /* Saw enough of a valid command to
                         * restart the timeout.
@@ -484,7 +481,6 @@ void main_loop(void)
                        lastcommand[0] = 0;
                }
        }
-#endif /*CONFIG_SYS_HUSH_PARSER*/
 }
 
 /*
@@ -1174,7 +1170,6 @@ int parse_line (char *line, char *argv[])
 
 /****************************************************************************/
 
-#ifndef CONFIG_SYS_HUSH_PARSER
 static void process_macros (const char *input, char *output)
 {
        char c, prev;
@@ -1382,7 +1377,6 @@ static int builtin_run_command(const char *cmd, int flag)
 
        return rc ? rc : repeatable;
 }
-#endif
 
 /*
  * Run a command using the selected parser.
@@ -1393,22 +1387,21 @@ static int builtin_run_command(const char *cmd, int 
flag)
  */
 int run_command(const char *cmd, int flag)
 {
-#ifndef CONFIG_SYS_HUSH_PARSER
-       /*
-        * builtin_run_command can return 0 or 1 for success, so clean up
-        * its result.
-        */
-       if (builtin_run_command(cmd, flag) == -1)
-               return 1;
-
-       return 0;
-#else
-       return parse_string_outer(cmd,
+       if (autoconf_sys_hush_parser()) {
+               return parse_string_outer(cmd,
                        FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP);
-#endif
+       } else {
+               /*
+               * builtin_run_command can return 0 or 1 for success, so
+               * clean up its result.
+               */
+               if (builtin_run_command(cmd, flag) == -1)
+                       return 1;
+
+               return 0;
+       }
 }
 
-#ifndef CONFIG_SYS_HUSH_PARSER
 /**
  * Execute a list of command separated by ; or \n using the built-in parser.
  *
@@ -1449,7 +1442,6 @@ static int builtin_run_command_list(char *cmd, int flag)
 
        return rcode;
 }
-#endif
 
 int run_command_list(const char *cmd, int len, int flag)
 {
@@ -1459,13 +1451,16 @@ int run_command_list(const char *cmd, int len, int flag)
 
        if (len == -1) {
                len = strlen(cmd);
-#ifdef CONFIG_SYS_HUSH_PARSER
-               /* hush will never change our string */
-               need_buff = 0;
-#else
-               /* the built-in parser will change our string if it sees \n */
-               need_buff = strchr(cmd, '\n') != NULL;
-#endif
+               if (autoconf_sys_hush_parser()) {
+                       /* hush will never change our string */
+                       need_buff = 0;
+               } else {
+                       /*
+                        * the built-in parser will change our string if it
+                        * sees \n
+                        */
+                       need_buff = strchr(cmd, '\n') != NULL;
+               }
        }
        if (need_buff) {
                buff = malloc(len + 1);
@@ -1474,20 +1469,20 @@ int run_command_list(const char *cmd, int len, int flag)
                memcpy(buff, cmd, len);
                buff[len] = '\0';
        }
-#ifdef CONFIG_SYS_HUSH_PARSER
-       rcode = parse_string_outer(buff, FLAG_PARSE_SEMICOLON);
-#else
-       /*
-        * This function will overwrite any \n it sees with a \0, which
-        * is why it can't work with a const char *. Here we are making
-        * using of internal knowledge of this function, to avoid always
-        * doing a malloc() which is actually required only in a case that
-        * is pretty rare.
-        */
-       rcode = builtin_run_command_list(buff, flag);
-       if (need_buff)
-               free(buff);
-#endif
+       if (autoconf_sys_hush_parser()) {
+               rcode = parse_string_outer(buff, FLAG_PARSE_SEMICOLON);
+       } else {
+               /*
+               * This function will overwrite any \n it sees with a \0, which
+               * is why it can't work with a const char *. Here we are making
+               * using of internal knowledge of this function, to avoid always
+               * doing a malloc() which is actually required only in a case
+               * that is pretty rare.
+               */
+               rcode = builtin_run_command_list(buff, flag);
+               if (need_buff)
+                       free(buff);
+       }
 
        return rcode;
 }
diff --git a/include/hush.h b/include/hush.h
index ecf9222..12c55f4 100644
--- a/include/hush.h
+++ b/include/hush.h
@@ -36,7 +36,5 @@ int set_local_var(const char *s, int flg_export);
 void unset_local_var(const char *name);
 char *get_local_var(const char *s);
 
-#if defined(CONFIG_HUSH_INIT_VAR)
 extern int hush_init_var (void);
 #endif
-#endif
-- 
1.8.3

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

Reply via email to