diff mbox

[U-Boot,RESEND,2/3] Add run_command_repeatable()

Message ID 1401991678-3046-3-git-send-email-thomas.betker@freenet.de
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Thomas Betker June 5, 2014, 6:07 p.m. UTC
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 <thomas.betker@rohde-schwarz.com>
---
 common/cli.c     | 24 ++++++++++++++++++++++++
 include/common.h |  1 +
 2 files changed, 25 insertions(+)

Comments

Simon Glass June 5, 2014, 6:18 p.m. UTC | #1
On 5 June 2014 12:07, Thomas Betker <thomas.betker@freenet.de> wrote:
> 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 <thomas.betker@rohde-schwarz.com>

I feel that a separate function is fine for now.

Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tom Rini June 11, 2014, 10:18 p.m. UTC | #2
On Thu, Jun 05, 2014 at 08:07:57PM +0200, Thomas Betker wrote:

> 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 <thomas.betker@rohde-schwarz.com>
> Acked-by: Simon Glass <sjg@chromium.org>
> Tested-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox

Patch

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