From patchwork Fri Aug 19 17:08:46 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alon Levy X-Patchwork-Id: 110707 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6E47CB6F68 for ; Sat, 20 Aug 2011 03:10:56 +1000 (EST) Received: from localhost ([::1]:47961 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QuSak-0003lI-JS for incoming@patchwork.ozlabs.org; Fri, 19 Aug 2011 13:10:46 -0400 Received: from eggs.gnu.org ([140.186.70.92]:54860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QuSaY-0003cc-64 for qemu-devel@nongnu.org; Fri, 19 Aug 2011 13:10:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QuSaX-0001B4-1h for qemu-devel@nongnu.org; Fri, 19 Aug 2011 13:10:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24392) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QuSaW-0001Aw-Og for qemu-devel@nongnu.org; Fri, 19 Aug 2011 13:10:33 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p7JHAV4V011417 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 19 Aug 2011 13:10:32 -0400 Received: from bow.redhat.com (vpn-9-99.rdu.redhat.com [10.11.9.99]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p7JHAPpc023778; Fri, 19 Aug 2011 13:10:29 -0400 From: Alon Levy To: qemu-devel@nongnu.org Date: Fri, 19 Aug 2011 10:08:46 -0700 Message-Id: <1313773728-6104-2-git-send-email-alevy@redhat.com> In-Reply-To: <1313773728-6104-1-git-send-email-alevy@redhat.com> References: <1313773728-6104-1-git-send-email-alevy@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kraxel@redhat.com Subject: [Qemu-devel] [PATCH 1/3] monitor: refactor whitespace and optional argument parsing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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++;