]> granicus.if.org Git - nethack/commitdiff
nethack --windowtype=badchoice
authorPatR <rankin@nethack.org>
Mon, 2 Jan 2023 01:35:06 +0000 (17:35 -0800)
committerPatR <rankin@nethack.org>
Mon, 2 Jan 2023 01:35:06 +0000 (17:35 -0800)
If you used the commandline to ask for an interface that doesn't exist
or isn't available, you'd get complaints about it not being recognized
twice.  First before any other options, then again after regular
option processing has taken place.  Clear the command line setting if
the first attempt gets rejected so that it won't be retried later and
be rejected again.  Probably the game should just quit if setting the
interface fails.

src/options.c

index 11d2940660255353f0c5fc62a36a52e46dfb30b6..312395258932b314663c7a1e08d8645f5301742b 100644 (file)
@@ -6525,10 +6525,17 @@ initoptions_init(void)
        set it again in initoptions_finish() so that NETHACKOPTIONS and
        .nethrackrc can't override it (command line takes precedence) */
     if (gc.cmdline_windowsys) {
+        nmcpy(gc.chosen_windowtype, gc.cmdline_windowsys, WINTYPELEN);
         config_error_init(FALSE, "command line", FALSE);
         choose_windows(gc.cmdline_windowsys);
         config_error_done();
-        /* do not free gc.cmdline_windowsys yet */
+        /* do not free gc.cmdline_windowsys yet unless it was rejected;
+           keeping it in that situation would complain about it twice */
+        if (!windowprocs.name
+            || strcmpi(windowprocs.name, gc.cmdline_windowsys) != 0) {
+            free((genericptr_t) gc.cmdline_windowsys),
+            gc.cmdline_windowsys = NULL;
+        }
     }
 
 #ifdef ENHANCED_SYMBOLS