/*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014, 2016 Leo C. <erbl259-lmu@yahoo.de>
*
* (C) Copyright 2000-2009
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
- * SPDX-License-Identifier: GPL-2.0+
+ * SPDX-License-Identifier: GPL-2.0
*/
/*
* Command Processor Table
*/
+#include "command.h"
#include "common.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <setjmp.h>
#include "config.h"
#include "print-utils.h"
#include "con-utils.h"
-#ifdef CONFIG_AUTO_COMPLETE
#include "env.h"
-#endif
#include "debug.h"
-#include "command.h"
+
+
+jmp_buf cmd_jbuf;
static void print_usage_line(const FLASH char *name, int width,
(void) flag;
+ char *optenv = getenv_str(PSTR("cmd"));
+ bool opt_debug = optenv && strstr_P(optenv, PSTR("debug")) != NULL;
+
if (argc == 1) { /*show list of commands */
cmd_tbl_t *cmd_array[cmd_items];
int i;
/* print short help (usage) */
for (i = 0; i < cmd_items; i++) {
- const FLASH char *usage = cmd_array[i]->usage;
-
- /* allow user abort */
- if (ctrlc ())
- return CMD_RET_FAILURE;
- if (usage == NULL)
- continue;
+ if (opt_debug || cmd_array[i]->name[0] != '!') {
+ const FLASH char *usage = cmd_array[i]->usage;
+
+ /* allow user abort */
+ if (ctrlc ())
+ return CMD_RET_FAILURE;
+ if (usage == NULL)
+ continue;
#ifdef GCC_BUG_61443
- print_usage_line(cmd_array[i]->name, max_len, usage);
+ print_usage_line(cmd_array[i]->name, max_len, usage);
#else
- printf_P(PSTR("%-" stringify(8) /*FIXME*/ "S - %S\n"),
- cmd_array[i]->name, usage);
+ printf_P(PSTR("%-" stringify(8) /*FIXME*/ "S - %S\n"),
+ cmd_array[i]->name, usage);
#endif
+ }
}
return CMD_RET_SUCCESS;
}
* command help (long version)
*/
for (i = 1; i < argc; ++i) {
- if ((cmdtp = find_cmd_tbl (argv[i], cmd_start, cmd_items )) != NULL) {
+ if ((cmdtp = find_cmd_tbl (argv[i], cmd_start, cmd_items )) != NULL &&
+ (opt_debug || cmdtp->name[0] != '!')) {
cmd_usage(cmdtp);
} else {
printf_P(PSTR("Unknown command '%s' - try 'help'"
size_t len;
uint_fast8_t n_found = 0;
+ char *optenv = getenv_str(PSTR("cmd"));
+ bool opt_debug = optenv && strstr_P(optenv, PSTR("debug")) != NULL;
+
if (!cmd)
return NULL;
for (cmdtp = table;
cmdtp != table + table_len;
cmdtp++) {
- if (strncmp_P(cmd, cmdtp->name, len) == 0) {
+ if (strncmp_P(cmd, cmdtp->name, len) == 0 &&
+ (opt_debug || cmdtp->name[0] != '!')) {
if (len == strlen_P(cmdtp->name))
return cmdtp; /* full match */
n_found++;
}
}
- if (n_found == 1) { /* exactly one match */
+ if (n_found == 1) /* exactly one match */
return cmdtp_temp;
- }
return NULL; /* not found or ambiguous command */
}
command_ret_t result;
result = (cmdtp->cmd)(cmdtp, flag, argc, argv);
- if (result != CMD_RET_SUCCESS)
- debug("Command failed, result=%d\n", result);
+// if (result != CMD_RET_SUCCESS)
+// debug("Command failed, result=%d\n", result);
return result;
}
}
#endif
+ if (setjmp(cmd_jbuf) != 0)
+ return CMD_RET_FAILURE;
+
/* If OK so far, then do the command */
if (!rc) {
rc = cmd_call(cmdtp, flag, argc, argv);