# endif /* CONFIG_AUTOBOOT_KEYED */
#endif /* CONFIG_BOOTDELAY >= 0 */
-/*
- * Return 0 on success, or != 0 on error.
- */
-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,
- FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP);
-#endif
-}
-
/****************************************************************************/
void main_loop (void)
if (len == -1)
puts ("<INTERRUPT>\n");
else
- rc = builtin_run_command(lastcommand, flag);
+ rc = run_command(lastcommand, flag);
if (rc <= 0) {
/* invalid command or not repeatable, forget it */
/****************************************************************************/
+#ifndef CONFIG_SYS_HUSH_PARSER
static void process_macros (const char *input, char *output)
{
char c, prev;
* the environment data, which may change magicly when the command we run
* creates or modifies environment variables (like "bootp" does).
*/
-
-int builtin_run_command(const char *cmd, int flag)
+static int builtin_run_command(const char *cmd, int flag)
{
- cmd_tbl_t *cmdtp;
char cmdbuf[CONFIG_SYS_CBSIZE]; /* working copy of cmd */
char *token; /* start of token in cmdbuf */
char *sep; /* end of token (separator) in cmdbuf */
continue;
}
- /* Look up command in command table */
- if ((cmdtp = find_cmd(argv[0])) == NULL) {
- printf ("Unknown command '%s' - try 'help'\n", argv[0]);
- rc = -1; /* give up after bad command */
- continue;
- }
-
- /* found - check max args */
- if (argc > cmdtp->maxargs) {
- cmd_usage(cmdtp);
+ if (cmd_process(flag, argc, argv, &repeatable))
rc = -1;
- continue;
- }
-
-#if defined(CONFIG_CMD_BOOTD)
- /* avoid "bootd" recursion */
- if (cmdtp->cmd == do_bootd) {
-#ifdef DEBUG_PARSER
- printf ("[%s]\n", finaltoken);
-#endif
- if (flag & CMD_FLAG_BOOTD) {
- puts ("'bootd' recursion detected\n");
- rc = -1;
- continue;
- } else {
- flag |= CMD_FLAG_BOOTD;
- }
- }
-#endif
-
- /* OK - call function to do the command */
- if ((cmdtp->cmd) (cmdtp, flag, argc, argv) != 0) {
- rc = -1;
- }
-
- repeatable &= cmdtp->repeatable;
/* Did the user stop this? */
if (had_ctrlc ())
return rc ? rc : repeatable;
}
+#endif
+
+/*
+ * Run a command using the selected parser.
+ *
+ * @param cmd Command to run
+ * @param flag Execution flags (CMD_FLAG_...)
+ * @return 0 on success, or != 0 on error.
+ */
+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,
+ FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP);
+#endif
+}
/****************************************************************************/
int i;
if (argc < 2)
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
for (i=1; i<argc; ++i) {
char *arg;