From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41258) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zf9AR-00063w-70 for qemu-devel@nongnu.org; Thu, 24 Sep 2015 12:14:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zf9AL-0001C2-Il for qemu-devel@nongnu.org; Thu, 24 Sep 2015 12:14:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56726) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zf9AL-0001Bf-E6 for qemu-devel@nongnu.org; Thu, 24 Sep 2015 12:14:37 -0400 References: <1442253680-8657-1-git-send-email-lvivier@redhat.com> <1442253680-8657-2-git-send-email-lvivier@redhat.com> From: Laurent Vivier Message-ID: <5604216B.6020601@redhat.com> Date: Thu, 24 Sep 2015 18:14:35 +0200 MIME-Version: 1.0 In-Reply-To: <1442253680-8657-2-git-send-email-lvivier@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [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 ping ? On 14/09/2015 20:01, Laurent Vivier wrote: > 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; >