Commit 1d43bfd2d54240c18ec6bfd68a57349cae839f13

Authored by Thomas Betker
Committed by Tom Rini
1 parent 73671dad49

Add run_command_repeatable()

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>

Showing 2 changed files with 25 additions and 0 deletions Side-by-side Diff

... ... @@ -41,6 +41,30 @@
41 41 #endif
42 42 }
43 43  
  44 +/*
  45 + * Run a command using the selected parser, and check if it is repeatable.
  46 + *
  47 + * @param cmd Command to run
  48 + * @param flag Execution flags (CMD_FLAG_...)
  49 + * @return 0 (not repeatable) or 1 (repeatable) on success, -1 on error.
  50 + */
  51 +int run_command_repeatable(const char *cmd, int flag)
  52 +{
  53 +#ifndef CONFIG_SYS_HUSH_PARSER
  54 + return cli_simple_run_command(cmd, flag);
  55 +#else
  56 + /*
  57 + * parse_string_outer() returns 1 for failure, so clean up
  58 + * its result.
  59 + */
  60 + if (parse_string_outer(cmd,
  61 + FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP))
  62 + return -1;
  63 +
  64 + return 0;
  65 +#endif
  66 +}
  67 +
44 68 int run_command_list(const char *cmd, int len, int flag)
45 69 {
46 70 int need_buff = 1;
... ... @@ -271,6 +271,7 @@
271 271 /* common/main.c */
272 272 void main_loop (void);
273 273 int run_command(const char *cmd, int flag);
  274 +int run_command_repeatable(const char *cmd, int flag);
274 275  
275 276 /**
276 277 * Run a list of commands separated by ; or even \0