Windows options dynamically

There are two executables int the windows binary, each of which
have different options and capabilities. Sharing of one dat/options
file hasn't really been an accurate approach.

Produce that information dynamically for the Windows exe files.

This impacts alt-v results.
This commit is contained in:
nhmall
2020-02-13 21:24:24 -05:00
parent cbe27c7702
commit 751f1f47ab
4 changed files with 130 additions and 55 deletions
+2
View File
@@ -35,6 +35,8 @@
#define QWERTZ_SUPPORT /* when swap_yz is True, numpad 7 is 'z' not 'y' */ #define QWERTZ_SUPPORT /* when swap_yz is True, numpad 7 is 'z' not 'y' */
#define OPTIONS_AT_RUNTIME /* build info done at runtime not text file */
/* /*
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* The remaining code shouldn't need modification. * The remaining code shouldn't need modification.
-3
View File
@@ -25,9 +25,6 @@ early_init()
decl_globals_init(); decl_globals_init();
objects_globals_init(); objects_globals_init();
monst_globals_init(); monst_globals_init();
#if defined(OPTIONS_AT_RUNTIME) || defined(CROSSCOMPILE_TARGET)
runtime_info_init();
#endif
sys_early_init(); sys_early_init();
} }
+108 -33
View File
@@ -47,7 +47,12 @@
#endif #endif
#endif /* !MAKEDEFS_C */ #endif /* !MAKEDEFS_C */
#if defined(MAKEDEFS_C) || defined(CROSSCOMPILE_TARGET) /* shorten up some lines */
#if defined(CROSSCOMPILE_TARGET) || defined(OPTIONS_AT_RUNTIME)
#define FOR_RUNTIME
#endif
#if defined(MAKEDEFS_C) || defined(FOR_RUNTIME)
/* REPRODUCIBLE_BUILD will change this to TRUE */ /* REPRODUCIBLE_BUILD will change this to TRUE */
static boolean date_via_env = FALSE; static boolean date_via_env = FALSE;
@@ -58,9 +63,14 @@ static char *FDECL(bannerc_string, (char *, const char *));
static int FDECL(case_insensitive_comp, (const char *, const char *)); static int FDECL(case_insensitive_comp, (const char *, const char *));
static void NDECL(make_version); static void NDECL(make_version);
static char *FDECL(eos, (char *)); static char *FDECL(eos, (char *));
#endif /* MAKEDEFS_C || CROSSCOMPILE_TARGET */ static char *FDECL(mdlib_strsubst, (char *, const char *, const char *));
#endif /* MAKEDEFS_C || FOR_RUNTIME */
#if !defined(MAKEDEFS_C) && defined(WIN32)
extern int GUILaunched;
#endif
void NDECL(build_options); void NDECL(build_options);
static int NDECL(count_and_validate_winopts);
static void FDECL(opt_out_words, (char *, int *)); static void FDECL(opt_out_words, (char *, int *));
static void NDECL(build_savebones_compat_string); static void NDECL(build_savebones_compat_string);
static int idxopttext, done_runtime_opt_init_once = 0; static int idxopttext, done_runtime_opt_init_once = 0;
@@ -74,6 +84,7 @@ static const char opt_indent[] = " ";
struct win_info { struct win_info {
const char *id, /* DEFAULT_WINDOW_SYS string */ const char *id, /* DEFAULT_WINDOW_SYS string */
*name; /* description, often same as id */ *name; /* description, often same as id */
boolean valid;
}; };
static struct win_info window_opts[] = { static struct win_info window_opts[] = {
@@ -85,42 +96,43 @@ static struct win_info window_opts[] = {
confusing to most users (and it will already be listed separately confusing to most users (and it will already be listed separately
in the compiled options section so users aware of it can find it) */ in the compiled options section so users aware of it can find it) */
#ifdef MSDOS #ifdef MSDOS
"traditional text with optional 'tiles' graphics" "traditional text with optional 'tiles' graphics",
#else #else
/* assume that one or more of IBMgraphics, DECgraphics, or MACgraphics /* assume that one or more of IBMgraphics, DECgraphics, or MACgraphics
can be enabled; we can't tell from here whether that is accurate */ can be enabled; we can't tell from here whether that is accurate */
"traditional text with optional line-drawing" "traditional text with optional line-drawing",
#endif #endif
TRUE
}, },
#endif /*TTY_GRAPHICS */ #endif /*TTY_GRAPHICS */
#ifdef CURSES_GRAPHICS #ifdef CURSES_GRAPHICS
{ "curses", "terminal-based graphics" }, { "curses", "terminal-based graphics", TRUE },
#endif #endif
#ifdef X11_GRAPHICS #ifdef X11_GRAPHICS
{ "X11", "X11" }, { "X11", "X11", TRUE },
#endif #endif
#ifdef QT_GRAPHICS /* too vague; there are multiple incompatible versions */ #ifdef QT_GRAPHICS /* too vague; there are multiple incompatible versions */
{ "Qt", "Qt" }, { "Qt", "Qt", TRUE },
#endif #endif
#ifdef GNOME_GRAPHICS /* unmaintained/defunct */ #ifdef GNOME_GRAPHICS /* unmaintained/defunct */
{ "Gnome", "Gnome" }, { "Gnome", "Gnome", TRUE },
#endif #endif
#ifdef MAC /* defunct OS 9 interface */ #ifdef MAC /* defunct OS 9 interface */
{ "mac", "Mac" }, { "mac", "Mac", TRUE },
#endif #endif
#ifdef AMIGA_INTUITION /* unmaintained/defunct */ #ifdef AMIGA_INTUITION /* unmaintained/defunct */
{ "amii", "Amiga Intuition" }, { "amii", "Amiga Intuition", TRUE },
#endif #endif
#ifdef GEM_GRAPHICS /* defunct Atari interface */ #ifdef GEM_GRAPHICS /* defunct Atari interface */
{ "Gem", "Gem" }, { "Gem", "Gem", TRUE },
#endif #endif
#ifdef MSWIN_GRAPHICS /* win32 */ #ifdef MSWIN_GRAPHICS /* win32 */
{ "mswin", "mswin" }, { "mswin", "mswin", TRUE },
#endif #endif
#ifdef BEOS_GRAPHICS /* unmaintained/defunct */ #ifdef BEOS_GRAPHICS /* unmaintained/defunct */
{ "BeOS", "BeOS InterfaceKit" }, { "BeOS", "BeOS InterfaceKit", TRUE },
#endif #endif
{ 0, 0 } { 0, 0, FALSE }
}; };
/* /*
@@ -222,7 +234,7 @@ make_version()
return; return;
} }
#if defined(MAKEDEFS_C) || defined(CROSSCOMPILE_TARGET) #if defined(MAKEDEFS_C) || defined(FOR_RUNTIME)
static char * static char *
version_string(outbuf, delim) version_string(outbuf, delim)
@@ -270,7 +282,7 @@ const char *build_date;
return outbuf; return outbuf;
} }
/* still within #if MAKDEFS_C || CROSSCOMPILE_TARGET */ /* still within #if MAKDEFS_C || FOR_RUNTIME */
static char * static char *
bannerc_string(outbuf, build_date) bannerc_string(outbuf, build_date)
@@ -303,7 +315,7 @@ const char *build_date;
return outbuf; return outbuf;
} }
#endif /* MAKEDEFS_C || CROSSCOMPILE_TARGET */ #endif /* MAKEDEFS_C || FOR_RUNTIME */
static int static int
case_insensitive_comp(s1, s2) case_insensitive_comp(s1, s2)
@@ -334,6 +346,25 @@ char *str;
return str; return str;
} }
static char *
mdlib_strsubst(bp, orig, replacement)
char *bp;
const char *orig, *replacement;
{
char *found, buf[BUFSZ];
if (bp) {
/* [this could be replaced by strNsubst(bp, orig, replacement, 1)] */
found = strstr(bp, orig);
if (found) {
Strcpy(buf, found + strlen(orig));
Strcpy(found, replacement);
Strcat(bp, buf);
}
}
return bp;
}
static char save_bones_compat_buf[BUFSZ]; static char save_bones_compat_buf[BUFSZ];
static void static void
@@ -419,7 +450,7 @@ static const char *build_opts[] = {
#ifdef PANICLOG #ifdef PANICLOG
"errors and warnings log file", "errors and warnings log file",
#endif #endif
#ifdef MAIL_STRUCTURES #ifdef MAIL
"mail daemon", "mail daemon",
#endif #endif
#if defined(GNUDOS) || defined(__DJGPP__) #if defined(GNUDOS) || defined(__DJGPP__)
@@ -540,6 +571,29 @@ static const char *build_opts[] = {
"and basic NetHack features" "and basic NetHack features"
}; };
int
count_and_validate_winopts(VOID_ARGS)
{
int i, cnt = 0;
/* window_opts has a fencepost entry at the end */
for (i = 0; i < SIZE(window_opts) - 1; i++) {
#if !defined(MAKEDEFS_C) && defined(FOR_RUNTIME)
#ifdef WIN32
window_opts[i].valid = FALSE;
if ((GUILaunched
&& case_insensitive_comp(window_opts[i].id, "mswin") != 0)
|| (!GUILaunched
&& case_insensitive_comp(window_opts[i].id, "mswin") == 0))
continue;
#endif
#endif /* !MAKEDEFS_C && FOR_RUNTIME */
++cnt;
window_opts[i].valid = TRUE;
}
return cnt;
}
static void static void
opt_out_words(str, length_p) opt_out_words(str, length_p)
char *str; /* input, but modified during processing */ char *str; /* input, but modified during processing */
@@ -575,8 +629,14 @@ void
build_options() build_options()
{ {
char buf[BUFSZ]; char buf[BUFSZ];
int i, length, winsyscnt; int i, length, winsyscnt, cnt = 0;
const char *defwinsys = DEFAULT_WINDOW_SYS;
#if !defined (MAKEDEFS_C) && defined(FOR_RUNTIME)
#ifdef WIN32
defwinsys = GUILaunched ? "mswin" : "tty";
#endif
#endif
build_savebones_compat_string(); build_savebones_compat_string();
opttext[idxopttext] = strdup(optbuf); opttext[idxopttext] = strdup(optbuf);
if (idxopttext < (MAXOPT - 1)) if (idxopttext < (MAXOPT - 1))
@@ -602,6 +662,14 @@ build_options()
optbuf[0] = '\0'; optbuf[0] = '\0';
length = COLNO + 1; /* force 1st item onto new line */ length = COLNO + 1; /* force 1st item onto new line */
for (i = 0; i < SIZE(build_opts); i++) { for (i = 0; i < SIZE(build_opts); i++) {
#if !defined(MAKEDEFS_C) && defined(FOR_RUNTIME)
#ifdef WIN32
/* ignore the console entry if GUI version */
if (GUILaunched
&& !strcmp("screen control via WIN32 console I/O", build_opts[i]))
continue;
#endif
#endif /* !MAKEDEFS_C && FOR_RUNTIME */
opt_out_words(strcat(strcpy(buf, build_opts[i]), opt_out_words(strcat(strcpy(buf, build_opts[i]),
(i < SIZE(build_opts) - 1) ? "," : "."), (i < SIZE(build_opts) - 1) ? "," : "."),
&length); &length);
@@ -610,7 +678,7 @@ build_options()
if (idxopttext < (MAXOPT - 1)) if (idxopttext < (MAXOPT - 1))
idxopttext++; idxopttext++;
optbuf[0] = '\0'; optbuf[0] = '\0';
winsyscnt = SIZE(window_opts) - 1; winsyscnt = count_and_validate_winopts();
opttext[idxopttext] = strdup(optbuf); opttext[idxopttext] = strdup(optbuf);
if (idxopttext < (MAXOPT - 1)) if (idxopttext < (MAXOPT - 1))
idxopttext++; idxopttext++;
@@ -621,7 +689,10 @@ build_options()
idxopttext++; idxopttext++;
optbuf[0] = '\0'; optbuf[0] = '\0';
length = COLNO + 1; /* force 1st item onto new line */ length = COLNO + 1; /* force 1st item onto new line */
for (i = 0; i < winsyscnt; i++) {
for (i = 0; i < SIZE(window_opts) - 1; i++) {
if (!window_opts[i].valid)
continue;
Sprintf(buf, "\"%s\"", window_opts[i].id); Sprintf(buf, "\"%s\"", window_opts[i].id);
if (strcmp(window_opts[i].name, window_opts[i].id)) if (strcmp(window_opts[i].name, window_opts[i].id))
Sprintf(eos(buf), " (%s)", window_opts[i].name); Sprintf(eos(buf), " (%s)", window_opts[i].name);
@@ -630,22 +701,26 @@ build_options()
* 2 : foo and bar (note no period; comes from 'with default' below) * 2 : foo and bar (note no period; comes from 'with default' below)
* 3+: for, bar, and quux * 3+: for, bar, and quux
*/ */
opt_out_words(strcat(buf, (winsyscnt == 1) ? "." /* no 'default' */ if (cnt != (winsyscnt - 1)) {
: (winsyscnt == 2 && i == 0) ? " and" Strcat(buf, (winsyscnt == 1) ? "." /* no 'default' */
: (i == winsyscnt - 2) ? ", and" : (winsyscnt == 2 && cnt == 0) ? " and"
: ","), : (cnt == winsyscnt - 2) ? ", and"
&length); : ",");
}
opt_out_words(buf, &length);
cnt++;
} }
if (winsyscnt > 1) { if (cnt > 1) {
Sprintf(buf, "with a default of \"%s\".", DEFAULT_WINDOW_SYS); Sprintf(buf, ", with a default of \"%s\".", defwinsys);
opt_out_words(buf, &length); opt_out_words(buf, &length);
} }
(void) mdlib_strsubst(optbuf, " , ", ", ");
opttext[idxopttext] = strdup(optbuf); opttext[idxopttext] = strdup(optbuf);
if (idxopttext < (MAXOPT - 1)) if (idxopttext < (MAXOPT - 1))
idxopttext++; idxopttext++;
optbuf[0] = '\0'; optbuf[0] = '\0';
#if defined(MAKEDEFS_C) || (defined(CROSSCOMPILE) && defined(CROSSCOMPILE_TARGET)) #if defined(MAKEDEFS_C) || defined(FOR_RUNTIME)
{ {
static const char *lua_info[] = { static const char *lua_info[] = {
"", "NetHack 3.7.* uses the 'Lua' interpreter to process some data:", "", "", "NetHack 3.7.* uses the 'Lua' interpreter to process some data:", "",
@@ -673,7 +748,7 @@ build_options()
idxopttext++; idxopttext++;
} }
} }
#endif /* MAKEDEFS_C || (CROSSCOMPILE && CROSSCOMPILE_TARGET) */ #endif /* MAKEDEFS_C || FOR_RUNTIME */
/* end with a blank line */ /* end with a blank line */
opttext[idxopttext] = strdup(""); opttext[idxopttext] = strdup("");
@@ -754,7 +829,7 @@ runtime_info_init()
extract_field(tmpbuf, rttimebuf, 2, 18); /* sec */ extract_field(tmpbuf, rttimebuf, 2, 18); /* sec */
t.tm_sec = atoi(tmpbuf); t.tm_sec = atoi(tmpbuf);
timeresult = mktime(&t); timeresult = mktime(&t);
#if defined(CROSSCOMPILE_TARGET) && !defined(MAKEDEFS_C) #if !defined(MAKEDEFS_C) && defined(CROSSCOMPILE_TARGET)
BUILD_TIME = (unsigned long) timeresult; BUILD_TIME = (unsigned long) timeresult;
BUILD_DATE = rttimebuf; BUILD_DATE = rttimebuf;
#endif #endif
@@ -762,7 +837,7 @@ runtime_info_init()
nhUse(strp); nhUse(strp);
#endif /* __DATE__ && __TIME__ */ #endif /* __DATE__ && __TIME__ */
#if defined(CROSSCOMPILE_TARGET) && !defined(MAKEDEFS_C) #if !defined(MAKEDEFS_C) && defined(CROSSCOMPILE_TARGET)
VERSION_NUMBER = version.incarnation; VERSION_NUMBER = version.incarnation;
VERSION_FEATURES = version.feature_set; VERSION_FEATURES = version.feature_set;
#ifdef MD_IGNORED_FEATURES #ifdef MD_IGNORED_FEATURES
@@ -781,7 +856,7 @@ runtime_info_init()
#ifdef NETHACK_HOST_GIT_BRANCH #ifdef NETHACK_HOST_GIT_BRANCH
NETHACK_GIT_BRANCH = strdup(NETHACK_HOST_GIT_BRANCH); NETHACK_GIT_BRANCH = strdup(NETHACK_HOST_GIT_BRANCH);
#endif #endif
#endif /* CROSSCOMPILE_TARGET && !MAKEDEFS_C */ #endif /* !MAKEDEFS_C && CROSSCOMPILE_TARGET */
} }
idxopttext = 0; idxopttext = 0;
build_options(); build_options();
+20 -19
View File
@@ -356,13 +356,14 @@ CURSESOBJ= $(O)cursdial.o $(O)cursinit.o $(O)cursinvt.o $(O)cursmain.o \
SOBJ = $(O)windmain.o $(O)winnt.o $(O)win10.o \ SOBJ = $(O)windmain.o $(O)winnt.o $(O)win10.o \
$(O)safeproc.o $(O)nhlan.o $(SOUND) $(O)safeproc.o $(O)nhlan.o $(SOUND)
OBJS = $(VOBJ01) $(VOBJ02) $(VOBJ03) $(VOBJ04) $(VOBJ05) \ OBJS = $(MDLIB) \
$(VOBJ06) $(VOBJ07) $(VOBJ08) $(VOBJ09) $(VOBJ10) \ $(VOBJ01) $(VOBJ02) $(VOBJ03) $(VOBJ04) $(VOBJ05) \
$(VOBJ11) $(VOBJ12) $(VOBJ13) $(VOBJ14) $(VOBJ15) \ $(VOBJ06) $(VOBJ07) $(VOBJ08) $(VOBJ09) $(VOBJ10) \
$(VOBJ16) $(VOBJ17) $(VOBJ18) $(VOBJ19) $(VOBJ20) \ $(VOBJ11) $(VOBJ12) $(VOBJ13) $(VOBJ14) $(VOBJ15) \
$(VOBJ21) $(VOBJ22) $(VOBJ23) $(VOBJ24) $(VOBJ25) \ $(VOBJ16) $(VOBJ17) $(VOBJ18) $(VOBJ19) $(VOBJ20) \
$(VOBJ26) $(VOBJ27) $(VOBJ28) $(VOBJ29) $(VOBJ30) \ $(VOBJ21) $(VOBJ22) $(VOBJ23) $(VOBJ24) $(VOBJ25) \
$(REGEX) $(CURSESOBJ) $(MDLIB) $(VOBJ26) $(VOBJ27) $(VOBJ28) $(VOBJ29) $(VOBJ30) \
$(REGEX) $(CURSESOBJ)
WINDHDR = $(MSWSYS)\win10.h $(MSWSYS)\winos.h $(MSWSYS)\win32api.h WINDHDR = $(MSWSYS)\win10.h $(MSWSYS)\winos.h $(MSWSYS)\win32api.h
@@ -904,7 +905,7 @@ $(GAMEDIR)\NetHack.exe : $(O)gamedir.tag $(O)tile.o $(O)nttty.o $(O)guistub.o \
$(ALLOBJ) $(TTYOBJ) $(O)console.res $(KEYDLLS) \ $(ALLOBJ) $(TTYOBJ) $(O)console.res $(KEYDLLS) \
$(LUATARGETS) $(PDCLIB) $(LUATARGETS) $(PDCLIB)
@if not exist $(GAMEDIR)\*.* mkdir $(GAMEDIR) @if not exist $(GAMEDIR)\*.* mkdir $(GAMEDIR)
@echo Linking $(@:\=/) @echo Linking $(@:\=/)
$(link) $(lflagsBuild) $(conlflags) /STACK:2048 /PDB:$(GAMEDIR)\$(@B).PDB /MAP:$(O)$(@B).MAP \ $(link) $(lflagsBuild) $(conlflags) /STACK:2048 /PDB:$(GAMEDIR)\$(@B).PDB /MAP:$(O)$(@B).MAP \
$(LIBS) $(PDCLIB) $(LUALIB) \ $(LIBS) $(PDCLIB) $(LUALIB) \
$(conlibs) $(BCRYPT) -out:$@ @<<$(@B).lnk $(conlibs) $(BCRYPT) -out:$@ @<<$(@B).lnk
@@ -1035,7 +1036,7 @@ $(O)sp_lev.tag:
$(O)utility.tag: $(INCL)\nhlua.h $(INCL)\date.h $(INCL)\onames.h $(INCL)\pm.h \ $(O)utility.tag: $(INCL)\nhlua.h $(INCL)\date.h $(INCL)\onames.h $(INCL)\pm.h \
$(SRC)\vis_tab.c $(INCL)\vis_tab.h $(TILEUTIL16) $(SRC)\vis_tab.c $(INCL)\vis_tab.h $(TILEUTIL16)
@echo utilities made >$@ @echo utilities made >$@
@echo utilities made. @echo utilities made.
$(INCL)\nhlua.h: $(INCL)\nhlua.h:
@@ -1193,7 +1194,7 @@ $(O)envchk.tag: $(O)obj.tag
# @echo Warning, the CL Environment variable is defined: # @echo Warning, the CL Environment variable is defined:
# @echo CL=$(CL) # @echo CL=$(CL)
! ENDIF ! ENDIF
echo envchk >$@ echo envchk >$@
#========================================== #==========================================
#=========== SECONDARY TARGETS ============ #=========== SECONDARY TARGETS ============
@@ -1625,15 +1626,15 @@ spotless: clean
if exist $(O)gamedir.tag del $(O)gamedir.tag if exist $(O)gamedir.tag del $(O)gamedir.tag
if exist $(O)nh*key.lib del $(O)nh*key.lib if exist $(O)nh*key.lib del $(O)nh*key.lib
if exist $(O)nh*key.exp del $(O)nh*key.exp if exist $(O)nh*key.exp del $(O)nh*key.exp
if exist $(MSWIN)\mnsel.bmp del $(MSWIN)\mnsel.bmp if exist $(MSWIN)\mnsel.bmp del $(MSWIN)\mnsel.bmp
if exist $(MSWIN)\mnselcnt.bmp del $(MSWIN)\mnselcnt.bmp if exist $(MSWIN)\mnselcnt.bmp del $(MSWIN)\mnselcnt.bmp
if exist $(MSWIN)\mnunsel.bmp del $(MSWIN)\mnunsel.bmp if exist $(MSWIN)\mnunsel.bmp del $(MSWIN)\mnunsel.bmp
if exist $(MSWIN)\petmark.bmp del $(MSWIN)\petmark.bmp if exist $(MSWIN)\petmark.bmp del $(MSWIN)\petmark.bmp
if exist $(MSWIN)\pilemark.bmp del $(MSWIN)\pilemark.bmp if exist $(MSWIN)\pilemark.bmp del $(MSWIN)\pilemark.bmp
if exist $(MSWIN)\rip.bmp del $(MSWIN)\rip.bmp if exist $(MSWIN)\rip.bmp del $(MSWIN)\rip.bmp
if exist $(MSWIN)\splash.bmp del $(MSWIN)\splash.bmp if exist $(MSWIN)\splash.bmp del $(MSWIN)\splash.bmp
if exist $(MSWIN)\nethack.ico del $(MSWIN)\nethack.ico if exist $(MSWIN)\nethack.ico del $(MSWIN)\nethack.ico
if exist $(MSWSYS)\nethack.ico del $(MSWSYS)\nethack.ico if exist $(MSWSYS)\nethack.ico del $(MSWSYS)\nethack.ico
if exist $(U)recover.exe del $(U)recover.exe if exist $(U)recover.exe del $(U)recover.exe
if exist $(U)tile2bmp.exe del $(U)tile2bmp.exe if exist $(U)tile2bmp.exe del $(U)tile2bmp.exe
if exist $(U)tilemap.exe del $(U)tilemap.exe if exist $(U)tilemap.exe del $(U)tilemap.exe