diff mbox

cocoa: do not create a spurious window for -version

Message ID 1300195102-52156-1-git-send-email-gingold@adacore.com
State New
Headers show

Commit Message

Tristan Gingold March 15, 2011, 1:18 p.m. UTC
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.

Signed-off-by: Tristan Gingold <gingold@adacore.com>
---
 ui/cocoa.m |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

Comments

Andreas Färber March 19, 2011, 1:44 p.m. UTC | #1
Hello Tristan,

Am 15.03.2011 um 14:18 schrieb Tristan Gingold:

> 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.
>
> Signed-off-by: Tristan Gingold <gingold@adacore.com>

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

> ---
> ui/cocoa.m |   15 ++++++++++++---
> 1 files changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/ui/cocoa.m b/ui/cocoa.m
> index 20f91bc..1ff1ac6 100644
> --- a/ui/cocoa.m
> +++ b/ui/cocoa.m
> @@ -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);
> +            }
>         }
>     }
>
> -- 
> 1.7.3.GIT
>
>
Tristan Gingold March 21, 2011, 8:30 a.m. UTC | #2
On Mar 19, 2011, at 2:44 PM, Andreas Färber wrote:

> Hello Tristan,
> 
> Am 15.03.2011 um 14:18 schrieb Tristan Gingold:
> 
>> 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.
>> 
>> Signed-off-by: Tristan Gingold <gingold@adacore.com>
> 
> Looks good to me except for the qemu_main() indentation.

Ah.  Sorry for the nit.

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

Yes please.

> 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.

> 
> Andreas
> 
>> ---
>> ui/cocoa.m |   15 ++++++++++++---
>> 1 files changed, 12 insertions(+), 3 deletions(-)
>> 
>> diff --git a/ui/cocoa.m b/ui/cocoa.m
>> index 20f91bc..1ff1ac6 100644
>> --- a/ui/cocoa.m
>> +++ b/ui/cocoa.m
>> @@ -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);
>> +            }
>>        }
>>    }
>> 
>> -- 
>> 1.7.3.GIT
>> 
>> 
>
Andreas Färber March 22, 2011, 11:55 p.m. UTC | #3
Am 21.03.2011 um 09:30 schrieb Tristan Gingold:

> On Mar 19, 2011, at 2:44 PM, Andreas Färber wrote:
>
>> Am 15.03.2011 um 14:18 schrieb Tristan Gingold:
>>
>>> 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.
>>>
>>> Signed-off-by: Tristan Gingold <gingold@adacore.com>
>>
>> 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
diff mbox

Patch

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 20f91bc..1ff1ac6 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -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);
+            }
         }
     }