[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH V8 04/13] monitor: avoid use of global *cur_mon in m
From: |
Wenchao Xia |
Subject: |
[Qemu-devel] [PATCH V8 04/13] monitor: avoid use of global *cur_mon in monitor_find_completion() |
Date: |
Fri, 26 Jul 2013 11:20:33 +0800 |
Parameter *mon is added, and local variable *mon added in previous patch
is removed. The caller readline_completion(), pass rs->mon as value, which
should be initialized in readline_init() called by monitor_init().
Signed-off-by: Wenchao Xia <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
include/monitor/readline.h | 3 ++-
monitor.c | 18 +++++++++---------
readline.c | 2 +-
3 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/include/monitor/readline.h b/include/monitor/readline.h
index fc9806e..0faf6e1 100644
--- a/include/monitor/readline.h
+++ b/include/monitor/readline.h
@@ -8,7 +8,8 @@
#define READLINE_MAX_COMPLETIONS 256
typedef void ReadLineFunc(Monitor *mon, const char *str, void *opaque);
-typedef void ReadLineCompletionFunc(const char *cmdline);
+typedef void ReadLineCompletionFunc(Monitor *mon,
+ const char *cmdline);
typedef struct ReadLineState {
char cmd_buf[READLINE_CMD_BUF_SIZE + 1];
diff --git a/monitor.c b/monitor.c
index 0ecb70a..06b4681 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4136,20 +4136,20 @@ static const char *next_arg_type(const char *typestr)
return (p != NULL ? ++p : typestr);
}
-static void monitor_find_completion(const char *cmdline)
+static void monitor_find_completion(Monitor *mon,
+ const char *cmdline)
{
const char *cmdname;
char *args[MAX_ARGS];
int nb_args, i, len;
const char *ptype, *str;
const mon_cmd_t *cmd;
- Monitor *mon = cur_mon;
MonitorBlockComplete mbs;
parse_cmdline(cmdline, &nb_args, args);
#ifdef DEBUG_COMPLETION
- for(i = 0; i < nb_args; i++) {
- monitor_printf(cur_mon, "arg%d = '%s'\n", i, (char *)args[i]);
+ for (i = 0; i < nb_args; i++) {
+ monitor_printf(mon, "arg%d = '%s'\n", i, args[i]);
}
#endif
@@ -4168,7 +4168,7 @@ static void monitor_find_completion(const char *cmdline)
cmdname = "";
else
cmdname = args[0];
- readline_set_completion_index(cur_mon->rs, strlen(cmdname));
+ readline_set_completion_index(mon->rs, strlen(cmdname));
for(cmd = mon_cmds; cmd->name != NULL; cmd++) {
cmd_completion(mon, cmdname, cmd->name);
}
@@ -4198,7 +4198,7 @@ static void monitor_find_completion(const char *cmdline)
switch(*ptype) {
case 'F':
/* file completion */
- readline_set_completion_index(cur_mon->rs, strlen(str));
+ readline_set_completion_index(mon->rs, strlen(str));
file_completion(mon, str);
break;
case 'B':
@@ -4211,7 +4211,7 @@ static void monitor_find_completion(const char *cmdline)
case 's':
/* XXX: more generic ? */
if (!strcmp(cmd->name, "info")) {
- readline_set_completion_index(cur_mon->rs, strlen(str));
+ readline_set_completion_index(mon->rs, strlen(str));
for(cmd = info_cmds; cmd->name != NULL; cmd++) {
cmd_completion(mon, str, cmd->name);
}
@@ -4219,12 +4219,12 @@ static void monitor_find_completion(const char *cmdline)
char *sep = strrchr(str, '-');
if (sep)
str = sep + 1;
- readline_set_completion_index(cur_mon->rs, strlen(str));
+ readline_set_completion_index(mon->rs, strlen(str));
for (i = 0; i < Q_KEY_CODE_MAX; i++) {
cmd_completion(mon, str, QKeyCode_lookup[i]);
}
} else if (!strcmp(cmd->name, "help|?")) {
- readline_set_completion_index(cur_mon->rs, strlen(str));
+ readline_set_completion_index(mon->rs, strlen(str));
for (cmd = mon_cmds; cmd->name != NULL; cmd++) {
cmd_completion(mon, str, cmd->name);
}
diff --git a/readline.c b/readline.c
index 1c0f7ee..c91b324 100644
--- a/readline.c
+++ b/readline.c
@@ -285,7 +285,7 @@ static void readline_completion(ReadLineState *rs)
cmdline = g_malloc(rs->cmd_buf_index + 1);
memcpy(cmdline, rs->cmd_buf, rs->cmd_buf_index);
cmdline[rs->cmd_buf_index] = '\0';
- rs->completion_finder(cmdline);
+ rs->completion_finder(rs->mon, cmdline);
g_free(cmdline);
/* no completion found */
--
1.7.1
- [Qemu-devel] [PATCH V8 00/13] monitor: support sub command group in auto completion and help, Wenchao Xia, 2013/07/25
- [Qemu-devel] [PATCH V8 01/13] monitor: avoid use of global *cur_mon in cmd_completion(), Wenchao Xia, 2013/07/25
- [Qemu-devel] [PATCH V8 05/13] monitor: avoid use of global *cur_mon in readline_completion(), Wenchao Xia, 2013/07/25
- [Qemu-devel] [PATCH V8 02/13] monitor: avoid use of global *cur_mon in file_completion(), Wenchao Xia, 2013/07/25
- [Qemu-devel] [PATCH V8 07/13] monitor: code move for parse_cmdline(), Wenchao Xia, 2013/07/25
- [Qemu-devel] [PATCH V8 08/13] monitor: refine parse_cmdline(), Wenchao Xia, 2013/07/25
- [Qemu-devel] [PATCH V8 03/13] monitor: avoid use of global *cur_mon in block_completion_it(), Wenchao Xia, 2013/07/25
- [Qemu-devel] [PATCH V8 04/13] monitor: avoid use of global *cur_mon in monitor_find_completion(),
Wenchao Xia <=
- [Qemu-devel] [PATCH V8 10/13] monitor: refine monitor_find_completion(), Wenchao Xia, 2013/07/25
- [Qemu-devel] [PATCH V8 06/13] monitor: avoid direct use of global variable *mon_cmds, Wenchao Xia, 2013/07/25
- [Qemu-devel] [PATCH V8 09/13] monitor: support sub command in help, Wenchao Xia, 2013/07/25
- [Qemu-devel] [PATCH V8 11/13] monitor: support sub command in auto completion, Wenchao Xia, 2013/07/25
- [Qemu-devel] [PATCH V8 12/13] monitor: allow "help" show message for single command in sub group, Wenchao Xia, 2013/07/25
- [Qemu-devel] [PATCH V8 13/13] monitor: improve auto complete of "help" for single command in sub group, Wenchao Xia, 2013/07/25
- Re: [Qemu-devel] [PATCH V8 00/13] monitor: support sub command group in auto completion and help, Luiz Capitulino, 2013/07/30