From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXwgf-0004va-6L for qemu-devel@nongnu.org; Fri, 04 Sep 2015 15:30:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZXwgb-0007EO-Pa for qemu-devel@nongnu.org; Fri, 04 Sep 2015 15:30:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45163) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXwgb-0007Dq-Jr for qemu-devel@nongnu.org; Fri, 04 Sep 2015 15:30:09 -0400 From: Laurent Vivier Date: Fri, 4 Sep 2015 21:30:03 +0200 Message-Id: <1441395005-14907-2-git-send-email-lvivier@redhat.com> In-Reply-To: <1441395005-14907-1-git-send-email-lvivier@redhat.com> References: <1441395005-14907-1-git-send-email-lvivier@redhat.com> Subject: [Qemu-devel] [PATCH v4 1/3] vl: Add a flags to define parameters with optional arguments. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, marcandre.lureau@gmail.com, eblake@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 | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/vl.c b/vl.c index 584ca88..a4fa7e5 100644 --- a/vl.c +++ b/vl.c @@ -1932,6 +1932,7 @@ static void help(int exitcode) } #define HAS_ARG 0x0001 +#define IS_OPT 0x0002 typedef struct QEMUOption { const char *name; @@ -2703,12 +2704,21 @@ static const QEMUOption *lookup_opt(int argc, char **argv, popt++; } if (popt->flags & HAS_ARG) { - if (optind >= argc) { - error_report("requires an argument"); - exit(1); + if (popt->flags & IS_OPT) { + if (optind < argc && argv[optind][0] != '-') { + optarg = argv[optind++]; + loc_set_cmdline(argv, optind - 2, 2); + } else { + optarg = NULL; + } + } else { + if (optind >= argc) { + error_report("requires an argument"); + exit(1); + } + optarg = argv[optind++]; + loc_set_cmdline(argv, optind - 2, 2); } - optarg = argv[optind++]; - loc_set_cmdline(argv, optind - 2, 2); } else { optarg = NULL; } -- 2.1.0