From patchwork Wed Oct 14 08:39:25 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 35927 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 ozlabs.org (Postfix) with ESMTPS id 531CCB7B70 for ; Wed, 14 Oct 2009 19:40:35 +1100 (EST) Received: from localhost ([127.0.0.1]:40144 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MxzPM-0006eZ-FY for incoming@patchwork.ozlabs.org; Wed, 14 Oct 2009 04:40:32 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MxzOV-0006dY-Gt for qemu-devel@nongnu.org; Wed, 14 Oct 2009 04:39:39 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MxzOQ-0006c0-CV for qemu-devel@nongnu.org; Wed, 14 Oct 2009 04:39:38 -0400 Received: from [199.232.76.173] (port=40700 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MxzOQ-0006bx-5q for qemu-devel@nongnu.org; Wed, 14 Oct 2009 04:39:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30597) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MxzOP-00048t-Jf for qemu-devel@nongnu.org; Wed, 14 Oct 2009 04:39:33 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9E8dWec006345 for ; Wed, 14 Oct 2009 04:39:32 -0400 Received: from zweiblum.home.kraxel.org (vpn1-5-6.ams2.redhat.com [10.36.5.6]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n9E8dVYY018128; Wed, 14 Oct 2009 04:39:31 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id D0A0B700FF; Wed, 14 Oct 2009 10:39:28 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 14 Oct 2009 10:39:25 +0200 Message-Id: <1255509568-10635-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1255509568-10635-1-git-send-email-kraxel@redhat.com> References: <1255509568-10635-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 1/4] QemuOpts: add find_list() 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 Factor out the QemuOptsList search code for upcoming users. Signed-off-by: Gerd Hoffmann --- qemu-config.c | 29 ++++++++++++++++++++--------- 1 files changed, 20 insertions(+), 9 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index bafaea2..f02dd42 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -193,11 +193,26 @@ static QemuOptsList *lists[] = { NULL, }; +static QemuOptsList *find_list(const char *group) +{ + int i; + + for (i = 0; lists[i] != NULL; i++) { + if (strcmp(lists[i]->name, group) == 0) + break; + } + if (lists[i] == NULL) { + qemu_error("there is no option group \"%s\"\n", group); + } + return lists[i]; +} + int qemu_set_option(const char *str) { char group[64], id[64], arg[64]; + QemuOptsList *list; QemuOpts *opts; - int i, rc, offset; + int rc, offset; rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset); if (rc < 3 || str[offset] != '=') { @@ -205,19 +220,15 @@ int qemu_set_option(const char *str) return -1; } - for (i = 0; lists[i] != NULL; i++) { - if (strcmp(lists[i]->name, group) == 0) - break; - } - if (lists[i] == NULL) { - qemu_error("there is no option group \"%s\"\n", group); + list = find_list(group); + if (list == NULL) { return -1; } - opts = qemu_opts_find(lists[i], id); + opts = qemu_opts_find(list, id); if (!opts) { qemu_error("there is no %s \"%s\" defined\n", - lists[i]->name, id); + list->name, id); return -1; }