From patchwork Tue Jan 10 23:04:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 135317 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 3804CB6FD9 for ; Wed, 11 Jan 2012 10:04:28 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0900828790; Wed, 11 Jan 2012 00:04:26 +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 kjfKerZb6KfT; Wed, 11 Jan 2012 00:04:25 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8B58128777; Wed, 11 Jan 2012 00:04:24 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1093628777 for ; Wed, 11 Jan 2012 00:04:23 +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 rfWQFRMF7Q25 for ; Wed, 11 Jan 2012 00:04:22 +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.serverraum.org (mail.serverraum.org [78.47.150.89]) by theia.denx.de (Postfix) with ESMTP id 4D0F82876C for ; Wed, 11 Jan 2012 00:04:21 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail.serverraum.org (Postfix) with ESMTP id 15B1E3EFAE; Wed, 11 Jan 2012 00:07:05 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail.serverraum.org Received: from mail.serverraum.org ([127.0.0.1]) by localhost (web.serverraum.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EPE9VRtIAIGF; Wed, 11 Jan 2012 00:07:04 +0100 (CET) Received: from thanatos.fritz.box (95-89-251-205-dynip.superkabel.de [95.89.251.205]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.serverraum.org (Postfix) with ESMTPSA id B4F6C3EFAD; Wed, 11 Jan 2012 00:07:04 +0100 (CET) From: Michael Walle To: u-boot@lists.denx.de Date: Wed, 11 Jan 2012 00:04:19 +0100 Message-Id: <1326236659-6257-1-git-send-email-michael@walle.cc> X-Mailer: git-send-email 1.7.2.5 Subject: [U-Boot] [PATCH] cmd_source: introduce run_script() 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 Move actual script execution into a new function run_script(), which then can be called from other modules. Signed-off-by: Michael Walle Cc: Wolfgang Denk --- common/cmd_source.c | 71 ++++++++++++++++++++++++++++---------------------- include/common.h | 1 + 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/common/cmd_source.c b/common/cmd_source.c index 16a627a..4b2740b 100644 --- a/common/cmd_source.c +++ b/common/cmd_source.c @@ -43,6 +43,45 @@ #include #endif +/* + * Run a series of commands, separated by '\n'. + * Beware, the contents of script may be modified while it is parsed. + */ +int run_script(char *script) +{ +#ifndef CONFIG_SYS_HUSH_PARSER /*?? */ + int rcode; + char *line = script; + char *next = script; + + /* + * break into individual lines and execute each line; + * terminate on error. + */ + while (*next) { + if (*next == '\n') { + *next = '\0'; + /* run only non-empty commands */ + if (*line) { + debug("** exec: \"%s\"\n", line); + if (run_command(line, 0) < 0) { + rcode = 1; + break; + } + } + line = next + 1; + } + ++next; + } + + if (rcode == 0 && *line) + rcode = (run_command(line, 0) >= 0); + return rcode; +#else + return parse_string_outer(script, FLAG_PARSE_SEMICOLON); +#endif +} + int source (ulong addr, const char *fit_uname) { @@ -160,38 +199,8 @@ source (ulong addr, const char *fit_uname) memmove (cmd, (char *)data, len); *(cmd + len) = 0; -#ifdef CONFIG_SYS_HUSH_PARSER /*?? */ - rcode = parse_string_outer (cmd, FLAG_PARSE_SEMICOLON); -#else - { - char *line = cmd; - char *next = cmd; + rcode = run_script(cmd); - /* - * break into individual lines, - * and execute each line; - * terminate on error. - */ - while (*next) { - if (*next == '\n') { - *next = '\0'; - /* run only non-empty commands */ - if (*line) { - debug ("** exec: \"%s\"\n", - line); - if (run_command (line, 0) < 0) { - rcode = 1; - break; - } - } - line = next + 1; - } - ++next; - } - if (rcode == 0 && *line) - rcode = (run_command(line, 0) >= 0); - } -#endif free (cmd); return rcode; } diff --git a/include/common.h b/include/common.h index 3df1def..dcfbed6 100644 --- a/include/common.h +++ b/include/common.h @@ -296,6 +296,7 @@ void board_pre_console_putc(int ch); void flash_perror (int); /* common/cmd_source.c */ +int run_script(char *script); int source (ulong addr, const char *fit_uname); extern ulong load_addr; /* Default Load Address */