From patchwork Mon Sep 7 16:06:03 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 33096 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id ADA6CB708B for ; Tue, 8 Sep 2009 02:29:58 +1000 (EST) Received: from localhost ([127.0.0.1]:52121 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mkh6I-000135-Or for incoming@patchwork.ozlabs.org; Mon, 07 Sep 2009 12:29:54 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mkgjw-0007WE-J9 for qemu-devel@nongnu.org; Mon, 07 Sep 2009 12:06:48 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mkgjo-0007Q5-4b for qemu-devel@nongnu.org; Mon, 07 Sep 2009 12:06:44 -0400 Received: from [199.232.76.173] (port=34955 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mkgjn-0007Pm-Ss for qemu-devel@nongnu.org; Mon, 07 Sep 2009 12:06:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49277) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mkgjn-0003Va-96 for qemu-devel@nongnu.org; Mon, 07 Sep 2009 12:06:39 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n87G6ciT009253 for ; Mon, 7 Sep 2009 12:06:38 -0400 Received: from zweiblum.home.kraxel.org (vpn2-9-74.ams2.redhat.com [10.36.9.74]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n87G6W9x008856; Mon, 7 Sep 2009 12:06:33 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id 48C4D700E0; Mon, 7 Sep 2009 18:06:25 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 7 Sep 2009 18:06:03 +0200 Message-Id: <1252339585-27797-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1252339585-27797-1-git-send-email-kraxel@redhat.com> References: <1252339585-27797-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 01/23] QemuOpts: split option parser into two functions. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org looking for id= and creating a new QemuOpts instance is splitted from the actual option parser code now, so the parser can be called from other contexts too. Signed-off-by: Gerd Hoffmann --- qemu-option.c | 46 +++++++++++++++++++++++++++++----------------- qemu-option.h | 1 + 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index 61141e0..d37ffe9 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -709,23 +709,11 @@ int qemu_opts_print(QemuOpts *opts, void *dummy) return 0; } -QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *firstname) +int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname) { - char option[128], value[128], *id = NULL; - QemuOpts *opts; + char option[128], value[128]; const char *p,*pe,*pc; - if (strncmp(params, "id=", 3) == 0) { - get_opt_value(value, sizeof(value), params+3); - id = qemu_strdup(value); - } else if ((p = strstr(params, ",id=")) != NULL) { - get_opt_value(value, sizeof(value), p+4); - id = qemu_strdup(value); - } - opts = qemu_opts_create(list, id, 1); - if (opts == NULL) - return NULL; - p = params; for(;;) { pe = strchr(p, '='); @@ -739,7 +727,7 @@ QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *fi } else { /* option without value, probably a flag */ p = get_opt_name(option, sizeof(option), p, ','); - if (strncmp(p, "no", 2) == 0) { + if (strncmp(option, "no", 2) == 0) { memmove(option, option+2, strlen(option+2)+1); pstrcpy(value, sizeof(value), "off"); } else { @@ -758,8 +746,7 @@ QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *fi if (strcmp(option, "id") != 0) { /* store and parse */ if (-1 == qemu_opt_set(opts, option, value)) { - qemu_opts_del(opts); - return NULL; + return -1; } } if (*p != ',') { @@ -767,6 +754,31 @@ QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *fi } p++; } + return 0; +} + +QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *firstname) +{ + char value[128], *id = NULL; + const char *p; + QemuOpts *opts; + + if (strncmp(params, "id=", 3) == 0) { + get_opt_value(value, sizeof(value), params+3); + id = qemu_strdup(value); + } else if ((p = strstr(params, ",id=")) != NULL) { + get_opt_value(value, sizeof(value), p+4); + id = qemu_strdup(value); + } + opts = qemu_opts_create(list, id, 1); + if (opts == NULL) + return NULL; + + if (qemu_opts_do_parse(opts, params, firstname) != 0) { + qemu_opts_del(opts); + return NULL; + } + return opts; } diff --git a/qemu-option.h b/qemu-option.h index 56c7eac..9e52625 100644 --- a/qemu-option.h +++ b/qemu-option.h @@ -114,6 +114,7 @@ int qemu_opts_set(QemuOptsList *list, const char *id, const char *name, const char *value); const char *qemu_opts_id(QemuOpts *opts); void qemu_opts_del(QemuOpts *opts); +int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname); QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *firstname); typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);