Skip to content

Commit

Permalink
monitor: avoid use of global *cur_mon in monitor_find_completion()
Browse files Browse the repository at this point in the history
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 <xiawenc@linux.vnet.ibm.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
  • Loading branch information
Wenchao Xia authored and Luiz Capitulino committed Aug 30, 2013
1 parent 599a926 commit d2674b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion include/monitor/readline.h
Expand Up @@ -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];
Expand Down
18 changes: 9 additions & 9 deletions monitor.c
Expand Up @@ -4141,20 +4141,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

Expand All @@ -4173,7 +4173,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);
}
Expand Down Expand Up @@ -4203,7 +4203,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':
Expand All @@ -4216,20 +4216,20 @@ 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);
}
} else if (!strcmp(cmd->name, "sendkey")) {
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);
}
Expand Down
2 changes: 1 addition & 1 deletion readline.c
Expand Up @@ -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 */
Expand Down

0 comments on commit d2674b2

Please sign in to comment.