* [Qemu-devel] [PATCH] monitor: refactor whitespace and optional argument parsing
@ 2011-10-20 18:39 Alon Levy
2011-10-20 18:43 ` Alon Levy
0 siblings, 1 reply; 3+ messages in thread
From: Alon Levy @ 2011-10-20 18:39 UTC (permalink / raw)
To: qemu-devel
Takes out the optional ('?') message parsing from the main switch loop
in monitor_parse_command. Adds optional argument option for boolean parameters.
Signed-off-by: Alon Levy <alevy@redhat.com>
---
Hi,
I think I've sent this before as part of another series, but the rest of the
patches became non relevant (the problem was fixed in another way), and since
I still have this floating around and it seems like a good fix - less code,
makes it easier to determine which paramter types can be used as optional
arguments, maybe someone can take it?
Alon
monitor.c | 79 +++++++++++++++++++++++-------------------------------------
1 files changed, 30 insertions(+), 49 deletions(-)
diff --git a/monitor.c b/monitor.c
index ffda0fe..de4ee2f 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3976,6 +3976,29 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
break;
c = *typestr;
typestr++;
+ while (qemu_isspace(*p)) {
+ p++;
+ }
+ /* take care of optional arguments */
+ switch (c) {
+ case 's':
+ case 'i':
+ case 'l':
+ case 'M':
+ case 'o':
+ case 'T':
+ case 'b':
+ if (*typestr == '?') {
+ typestr++;
+ if (*p == '\0') {
+ /* missing optional argument: NULL argument */
+ qemu_free(key);
+ key = NULL;
+ continue;
+ }
+ }
+ break;
+ }
switch(c) {
case 'F':
case 'B':
@@ -3983,15 +4006,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
{
int ret;
- while (qemu_isspace(*p))
- p++;
- if (*typestr == '?') {
- typestr++;
- if (*p == '\0') {
- /* no optional string: NULL argument */
- break;
- }
- }
ret = get_str(buf, sizeof(buf), &p);
if (ret < 0) {
switch(c) {
@@ -4021,9 +4035,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
if (!opts_list || opts_list->desc->name) {
goto bad_type;
}
- while (qemu_isspace(*p)) {
- p++;
- }
if (!*p)
break;
if (get_str(buf, sizeof(buf), &p) < 0) {
@@ -4041,8 +4052,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
{
int count, format, size;
- while (qemu_isspace(*p))
- p++;
if (*p == '/') {
/* format found */
p++;
@@ -4122,23 +4131,15 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
{
int64_t val;
- while (qemu_isspace(*p))
- p++;
- if (*typestr == '?' || *typestr == '.') {
- if (*typestr == '?') {
- if (*p == '\0') {
- typestr++;
- break;
- }
- } else {
- if (*p == '.') {
+ if (*typestr == '.') {
+ if (*p == '.') {
+ p++;
+ while (qemu_isspace(*p)) {
p++;
- while (qemu_isspace(*p))
- p++;
- } else {
- typestr++;
- break;
}
+ } else {
+ typestr++;
+ break;
}
typestr++;
}
@@ -4160,15 +4161,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
int64_t val;
char *end;
- while (qemu_isspace(*p)) {
- p++;
- }
- if (*typestr == '?') {
- typestr++;
- if (*p == '\0') {
- break;
- }
- }
val = strtosz(p, &end);
if (val < 0) {
monitor_printf(mon, "invalid size\n");
@@ -4182,14 +4174,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
{
double val;
- while (qemu_isspace(*p))
- p++;
- if (*typestr == '?') {
- typestr++;
- if (*p == '\0') {
- break;
- }
- }
if (get_double(mon, &val, &p) < 0) {
goto fail;
}
@@ -4215,9 +4199,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
const char *beg;
int val;
- while (qemu_isspace(*p)) {
- p++;
- }
beg = p;
while (qemu_isgraph(*p)) {
p++;
--
1.7.6.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH] monitor: refactor whitespace and optional argument parsing
2011-10-20 18:39 [Qemu-devel] [PATCH] monitor: refactor whitespace and optional argument parsing Alon Levy
@ 2011-10-20 18:43 ` Alon Levy
2011-10-24 8:49 ` Markus Armbruster
0 siblings, 1 reply; 3+ messages in thread
From: Alon Levy @ 2011-10-20 18:43 UTC (permalink / raw)
To: qemu-devel
Takes out the optional ('?') message parsing from the main switch loop
in monitor_parse_command. Adds optional argument option for boolean parameters.
Signed-off-by: Alon Levy <alevy@redhat.com>
---
Previous patch used qemu_free (that's how old it is), fixed.
monitor.c | 79 +++++++++++++++++++++++-------------------------------------
1 files changed, 30 insertions(+), 49 deletions(-)
diff --git a/monitor.c b/monitor.c
index ffda0fe..a482705 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3976,6 +3976,29 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
break;
c = *typestr;
typestr++;
+ while (qemu_isspace(*p)) {
+ p++;
+ }
+ /* take care of optional arguments */
+ switch (c) {
+ case 's':
+ case 'i':
+ case 'l':
+ case 'M':
+ case 'o':
+ case 'T':
+ case 'b':
+ if (*typestr == '?') {
+ typestr++;
+ if (*p == '\0') {
+ /* missing optional argument: NULL argument */
+ g_free(key);
+ key = NULL;
+ continue;
+ }
+ }
+ break;
+ }
switch(c) {
case 'F':
case 'B':
@@ -3983,15 +4006,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
{
int ret;
- while (qemu_isspace(*p))
- p++;
- if (*typestr == '?') {
- typestr++;
- if (*p == '\0') {
- /* no optional string: NULL argument */
- break;
- }
- }
ret = get_str(buf, sizeof(buf), &p);
if (ret < 0) {
switch(c) {
@@ -4021,9 +4035,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
if (!opts_list || opts_list->desc->name) {
goto bad_type;
}
- while (qemu_isspace(*p)) {
- p++;
- }
if (!*p)
break;
if (get_str(buf, sizeof(buf), &p) < 0) {
@@ -4041,8 +4052,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
{
int count, format, size;
- while (qemu_isspace(*p))
- p++;
if (*p == '/') {
/* format found */
p++;
@@ -4122,23 +4131,15 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
{
int64_t val;
- while (qemu_isspace(*p))
- p++;
- if (*typestr == '?' || *typestr == '.') {
- if (*typestr == '?') {
- if (*p == '\0') {
- typestr++;
- break;
- }
- } else {
- if (*p == '.') {
+ if (*typestr == '.') {
+ if (*p == '.') {
+ p++;
+ while (qemu_isspace(*p)) {
p++;
- while (qemu_isspace(*p))
- p++;
- } else {
- typestr++;
- break;
}
+ } else {
+ typestr++;
+ break;
}
typestr++;
}
@@ -4160,15 +4161,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
int64_t val;
char *end;
- while (qemu_isspace(*p)) {
- p++;
- }
- if (*typestr == '?') {
- typestr++;
- if (*p == '\0') {
- break;
- }
- }
val = strtosz(p, &end);
if (val < 0) {
monitor_printf(mon, "invalid size\n");
@@ -4182,14 +4174,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
{
double val;
- while (qemu_isspace(*p))
- p++;
- if (*typestr == '?') {
- typestr++;
- if (*p == '\0') {
- break;
- }
- }
if (get_double(mon, &val, &p) < 0) {
goto fail;
}
@@ -4215,9 +4199,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
const char *beg;
int val;
- while (qemu_isspace(*p)) {
- p++;
- }
beg = p;
while (qemu_isgraph(*p)) {
p++;
--
1.7.6.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] monitor: refactor whitespace and optional argument parsing
2011-10-20 18:43 ` Alon Levy
@ 2011-10-24 8:49 ` Markus Armbruster
0 siblings, 0 replies; 3+ messages in thread
From: Markus Armbruster @ 2011-10-24 8:49 UTC (permalink / raw)
To: Alon Levy; +Cc: qemu-devel
Alon Levy <alevy@redhat.com> writes:
> Takes out the optional ('?') message parsing from the main switch loop
> in monitor_parse_command. Adds optional argument option for boolean parameters.
>
> Signed-off-by: Alon Levy <alevy@redhat.com>
> ---
> Previous patch used qemu_free (that's how old it is), fixed.
>
> monitor.c | 79 +++++++++++++++++++++++-------------------------------------
> 1 files changed, 30 insertions(+), 49 deletions(-)
>
> diff --git a/monitor.c b/monitor.c
> index ffda0fe..a482705 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -3976,6 +3976,29 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
> break;
> c = *typestr;
> typestr++;
> + while (qemu_isspace(*p)) {
> + p++;
> + }
> + /* take care of optional arguments */
> + switch (c) {
> + case 's':
> + case 'i':
> + case 'l':
> + case 'M':
> + case 'o':
> + case 'T':
> + case 'b':
> + if (*typestr == '?') {
> + typestr++;
> + if (*p == '\0') {
> + /* missing optional argument: NULL argument */
> + g_free(key);
> + key = NULL;
> + continue;
> + }
> + }
> + break;
> + }
> switch(c) {
> case 'F':
> case 'B':
> @@ -3983,15 +4006,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
> {
> int ret;
>
> - while (qemu_isspace(*p))
> - p++;
> - if (*typestr == '?') {
> - typestr++;
> - if (*p == '\0') {
> - /* no optional string: NULL argument */
> - break;
> - }
> - }
> ret = get_str(buf, sizeof(buf), &p);
> if (ret < 0) {
> switch(c) {
This is cases 'F', 'B' and 's'. I'm afraid your new code covers only
's'.
> @@ -4021,9 +4035,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
> if (!opts_list || opts_list->desc->name) {
> goto bad_type;
> }
> - while (qemu_isspace(*p)) {
> - p++;
> - }
> if (!*p)
> break;
> if (get_str(buf, sizeof(buf), &p) < 0) {
> @@ -4041,8 +4052,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
> {
> int count, format, size;
>
> - while (qemu_isspace(*p))
> - p++;
> if (*p == '/') {
> /* format found */
> p++;
> @@ -4122,23 +4131,15 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
> {
> int64_t val;
>
> - while (qemu_isspace(*p))
> - p++;
> - if (*typestr == '?' || *typestr == '.') {
> - if (*typestr == '?') {
> - if (*p == '\0') {
> - typestr++;
> - break;
> - }
> - } else {
> - if (*p == '.') {
> + if (*typestr == '.') {
> + if (*p == '.') {
> + p++;
> + while (qemu_isspace(*p)) {
> p++;
> - while (qemu_isspace(*p))
> - p++;
> - } else {
> - typestr++;
> - break;
> }
> + } else {
> + typestr++;
> + break;
> }
> typestr++;
> }
> @@ -4160,15 +4161,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
> int64_t val;
> char *end;
>
> - while (qemu_isspace(*p)) {
> - p++;
> - }
> - if (*typestr == '?') {
> - typestr++;
> - if (*p == '\0') {
> - break;
> - }
> - }
> val = strtosz(p, &end);
> if (val < 0) {
> monitor_printf(mon, "invalid size\n");
> @@ -4182,14 +4174,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
> {
> double val;
>
> - while (qemu_isspace(*p))
> - p++;
> - if (*typestr == '?') {
> - typestr++;
> - if (*p == '\0') {
> - break;
> - }
> - }
> if (get_double(mon, &val, &p) < 0) {
> goto fail;
> }
> @@ -4215,9 +4199,6 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
> const char *beg;
> int val;
>
> - while (qemu_isspace(*p)) {
> - p++;
> - }
> beg = p;
> while (qemu_isgraph(*p)) {
> p++;
Could be split into parts:
1. Hoist the space skip out of the switch
2. Hoist handling of '?' out of the switch
3. Permit optional boolean parameters
I'd delay the third part until there's a user.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-10-24 8:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-20 18:39 [Qemu-devel] [PATCH] monitor: refactor whitespace and optional argument parsing Alon Levy
2011-10-20 18:43 ` Alon Levy
2011-10-24 8:49 ` Markus Armbruster
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).