Re: [U-Boot] [PATCH v4 6/8] main: Use autoconf for parser selection

2013-10-28 Thread Michal Simek
On 10/26/2013 05:14 PM, Simon Glass wrote:
 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 b744234..060da11 100644
 --- a/common/main.c
 +++ b/common/main.c
 @@ -366,12 +366,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
 @@ -428,12 +426,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.
 @@ -468,7 +465,6 @@ void main_loop(void)
   lastcommand[0] = 0;
   }
   }
 -#endif /*CONFIG_SYS_HUSH_PARSER*/
  }
  
  /*
 @@ -1158,7 +1154,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;
 @@ -1366,7 +1361,6 @@ static int builtin_run_command(const char *cmd, int 
 flag)
  
   return rc ? rc : repeatable;
  }
 -#endif
  
  /*
   * Run a command using the selected parser.
 @@ -1377,22 +1371,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.
 + */

same here.

 + 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.
   *
 @@ -1433,7 +1426,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)
  {
 @@ -1443,13 +1435,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);
 @@ -1458,20 +1453,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 {
 +

[U-Boot] [PATCH v4 6/8] main: Use autoconf for parser selection

2013-10-26 Thread Simon Glass
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 b744234..060da11 100644
--- a/common/main.c
+++ b/common/main.c
@@ -366,12 +366,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
@@ -428,12 +426,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.
@@ -468,7 +465,6 @@ void main_loop(void)
lastcommand[0] = 0;
}
}
-#endif /*CONFIG_SYS_HUSH_PARSER*/
 }
 
 /*
@@ -1158,7 +1154,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;
@@ -1366,7 +1361,6 @@ static int builtin_run_command(const char *cmd, int flag)
 
return rc ? rc : repeatable;
 }
-#endif
 
 /*
  * Run a command using the selected parser.
@@ -1377,22 +1371,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.
  *
@@ -1433,7 +1426,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)
 {
@@ -1443,13 +1435,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);
@@ -1458,20 +1453,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 

[U-Boot] [PATCH v4 6/8] main: Use autoconf for parser selection

2013-06-17 Thread Simon Glass
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