monitor: Drop args[] handling code

This commit drops all the code used to handle the 'args[]' array,
as now we use a dictionary to pass arguments.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Luiz Capitulino 2009-08-28 15:27:25 -03:00 committed by Anthony Liguori
parent 590fb3b78b
commit 53773581b8

View File

@ -2583,12 +2583,11 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
QDict *qdict) QDict *qdict)
{ {
const char *p, *typestr; const char *p, *typestr;
int c, nb_args, has_arg; int c;
const mon_cmd_t *cmd; const mon_cmd_t *cmd;
char cmdname[256]; char cmdname[256];
char buf[1024]; char buf[1024];
char *key; char *key;
void *args[MAX_ARGS];
#ifdef DEBUG #ifdef DEBUG
monitor_printf(mon, "command='%s'\n", cmdline); monitor_printf(mon, "command='%s'\n", cmdline);
@ -2612,7 +2611,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
/* parse the parameters */ /* parse the parameters */
typestr = cmd->args_type; typestr = cmd->args_type;
nb_args = 0;
for(;;) { for(;;) {
typestr = key_get_info(typestr, &key); typestr = key_get_info(typestr, &key);
if (!typestr) if (!typestr)
@ -2625,7 +2623,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
case 's': case 's':
{ {
int ret; int ret;
char *str;
while (qemu_isspace(*p)) while (qemu_isspace(*p))
p++; p++;
@ -2633,8 +2630,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
typestr++; typestr++;
if (*p == '\0') { if (*p == '\0') {
/* no optional string: NULL argument */ /* no optional string: NULL argument */
str = NULL; break;
goto add_str;
} }
} }
ret = get_str(buf, sizeof(buf), &p); ret = get_str(buf, sizeof(buf), &p);
@ -2654,18 +2650,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
} }
goto fail; goto fail;
} }
str = qemu_malloc(strlen(buf) + 1); qdict_put(qdict, key, qstring_from_str(buf));
pstrcpy(str, sizeof(buf), buf);
add_str:
if (nb_args >= MAX_ARGS) {
error_args:
monitor_printf(mon, "%s: too many arguments\n", cmdname);
goto fail;
}
args[nb_args++] = str;
if (str)
qdict_put(qdict, key, qstring_from_str(str));
qemu_free(str);
} }
break; break;
case '/': case '/':
@ -2742,11 +2727,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
size = -1; size = -1;
} }
} }
if (nb_args + 3 > MAX_ARGS)
goto error_args;
args[nb_args++] = (void*)(long)count;
args[nb_args++] = (void*)(long)format;
args[nb_args++] = (void*)(long)size;
qdict_put(qdict, "count", qint_from_int(count)); qdict_put(qdict, "count", qint_from_int(count));
qdict_put(qdict, "format", qint_from_int(format)); qdict_put(qdict, "format", qint_from_int(format));
qdict_put(qdict, "size", qint_from_int(size)); qdict_put(qdict, "size", qint_from_int(size));
@ -2756,58 +2736,30 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
case 'l': case 'l':
{ {
int64_t val; int64_t val;
int dict_add = 1;
while (qemu_isspace(*p)) while (qemu_isspace(*p))
p++; p++;
if (*typestr == '?' || *typestr == '.') { if (*typestr == '?' || *typestr == '.') {
if (*typestr == '?') { if (*typestr == '?') {
if (*p == '\0') if (*p == '\0') {
has_arg = 0; typestr++;
else break;
has_arg = 1; }
} else { } else {
if (*p == '.') { if (*p == '.') {
p++; p++;
while (qemu_isspace(*p)) while (qemu_isspace(*p))
p++; p++;
has_arg = 1;
} else { } else {
has_arg = 0; typestr++;
break;
} }
} }
typestr++; typestr++;
if (nb_args >= MAX_ARGS)
goto error_args;
dict_add = has_arg;
args[nb_args++] = (void *)(long)has_arg;
if (!has_arg) {
if (nb_args >= MAX_ARGS)
goto error_args;
val = -1;
goto add_num;
}
} }
if (get_expr(mon, &val, &p)) if (get_expr(mon, &val, &p))
goto fail; goto fail;
add_num: qdict_put(qdict, key, qint_from_int(val));
if (c == 'i') {
if (nb_args >= MAX_ARGS)
goto error_args;
args[nb_args++] = (void *)(long)val;
if (dict_add)
qdict_put(qdict, key, qint_from_int(val));
} else {
if ((nb_args + 1) >= MAX_ARGS)
goto error_args;
#if TARGET_PHYS_ADDR_BITS > 32
args[nb_args++] = (void *)(long)((val >> 32) & 0xffffffff);
#else
args[nb_args++] = (void *)0;
#endif
args[nb_args++] = (void *)(long)(val & 0xffffffff);
qdict_put(qdict, key, qint_from_int(val));
}
} }
break; break;
case '-': case '-':
@ -2831,9 +2783,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
p++; p++;
has_option = 1; has_option = 1;
} }
if (nb_args >= MAX_ARGS)
goto error_args;
args[nb_args++] = (void *)(long)has_option;
qdict_put(qdict, key, qint_from_int(has_option)); qdict_put(qdict, key, qint_from_int(has_option));
} }
break; break;