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 <armbru@redhat.com>
Message-Id: <20230124121946.1139465-7-armbru@redhat.com>
This commit is contained in:
Markus Armbruster 2023-01-24 13:19:20 +01:00
parent 444ee02c5f
commit 52f50b1e9f
4 changed files with 41 additions and 66 deletions

View file

@ -286,6 +286,14 @@ void readline_add_completion(ReadLineState *rs, const char *str)
}
}
void readline_add_completion_of(ReadLineState *rs,
const char *pfx, const char *str)
{
if (!strncmp(str, pfx, strlen(pfx))) {
readline_add_completion(rs, str);
}
}
void readline_set_completion_index(ReadLineState *rs, int index)
{
rs->completion_index = index;