]> granicus.if.org Git - nethack/commitdiff
Unix: command line --windowtype:foo fix
authorPatR <rankin@nethack.org>
Sun, 28 Aug 2022 07:09:50 +0000 (00:09 -0700)
committerPatR <rankin@nethack.org>
Sun, 28 Aug 2022 07:09:50 +0000 (00:09 -0700)
initoptions(), including initoptions_finish(), was running to
completion with the default window system before windowtype from the
command was parsed and activated.  When the default window system
is tty without MS-DOS the map type gets set to ascii; command line
--windowtype:X11 doesn't switch it back to the X11 default of tiled.

So,
| NETHACKOPTIONS=windowtype:X11 nethack
ran nethack in tiles mode but
| nethack --windowtype:X11
ran it in text mode (assuming .nethackrc left tiles vs text with the
default setting).

I think this fix is quite iffy but it seems to work as intended....
It reclassifies '--windowtype' as an "early option" in unixmain.c,
and the options.c code ultimately processes it twice.

doc/fixes3-7-0.txt
include/decl.h
src/decl.c
src/options.c
src/windows.c
sys/unix/unixmain.c

index 131620155fdcc658d8e557d1c2bb53c4e11c746a..6c838961a3bafe3f46995c0310b26ab7d1a81c8d 100644 (file)
@@ -1369,6 +1369,10 @@ end of game with DUMPLOG could panic due to perm_invent handling, even when
 with color Off and the screen symbol for ice the same as for floor, the black
        and white ice was supposed to be rendered in inverse video but that
        got broken by the symbols and glyphs overhaul
+command line processing interleaved with options file processing is complex:
+       a recent change to make 'color' show up for tty in the short options
+       menu resulted in 'nethack --windowtype:X11' running X11 with ascii map
+       ('NETHACKOPTIONS=windowtype:X11 nethack' continued to default to tiles)
 
 curses: 'msg_window' option wasn't functional for curses unless the binary
        also included tty support
index 562678b9ac7821847be5e2f1f4ca0e2349a63c72..e931fc09b7f88e892d66e1fac13ff936cf7fbeaa 100644 (file)
@@ -1087,6 +1087,7 @@ struct instance_globals {
     boolean opt_from_file;
     boolean opt_need_redraw; /* for doset() */
     boolean opt_need_glyph_reset;
+    char *cmdline_windowsys; /* set in unixmain.c */
     /* use menucolors to show colors in the pick-a-color menu */
     boolean save_menucolors; /* copy of iflags.use_menu_colors */
     struct menucoloring *save_colorings; /* copy of g.menu_colorings */
index 150c945e6cf0ca7aad7813082423cdd0b8fb0198..721fda639467bbde55e3264e982e68a19a650b7b 100644 (file)
@@ -528,6 +528,7 @@ const struct instance_globals g_init = {
     FALSE, /* opt_from_file */
     FALSE, /* opt_need_redraw */
     FALSE, /* opt_need_glyph_reset */
+    NULL, /* cmdline_windowsys */
     FALSE, /* save_menucolors */
     (struct menucoloring *) 0, /* save_colorings */
     (struct menucoloring *) 0, /* color_colorings */
index af835e2ace4485ea02cc7e77159d53eb814ae5c4..0029210ab81e0c7eb648edfec4400ba0631f26e0 100644 (file)
@@ -354,7 +354,10 @@ extern char *curses_fmt_attrs(char *);
  **********************************
  */
 boolean
-parseoptions(register char *opts, boolean tinitial, boolean tfrom_file)
+parseoptions(
+    register char *opts,
+    boolean tinitial,
+    boolean tfrom_file)
 {
     char *op;
     boolean negated, got_match = FALSE, pfx_match = FALSE;
@@ -6242,6 +6245,17 @@ initoptions_init(void)
     memcpy(allopt, allopt_init, sizeof(allopt));
     determine_ambiguities();
 
+    /* if windowtype has been specified on the command line, set it up
+       early so windowtype-specific options use it as their base; we will
+       set it again in initoptions_finish() so that NETHACKOPTIONS and
+       .nethrackrc can't override it (command line takes precedence) */
+    if (g.cmdline_windowsys) {
+        config_error_init(FALSE, "command line", FALSE);
+        choose_windows(g.cmdline_windowsys);
+        config_error_done();
+        /* do not free g.cmdline_windowsys yet */
+    }
+
 #ifdef ENHANCED_SYMBOLS
     /* make any symbol parsing quicker */
     if (!glyphid_cache_status())
@@ -6452,6 +6466,14 @@ initoptions_finish(void)
         config_error_done();
     }
 
+    /* after .nethackrc and NETHACKOPTIONS so that cmdline takes precedence */
+    if (g.cmdline_windowsys) {
+        config_error_init(FALSE, "command line", FALSE);
+        choose_windows(g.cmdline_windowsys);
+        config_error_done();
+        free((genericptr_t) g.cmdline_windowsys), g.cmdline_windowsys = NULL;
+    }
+
     if (g.cmdline_rcfile)
         free((genericptr_t) g.cmdline_rcfile), g.cmdline_rcfile = 0;
     /*[end of nethackrc handling]*/
@@ -9511,4 +9533,3 @@ enhance_menu_text(
 #endif /* OPTION_LISTS_ONLY */
 
 /*options.c*/
-
index c1c983e21c2d571d682b400fb68ed0726b413a55..98be242d372bf570729910fe04c344d42e40429a 100644 (file)
@@ -311,8 +311,7 @@ choose_windows(const char *s)
     if (tmps)
         free((genericptr_t) tmps) /*, tmps = 0*/ ;
 
-    if (windowprocs.win_raw_print == def_raw_print
-            || WINDOWPORT(safestartup))
+    if (windowprocs.win_raw_print == def_raw_print || WINDOWPORT(safestartup))
         nh_terminate(EXIT_SUCCESS);
 }
 
index 6f9dc42e04d0ea8af4081048882b1f1550ca239d..733d20d58b39b484b6c8b5fc5e017be32692be53 100644 (file)
@@ -376,7 +376,7 @@ lopt(
     return p;
 }
 
-/* caveat: argv elements might be arbitrary long */
+/* caveat: argv elements might be arbitrarily long */
 static void
 process_options(int argc, char *argv[])
 {
@@ -479,14 +479,6 @@ process_options(int argc, char *argv[])
                     flags.initrace = i;
             }
             break;
-        case 'w': /* windowtype: "-wfoo" or "-w[indowtype]=foo"
-                   * or "-w[indowtype]:foo" or "-w[indowtype] foo" */
-            arg = lopt(arg,
-                       (ArgValRequired | ArgNamOneLetter | ArgErrComplain),
-                       "-windowtype", origarg, &argc, &argv);
-            if (arg)
-                choose_windows(arg);
-            break;
         case '@':
             flags.randomall = 1;
             break;
@@ -667,6 +659,15 @@ early_options(int *argc_p, char ***argv_p, char **hackdir_p)
                 /*NOTREACHED*/
             }
             break;
+        case 'w': /* windowtype: "-wfoo" or "-w[indowtype]=foo"
+                   * or "-w[indowtype]:foo" or "-w[indowtype] foo" */
+            arg = lopt(arg,
+                       (ArgValRequired | ArgNamOneLetter | ArgErrComplain),
+                       "-windowtype", origarg, &argc, &argv);
+            if (g.cmdline_windowsys)
+                free((genericptr_t) g.cmdline_windowsys);
+            g.cmdline_windowsys = arg ? dupstr(arg) : NULL;
+            break;
         default:
             break;
         }