qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v4 1/3] vl: Add a flags to define parameters with op


From: Laurent Vivier
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

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 <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]