static ResultCode cmd_help(void) { #ifdef _DEBUG // FIXME: There is no way at the moment to access the serial port. Dump // this through JTAG for now for (HashIterator iter = ht_iter_begin(&commands); !ht_iter_cmp(iter, ht_iter_end(&commands)); iter = ht_iter_next(iter)) { struct CmdTemplate* cmd = (struct CmdTemplate*)ht_iter_get(iter); kprintf("%-20s", cmd->name); for (unsigned j = 0; cmd->arg_fmt[j]; ++j) kprintf("%c ", 'a' + j); kprintf("\r\n"); } #endif return RC_OK; }
/// Hook provided by the parser for matching of command names (TAB completion) for readline const char* parser_rl_match(UNUSED_ARG(void *,dummy), const char *word, int word_len) { HashIterator cur; HashIterator end = ht_iter_end(&commands); const char *found = NULL; for (cur = ht_iter_begin(&commands); !ht_iter_cmp(cur, end); cur = ht_iter_next(cur)) { const struct CmdTemplate* cmdp = (const struct CmdTemplate*)ht_iter_get(cur); if (strncmp(cmdp->name, word, word_len) == 0) { // If there was another matching word, it means that we have a multiple // match: then return NULL. if (found) return NULL; found = cmdp->name; } } return found; }