All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Simek <monstr@monstr.eu>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 6/8] main: Use autoconf for parser selection
Date: Mon, 28 Oct 2013 15:21:18 +0100	[thread overview]
Message-ID: <526E72DE.70006@monstr.eu> (raw)
In-Reply-To: <1382800457-26608-7-git-send-email-sjg@chromium.org>

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 <sjg@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 {
> +		/*
> +		* 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.
> +		*/

here too.

M

-- 
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/
Maintainer of Linux kernel - Xilinx Zynq ARM architecture
Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 263 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20131028/60575f1d/attachment.pgp>

  reply	other threads:[~2013-10-28 14:21 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-26 15:14 [U-Boot] [PATCH v4 0/8] Provide a mechanism to avoid using #ifdef everywhere Simon Glass
2013-10-26 15:14 ` [U-Boot] [PATCH v4 1/8] Implement autoconf header file Simon Glass
2013-11-10 19:47   ` Marek Vasut
2013-10-26 15:14 ` [U-Boot] [PATCH v4 2/8] main: Use autoconf for boot retry feature Simon Glass
2013-10-26 15:14 ` [U-Boot] [PATCH v4 3/8] main: Remove CONFIG #ifdefs from the abortboot() code Simon Glass
2013-10-26 15:14 ` [U-Boot] [PATCH v4 4/8] main: Use autoconf to remove #ifdefs around process_boot_delay() Simon Glass
2013-10-26 15:14 ` [U-Boot] [PATCH v4 5/8] main: Use autoconf for boot_delay code Simon Glass
2013-10-26 15:14 ` [U-Boot] [PATCH v4 6/8] main: Use autoconf for parser selection Simon Glass
2013-10-28 14:21   ` Michal Simek [this message]
2013-10-26 15:14 ` [U-Boot] [PATCH v4 7/8] main: Use autoconf in command line reading Simon Glass
2013-10-26 15:14 ` [U-Boot] [PATCH v4 8/8] main: Use autoconf in main_loop() Simon Glass
2013-10-28 14:44 ` [U-Boot] [PATCH v4 0/8] Provide a mechanism to avoid using #ifdef everywhere Wolfgang Denk
2013-10-28 15:32   ` Tom Rini
2013-10-28 20:31     ` Simon Glass
2013-11-06  7:24 ` Wolfgang Denk
2013-11-06  8:30   ` Stefan Roese
2013-11-07  9:20   ` Albert ARIBAUD
2013-11-10  4:24   ` Simon Glass
2013-11-10 12:58     ` Wolfgang Denk
2014-01-14 10:11     ` Detlev Zundel
2014-01-15 18:11       ` Simon Glass
2014-01-17 15:13         ` Detlev Zundel
2014-01-26 20:58           ` Simon Glass
  -- strict thread matches above, loose matches on Subject: below --
2013-06-17 14:44 Simon Glass
2013-06-17 14:44 ` [U-Boot] [PATCH v4 6/8] main: Use autoconf for parser selection Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=526E72DE.70006@monstr.eu \
    --to=monstr@monstr.eu \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.