From: Anthony Liguori <aliguori@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>
Subject: [Qemu-devel] [PATCH 2/3] Move out option lookup into a separate function
Date: Sun, 24 Jan 2010 08:22:17 -0600 [thread overview]
Message-ID: <1264342938-7363-3-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <1264342938-7363-1-git-send-email-aliguori@us.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
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);
--
1.6.5.2
next prev parent reply other threads:[~2010-01-24 14:22 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-24 14:22 [Qemu-devel] [PATCH 0/4] Introduce global config (v3) Anthony Liguori
2010-01-24 14:22 ` [Qemu-devel] [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v3) Anthony Liguori
2010-01-24 14:45 ` [Qemu-devel] " Paolo Bonzini
2010-01-24 15:23 ` Anthony Liguori
2010-01-25 14:43 ` Avi Kivity
2010-01-25 21:05 ` Paolo Bonzini
2010-01-25 21:14 ` Anthony Liguori
2010-01-25 21:19 ` Paolo Bonzini
2010-01-26 8:56 ` Avi Kivity
2010-01-24 14:22 ` Anthony Liguori [this message]
2010-01-24 14:22 ` [Qemu-devel] [PATCH 3/3] Load global config files by default (v3) Anthony Liguori
2010-01-24 15:00 ` [Qemu-devel] [PATCH 0/4] Introduce global config (v3) Avi Kivity
2010-01-24 15:23 ` Anthony Liguori
2010-01-24 15:04 ` Avi Kivity
2010-01-24 15:10 ` Paolo Bonzini
2010-01-25 11:31 ` Daniel P. Berrange
2010-01-25 13:59 ` Anthony Liguori
2010-01-24 15:25 ` Anthony Liguori
-- strict thread matches above, loose matches on Subject: below --
2010-01-22 16:08 [Qemu-devel] Introduce global config (v2) Anthony Liguori
2010-01-22 16:09 ` [Qemu-devel] [PATCH 2/3] Move out option lookup into a separate function Anthony Liguori
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=1264342938-7363-3-git-send-email-aliguori@us.ibm.com \
--to=aliguori@us.ibm.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).