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.
This commit is contained in:
nethack.allison
2002-06-29 12:44:54 +00:00
parent c0f63425df
commit 6b47ae351d
11 changed files with 75 additions and 38 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ typedef long off_t;
#define NOCWD_ASSUMPTIONS /* Allow paths to be specified for HACKDIR, #define NOCWD_ASSUMPTIONS /* Allow paths to be specified for HACKDIR,
LEVELDIR, SAVEDIR, BONESDIR, DATADIR, LEVELDIR, SAVEDIR, BONESDIR, DATADIR,
SCOREDIR, LOCKDIR, and CONFIGDIR. */ SCOREDIR, LOCKDIR, CONFIGDIR, and TROUBLEDIR */
/* data librarian defs */ /* data librarian defs */
#ifndef NOCWD_ASSUMPTIONS #ifndef NOCWD_ASSUMPTIONS
+3 -2
View File
@@ -348,11 +348,12 @@ E const char *monexplain[], *invisexplain, *objexplain[], *oclass_names[];
#define LEVELPREFIX 1 #define LEVELPREFIX 1
#define SAVEPREFIX 2 #define SAVEPREFIX 2
#define BONESPREFIX 3 #define BONESPREFIX 3
#define DATAPREFIX 4 #define DATAPREFIX 4 /* this one must match hardcoded value in dlb.c */
#define SCOREPREFIX 5 #define SCOREPREFIX 5
#define LOCKPREFIX 6 #define LOCKPREFIX 6
#define CONFIGPREFIX 7 #define CONFIGPREFIX 7
#define PREFIX_COUNT 8 #define TROUBLEPREFIX 8
#define PREFIX_COUNT 9
/* used in files.c; xxconf.h can override if needed */ /* used in files.c; xxconf.h can override if needed */
# ifndef FQN_MAX_FILENAME # ifndef FQN_MAX_FILENAME
#define FQN_MAX_FILENAME 512 #define FQN_MAX_FILENAME 512
+1 -1
View File
@@ -596,7 +596,7 @@ E void NDECL(makerogueghost);
/* ### files.c ### */ /* ### files.c ### */
E const char *FDECL(fqname, (const char *, int, int)); 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 boolean FDECL(uptodate, (int,const char *));
E void FDECL(store_version, (int)); E void FDECL(store_version, (int));
#ifdef MFLOPPY #ifdef MFLOPPY
+1 -1
View File
@@ -35,7 +35,7 @@
it is defined for WIN32. it is defined for WIN32.
Allow paths to be specified for HACKDIR, Allow paths to be specified for HACKDIR,
LEVELDIR, SAVEDIR, BONESDIR, DATADIR, LEVELDIR, SAVEDIR, BONESDIR, DATADIR,
SCOREDIR, LOCKDIR, and CONFIGDIR */ SCOREDIR, LOCKDIR, CONFIGDIR, and TROUBLEDIR */
#define NO_TERMS #define NO_TERMS
#define ASCIIGRAPH #define ASCIIGRAPH
+1 -1
View File
@@ -141,7 +141,7 @@
# endif # endif
#define NOCWD_ASSUMPTIONS /* Allow paths to be specified for HACKDIR, #define NOCWD_ASSUMPTIONS /* Allow paths to be specified for HACKDIR,
LEVELDIR, SAVEDIR, BONESDIR, DATADIR, LEVELDIR, SAVEDIR, BONESDIR, DATADIR,
SCOREDIR, LOCKDIR, and CONFIGDIR */ SCOREDIR, LOCKDIR, CONFIGDIR, and TROUBLEDIR. */
#endif /* MSDOS configuration stuff */ #endif /* MSDOS configuration stuff */
+2 -2
View File
@@ -263,12 +263,12 @@ char toplines[TBUFSZ];
struct tc_gbl_data tc_gbl_data = { 0,0, 0,0 }; /* AS,AE, LI,CO */ 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 *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 #ifdef PREFIXES_IN_USE
char *fqn_prefix_names[PREFIX_COUNT] = { "hackdir", "leveldir", "savedir", char *fqn_prefix_names[PREFIX_COUNT] = { "hackdir", "leveldir", "savedir",
"bonesdir", "datadir", "scoredir", "bonesdir", "datadir", "scoredir",
"lockdir", "configdir" }; "lockdir", "configdir", "troubledir" };
#endif #endif
/* dummy routine used to force linkage */ /* dummy routine used to force linkage */
+5 -3
View File
@@ -9,6 +9,8 @@
#include <string.h> #include <string.h>
#endif #endif
#define DATAPREFIX 4
#ifdef DLB #ifdef DLB
/* /*
* Data librarian. Present a STDIO-like interface to NetHack while * Data librarian. Present a STDIO-like interface to NetHack while
@@ -29,7 +31,7 @@ typedef struct dlb_procs {
} dlb_procs_t; } dlb_procs_t;
/* without extern.h via hack.h, these haven't been declared for us */ /* 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 #ifdef DLBLIB
/* /*
@@ -199,7 +201,7 @@ open_library(lib_name, lp)
{ {
boolean status = FALSE; boolean status = FALSE;
lp->fdata = fopen_datafile(lib_name, RDBMODE, FALSE); lp->fdata = fopen_datafile(lib_name, RDBMODE, DATAPREFIX);
if (lp->fdata) { if (lp->fdata) {
if (readlibdir(lp)) { if (readlibdir(lp)) {
status = TRUE; status = TRUE;
@@ -460,7 +462,7 @@ dlb_fopen(name, mode)
dp = (dlb *) alloc(sizeof(dlb)); dp = (dlb *) alloc(sizeof(dlb));
if (do_dlb_fopen(dp, name, mode)) if (do_dlb_fopen(dp, name, mode))
dp->fp = (FILE *) 0; 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; dp->fp = fp;
else { else {
/* can't find anything */ /* can't find anything */
+7 -6
View File
@@ -34,7 +34,7 @@ extern int errno;
#endif #endif
#ifdef PREFIXES_IN_USE #ifdef PREFIXES_IN_USE
#define FQN_NUMBUF 3 #define FQN_NUMBUF 4
static char fqn_filename_buffer[FQN_NUMBUF][FQN_MAX_FILENAME]; static char fqn_filename_buffer[FQN_NUMBUF][FQN_MAX_FILENAME];
#endif #endif
@@ -157,14 +157,13 @@ int whichprefix, buffnum;
/* fopen a file, with OS-dependent bells and whistles */ /* fopen a file, with OS-dependent bells and whistles */
/* NOTE: a simpler version of this routine also exists in util/dlb_main.c */ /* NOTE: a simpler version of this routine also exists in util/dlb_main.c */
FILE * FILE *
fopen_datafile(filename, mode, use_scoreprefix) fopen_datafile(filename, mode, prefix)
const char *filename, *mode; const char *filename, *mode;
boolean use_scoreprefix; int prefix;
{ {
FILE *fp; FILE *fp;
filename = fqname(filename, filename = fqname(filename, prefix, prefix == TROUBLEPREFIX ? 3 : 0);
use_scoreprefix ? SCOREPREFIX : DATAPREFIX, 0);
#ifdef VMS /* essential to have punctuation, to avoid logical names */ #ifdef VMS /* essential to have punctuation, to avoid logical names */
{ {
char tmp[BUFSIZ]; char tmp[BUFSIZ];
@@ -1302,6 +1301,8 @@ char *tmp_levels;
adjust_prefix(bufp, LOCKPREFIX); adjust_prefix(bufp, LOCKPREFIX);
} else if (match_varname(buf, "CONFIGDIR", 4)) { } else if (match_varname(buf, "CONFIGDIR", 4)) {
adjust_prefix(bufp, CONFIGPREFIX); adjust_prefix(bufp, CONFIGPREFIX);
} else if (match_varname(buf, "TROUBLEDIR", 4)) {
adjust_prefix(bufp, TROUBLEPREFIX);
#else /*NOCWD_ASSUMPTIONS*/ #else /*NOCWD_ASSUMPTIONS*/
# ifdef MICRO # ifdef MICRO
} else if (match_varname(buf, "HACKDIR", 4)) { } else if (match_varname(buf, "HACKDIR", 4)) {
@@ -1793,7 +1794,7 @@ const char* s;
#ifdef PANICLOG #ifdef PANICLOG
FILE *lfile; FILE *lfile;
lfile = fopen_datafile(PANICLOG, "a", TRUE); lfile = fopen_datafile(PANICLOG, "a", TROUBLEPREFIX);
if (lfile) { if (lfile) {
(void) fprintf(lfile, "%08ld: %s %s\n", (void) fprintf(lfile, "%08ld: %s %s\n",
yyyymmdd((time_t)0L), why, s); yyyymmdd((time_t)0L), why, s);
+6 -6
View File
@@ -340,7 +340,7 @@ int how;
#ifdef LOGFILE /* used for debugging (who dies of what, where) */ #ifdef LOGFILE /* used for debugging (who dies of what, where) */
if (lock_file(LOGFILE, SCOREPREFIX, 10)) { 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!"); HUP raw_print("Cannot open log file!");
} else { } else {
writeentry(lfile, t0); writeentry(lfile, t0);
@@ -366,9 +366,9 @@ int how;
goto destroywin; goto destroywin;
#ifdef UPDATE_RECORD_IN_PLACE #ifdef UPDATE_RECORD_IN_PLACE
rfile = fopen_datafile(RECORD, "r+", TRUE); rfile = fopen_datafile(RECORD, "r+", SCOREPREFIX);
#else #else
rfile = fopen_datafile(RECORD, "r", TRUE); rfile = fopen_datafile(RECORD, "r", SCOREPREFIX);
#endif #endif
if (!rfile) { if (!rfile) {
@@ -445,7 +445,7 @@ int how;
t0->fpos : final_fpos), SEEK_SET); t0->fpos : final_fpos), SEEK_SET);
#else #else
(void) fclose(rfile); (void) fclose(rfile);
if(!(rfile = fopen_datafile(RECORD, "w", TRUE))){ if(!(rfile = fopen_datafile(RECORD, "w", SCOREPREFIX))){
HUP raw_print("Cannot write record file"); HUP raw_print("Cannot write record file");
unlock_file(RECORD); unlock_file(RECORD);
free_ttlist(tt_head); free_ttlist(tt_head);
@@ -762,7 +762,7 @@ char **argv;
return; return;
} }
rfile = fopen_datafile(RECORD, "r", TRUE); rfile = fopen_datafile(RECORD, "r", SCOREPREFIX);
if (!rfile) { if (!rfile) {
raw_print("Cannot open record file!"); raw_print("Cannot open record file!");
return; return;
@@ -922,7 +922,7 @@ struct obj *otmp;
if (!otmp) return((struct obj *) 0); if (!otmp) return((struct obj *) 0);
rfile = fopen_datafile(RECORD, "r", TRUE); rfile = fopen_datafile(RECORD, "r", SCOREPREFIX);
if (!rfile) { if (!rfile) {
impossible("Cannot open record file!"); impossible("Cannot open record file!");
return (struct obj *)0; return (struct obj *)0;
+25 -7
View File
@@ -61,16 +61,34 @@ OPTIONS=time,noshowexp,number_pad,lit_corridor,rest_on_space
#OPTIONS=suppress_alert:3.3.1 #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 #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 *** # *** CHARACTER GRAPHICS ***
# #
# See the on-line help or the Guidebook for which symbols are in which # See the on-line help or the Guidebook for which symbols are in which
+23 -8
View File
@@ -72,18 +72,33 @@ OPTIONS=hilite_pet,!toptenwin
# window, windowframe, windowtext. # window, windowframe, windowtext.
#OPTIONS=windowcolors:status windowtext/window message windowtext/window #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 # Note: On Windows HACKDIR defaults to the location
# of the NetHack.exe or NetHackw.exe file. # of the NetHack.exe or NetHackw.exe file so
# Setting HACKDIR above will override that. # 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 *** # *** CHARACTER GRAPHICS ***
# #
# See the on-line help or the Guidebook for which symbols are in which # See the on-line help or the Guidebook for which symbols are in which