From: Laurent Vivier <lvivier@redhat.com>
To: qemu-devel@nongnu.org, marcandre.lureau@gmail.com, eblake@redhat.com
Subject: [Qemu-devel] [PATCH v4 1/3] vl: Add a flags to define parameters with optional arguments.
Date: Fri, 4 Sep 2015 21:30:03 +0200 [thread overview]
Message-ID: <1441395005-14907-2-git-send-email-lvivier@redhat.com> (raw)
In-Reply-To: <1441395005-14907-1-git-send-email-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 <lvivier@redhat.com>
---
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
next prev parent reply other threads:[~2015-09-04 19:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-04 19:30 [Qemu-devel] [PATCH v4 0/3] Improve -help Laurent Vivier
2015-09-04 19:30 ` Laurent Vivier [this message]
2015-09-04 19:42 ` [Qemu-devel] [PATCH v4 1/3] vl: Add a flags to define parameters with optional arguments Eric Blake
2015-09-04 19:52 ` Eric Blake
2015-09-04 19:55 ` Stefan Weil
2015-09-04 20:06 ` Eric Blake
2015-09-04 19:30 ` [Qemu-devel] [PATCH v4 2/3] help: fix typo Laurent Vivier
2015-09-04 19:34 ` Eric Blake
2015-09-06 11:06 ` Michael Tokarev
2015-09-04 19:30 ` [Qemu-devel] [PATCH v4 3/3] Use help sub-sections to create sub-help options Laurent Vivier
2015-09-04 20:13 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1441395005-14907-2-git-send-email-lvivier@redhat.com \
--to=lvivier@redhat.com \
--cc=eblake@redhat.com \
--cc=marcandre.lureau@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).