Unix: command line --windowtype:foo fix

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.
This commit is contained in:
PatR
2022-08-28 00:09:50 -07:00
parent 1bdfeb04ab
commit 11c8d5cd5e
6 changed files with 40 additions and 13 deletions

View 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 */

View 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*/

View 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);
}