From 41ac4aef9272d17525c19fe91d118d210ece05ac Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 21 Mar 2015 15:38:31 -0400 Subject: [PATCH 01/10] fix SYSCF so that things build when first defined Things won't build for ports that first define SYSCF. This moves assure_syscf_file() from unixmain.c to files.c and adjusts extern.h to get it out from under #ifdef UNIX. The call to assure_syscf_file() in options.c was only #ifdef SYSCF, SYSCF_FILE and not UNIX, so new ports #defining SYSCF would get an erro. assure_syscf_file() will be utilized by mswin when SYSCF is defined. --- include/extern.h | 8 ++++---- include/ntconf.h | 5 ++++- src/files.c | 25 ++++++++++++++++++++++++- sys/share/pcmain.c | 7 +++++-- sys/unix/unixmain.c | 18 +----------------- 5 files changed, 38 insertions(+), 25 deletions(-) diff --git a/include/extern.h b/include/extern.h index 1ba3e110f..da9bf7eff 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1,4 +1,4 @@ -/* NetHack 3.5 extern.h $NHDT-Date: 1426496453 2015/03/16 09:00:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.407 $ */ +/* NetHack 3.5 extern.h $NHDT-Date: 1426966688 2015/03/21 19:38:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.411 $ */ /* NetHack 3.5 extern.h $Date: 2013/11/05 00:57:53 $ $Revision: 1.380 $ */ /* Copyright (c) Steve Creps, 1988. */ /* NetHack may be freely redistributed. See license for details. */ @@ -739,6 +739,9 @@ E void FDECL(free_saved_games, (char**)); #ifdef SELF_RECOVER E boolean NDECL(recover_savefile); #endif +#ifdef SYSCF_FILE +E void NDECL(assure_syscf_file); +#endif #ifdef HOLD_LOCKFILE_OPEN E void NDECL(really_close); #endif @@ -2288,9 +2291,6 @@ E void NDECL(port_help); E void FDECL(sethanguphandler, (void (*)(int))); E boolean NDECL(authorize_wizard_mode); E boolean FDECL(check_user_string, (char *)); -# ifdef SYSCF_FILE -E void NDECL(assure_syscf_file); -# endif #endif /* UNIX */ /* ### unixtty.c ### */ diff --git a/include/ntconf.h b/include/ntconf.h index 95a506635..b51459151 100644 --- a/include/ntconf.h +++ b/include/ntconf.h @@ -1,4 +1,4 @@ -/* NetHack 3.5 ntconf.h $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.5 ntconf.h $NHDT-Date: 1426966690 2015/03/21 19:38:10 $ $NHDT-Branch: master $:$NHDT-Revision: 1.37 $ */ /* NetHack 3.5 ntconf.h $Date: 2012/01/15 19:11:38 $ $Revision: 1.35 $ */ /* SCCS Id: @(#)ntconf.h 3.5 2002/03/10 */ /* Copyright (c) NetHack PC Development Team 1993, 1994. */ @@ -25,6 +25,9 @@ #define SELF_RECOVER /* Allow the game itself to recover from an aborted game */ +#define SYSCF /* Use a global configuration */ +#define SYSCF_FILE "sysconf" /* Use a file to hold the SYSCF configuration */ + #define USER_SOUNDS #ifdef WIN32CON diff --git a/src/files.c b/src/files.c index a6f17b906..e85a85ae4 100644 --- a/src/files.c +++ b/src/files.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 files.c $NHDT-Date: 1426544796 2015/03/16 22:26:36 $ $NHDT-Branch: master $:$NHDT-Revision: 1.134 $ */ +/* NetHack 3.5 files.c $NHDT-Date: 1426966692 2015/03/21 19:38:12 $ $NHDT-Branch: master $:$NHDT-Revision: 1.135 $ */ /* NetHack 3.5 files.c $Date: 2012/03/10 02:49:08 $ $Revision: 1.124 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -3199,6 +3199,29 @@ int ifd, ofd; /* ---------- END INTERNAL RECOVER ----------- */ #endif /*SELF_RECOVER*/ +/* ---------- OTHER ----------- */ + +#ifdef SYSCF +# ifdef SYSCF_FILE +void +assure_syscf_file() { + /* All we really care about is the end result - can we read the file? + * So just check that directly. */ + int fd; + fd = open(SYSCF_FILE, O_RDONLY); + if(fd >= 0){ + /* readable */ + close(fd); + return; + } + raw_printf("Unable to open SYSCF_FILE.\n"); + exit(EXIT_FAILURE); +} + +# endif /* SYSCF_FILE */ +#endif /* SYSCF */ + + #ifdef DEBUG /* used by debugpline() to decide whether to issue a message from a partiular source file; caller passes __FILE__ and we check diff --git a/sys/share/pcmain.c b/sys/share/pcmain.c index 6635c56ad..67ae57dba 100644 --- a/sys/share/pcmain.c +++ b/sys/share/pcmain.c @@ -1,9 +1,9 @@ -/* NetHack 3.5 pcmain.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.5 pcmain.c $NHDT-Date: 1426966701 2015/03/21 19:38:21 $ $NHDT-Branch: master $:$NHDT-Revision: 1.51 $ */ /* NetHack 3.5 pcmain.c $Date: 2012/01/20 03:41:31 $ $Revision: 1.48 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ -/* main.c - MSDOS, OS/2, ST, Amiga, and NT NetHack */ +/* main.c - MSDOS, OS/2, ST, Amiga, and Windows NetHack */ #include "hack.h" #include "dlb.h" @@ -244,6 +244,9 @@ char *argv[]; #if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) chdirx(hackdir,0); +#endif +#ifdef SYSCF + initoptions(); #endif prscore(argc, argv); nethack_exit(EXIT_SUCCESS); diff --git a/sys/unix/unixmain.c b/sys/unix/unixmain.c index c470dc6e0..f7f1ac87e 100644 --- a/sys/unix/unixmain.c +++ b/sys/unix/unixmain.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 unixmain.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.5 unixmain.c $NHDT-Date: 1426966705 2015/03/21 19:38:25 $ $NHDT-Branch: master $:$NHDT-Revision: 1.44 $ */ /* NetHack 3.5 unixmain.c $Date: 2012/01/27 20:15:31 $ $Revision: 1.42 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -648,20 +648,4 @@ get_unix_pw() return pw; } -#ifdef SYSCF_FILE -void -assure_syscf_file(){ - /* All we really care about is the end result - can we read the file? - * So just check that directly. */ - int fd; - fd = open(SYSCF_FILE, O_RDONLY); - if(fd >= 0){ - /* readable */ - close(fd); - return; - } - raw_printf("Unable to open SYSCF_FILE.\n"); - exit(EXIT_FAILURE); -} -#endif /*unixmain.c*/ From 734d118d39c3fca6b3267e2ade39601c285631db Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 21 Mar 2015 15:50:03 -0400 Subject: [PATCH 02/10] a sys/winnt/Makefile.msc update --- sys/winnt/Makefile.msc | 92 ++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/sys/winnt/Makefile.msc b/sys/winnt/Makefile.msc index 0216092cc..a1dfdbcd8 100644 --- a/sys/winnt/Makefile.msc +++ b/sys/winnt/Makefile.msc @@ -1,4 +1,4 @@ -# NetHack 3.5 Makefile.msc $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +# NetHack 3.5 Makefile.msc $NHDT-Date: 1426967393 2015/03/21 19:49:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.72 $ */ # Copyright (c) NetHack PC Development Team 1993-2015 # #============================================================================== @@ -79,6 +79,13 @@ TARGET_CPU=x86 GAMEDIR = ..\binary # Game directory +# +#--------------------------------------------------------------- +# 4. Do you want debug information in the executable? +# + +DEBUGINFO = Y + # This marks the end of the BUILD DECISIONS section. #============================================================================== # @@ -111,7 +118,7 @@ DOC = ..\doc # NetHack documentation files UTIL = ..\util # Utility source SRC = ..\src # Main source SSYS = ..\sys\share # Shared system files -NTSYS = ..\sys\winnt # NT Win32 specific files +MSWSYS= ..\sys\winnt # mswin specific files TTY = ..\win\tty # window port files (tty) WIN32 = ..\win\win32 # window port files (Win32) WSHR = ..\win\share # Tile support files @@ -144,7 +151,7 @@ TARGET_CPU=x86 # -Zd - generate only public symbols and line numbers for debugging # -GS - enable security checks # -ccommon=-c -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -nologo -GS -c +ccommon=-c $(CDBFLAG) -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -nologo -GS -c lflags=/INCREMENTAL:NO /NOLOGO !IF "$(TARGET_CPU)" == "x86" @@ -201,18 +208,6 @@ guilibs = $(winlibs) RANDOM = $(OBJ)\random.o #RANDOM = -# -# Uncomment the next 2 lines _ONLY_ if you DO NOT want any -# debug capability in the object files, or in the NetHack executable. -# Comment them if you want debug capability. - -#ldebug = -#cdebug = - -# -# Compiler and Linker flags -# - PRECOMPHEAD = N # set to Y if you want to use precomp. headers # @@ -276,10 +271,20 @@ DLBFLG = #========================================== #========================================== -PDBFILE= /PDB:"$(O)$(GAME).PDB" -MAPFILE= /MAP:"$(O)$(GAME).MAP" INCLDIR= /I..\include +!IF "$(DEBUGINFO)" == "Y" +CDBGFLAG=-Zi +LDBGFLAG=/debug +cdebug = -Zi -Od +ldebug = /DEBUG +!ELSE +CDBGFLAG= +LDBGFLAG= +ldebug = +cdebug = +!ENDIF + !IF ("$(ldebug)" != "") !IF ("$(ldebug)" != "/RELEASE") ldebug = /DEBUG @@ -316,14 +321,14 @@ LIBS= user32.lib winmm.lib $(ZLIB) !IF ("$(GRAPHICAL)"=="Y") cflagsGame = $(cdebug) $(cflags2) $(guiflags) $(INCLDIR) \ - $(WINPFLAG) $(DLBFLG) $(GAMEPDBFILE) $(GAMEMAPFILE) -lflagsGame = $(ldebug) $(lflags) $(guilibs) + $(WINPFLAG) $(DLBFLG) +lflagsGame = $(ldebug) $(lflags) $(guilibs) $(GAMEPDBFILE) $(GAMEMAPFILE) !ELSE cflagsGame = $(cdebug) $(cflags2) $(conflags) $(INCLDIR) \ - $(WINPFLAG) $(DLBFLG) $(GAMEPDBFILE) $(GAMEMAPFILE) -lflagsGame = $(ldebug) $(lflags) $(conlibs) + $(WINPFLAG) $(DLBFLG) +lflagsGame = $(ldebug) $(lflags) $(conlibs) $(GAMEPDBFILE) $(GAMEMAPFILE) !ENDIF @@ -362,10 +367,10 @@ DLB = # Rules for files in sys\winnt #========================================== -{$(NTSYS)}.c{$(OBJ)}.o: +{$(MSWSYS)}.c{$(OBJ)}.o: @$(CC) $(cflagsUtil) -Fo$@ $< -{$(NTSYS)}.h{$(INCL)}.h: +{$(MSWSYS)}.h{$(INCL)}.h: @copy $< $@ #========================================== @@ -410,7 +415,7 @@ DLB = # referenced later on in the Makefile. # -DEFFILE = $(NTSYS)\$(GAME).def +DEFFILE = $(MSWSYS)\$(GAME).def # # Shorten up the location for some files @@ -595,15 +600,16 @@ $(O)install.tag: $(DAT)\data $(DAT)\rumors $(DAT)\dungeon \ copy $(DAT)\*.lev $(GAMEDIR) if exist $(GAMEDIR)\makefile del $(GAMEDIR)\makefile ! ENDIF + if not exist $(GAMEDIR)\sysconf copy $(MSWSYS)\sysconf $(GAMEDIR) if exist $(DAT)\symbols copy $(DAT)\symbols $(GAMEDIR) if exist $(DOC)\guidebook.txt copy $(DOC)\guidebook.txt $(GAMEDIR)\Guidebook.txt if exist $(DOC)\nethack.txt copy $(DOC)\nethack.txt $(GAMEDIR)\NetHack.txt @if exist $(O)$(GAME).PDB copy $(O)$(GAME).pdb $(GAMEDIR)\$(GAME).pdb @if exist $(GAMEDIR)\$(GAME).PDB echo NOTE: You may want to remove $(GAMEDIR)\$(GAME).pdb to conserve space - -copy $(NTSYS)\defaults.nh $(GAMEDIR)\defaults.nh + -copy $(MSWSYS)\defaults.nh $(GAMEDIR)\defaults.nh echo install done > $@ -# copy $(NTSYS)\winnt.hlp $(GAMEDIR) +# copy $(MSWSYS)\winnt.hlp $(GAMEDIR) recover: $(U)recover.exe if exist $(U)recover.exe copy $(U)recover.exe $(GAMEDIR) @@ -662,8 +668,8 @@ $(NHRES): $(TILEBMP16) $(WIN32)\winhack.rc $(WIN32)\mnsel.bmp \ $(WIN32)\splash.bmp @$(rc) -r -fo$@ -i$(WIN32) -dNDEBUG $(WIN32)\winhack.rc !ELSE -$(NHRES): $(NTSYS)\console.rc $(NTSYS)\NetHack.ico - @$(rc) -r -fo$@ -i$(NTSYS) -dNDEBUG $(NTSYS)\console.rc +$(NHRES): $(MSWSYS)\console.rc $(MSWSYS)\NetHack.ico + @$(rc) -r -fo$@ -i$(MSWSYS) -dNDEBUG $(MSWSYS)\console.rc !ENDIF #========================================== @@ -834,12 +840,12 @@ $(U)uudecode.exe: $(O)uudecode.o $(O)uudecode.o: $(SSYS)\uudecode.c @$(CC) $(cflagsUtil) /D_CRT_SECURE_NO_DEPRECATE -Fo$@ $(SSYS)\uudecode.c -$(NTSYS)\NetHack.ico : $(U)uudecode.exe $(NTSYS)\nhico.uu - chdir $(NTSYS) +$(MSWSYS)\NetHack.ico : $(U)uudecode.exe $(MSWSYS)\nhico.uu + chdir $(MSWSYS) ..\..\util\uudecode.exe nhico.uu chdir ..\..\src -$(WIN32)\NetHack.ico : $(U)uudecode.exe $(NTSYS)\nhico.uu +$(WIN32)\NetHack.ico : $(U)uudecode.exe $(MSWSYS)\nhico.uu chdir $(WIN32) ..\..\util\uudecode.exe ../../sys/winnt/nhico.uu chdir ..\..\src @@ -974,8 +980,8 @@ envchk: # Header files NOT distributed in $(INCL) #=========================================== -$(INCL)\win32api.h: $(NTSYS)\win32api.h - copy $(NTSYS)\win32api.h $@ +$(INCL)\win32api.h: $(MSWSYS)\win32api.h + copy $(MSWSYS)\win32api.h $@ #========================================== @@ -996,8 +1002,8 @@ $(O)dlb.o: $(O)dlb_main.o $(O)alloc.o $(O)panic.o $(INCL)\dlb.h $(O)dlb_main.o: $(UTIL)\dlb_main.c $(INCL)\config.h $(INCL)\dlb.h @$(CC) $(cflagsUtil) /Fo$@ $(UTIL)\dlb_main.c -$(DAT)\porthelp: $(NTSYS)\porthelp - @copy $(NTSYS)\porthelp $@ >nul +$(DAT)\porthelp: $(MSWSYS)\porthelp + @copy $(MSWSYS)\porthelp $@ >nul nhdat: $(U)dlb_main.exe $(DAT)\data $(DAT)\oracles $(OPTIONS_FILE) \ $(DAT)\quest.dat $(DAT)\rumors $(DAT)\help $(DAT)\hh $(DAT)\cmdhelp \ @@ -1292,14 +1298,14 @@ $(DAT)\dungeon: $(O)utility.tag $(DAT)\dungeon.def # NT dependencies # -$(O)nttty.o: $(HACK_H) $(TILE_H) $(INCL)\win32api.h $(NTSYS)\nttty.c - @$(CC) $(cflagsUtil) -I$(WSHR) -Fo$@ $(NTSYS)\nttty.c -$(O)nhkeys.o: $(HACK_H) $(TILE_H) $(INCL)\win32api.h $(NTSYS)\nhkeys.c - @$(CC) $(cflagsUtil) -I$(WSHR) -Fo$@ $(NTSYS)\nhkeys.c -$(O)winnt.o: $(HACK_H) $(INCL)\win32api.h $(NTSYS)\winnt.c - @$(CC) $(cflagsUtil) -Fo$@ $(NTSYS)\winnt.c -$(O)ntsound.o: $(HACK_H) $(NTSYS)\ntsound.c - @$(CC) $(cflagsUtil) -Fo$@ $(NTSYS)\ntsound.c +$(O)nttty.o: $(HACK_H) $(TILE_H) $(INCL)\win32api.h $(MSWSYS)\nttty.c + @$(CC) $(cflagsUtil) -I$(WSHR) -Fo$@ $(MSWSYS)\nttty.c +$(O)nhkeys.o: $(HACK_H) $(TILE_H) $(INCL)\win32api.h $(MSWSYS)\nhkeys.c + @$(CC) $(cflagsUtil) -I$(WSHR) -Fo$@ $(MSWSYS)\nhkeys.c +$(O)winnt.o: $(HACK_H) $(INCL)\win32api.h $(MSWSYS)\winnt.c + @$(CC) $(cflagsUtil) -Fo$@ $(MSWSYS)\winnt.c +$(O)ntsound.o: $(HACK_H) $(MSWSYS)\ntsound.c + @$(CC) $(cflagsUtil) -Fo$@ $(MSWSYS)\ntsound.c # # util dependencies From b8515fb5fdbb8efe4d8db4bcfe35dfe454f2ef3e Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 21 Mar 2015 15:54:30 -0400 Subject: [PATCH 03/10] throw in a windows sysconf skeleton --- sys/winnt/sysconf | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 sys/winnt/sysconf diff --git a/sys/winnt/sysconf b/sys/winnt/sysconf new file mode 100644 index 000000000..67c0b814d --- /dev/null +++ b/sys/winnt/sysconf @@ -0,0 +1,78 @@ +# +# NetHack 3.5 sysconf $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ +# NetHack 3.5 sysconf $Date: 2012/01/27 20:15:31 $ $Revision: 1.6 $ +# +# Sample sysconf file. +# The sysconf file is only used if NetHack is compiled with SYSCF defined. +# This file uses the same syntax as nethack.cf. + +# Which users can use WIZARD (debugging) mode (the -D flag). +# A value of * allows anyone to enter debugging mode. +WIZARDS=* + +# Users allowed to use the ! (shell escape) command or to suspend the game. +# Uses the same syntax as the WIZARDS option above. +#SHELLERS= + +# Show debugging information originating from these source files. +# Use '*' for all, or list source files separated by spaces. +# Only available if game has been compiled with DEBUG. +#DEBUGFILES=* + +# Limit the number of simultaneous games (see also nethack.sh). +#MAXPLAYERS=10 + +# If not null, added to string "To get local support, " in the support +# information help. +#SUPPORT=call Izchak at extension 42. + +# Uncomment the next line to disable the SEDUCE option. +#SEDUCE=0 + +# Record (high score) file options. +# CAUTION: changing these after people have started playing games can +# lead to lost high scores! +# Maximum entries for one person. +#PERSMAX=10 +# Maximum entries in the record file. +#ENTRYMAX=100 +# Minimum points to get an entry. +#POINTSMIN=1 +# Determine identity of "person" in the score file with name (0) or +# numeric (1) user id. +#PERS_IS_UID=1 + +# Maximum number of score file entries to use for random statue names +#MAX_STATUENAME_RANK=10 + +# *** LOCATIONS *** +# IMPORTANT: If you change any of these locations, the directories they +# point at must exist. NetHack will not create them for you. +# +# HACKDIR is the default location for everything. +# Note: On Windows HACKDIR defaults to the location +# of the NetHack.exe or NetHackw.exe file so +# setting HACKDIR below to override that is +# not usually necessary or recommended. +#HACKDIR=c:\games\nethack +# +# The location that users can adjust their config file startup options +#CONFIGDIR=c:\games\nethack +# +# The location that level files in progress are stored (default=HACKDIR, writeable) +#LEVELDIR=c:\nethack\levels +# +# The location where saved games are kept (default=HACKDIR, writeable) +#SAVEDIR=c:\nethack\save +# +# The location that bones files are kept (default=HACKDIR, writeable) +#BONESDIR=c:\nethack\save +# +# The location that file synchronization locks are stored (default=HACKDIR, writeable) +#LOCKDIR=c:\nethack\levels +# +# The location that a record of game aborts and self-diagnosed game problems +# is kept (default=HACKDIR, writeable) +#TROUBLEDIR=c:\nethack\trouble + + From 349e264ac3eccab996cc065867cd2808785d9e32 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 21 Mar 2015 16:01:03 -0400 Subject: [PATCH 04/10] remove a troublesome line of code Whenever SYSCF was enabled on Windows, the option processing would go bonkers with illegal options at startup. I noticed it months ago, and Derek had it happen the other evening. It turns out, the hard-coded 'defaults.nh' setting was being overwritten with the name sysconf on the first SET_IN_SYS pass, so all subsequent passes were re-opening the SYSC_FILE instead of the user config file. I opted to take it out as I couldn't ascertain why it was there in the first place. --- src/files.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/files.c b/src/files.c index e85a85ae4..eeebd6e08 100644 --- a/src/files.c +++ b/src/files.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 files.c $NHDT-Date: 1426966692 2015/03/21 19:38:12 $ $NHDT-Branch: master $:$NHDT-Revision: 1.135 $ */ +/* NetHack 3.5 files.c $NHDT-Date: 1426968058 2015/03/21 20:00:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.136 $ */ /* NetHack 3.5 files.c $Date: 2012/03/10 02:49:08 $ $Revision: 1.124 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1858,7 +1858,6 @@ int src; } else #endif if ((fp = fopenp(filename, "r")) != (FILE *)0) { - configfile = filename; return(fp); #if defined(UNIX) || defined(VMS) } else { From af9af8b7018f481588098974872b887bd8ad63cc Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 21 Mar 2015 16:17:17 -0400 Subject: [PATCH 05/10] put mystery line back but !WIN32 Since that line of code is used by a lot of different ports, I decided to recant its removal and just add #ifdef to ensure it isn't compiled on WIN32. I think other ports might encounter the same issue where the first pass with filename set to 'sysconf', is then going to overwrite the hard-coded user config file name, but I can't fix or test those so for those ports, it will be now be back the way it was. --- src/files.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/files.c b/src/files.c index eeebd6e08..b9942246a 100644 --- a/src/files.c +++ b/src/files.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 files.c $NHDT-Date: 1426968058 2015/03/21 20:00:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.136 $ */ +/* NetHack 3.5 files.c $NHDT-Date: 1426969026 2015/03/21 20:17:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.137 $ */ /* NetHack 3.5 files.c $Date: 2012/03/10 02:49:08 $ $Revision: 1.124 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1858,6 +1858,9 @@ int src; } else #endif if ((fp = fopenp(filename, "r")) != (FILE *)0) { +#ifndef WIN32 + configfile = filename; +#endif return(fp); #if defined(UNIX) || defined(VMS) } else { From 91b13d939a7c4e5409cff4b855127b558c2fcd27 Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 21 Mar 2015 15:36:47 -0700 Subject: [PATCH 06/10] wishing fix for "eyes" No, not a blindness cure. :-} Post-3.4.3 revisions to makesingular() inadvertently made it impossible to successfully wish for "the Eyes of the Overworld" because the string got changed into "the Eye of the Overworld" which doesn't match anything. So don't singularize "eyes". (After this fix, wishing for "the Eyes of the Aethiopica" no longer yields the Eye of same, but I think that's the correct behavior.) --- src/objnam.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/objnam.c b/src/objnam.c index fe692b226..898dfb60a 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 objnam.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.5 objnam.c $NHDT-Date: 1426977394 2015/03/21 22:36:34 $ $NHDT-Branch: master $:$NHDT-Revision: 1.108 $ */ /* NetHack 3.5 objnam.c $Date: 2011/10/27 02:24:54 $ $Revision: 1.101 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1682,7 +1682,7 @@ static struct sing_plur one_off[] = { static const char *const as_is[] = { /* makesingular() leaves these plural due to how they're used */ "boots", "shoes", - "gloves", "lenses", "scales", + "gloves", "lenses", "scales", "eyes", "gauntlets", "iron bars", /* both singular and plural are spelled the same */ From 86959fe242fe238ab8266345acd1c34ba985850d Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 21 Mar 2015 19:24:08 -0700 Subject: [PATCH 07/10] fix "mysterious force" probabilities in do.c comment Reported by Alex, the probabilites shown in the comment about the effect of the mysterious force have been wrong ever since they were added 20 or so years ago. Lawfuls and neutrals are much more likely to go down just one level rather than 2 or 3. --- src/do.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/do.c b/src/do.c index 34635af72..b387752d6 100644 --- a/src/do.c +++ b/src/do.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 do.c $NHDT-Date: 1426497723 2015/03/16 09:22:03 $ $NHDT-Branch: H3724 $:$NHDT-Revision: 1.109 $ */ +/* NetHack 3.5 do.c $NHDT-Date: 1426991040 2015/03/22 02:24:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.111 $ */ /* NetHack 3.5 do.c $Date: 2014/11/18 03:10:39 $ $Revision: 1.101 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1014,15 +1014,18 @@ boolean at_stairs, falling, portal; /* If you have the amulet and are trying to get out of Gehennom, going * up a set of stairs sometimes does some very strange things! - * Biased against law and towards chaos, but not nearly as strongly - * as it used to be (prior to 3.2.0). - * Odds: old new - * "up" L N C "up" L N C - * +1 75.0 75.0 75.0 +1 75.0 75.0 75.0 - * 0 0.0 12.5 25.0 0 6.25 8.33 12.5 - * -1 8.33 4.17 0.0 -1 6.25 8.33 12.5 - * -2 8.33 4.17 0.0 -2 6.25 8.33 0.0 - * -3 8.33 4.17 0.0 -3 6.25 0.0 0.0 + * Biased against law and towards chaos. (The chance to be sent + * down multiple levels when attempting to go up are significantly + * less than the corresponding comment in older versions indicated + * due to overlooking the effect of the call to assign_rnd_lvl().) + * + * Odds for making it to the next level up, or of being sent down: + * "up" L N C + * +1 75.0 75.0 75.0 + * 0 6.25 8.33 12.5 + * -1 11.46 12.50 12.5 + * -2 5.21 4.17 0.0 + * -3 2.08 0.0 0.0 */ if (Inhell && up && u.uhave.amulet && !newdungeon && !portal && (dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz)-3)) { From c3c968f87cc04ee155b970c927cbf2b109b76f16 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sun, 22 Mar 2015 10:44:36 -0400 Subject: [PATCH 08/10] options and config file handling With SYSCF, the SYSCF_FILE name was overwriting the default config file name making it unavailable for subsequent user config file options handling. - Keep the name of the last config file successfully opened. - Do it without orphaning the default config file name needed for the next pass. --- include/decl.h | 3 ++- src/files.c | 55 +++++++++++++++++++++++++++++++++----------------- src/options.c | 10 ++++----- 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/include/decl.h b/include/decl.h index bacff08d9..5dea2ff43 100644 --- a/include/decl.h +++ b/include/decl.h @@ -1,4 +1,4 @@ -/* NetHack 3.5 decl.h $NHDT-Date: 1425081976 2015/02/28 00:06:16 $ $NHDT-Branch: master $:$NHDT-Revision: 1.50 $ */ +/* NetHack 3.5 decl.h $NHDT-Date: 1427035422 2015/03/22 14:43:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.56 $ */ /* NetHack 3.5 decl.h $Date: 2011/12/29 20:06:27 $ $Revision: 1.44 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -184,6 +184,7 @@ E NEARDATA struct kinfo { E long done_money; E const char *configfile; +E char lastconfigfile[BUFSZ]; /* used for messaging */ E NEARDATA char plname[PL_NSIZ]; E NEARDATA char dogname[]; E NEARDATA char catname[]; diff --git a/src/files.c b/src/files.c index b9942246a..e638fa640 100644 --- a/src/files.c +++ b/src/files.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 files.c $NHDT-Date: 1426969026 2015/03/21 20:17:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.137 $ */ +/* NetHack 3.5 files.c $NHDT-Date: 1427035432 2015/03/22 14:43:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.138 $ */ /* NetHack 3.5 files.c $Date: 2012/03/10 02:49:08 $ $Revision: 1.124 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1811,6 +1811,8 @@ const char *configfile = # endif #endif +/* used for messaging */ +char lastconfigfile[BUFSZ]; #ifdef MSDOS /* conflict with speed-dial under windows @@ -1857,10 +1859,9 @@ int src; /* fall through to standard names */ } else #endif - if ((fp = fopenp(filename, "r")) != (FILE *)0) { -#ifndef WIN32 - configfile = filename; -#endif + (void) strncpy(lastconfigfile, filename, BUFSZ-1); + lastconfigfile[BUFSZ-1] = '\0'; + if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) { return(fp); #if defined(UNIX) || defined(VMS) } else { @@ -1874,24 +1875,32 @@ int src; } #if defined(MICRO) || defined(MAC) || defined(__BEOS__) || defined(WIN32) - if ((fp = fopenp(fqname(configfile, CONFIGPREFIX, 0), "r")) - != (FILE *)0) + (void) strncpy(lastconfigfile, + fqname(configfile, CONFIGPREFIX, 0), BUFSZ-1); + lastconfigfile[BUFSZ-1] = '\0'; + if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) { return(fp); + } # ifdef MSDOS - else if ((fp = fopenp(fqname(backward_compat_configfile, - CONFIGPREFIX, 0), "r")) != (FILE *)0) + (void) strncpy(lastconfigfile, + fqname(backward_compat_configfile, CONFIGPREFIX, 0), + BUFSZ-1); + lastconfigfile[BUFSZ-1] = '\0'; + else if ((fp = fopenp(fqname(lastconfigfile, "r")) != (FILE *)0) return(fp); # endif #else /* constructed full path names don't need fqname() */ # ifdef VMS - if ((fp = fopenp(fqname("nethackini", CONFIGPREFIX, 0), "r")) - != (FILE *)0) { - configfile = "nethackini"; + (void) strncpy(lastconfigfile, fqname("nethackini", CONFIGPREFIX, 0), + BUFSZ-1); + lastconfigfile[BUFSZ-1] = '\0'; + if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) { return(fp); } - if ((fp = fopenp("sys$login:nethack.ini", "r")) != (FILE *)0) { - configfile = "nethack.ini"; + (void) strncpy(lastconfigfile,"sys$login:nethack.ini", BUFSZ-1); + lastconfigfile[BUFSZ-1] = '\0'; + if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) { return(fp); } @@ -1900,6 +1909,9 @@ int src; Strcpy(tmp_config, "NetHack.cnf"); else Sprintf(tmp_config, "%s%s", envp, "NetHack.cnf"); + + (void) strncpy(lastconfigfile, tmp_config, BUFSZ-1); + lastconfigfile[BUFSZ-1] = '\0'; if ((fp = fopenp(tmp_config, "r")) != (FILE *)0) return(fp); # else /* should be only UNIX left */ @@ -1908,18 +1920,25 @@ int src; Strcpy(tmp_config, ".nethackrc"); else Sprintf(tmp_config, "%s/%s", envp, ".nethackrc"); - if ((fp = fopenp(tmp_config, "r")) != (FILE *)0) + + (void) strncpy(lastconfigfile, tmp_config, BUFSZ-1); + lastconfigfile[BUFSZ-1] = '\0'; + if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) return(fp); # if defined(__APPLE__) /* try an alternative */ if (envp) { Sprintf(tmp_config, "%s/%s", envp, "Library/Preferences/NetHack Defaults"); - if ((fp = fopenp(tmp_config, "r")) != (FILE *)0) + (void) strncpy(lastconfigfile, tmp_config, BUFSZ-1); + lastconfigfile[BUFSZ-1] = '\0'; + if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) return(fp); Sprintf(tmp_config, "%s/%s", envp, "Library/Preferences/NetHack Defaults.txt"); - if ((fp = fopenp(tmp_config, "r")) != (FILE *)0) + (void) strncpy(lastconfigfile, tmp_config, BUFSZ-1); + lastconfigfile[BUFSZ-1] = '\0'; + if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) return(fp); } # endif @@ -1934,7 +1953,7 @@ int src; # endif details = ""; raw_printf("Couldn't open default config file %s %s(%d).", - tmp_config, details, errno); + lastconfigfile, details, errno); wait_synch(); } # endif /* Unix */ diff --git a/src/options.c b/src/options.c index 98ab3724b..c21010ab1 100644 --- a/src/options.c +++ b/src/options.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 options.c $NHDT-Date: 1425083082 2015/02/28 00:24:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.158 $ */ +/* NetHack 3.5 options.c $NHDT-Date: 1427035440 2015/03/22 14:44:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.163 $ */ /* NetHack 3.5 options.c $Date: 2012/04/09 02:56:30 $ $Revision: 1.153 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -798,10 +798,10 @@ rejectoption(optname) const char *optname; { #ifdef MICRO - pline("\"%s\" settable only from %s.", optname, configfile); + pline("\"%s\" settable only from %s.", optname, lastconfigfile); #else pline("%s can be set only from NETHACKOPTIONS or %s.", optname, - configfile); + lastconfigfile); #endif } @@ -821,7 +821,7 @@ const char *opts; #endif if(from_file) - raw_printf("Bad syntax in OPTIONS in %s: %s.", configfile, opts); + raw_printf("Bad syntax in OPTIONS in %s: %s.", lastconfigfile, opts); else raw_printf("Bad syntax in NETHACKOPTIONS: %s.", opts); @@ -4070,7 +4070,7 @@ option_help() winid datawin; datawin = create_nhwindow(NHW_TEXT); - Sprintf(buf, "Set options as OPTIONS= in %s", configfile); + Sprintf(buf, "Set options as OPTIONS= in %s", lastconfigfile); opt_intro[CONFIG_SLOT] = (const char *) buf; for (i = 0; opt_intro[i]; i++) putstr(datawin, 0, opt_intro[i]); From 74c5f489aebba3d8d39b9acc5e46135ce3926ddc Mon Sep 17 00:00:00 2001 From: nhmall Date: Sun, 22 Mar 2015 11:11:41 -0400 Subject: [PATCH 09/10] adjust PREFIXES_IN_USE for SYSCF --- include/decl.h | 9 +++++---- src/decl.c | 6 ++++-- src/files.c | 14 +++++++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/include/decl.h b/include/decl.h index 5dea2ff43..15191842e 100644 --- a/include/decl.h +++ b/include/decl.h @@ -1,4 +1,4 @@ -/* NetHack 3.5 decl.h $NHDT-Date: 1427035422 2015/03/22 14:43:42 $ $NHDT-Branch: master $:$NHDT-Revision: 1.56 $ */ +/* NetHack 3.5 decl.h $NHDT-Date: 1425081976 2015/02/28 00:06:16 $ $NHDT-Branch: master $:$NHDT-Revision: 1.50 $ */ /* NetHack 3.5 decl.h $Date: 2011/12/29 20:06:27 $ $Revision: 1.44 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -363,9 +363,10 @@ E const char * const monexplain[], invisexplain[], * const oclass_names[]; #define DATAPREFIX 4 /* this one must match hardcoded value in dlb.c */ #define SCOREPREFIX 5 #define LOCKPREFIX 6 -#define CONFIGPREFIX 7 -#define TROUBLEPREFIX 8 -#define PREFIX_COUNT 9 +#define SYSCONFPREFIX 7 +#define CONFIGPREFIX 8 +#define TROUBLEPREFIX 9 +#define PREFIX_COUNT 10 /* used in files.c; xxconf.h can override if needed */ # ifndef FQN_MAX_FILENAME #define FQN_MAX_FILENAME 512 diff --git a/src/decl.c b/src/decl.c index d0d29a35f..75203c056 100644 --- a/src/decl.c +++ b/src/decl.c @@ -268,12 +268,14 @@ char toplines[TBUFSZ]; struct tc_gbl_data tc_gbl_data = { 0,0, 0,0 }; /* AS,AE, LI,CO */ char *fqn_prefix[PREFIX_COUNT] = { (char *)0, (char *)0, (char *)0, (char *)0, - (char *)0, (char *)0, (char *)0, (char *)0, (char *)0 }; + (char *)0, (char *)0, (char *)0, (char *)0, + (char *)0 , (char *)0 }; #ifdef PREFIXES_IN_USE char *fqn_prefix_names[PREFIX_COUNT] = { "hackdir", "leveldir", "savedir", "bonesdir", "datadir", "scoredir", - "lockdir", "configdir", "troubledir" }; + "lockdir", "sysconfdir", "configdir", + "troubledir" }; #endif NEARDATA struct savefile_info sfcap = { diff --git a/src/files.c b/src/files.c index e638fa640..ace417e7d 100644 --- a/src/files.c +++ b/src/files.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 files.c $NHDT-Date: 1427035432 2015/03/22 14:43:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.138 $ */ +/* NetHack 3.5 files.c $NHDT-Date: 1426969026 2015/03/21 20:17:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.137 $ */ /* NetHack 3.5 files.c $Date: 2012/03/10 02:49:08 $ $Revision: 1.124 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -362,7 +362,9 @@ char *reasonbuf; /* reasonbuf must be at least BUFSZ, supplied by caller */ #if defined(NOCWD_ASSUMPTIONS) for (prefcnt = 1; prefcnt < PREFIX_COUNT; prefcnt++) { /* don't test writing to configdir or datadir; they're readonly */ - if (prefcnt == CONFIGPREFIX || prefcnt == DATAPREFIX) continue; + if (prefcnt == SYSCONFPREFIX || + prefcnt == CONFIGPREFIX || + prefcnt == DATAPREFIX) continue; filename = fqname("validate", prefcnt, 3); if ((fp = fopen(filename, "w"))) { fclose(fp); @@ -1858,6 +1860,12 @@ int src; wait_synch(); /* fall through to standard names */ } else +#endif +#ifdef PREFIXES_IN_USE + if (src == SET_IN_SYS) { + (void) strncpy(lastconfigfile, + fqname(filename, SYSCONFPREFIX, 0), BUFSZ-1); + } else #endif (void) strncpy(lastconfigfile, filename, BUFSZ-1); lastconfigfile[BUFSZ-1] = '\0'; @@ -1886,7 +1894,7 @@ int src; fqname(backward_compat_configfile, CONFIGPREFIX, 0), BUFSZ-1); lastconfigfile[BUFSZ-1] = '\0'; - else if ((fp = fopenp(fqname(lastconfigfile, "r")) != (FILE *)0) + else if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) return(fp); # endif #else From 3b064145a37df3c4a16e6c8cbff3b28c8fa0e0a3 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sun, 22 Mar 2015 15:05:18 -0400 Subject: [PATCH 10/10] File for explaining code quirks/features/caveats - added NOCWD_ASSUMPTIONS and PREFIXES_IN_USE section. --- DEVEL/code_features.txt | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 DEVEL/code_features.txt diff --git a/DEVEL/code_features.txt b/DEVEL/code_features.txt new file mode 100644 index 000000000..08c42c9d7 --- /dev/null +++ b/DEVEL/code_features.txt @@ -0,0 +1,55 @@ +$NHDT-Date: 1426969026 2015/03/21 20:17:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.137 $ +code_features.txt + +Developer-useful info about code features, assumptions, purpose, +rationale, etc. + +============================================== +PREFIXES_IN_USE and NOCWD_ASSUMPTIONS + +Those provide a storage mechanism for holding the paths to various different +types of files. Those paths are stored in the fqn_prefix[] array. They are a +mechanism for enabling separation of the different files that NetHack needs. + +The prefixes are added to the beginning of file names by various routines in +files.c immediately prior to opening one of the types of files that the game +uses. + +They aren't about config file options (although config file options would be +one way to set non-default values for some of the paths in the fqn_prefix[] +array). Obviously the very first path needed (now sysconfdir, previously +configdir) isn't viable for setting via config file options, but the game +still needs to hunt it down "someplace." When the "someplace" is figured +out, that place (path) would be stored in fqn_prefix[SYSCONPREFIX]. How it +gets stored in fqn_prefix[SYSCONPREFIX] is up to us as developers. + +Any of the fqn_prefix[] entries can be set somehow. It could be done in port +startup code; in options processing; in config file processing; by +translating a system environment variable such as USERPROFILE; whatever +you/we want. The point is that NOCWD_ASSUMPTIONS and PREFIXES_IN_USE are +there to ensure that there is a place to store that path information. The +code to *utilize* the information is already in files.c (see fqname()). + +There is a fqn_prefix[] entry for holding the path to each of the following: + PREFIX NAME +0 HACKPREFIX hackdir +1 LEVELPREFIX leveldir location to create level files +2 SAVEPREFIX savedir location to create/read saved games +3 BONESPREFIX bonesir location to create/read bones +4 DATAPREFIX datadir location to read data.base etc. +5 SCOREPREFIX scoredir location to read/write scorefile +6 LOCKPREFIX lockdir location to create/read lock files +7 SYSCONFPREFIX sysconfdir location to read SYSCF_FILE +8 CONFIGPREFIX configdir location to read user configuration file +9 TROUBLEPREFIX troubledir location to place panic files etc. + +To recap, they are about enabling "different paths for different things", and +separation of: +- read-only stuff from read-write stuff. +- sysadmin stuff from user-writeable stuff. +etc. + +=================== NEXT FEATURE ========================== + + +