From 6b47ae351d11379a3b53f4d3bade761d2ff48a6f Mon Sep 17 00:00:00 2001 From: "nethack.allison" Date: Sat, 29 Jun 2002 12:44:54 +0000 Subject: [PATCH] more NOCWD_ASSUMPTIONS The NOCWD_ASSUMPTIONS conditional code allows readonly parts of NetHack to be separated from areas that require write-access. This allows the recent panic log needed a prefix. --- include/amiconf.h | 2 +- include/decl.h | 5 +++-- include/extern.h | 2 +- include/ntconf.h | 2 +- include/pcconf.h | 2 +- src/decl.c | 4 ++-- src/dlb.c | 8 +++++--- src/files.c | 13 +++++++------ src/topten.c | 12 ++++++------ sys/share/NetHack.cnf | 32 +++++++++++++++++++++++++------- sys/winnt/defaults.nh | 31 +++++++++++++++++++++++-------- 11 files changed, 75 insertions(+), 38 deletions(-) diff --git a/include/amiconf.h b/include/amiconf.h index 4cc3963fa..7a7e980c0 100644 --- a/include/amiconf.h +++ b/include/amiconf.h @@ -38,7 +38,7 @@ typedef long off_t; #define NOCWD_ASSUMPTIONS /* Allow paths to be specified for HACKDIR, LEVELDIR, SAVEDIR, BONESDIR, DATADIR, - SCOREDIR, LOCKDIR, and CONFIGDIR. */ + SCOREDIR, LOCKDIR, CONFIGDIR, and TROUBLEDIR */ /* data librarian defs */ #ifndef NOCWD_ASSUMPTIONS diff --git a/include/decl.h b/include/decl.h index 717a23fdd..a1e3cbc40 100644 --- a/include/decl.h +++ b/include/decl.h @@ -348,11 +348,12 @@ E const char *monexplain[], *invisexplain, *objexplain[], *oclass_names[]; #define LEVELPREFIX 1 #define SAVEPREFIX 2 #define BONESPREFIX 3 -#define DATAPREFIX 4 +#define DATAPREFIX 4 /* this one must match hardcoded value in dlb.c */ #define SCOREPREFIX 5 #define LOCKPREFIX 6 #define CONFIGPREFIX 7 -#define PREFIX_COUNT 8 +#define TROUBLEPREFIX 8 +#define PREFIX_COUNT 9 /* used in files.c; xxconf.h can override if needed */ # ifndef FQN_MAX_FILENAME #define FQN_MAX_FILENAME 512 diff --git a/include/extern.h b/include/extern.h index 1a0cfa86b..938b6ca3c 100644 --- a/include/extern.h +++ b/include/extern.h @@ -596,7 +596,7 @@ E void NDECL(makerogueghost); /* ### files.c ### */ E const char *FDECL(fqname, (const char *, int, int)); -E FILE *FDECL(fopen_datafile, (const char *,const char *,BOOLEAN_P)); +E FILE *FDECL(fopen_datafile, (const char *,const char *,int)); E boolean FDECL(uptodate, (int,const char *)); E void FDECL(store_version, (int)); #ifdef MFLOPPY diff --git a/include/ntconf.h b/include/ntconf.h index db358b8e1..a4cecf427 100644 --- a/include/ntconf.h +++ b/include/ntconf.h @@ -35,7 +35,7 @@ it is defined for WIN32. Allow paths to be specified for HACKDIR, LEVELDIR, SAVEDIR, BONESDIR, DATADIR, - SCOREDIR, LOCKDIR, and CONFIGDIR */ + SCOREDIR, LOCKDIR, CONFIGDIR, and TROUBLEDIR */ #define NO_TERMS #define ASCIIGRAPH diff --git a/include/pcconf.h b/include/pcconf.h index ddfa16b7e..9100df839 100644 --- a/include/pcconf.h +++ b/include/pcconf.h @@ -141,7 +141,7 @@ # endif #define NOCWD_ASSUMPTIONS /* Allow paths to be specified for HACKDIR, LEVELDIR, SAVEDIR, BONESDIR, DATADIR, - SCOREDIR, LOCKDIR, and CONFIGDIR */ + SCOREDIR, LOCKDIR, CONFIGDIR, and TROUBLEDIR. */ #endif /* MSDOS configuration stuff */ diff --git a/src/decl.c b/src/decl.c index 69988fe86..349ad5064 100644 --- a/src/decl.c +++ b/src/decl.c @@ -263,12 +263,12 @@ 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 }; #ifdef PREFIXES_IN_USE char *fqn_prefix_names[PREFIX_COUNT] = { "hackdir", "leveldir", "savedir", "bonesdir", "datadir", "scoredir", - "lockdir", "configdir" }; + "lockdir", "configdir", "troubledir" }; #endif /* dummy routine used to force linkage */ diff --git a/src/dlb.c b/src/dlb.c index d6f2bf5e6..5d423263e 100644 --- a/src/dlb.c +++ b/src/dlb.c @@ -9,6 +9,8 @@ #include #endif +#define DATAPREFIX 4 + #ifdef DLB /* * Data librarian. Present a STDIO-like interface to NetHack while @@ -29,7 +31,7 @@ typedef struct dlb_procs { } dlb_procs_t; /* without extern.h via hack.h, these haven't been declared for us */ -extern FILE *FDECL(fopen_datafile, (const char *,const char *,BOOLEAN_P)); +extern FILE *FDECL(fopen_datafile, (const char *,const char *,int)); #ifdef DLBLIB /* @@ -199,7 +201,7 @@ open_library(lib_name, lp) { boolean status = FALSE; - lp->fdata = fopen_datafile(lib_name, RDBMODE, FALSE); + lp->fdata = fopen_datafile(lib_name, RDBMODE, DATAPREFIX); if (lp->fdata) { if (readlibdir(lp)) { status = TRUE; @@ -460,7 +462,7 @@ dlb_fopen(name, mode) dp = (dlb *) alloc(sizeof(dlb)); if (do_dlb_fopen(dp, name, mode)) dp->fp = (FILE *) 0; - else if ((fp = fopen_datafile(name, mode, FALSE)) != 0) + else if ((fp = fopen_datafile(name, mode, DATAPREFIX)) != 0) dp->fp = fp; else { /* can't find anything */ diff --git a/src/files.c b/src/files.c index 6813c250b..6df6b9556 100644 --- a/src/files.c +++ b/src/files.c @@ -34,7 +34,7 @@ extern int errno; #endif #ifdef PREFIXES_IN_USE -#define FQN_NUMBUF 3 +#define FQN_NUMBUF 4 static char fqn_filename_buffer[FQN_NUMBUF][FQN_MAX_FILENAME]; #endif @@ -157,14 +157,13 @@ int whichprefix, buffnum; /* fopen a file, with OS-dependent bells and whistles */ /* NOTE: a simpler version of this routine also exists in util/dlb_main.c */ FILE * -fopen_datafile(filename, mode, use_scoreprefix) +fopen_datafile(filename, mode, prefix) const char *filename, *mode; -boolean use_scoreprefix; +int prefix; { FILE *fp; - filename = fqname(filename, - use_scoreprefix ? SCOREPREFIX : DATAPREFIX, 0); + filename = fqname(filename, prefix, prefix == TROUBLEPREFIX ? 3 : 0); #ifdef VMS /* essential to have punctuation, to avoid logical names */ { char tmp[BUFSIZ]; @@ -1302,6 +1301,8 @@ char *tmp_levels; adjust_prefix(bufp, LOCKPREFIX); } else if (match_varname(buf, "CONFIGDIR", 4)) { adjust_prefix(bufp, CONFIGPREFIX); + } else if (match_varname(buf, "TROUBLEDIR", 4)) { + adjust_prefix(bufp, TROUBLEPREFIX); #else /*NOCWD_ASSUMPTIONS*/ # ifdef MICRO } else if (match_varname(buf, "HACKDIR", 4)) { @@ -1793,7 +1794,7 @@ const char* s; #ifdef PANICLOG FILE *lfile; - lfile = fopen_datafile(PANICLOG, "a", TRUE); + lfile = fopen_datafile(PANICLOG, "a", TROUBLEPREFIX); if (lfile) { (void) fprintf(lfile, "%08ld: %s %s\n", yyyymmdd((time_t)0L), why, s); diff --git a/src/topten.c b/src/topten.c index 7ceb275e1..03fbac489 100644 --- a/src/topten.c +++ b/src/topten.c @@ -340,7 +340,7 @@ int how; #ifdef LOGFILE /* used for debugging (who dies of what, where) */ if (lock_file(LOGFILE, SCOREPREFIX, 10)) { - if(!(lfile = fopen_datafile(LOGFILE, "a", TRUE))) { + if(!(lfile = fopen_datafile(LOGFILE, "a", SCOREPREFIX))) { HUP raw_print("Cannot open log file!"); } else { writeentry(lfile, t0); @@ -366,9 +366,9 @@ int how; goto destroywin; #ifdef UPDATE_RECORD_IN_PLACE - rfile = fopen_datafile(RECORD, "r+", TRUE); + rfile = fopen_datafile(RECORD, "r+", SCOREPREFIX); #else - rfile = fopen_datafile(RECORD, "r", TRUE); + rfile = fopen_datafile(RECORD, "r", SCOREPREFIX); #endif if (!rfile) { @@ -445,7 +445,7 @@ int how; t0->fpos : final_fpos), SEEK_SET); #else (void) fclose(rfile); - if(!(rfile = fopen_datafile(RECORD, "w", TRUE))){ + if(!(rfile = fopen_datafile(RECORD, "w", SCOREPREFIX))){ HUP raw_print("Cannot write record file"); unlock_file(RECORD); free_ttlist(tt_head); @@ -762,7 +762,7 @@ char **argv; return; } - rfile = fopen_datafile(RECORD, "r", TRUE); + rfile = fopen_datafile(RECORD, "r", SCOREPREFIX); if (!rfile) { raw_print("Cannot open record file!"); return; @@ -922,7 +922,7 @@ struct obj *otmp; if (!otmp) return((struct obj *) 0); - rfile = fopen_datafile(RECORD, "r", TRUE); + rfile = fopen_datafile(RECORD, "r", SCOREPREFIX); if (!rfile) { impossible("Cannot open record file!"); return (struct obj *)0; diff --git a/sys/share/NetHack.cnf b/sys/share/NetHack.cnf index f8703df2e..0bb022da4 100644 --- a/sys/share/NetHack.cnf +++ b/sys/share/NetHack.cnf @@ -61,16 +61,34 @@ OPTIONS=time,noshowexp,number_pad,lit_corridor,rest_on_space #OPTIONS=suppress_alert:3.3.1 # # +# *** LOCATIONS *** +# Some platforms allow you to change the location where various things are kept. +# IMPORTANT: If you change any of these locations, the directories they +# point at must exist. NetHack will not create them for you. +# +# 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 -# -# Note: Under MSDOS ports HACKDIR defaults to the location -# of the NetHack.exe file. Setting HACKDIR above will override that. # -# LEVELS and SAVE default to HACKDIR +# 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 # -#LEVELS=c:\games\nethack\bones -#SAVE=c:\games\nethack\bones - # *** CHARACTER GRAPHICS *** # # See the on-line help or the Guidebook for which symbols are in which diff --git a/sys/winnt/defaults.nh b/sys/winnt/defaults.nh index 32e057cdf..0b437d34b 100644 --- a/sys/winnt/defaults.nh +++ b/sys/winnt/defaults.nh @@ -72,18 +72,33 @@ OPTIONS=hilite_pet,!toptenwin # window, windowframe, windowtext. #OPTIONS=windowcolors:status windowtext/window message windowtext/window +# *** LOCATIONS *** +# IMPORTANT: If you change any of these locations, the directories they +# point at must exist. NetHack will not create them for you. # -#HACKDIR=c:\games\nethack -# +# HACKDIR is the default location for everything. # Note: On Windows HACKDIR defaults to the location -# of the NetHack.exe or NetHackw.exe file. -# Setting HACKDIR above will override that. +# 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 # -# LEVELS and SAVE default to HACKDIR +# 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 # -#LEVELS=c:\games\nethack\bones -#SAVE=c:\games\nethack\bones - # *** CHARACTER GRAPHICS *** # # See the on-line help or the Guidebook for which symbols are in which -- 2.40.0