| Submitter | Simon Glass |
|---|---|
| Date | Feb. 24, 2013, 5:26 p.m. |
| Message ID | <1361726773-18639-11-git-send-email-sjg@chromium.org> |
| Download | mbox | patch |
| Permalink | /patch/222781/ |
| State | Superseded, archived |
| Headers | show |
Comments
Hi Simon, On Sun, Feb 24, 2013 at 11:26 AM, Simon Glass <sjg@chromium.org> wrote: > 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> > --- > Changes in v2: None > > common/main.c | 92 +++++++++++++++++++++++++++------------------------------- > include/hush.h | 2 -- > 2 files changed, 42 insertions(+), 52 deletions(-) > > diff --git a/common/main.c b/common/main.c > index a5d3f82..e1483db 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> > > @@ -382,12 +379,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 > @@ -447,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. > @@ -487,7 +481,6 @@ void main_loop(void) > lastcommand[0] = 0; > } > } > -#endif /*CONFIG_SYS_HUSH_PARSER*/ > } > > /* > @@ -1186,7 +1179,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; > @@ -1402,7 +1394,6 @@ static int builtin_run_command(const char *cmd, int flag) > > return rc ? rc : repeatable; > } > -#endif > > /* > * Run a command using the selected parser. > @@ -1413,22 +1404,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. > * > @@ -1469,7 +1459,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) > { > @@ -1479,13 +1468,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); > @@ -1494,20 +1486,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.1.3 > > _______________________________________________ > U-Boot mailing list > U-Boot@lists.denx.de > http://lists.denx.de/mailman/listinfo/u-boot Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
Patch
diff --git a/common/main.c b/common/main.c index a5d3f82..e1483db 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> @@ -382,12 +379,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 @@ -447,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. @@ -487,7 +481,6 @@ void main_loop(void) lastcommand[0] = 0; } } -#endif /*CONFIG_SYS_HUSH_PARSER*/ } /* @@ -1186,7 +1179,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; @@ -1402,7 +1394,6 @@ static int builtin_run_command(const char *cmd, int flag) return rc ? rc : repeatable; } -#endif /* * Run a command using the selected parser. @@ -1413,22 +1404,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. * @@ -1469,7 +1459,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) { @@ -1479,13 +1468,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); @@ -1494,20 +1486,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
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> --- Changes in v2: None common/main.c | 92 +++++++++++++++++++++++++++------------------------------- include/hush.h | 2 -- 2 files changed, 42 insertions(+), 52 deletions(-)