+/***************************************************************************
+ * 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;
+}
+