Skip to contentSkip to conversation

cocoa: do not create a spurious window for -version

PATCH Applied Tristan Gingold 2 participants 4 messages Mar 15, 2011 – Mar 22, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cocoa: do not create a spurious window for -version

When invoked with -version, qemu will exit just after displaying the version, so there is no need to create a window.
Also handles --XXX options.

---
 ui/cocoa.m |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
ui/cocoa.m +12 -3
index 20f91bc..1ff1ac6 100644
@@ -865,10 +865,19 @@ int main (int argc, const char * argv[]) {
 
     /* In case we don't need to display a window, let's not do that */
     for (i = 1; i < argc; i++) {
-        if (!strcmp(argv[i], "-vnc") ||
-            !strcmp(argv[i], "-nographic") ||
-            !strcmp(argv[i], "-curses")) {
+        const char *opt = argv[i];
+
+        if (opt[0] == '-') {
+            /* Treat --foo the same as -foo.  */
+            if (opt[1] == '-') {
+                opt++;
+            }
+            if (!strcmp(opt, "-vnc") ||
+                !strcmp(opt, "-nographic") ||
+                !strcmp(opt, "-version") ||
+                !strcmp(opt, "-curses")) {
                 return qemu_main(gArgc, gArgv);
+            }
         }
     }
 
Signature · 1 line
1.7.3.GIT
#1 lore raw

Hello Tristan,

Am 15.03.2011 um 14:18 schrieb Tristan Gingold:

Quoted 5 lines

When invoked with -version, qemu will exit just after displaying the version, so there is no need to create a window.
Also handles --XXX options.

Looks good to me except for the qemu_main() indentation. Should I fix it and enqueue it on my cocoa branch for the next pull?

Just wondering, since when do we support -- options?

Andreas

Quoted 35 lines

---
ui/cocoa.m | 15 ++++++++++++---

1 files changed, 12 insertions(+), 3 deletions(-)
ui/cocoa.m +12 -3
index 20f91bc..1ff1ac6 100644
@@ -865,10 +865,19 @@ int main (int argc, const char * argv[]) {
 
    /* In case we don't need to display a window, let's not do that */
    for (i = 1; i < argc; i++) {
-        if (!strcmp(argv[i], "-vnc") ||
-            !strcmp(argv[i], "-nographic") ||
-            !strcmp(argv[i], "-curses")) {
+        const char *opt = argv[i];
+
+        if (opt[0] == '-') {
+            /* Treat --foo the same as -foo.  */
+            if (opt[1] == '-') {
+                opt++;
+            }
+            if (!strcmp(opt, "-vnc") ||
+                !strcmp(opt, "-nographic") ||
+                !strcmp(opt, "-version") ||
+                !strcmp(opt, "-curses")) {
                return qemu_main(gArgc, gArgv);
+            }
        }
    }
 
Signature · 1 line
1.7.3.GIT
#2 lore raw
Quoted 11 lines · Andreas Färber

Hello Tristan,

Am 15.03.2011 um 14:18 schrieb Tristan Gingold:

Quoted 5 lines

When invoked with -version, qemu will exit just after displaying the version, so there is no need to create a window.
Also handles --XXX options.

Looks good to me except for the qemu_main() indentation.

Ah. Sorry for the nit.

Quoted 1 line

Should I fix it and enqueue it on my cocoa branch for the next pull?

Yes please.

Quoted 1 line

Just wondering, since when do we support -- options?

No idea. Wasn't aware of that before someone else in our company used this flag.

Thanks,
Tristan.

Quoted 39 lines

Andreas

Quoted 35 lines

---
ui/cocoa.m | 15 ++++++++++++---

1 files changed, 12 insertions(+), 3 deletions(-)
ui/cocoa.m +12 -3
index 20f91bc..1ff1ac6 100644
@@ -865,10 +865,19 @@ int main (int argc, const char * argv[]) {
 
   /* In case we don't need to display a window, let's not do that */
   for (i = 1; i < argc; i++) {
-        if (!strcmp(argv[i], "-vnc") ||
-            !strcmp(argv[i], "-nographic") ||
-            !strcmp(argv[i], "-curses")) {
+        const char *opt = argv[i];
+
+        if (opt[0] == '-') {
+            /* Treat --foo the same as -foo.  */
+            if (opt[1] == '-') {
+                opt++;
+            }
+            if (!strcmp(opt, "-vnc") ||
+                !strcmp(opt, "-nographic") ||
+                !strcmp(opt, "-version") ||
+                !strcmp(opt, "-curses")) {
               return qemu_main(gArgc, gArgv);
+            }
       }
   }
 
Signature · 1 line
1.7.3.GIT
#3 lore raw

Am 21.03.2011 um 09:30 schrieb Tristan Gingold:

Quoted 11 lines · Andreas Färber
Quoted 10 lines

Am 15.03.2011 um 14:18 schrieb Tristan Gingold:

Quoted 5 lines

When invoked with -version, qemu will exit just after displaying the version, so there is no need to create a window.
Also handles --XXX options.

Looks good to me except for the qemu_main() indentation.

My apologies, that was for one thing my mailer, and my original indentation had an extra four spaces indentation for readability that we're now eating up. No changes necessary from my side then.

Applied to my Cocoa branch for cherry-picking / pulling:

git://repo.or.cz/qemu/afaerber.git cocoa-for-upstream

Note that we still have the same issue with '-cpu ?' and others. Same for errors such as specifying too much RAM for a machine. I was definitely not planning to handle all of those here.

The path I wanted to take instead would be to redefine hw_error() etc. as macros that display the message in a window-modal sheet rather than postponing the window creation for all potential error cases. Patches welcome. :)

Andreas