Move the code used to locate an info command entry to its own function, as it's going to be used by other functions.
Signed-off-by: Luiz Capitulino <lcapitul...@redhat.com> --- monitor.c | 21 +++++++++++++++------ 1 files changed, 15 insertions(+), 6 deletions(-) diff --git a/monitor.c b/monitor.c index 9070a0c..5851b6d 100644 --- a/monitor.c +++ b/monitor.c @@ -538,6 +538,19 @@ static void user_async_info_handler(Monitor *mon, const mon_cmd_t *cmd) } } +static const mon_cmd_t *monitor_find_info_command(const char *name) +{ + const mon_cmd_t *cmd; + + for (cmd = info_cmds; cmd->name != NULL; cmd++) { + if (compare_cmd(name, cmd->name)) { + return cmd; + } + } + + return NULL; +} + static void do_info(Monitor *mon, const QDict *qdict, QObject **ret_data) { const mon_cmd_t *cmd; @@ -548,12 +561,8 @@ static void do_info(Monitor *mon, const QDict *qdict, QObject **ret_data) goto help; } - for (cmd = info_cmds; cmd->name != NULL; cmd++) { - if (compare_cmd(item, cmd->name)) - break; - } - - if (cmd->name == NULL) { + cmd = monitor_find_info_command(item); + if (!cmd) { if (monitor_ctrl_mode(mon)) { qemu_error_new(QERR_COMMAND_NOT_FOUND, item); return; -- 1.6.6