From patchwork Sun Jan 24 14:22:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 43592 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 1D5731007D2 for ; Mon, 25 Jan 2010 01:29:44 +1100 (EST) Received: from localhost ([127.0.0.1]:52952 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZ3RB-0002hj-5K for incoming@patchwork.ozlabs.org; Sun, 24 Jan 2010 09:27:37 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NZ3MN-0001Wi-6s for qemu-devel@nongnu.org; Sun, 24 Jan 2010 09:22:39 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NZ3MI-0001TU-Kl for qemu-devel@nongnu.org; Sun, 24 Jan 2010 09:22:38 -0500 Received: from [199.232.76.173] (port=51939 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZ3MI-0001TN-5w for qemu-devel@nongnu.org; Sun, 24 Jan 2010 09:22:34 -0500 Received: from e32.co.us.ibm.com ([32.97.110.150]:55022) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NZ3MI-0008Tq-16 for qemu-devel@nongnu.org; Sun, 24 Jan 2010 09:22:34 -0500 Received: from d03relay01.boulder.ibm.com (d03relay01.boulder.ibm.com [9.17.195.226]) by e32.co.us.ibm.com (8.14.3/8.13.1) with ESMTP id o0OEGRVc032497 for ; Sun, 24 Jan 2010 07:16:27 -0700 Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay01.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o0OEMSqr172336 for ; Sun, 24 Jan 2010 07:22:28 -0700 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o0OEMSxQ028305 for ; Sun, 24 Jan 2010 07:22:28 -0700 Received: from localhost.localdomain (sig-9-65-101-121.mts.ibm.com [9.65.101.121]) by d03av04.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o0OEMOq2028158; Sun, 24 Jan 2010 07:22:27 -0700 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Sun, 24 Jan 2010 08:22:17 -0600 Message-Id: <1264342938-7363-3-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1264342938-7363-1-git-send-email-aliguori@us.ibm.com> References: <1264342938-7363-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Anthony Liguori Subject: [Qemu-devel] [PATCH 2/3] Move out option lookup into a separate function 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 Signed-off-by: Anthony Liguori --- vl.c | 72 +++++++++++++++++++++++++++++++++++++++-------------------------- 1 files changed, 43 insertions(+), 29 deletions(-) diff --git a/vl.c b/vl.c index e070ec9..e00ae0d 100644 --- a/vl.c +++ b/vl.c @@ -4658,6 +4658,46 @@ static int debugcon_parse(const char *devname) return 0; } +static const QEMUOption *lookup_opt(int argc, char **argv, + const char **poptarg, int *poptind) +{ + const QEMUOption *popt; + int optind = *poptind; + char *r = argv[optind]; + const char *optarg; + + optind++; + /* Treat --foo the same as -foo. */ + if (r[1] == '-') + r++; + popt = qemu_options; + for(;;) { + if (!popt->name) { + fprintf(stderr, "%s: invalid option -- '%s'\n", + argv[0], r); + exit(1); + } + if (!strcmp(popt->name, r + 1)) + break; + popt++; + } + if (popt->flags & HAS_ARG) { + if (optind >= argc) { + fprintf(stderr, "%s: option '%s' requires an argument\n", + argv[0], r); + exit(1); + } + optarg = argv[optind++]; + } else { + optarg = NULL; + } + + *poptarg = optarg; + *poptind = optind; + + return popt; +} + int main(int argc, char **argv, char **envp) { const char *gdbstub_dev = NULL; @@ -4672,7 +4712,7 @@ int main(int argc, char **argv, char **envp) int cyls, heads, secs, translation; QemuOpts *hda_opts = NULL, *opts; int optind; - const char *r, *optarg; + const char *optarg; const char *loadvm = NULL; QEMUMachine *machine; const char *cpu_model; @@ -4753,38 +4793,12 @@ int main(int argc, char **argv, char **envp) for(;;) { if (optind >= argc) break; - r = argv[optind]; - if (r[0] != '-') { + if (argv[optind][0] != '-') { hda_opts = drive_add(argv[optind++], HD_ALIAS, 0); } else { const QEMUOption *popt; - optind++; - /* Treat --foo the same as -foo. */ - if (r[1] == '-') - r++; - popt = qemu_options; - for(;;) { - if (!popt->name) { - fprintf(stderr, "%s: invalid option -- '%s'\n", - argv[0], r); - exit(1); - } - if (!strcmp(popt->name, r + 1)) - break; - popt++; - } - if (popt->flags & HAS_ARG) { - if (optind >= argc) { - fprintf(stderr, "%s: option '%s' requires an argument\n", - argv[0], r); - exit(1); - } - optarg = argv[optind++]; - } else { - optarg = NULL; - } - + popt = lookup_opt(argc, argv, &optarg, &optind); switch(popt->index) { case QEMU_OPTION_M: machine = find_machine(optarg);