diff options
Diffstat (limited to 'monitor.c')
-rw-r--r-- | monitor.c | 78 |
1 files changed, 76 insertions, 2 deletions
@@ -911,6 +911,80 @@ static mon_cmd_t * get_command_table(Monitor *mon, cmd_table_t cmds) } } +static void android_console_help(Monitor *mon, const QDict *qdict) +{ + const char *name = qdict_get_try_str(qdict, "helptext"); + const mon_cmd_t *cmd; + const mon_cmd_t *cmds = get_command_table(mon, mon->cmds); + char *args[MAX_ARGS]; + int nb_args = 0; + int thisarg = 0; + const mon_cmd_t *parent_cmd = NULL; + + if (!name) { + /* No arguments, just print command list */ + monitor_printf(mon, "Android console command help:\n\n"); + for (cmd = cmds; cmd->name; cmd++) { + monitor_printf(mon, " %-15s %s\n", cmd->name, cmd->help); + } + monitor_printf(mon, + "\ntry 'help <command>' for command-specific help\n"); + return; + } + + /* With an argument, look for it */ + if (!parse_cmdline(name, &nb_args, args) < 0 || nb_args == 0) { + monitor_printf(mon, "KO: couldn't parse help text\n"); + return; + } + + for (;;) { + mon_cmd_t *sub_cmds; + + for (cmd = cmds; cmd->name; cmd++) { + if (compare_cmd(args[thisarg], cmd->name)) { + break; + } + } + if (!cmd->name) { + /* command/subcommand not found */ + monitor_printf(mon, "try one of these instead:\n\n"); + for (cmd = cmds; cmd->name; cmd++) { + int i; + monitor_printf(mon, " "); + for (i = 0; i < thisarg; i++) { + monitor_printf(mon, "%s ", args[i]); + } + monitor_printf(mon, "%s\n", cmd->name); + } + monitor_printf(mon, "\nKO: unknown command\n"); + return; + } + + thisarg++; + sub_cmds = get_command_table(mon, cmd->sub_cmds); + + if (thisarg >= nb_args || !sub_cmds) { + /* For subtables, the command handler for the entry in the 1st + * level of commands deals with help (including "help subcommand" + * where there is no following second level command in the help + * string). For top level commands, we just print the short text. + */ + if (parent_cmd) { + parent_cmd->mhandler.cmd(mon, qdict); + } else if (sub_cmds) { + cmd->mhandler.cmd(mon, qdict); + } else { + monitor_printf(mon, "%s\nOK\n", cmd->help); + } + return; + } + + parent_cmd = cmd; + cmds = sub_cmds; + } +} + static void do_trace_event_set_state(Monitor *mon, const QDict *qdict) { const char *tp_name = qdict_get_str(qdict, "name"); @@ -3740,7 +3814,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, cmd = search_dispatch_table(table, cmdname); if (!cmd) { - if (mon->cmd_table == android_cmds) { + if (mon->flags & MONITOR_ANDROID_CONSOLE) { monitor_printf(mon, "KO: unknown command, try 'help'\n"); } else { monitor_printf(mon, "unknown command: '%.*s'\n", @@ -5423,7 +5497,7 @@ Monitor * monitor_init(CharDriverState *chr, int flags) mon->print_error = monitor_printf; if (flags & MONITOR_ANDROID_CONSOLE) { - mon->cmd_table = android_cmds; + mon->cmds.static_table = android_cmds; mon->prompt = ""; mon->banner = "Android Console: type 'help' for a list of commands"; mon->print_error = android_monitor_print_error; |