unsigned char get_command (const char * prompt, unsigned mask) { char * line; unsigned char command; while (1) { printf("%s", prompt); line = read_line(stdin); if (!*line) { free(line); if ((last_command_entered < 0) || !(mask & (1 << last_command_entered))) { print_command_help(mask); continue; } return last_command_entered; } if (!(strcmp(line, "?") && strcmp(line, "help"))) { print_command_help(mask); free(line); last_command_entered = -1; continue; } for (command = 0; commands[command].name; command ++) { if (!(mask & (1 << command))) continue; if (!strcmp(line, commands[command].name) || (commands[command].alias && !strcmp(line, commands[command].alias))) { free(line); last_command_entered = command; return command; } } free(line); printf("Invalid command, enter ? for help.\n"); } }
/** * @see cmd_line_base */ virtual void print_specific_commands() { print_command_help(PROGRAM_SET_INT_CMD, "<positive integer>", "set the number of incoming pool threads"); print_command_help(PROGRAM_SET_ONT_CMD, "<positive integer>", "set the number of outgoing pool threads"); }