char* match_cmd(const char* text, int state) { static STR_FUNC_MAP_ITER it; static int len = 0; const char* cmd = NULL; if (!state) { it = g_cmd_map.begin(); len = strlen(text); } while(it != g_cmd_map.end()) { cmd = it->first.c_str(); it++; if (strncmp(cmd, text, len) == 0) { int32_t cmd_len = strlen(cmd) + 1; // memory will be freed by readline return strncpy(new char[cmd_len], cmd, cmd_len); } } return NULL; }
int cmd_show_help(const VSTRING&) { fprintf(stderr, "\nsupported command:"); for (STR_FUNC_MAP_ITER it = g_cmd_map.begin(); it != g_cmd_map.end(); it++) { fprintf(stderr, "\n%-40s %s", it->second.syntax_, it->second.info_); } fprintf(stderr, "\n\n"); return TFS_SUCCESS; }
int ToolUtil::show_help(const STR_FUNC_MAP& cmd_map) { fprintf(stdout, "\nsupported command:"); for (STR_FUNC_MAP_CONST_ITER it = cmd_map.begin(); it != cmd_map.end(); it++) { fprintf(stdout, "\n%-40s %s", it->second.syntax_, it->second.info_); } fprintf(stdout, "\n\n"); return TFS_SUCCESS; }