diff options
Diffstat (limited to 'avr/command.c')
-rw-r--r-- | avr/command.c | 91 |
1 files changed, 50 insertions, 41 deletions
diff --git a/avr/command.c b/avr/command.c index 07fff78..938edc3 100644 --- a/avr/command.c +++ b/avr/command.c @@ -69,17 +69,64 @@ int cmd_tbl_item_count(cmd_tbl_t *p) return count; } +/*************************************************************************** + * find command table entry for a command + */ +cmd_tbl_t *find_cmd (const char *cmd, cmd_tbl_t *table) +{ + cmd_tbl_t *cmdtp; + cmd_tbl_t *cmdtp_temp = table; /*Init value */ + int table_len = cmd_tbl_item_count(table); + 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; + + len = strlen(cmd); + + for (cmdtp = table; + cmdtp != table + table_len; + cmdtp++) { + if (strncmp_P(cmd, cmdtp->name, len) == 0 && + (opt_debug || cmdtp->name[0] != '!')) { + if (len == strlen_P(cmdtp->name)) + return cmdtp; /* full match */ + + cmdtp_temp = cmdtp; /* abbreviated command ? */ + n_found++; + } + } + if (n_found == 1) /* exactly one match */ + return cmdtp_temp; + + return NULL; /* not found or ambiguous command */ +} + +cmd_tbl_t *get_cmd_tbl_start(cmd_tbl_t *cmdtp) +{ + cmd_tbl_t *p = cmdtp; + + while (p->name != NULL) + ++p; + + return p->subcmd; +} + /* * Use puts() instead of printf() to avoid printf buffer overflow * for long help messages */ -command_ret_t _do_help(cmd_tbl_t *tbl_start, cmd_tbl_t * cmdtp, - uint_fast8_t flag, int argc, char * const argv[]) +command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]) { - (void) flag; + cmd_tbl_t *tbl_start = get_cmd_tbl_start(cmdtp); + char *optenv = getenv_str(PSTR("cmd")); bool opt_debug = optenv && strstr_P(optenv, PSTR("debug")) != NULL; @@ -139,44 +186,6 @@ command_ret_t _do_help(cmd_tbl_t *tbl_start, cmd_tbl_t * cmdtp, return CMD_RET_SUCCESS; } -/*************************************************************************** - * find command table entry for a command - */ -cmd_tbl_t *find_cmd (const char *cmd, cmd_tbl_t *table) -{ - cmd_tbl_t *cmdtp; - cmd_tbl_t *cmdtp_temp = table; /*Init value */ - int table_len = cmd_tbl_item_count(table); - 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; - - len = strlen(cmd); - - for (cmdtp = table; - cmdtp != table + table_len; - cmdtp++) { - if (strncmp_P(cmd, cmdtp->name, len) == 0 && - (opt_debug || cmdtp->name[0] != '!')) { - if (len == strlen_P(cmdtp->name)) - return cmdtp; /* full match */ - - cmdtp_temp = cmdtp; /* abbreviated command ? */ - n_found++; - } - } - if (n_found == 1) /* exactly one match */ - return cmdtp_temp; - - return NULL; /* not found or ambiguous command */ -} - - command_ret_t cmd_usage(const FLASH cmd_tbl_t *cmdtp) { |