From patchwork Thu Jun 5 18:07:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Betker X-Patchwork-Id: 356569 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 CA208140094 for ; Fri, 6 Jun 2014 04:11:41 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B25684B794; Thu, 5 Jun 2014 20:11:34 +0200 (CEST) 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 T+jbn91I1kHk; Thu, 5 Jun 2014 20:11:34 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7AB314B795; Thu, 5 Jun 2014 20:11:25 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5A4CE4B785 for ; Thu, 5 Jun 2014 20:10:44 +0200 (CEST) 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 BRXa85xsSMwd for ; Thu, 5 Jun 2014 20:10:39 +0200 (CEST) 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 mout2.freenet.de (mout2.freenet.de [195.4.92.92]) by theia.denx.de (Postfix) with ESMTPS id A2B044B78B for ; Thu, 5 Jun 2014 20:10:37 +0200 (CEST) Received: from [195.4.92.141] (helo=mjail1.freenet.de) by mout2.freenet.de with esmtpa (ID thomas.betker@freenet.de) (port 25) (Exim 4.82 #1) id 1Wsc7X-0003EH-2P; Thu, 05 Jun 2014 20:10:35 +0200 Received: from localhost ([::1]:47459 helo=mjail1.freenet.de) by mjail1.freenet.de with esmtpa (ID thomas.betker@freenet.de) (Exim 4.82 #1) id 1Wsc7W-0001Qf-Uc; Thu, 05 Jun 2014 20:10:35 +0200 Received: from mx15.freenet.de ([195.4.92.25]:49611) by mjail1.freenet.de with esmtpa (ID thomas.betker@freenet.de) (Exim 4.82 #1) id 1Wsc5U-0007eo-OS; Thu, 05 Jun 2014 20:08:28 +0200 Received: from dslb-088-064-108-020.pools.arcor-ip.net ([88.64.108.20]:36079 helo=linux-thh9.site) by mx15.freenet.de with esmtpsa (ID thomas.betker@freenet.de) (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (port 587) (Exim 4.82 #1) id 1Wsc5U-0003VX-IG; Thu, 05 Jun 2014 20:08:28 +0200 From: Thomas Betker To: u-boot@lists.denx.de Date: Thu, 5 Jun 2014 20:07:57 +0200 Message-Id: <1401991678-3046-3-git-send-email-thomas.betker@freenet.de> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1401991678-3046-1-git-send-email-thomas.betker@freenet.de> References: <1401991678-3046-1-git-send-email-thomas.betker@freenet.de> X-Originated-At: 88.64.108.20!36079 X-Mailman-Approved-At: Thu, 05 Jun 2014 20:11:23 +0200 Cc: Thomas Betker Subject: [U-Boot] [RESEND PATCH 2/3] Add run_command_repeatable() 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 run_command() returns 0 on success and 1 on error. However, there are some invocations which expect 0 or 1 for success (not repeatable or repeatable) and -1 for error; add run_command_repeatable() for this purpose. Signed-off-by: Thomas Betker Acked-by: Simon Glass Tested-by: Simon Glass --- common/cli.c | 24 ++++++++++++++++++++++++ include/common.h | 1 + 2 files changed, 25 insertions(+) diff --git a/common/cli.c b/common/cli.c index ea6bfb3..272b028 100644 --- a/common/cli.c +++ b/common/cli.c @@ -41,6 +41,30 @@ int run_command(const char *cmd, int flag) #endif } +/* + * Run a command using the selected parser, and check if it is repeatable. + * + * @param cmd Command to run + * @param flag Execution flags (CMD_FLAG_...) + * @return 0 (not repeatable) or 1 (repeatable) on success, -1 on error. + */ +int run_command_repeatable(const char *cmd, int flag) +{ +#ifndef CONFIG_SYS_HUSH_PARSER + return cli_simple_run_command(cmd, flag); +#else + /* + * parse_string_outer() returns 1 for failure, so clean up + * its result. + */ + if (parse_string_outer(cmd, + FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP)) + return -1; + + return 0; +#endif +} + int run_command_list(const char *cmd, int len, int flag) { int need_buff = 1; diff --git a/include/common.h b/include/common.h index 91dc0f3..cc74633 100644 --- a/include/common.h +++ b/include/common.h @@ -271,6 +271,7 @@ int print_buffer(ulong addr, const void *data, uint width, uint count, /* common/main.c */ void main_loop (void); int run_command(const char *cmd, int flag); +int run_command_repeatable(const char *cmd, int flag); /** * Run a list of commands separated by ; or even \0