From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZbY4L-0004Te-G3 for qemu-devel@nongnu.org; Mon, 14 Sep 2015 14:01:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZbY4F-0002UQ-Kv for qemu-devel@nongnu.org; Mon, 14 Sep 2015 14:01:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48760) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZbY4F-0002Tk-GS for qemu-devel@nongnu.org; Mon, 14 Sep 2015 14:01:27 -0400 From: Laurent Vivier Date: Mon, 14 Sep 2015 20:01:19 +0200 Message-Id: <1442253680-8657-2-git-send-email-lvivier@redhat.com> In-Reply-To: <1442253680-8657-1-git-send-email-lvivier@redhat.com> References: <1442253680-8657-1-git-send-email-lvivier@redhat.com> Subject: [Qemu-devel] [PATCH v5 1/2] vl: Allow to define optional parameter with -arg[=params] List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, marcandre.lureau@gmail.com, eblake@redhat.com Cc: lvivier@redhat.com The goal is to be able to use '-help' alone, or with a sub-section, i.e. '-help=network,usb'. Signed-off-by: Laurent Vivier --- vl.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/vl.c b/vl.c index 1c8b28d..586ce55 100644 --- a/vl.c +++ b/vl.c @@ -2703,19 +2703,28 @@ static const QEMUOption *lookup_opt(int argc, char **argv, error_report("invalid option"); exit(1); } - if (!strcmp(popt->name, r + 1)) - break; - popt++; - } - if (popt->flags & HAS_ARG) { - if (optind >= argc) { - error_report("requires an argument"); - exit(1); + /* manage arg type: -arg[=param] */ + optarg = strchr(r + 1, '='); + if (optarg) { + if (!strncmp(popt->name, r + 1, optarg - (r + 1))) { + optarg++; /* skip '=' */ + break; + } + } else { + if (!strcmp(popt->name, r + 1)) { + if (popt->flags & HAS_ARG) { + if (optind >= argc) { + error_report("requires an argument"); + exit(1); + } + optarg = argv[optind++]; + loc_set_cmdline(argv, optind - 2, 2); + } + break; + } } - optarg = argv[optind++]; - loc_set_cmdline(argv, optind - 2, 2); - } else { optarg = NULL; + popt++; } *poptarg = optarg; -- 2.1.0