From: Alon Levy <alevy@redhat.com>
To: qemu-devel@nongnu.org
Cc: kraxel@redhat.com
Subject: [Qemu-devel] [PATCH 1/3] monitor: refactor whitespace and optional argument parsing
Date: Fri, 19 Aug 2011 10:08:46 -0700 [thread overview]
Message-ID: <1313773728-6104-2-git-send-email-alevy@redhat.com> (raw)
In-Reply-To: <1313773728-6104-1-git-send-email-alevy@redhat.com>
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>
---
monitor.c | 79 +++++++++++++++++++++++-------------------------------------
1 files changed, 30 insertions(+), 49 deletions(-)
diff --git a/monitor.c b/monitor.c
index 6e3d970..baf46ba 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4122,6 +4122,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':
@@ -4129,15 +4152,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) {
@@ -4167,9 +4181,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) {
@@ -4187,8 +4198,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++;
@@ -4268,23 +4277,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++;
}
@@ -4306,15 +4307,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");
@@ -4328,14 +4320,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;
}
@@ -4361,9 +4345,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
next prev parent reply other threads:[~2011-08-19 17:10 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-19 17:08 [Qemu-devel] [PATCH 0/3] client_migrate_switch and auto_switch (RHBZ 725009) Alon Levy
2011-08-19 17:08 ` Alon Levy [this message]
2011-08-19 17:08 ` [Qemu-devel] [PATCH 2/3] spice-core: client_migrate_info: add optional auto_switch parameter " Alon Levy
2011-08-19 17:08 ` [Qemu-devel] [PATCH 3/3] monitor: add client_migrate_switch command " Alon Levy
2011-08-26 9:54 ` [Qemu-devel] [PATCH 0/3] client_migrate_switch and auto_switch " Gerd Hoffmann
2011-08-26 10:03 ` Daniel P. Berrange
2011-08-26 10:17 ` Gerd Hoffmann
2011-08-26 10:43 ` Alon Levy
2011-08-26 11:00 ` Gerd Hoffmann
2011-08-26 11:04 ` Daniel P. Berrange
2011-08-26 12:39 ` Gerd Hoffmann
2011-08-26 13:13 ` Daniel P. Berrange
2011-08-26 10:23 ` Alon Levy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1313773728-6104-2-git-send-email-alevy@redhat.com \
--to=alevy@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).