]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
Enable monitor debugging commands only, if env var 'cmd' is set to 'debug'.
authorLeo C <erbl259-lmu@yahoo.de>
Fri, 17 Jun 2016 19:47:17 +0000 (21:47 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Tue, 21 Jun 2016 15:11:10 +0000 (17:11 +0200)
avr/command.c

index e696202cf0287b0345b5d3464ca69c134e66ddea..5499b9d08716d79a06268936bdddf927a00e7a19 100644 (file)
@@ -1,10 +1,10 @@
 /*
- * (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
  */
 
 /*
@@ -19,9 +19,7 @@
 #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"
 
@@ -81,6 +79,9 @@ command_ret_t _do_help(cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp,
 
        (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;
@@ -99,19 +100,21 @@ command_ret_t _do_help(cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp,
 
                /* 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;
        }
@@ -119,7 +122,8 @@ command_ret_t _do_help(cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp,
         * 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'"
@@ -141,6 +145,9 @@ cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len)
        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;
 
@@ -149,7 +156,8 @@ cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len)
        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 */
 
@@ -157,9 +165,8 @@ cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len)
                        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 */
 }