Patchwork [U-Boot,v3,10/16] main: Use autoconf for parser selection

login
register
mail settings
Submitter Simon Glass
Date Feb. 26, 2013, 4:11 p.m.
Message ID <1361895069-7343-11-git-send-email-sjg@chromium.org>
Download mbox | patch
Permalink /patch/223319/
State Deferred
Delegated to: Tom Rini
Headers show

Comments

Simon Glass - Feb. 26, 2013, 4:11 p.m.
Allow parser selection to make use of autoconf instead of #ifdefs. This
requires us to make header includes unconditional, but this is simpler
anyway.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
---
Changes in v3: None
Changes in v2: None

 common/main.c  | 92 +++++++++++++++++++++++++++-------------------------------
 include/hush.h |  2 --
 2 files changed, 42 insertions(+), 52 deletions(-)

Patch

diff --git a/common/main.c b/common/main.c
index 974fc82..d49692d 100644
--- a/common/main.c
+++ b/common/main.c
@@ -32,14 +32,11 @@ 
 #include <command.h>
 #include <fdtdec.h>
 #include <fdt_support.h>
+#include <hush.h>
 #include <malloc.h>
 #include <menu.h>
 #include <version.h>
 
-#ifdef CONFIG_SYS_HUSH_PARSER
-#include <hush.h>
-#endif
-
 #include <post.h>
 #include <linux/ctype.h>
 
@@ -381,12 +378,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
@@ -446,12 +441,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.
@@ -486,7 +480,6 @@  void main_loop(void)
 			lastcommand[0] = 0;
 		}
 	}
-#endif /*CONFIG_SYS_HUSH_PARSER*/
 }
 
 /*
@@ -1184,7 +1177,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;
@@ -1400,7 +1392,6 @@  static int builtin_run_command(const char *cmd, int flag)
 
 	return rc ? rc : repeatable;
 }
-#endif
 
 /*
  * Run a command using the selected parser.
@@ -1411,22 +1402,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.
  *
@@ -1467,7 +1457,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)
 {
@@ -1477,13 +1466,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);
@@ -1492,20 +1484,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