From patchwork Tue Feb 26 16:11:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 223319 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 13D652C0077 for ; Wed, 27 Feb 2013 03:15:28 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4A4D14A13F; Tue, 26 Feb 2013 17:14:41 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LTfOiZZGIbuk; Tue, 26 Feb 2013 17:14:41 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8F0564A142; Tue, 26 Feb 2013 17:13:26 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7C6FD4A0BF for ; Tue, 26 Feb 2013 17:13:10 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5Xj5ripq6u3u for ; Tue, 26 Feb 2013 17:13:09 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-qe0-f73.google.com (mail-qe0-f73.google.com [209.85.128.73]) by theia.denx.de (Postfix) with ESMTPS id D06E24A0C6 for ; Tue, 26 Feb 2013 17:13:02 +0100 (CET) Received: by mail-qe0-f73.google.com with SMTP id a11so31443qen.4 for ; Tue, 26 Feb 2013 08:13:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=i2kUNKbnC5ksLck0IuJkwFq5PYWp8KGUNJupARm+evo=; b=LP+hHgjPBiKqksjnzM3p7aahhgvJgWgVOGTMF+TjG1BqvB4oETUEWC0r4vAnWrnJA+ fcqxqy0BIlGKwweCeUXno/WXduhOETDfPvbpR5JDauzJZPO5Ako/uyKIquj9aHD0pv0U IV3KIeZsTfN1ZniyXRnoDRmF2TkgtUdIexzOV8CR3ZlkWcVpPKQVaOHaBRiYWqk22K93 7+xWLPqltNgOlb8A5fVz5PZiM+XnfGd4sTEAO4jYx6l4QQeo2cV948uMoteoiLYTH/6O b6gGUw/YsGHlGEIh4DXqYGTch5gTHmyT1V347Q2+FeiKGGsS3XjR1pvVp54i/WwFo61z Kkag== X-Received: by 10.236.162.134 with SMTP id y6mr9836876yhk.3.1361895181080; Tue, 26 Feb 2013 08:13:01 -0800 (PST) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id u21si65251yhj.0.2013.02.26.08.13.01 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Tue, 26 Feb 2013 08:13:01 -0800 (PST) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id D6D5731C2CF; Tue, 26 Feb 2013 08:13:00 -0800 (PST) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id B613A1608FB; Tue, 26 Feb 2013 08:13:00 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Date: Tue, 26 Feb 2013 08:11:03 -0800 Message-Id: <1361895069-7343-11-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.8.1.3 In-Reply-To: <1361895069-7343-1-git-send-email-sjg@chromium.org> References: <1361895069-7343-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQleA8rq6z29vhImuKfCZo7WFQCKl60S2ogBWNkYkJcVO507FxzeXaeqRzMvs2CTGNJCI2AZvmw7g08uIXOJVc9mmVVpsPt0E7uzhbfAutuksk97g1SitrX94Zvitb27gBIwTgI+gbjpBWJbQ0o+NMzllwWF9pOgxgiooxIrU/R3CjbCNrXKjTXBOM1iEJbhbz9HGBDH Cc: David Hendrix , Graeme Russ , Joe Hershberger , Tom Rini , Vadim Bendebury Subject: [U-Boot] [PATCH v3 10/16] main: Use autoconf for parser selection X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 Reviewed-by: Joe Hershberger --- Changes in v3: None 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 974fc82..d49692d 100644 --- a/common/main.c +++ b/common/main.c @@ -32,14 +32,11 @@ #include #include #include +#include #include #include #include -#ifdef CONFIG_SYS_HUSH_PARSER -#include -#endif - #include #include @@ -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