From 52f50b1e9f8fd410d4293a211d549ec61b902728 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 24 Jan 2023 13:19:20 +0100 Subject: readline: Extract readline_add_completion_of() from monitor monitor/misc.h has static add_completion_option(). It's useful elsewhere in the monitor. Since it's not monitor-specific, move it to util/readline.c renamed to readline_add_completion_of(), and put it to use. Signed-off-by: Markus Armbruster Message-Id: <20230124121946.1139465-7-armbru@redhat.com> --- monitor/hmp.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'monitor/hmp.c') diff --git a/monitor/hmp.c b/monitor/hmp.c index e5d914b1f5..1b04f01244 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -1189,8 +1189,8 @@ static void cmd_completion(MonitorHMP *mon, const char *name, const char *list) } memcpy(cmd, pstart, len); cmd[len] = '\0'; - if (name[0] == '\0' || !strncmp(name, cmd, strlen(name))) { - readline_add_completion(mon->rs, cmd); + if (name[0] == '\0') { + readline_add_completion_of(mon->rs, name, cmd); } if (*p == '\0') { break; @@ -1270,7 +1270,7 @@ static void monitor_find_completion_by_table(MonitorHMP *mon, { const char *cmdname; int i; - const char *ptype, *old_ptype, *str, *name; + const char *ptype, *old_ptype, *str; const HMPCommand *cmd; BlockBackend *blk = NULL; @@ -1335,10 +1335,8 @@ static void monitor_find_completion_by_table(MonitorHMP *mon, /* block device name completion */ readline_set_completion_index(mon->rs, strlen(str)); while ((blk = blk_next(blk)) != NULL) { - name = blk_name(blk); - if (str[0] == '\0' || - !strncmp(name, str, strlen(str))) { - readline_add_completion(mon->rs, name); + if (str[0] == '\0') { + readline_add_completion_of(mon->rs, str, blk_name(blk)); } } break; -- cgit 1.4.1