Fix: SE024 Problem: No support for the Filesystem Hierarchy Standard. We really need to be able to configure where files are stored and to split these areas into variable and invariant, shareable and unshareable in order to conform to the standard. This implementation is perhaps a little over-engineered, but it does have some nice consequences. For example, the tile file can be specified in the application defaults file as simply "x11tiles", in which case Slash'EM will look for it in the shareable area or with an absolute path, in which case Slash'EM will use that path. Speaking of the x11tile file, I have modified the internal format so that it is shareable (the XPM version is already). This makes Makefile.top much easier to write. The cost is negligible. This patch provides support for FSSTND 1.2 and FHS 2.0, but comes configured for compatability with previous versions of Slash'EM. To enable support for either of these standards you will need to edit ./include/unixconf.h and ./Makefile. Compatible with: Slash'EM 0.0.5E6F1 Author: J. Ali Harlow, ali@avrc.city.ac.uk Date: 24 Nov 1999 *** include/config.h.orig Mon Nov 1 12:48:17 1999 --- include/config.h Wed Nov 24 11:28:32 1999 *************** *** 295,301 **** --- 295,303 ---- #endif #define LOGFILE "logfile" /* larger file for debugging purposes */ + #define LOGAREA FILE_AREA_VAR #define NEWS "news" /* the file containing the latest hack news */ + #define NEWS_AREA FILE_AREA_SHARE /* * If COMPRESS is defined, it should contain the full path name of your *** include/dlb.h.orig Mon Nov 1 12:47:55 1999 --- include/dlb.h Wed Nov 17 18:32:18 1999 *************** *** 38,44 **** --- 38,48 ---- boolean NDECL(dlb_init); void NDECL(dlb_cleanup); + #ifndef FILE_AREAS dlb *FDECL(dlb_fopen,(const char *, const char *)); + #else + dlb *FDECL(dlb_fopen_area,(const char *, const char *, const char *)); + #endif int FDECL(dlb_fclose,(dlb *)); /*WAC made dlb_fread void *, rather than char * to parralel fread*/ int FDECL(dlb_fread,(void *, int, int, dlb *)); *************** *** 49,55 **** /* data librarian definitions */ # ifndef DLBFILE ! # define DLBFILE "nhdat" /* name of library */ # endif # ifndef FILENAME_CMP # define FILENAME_CMP strcmp /* case sensitive */ --- 53,62 ---- /* data librarian definitions */ # ifndef DLBFILE ! # define DLBFILE "nhshare" /* shareable library */ ! # define DLBAREA FILE_AREA_SHARE ! # define DLBFILE2 "nhunshare" /* unshareable library */ ! # define DLBAREA2 FILE_AREA_UNSHARE # endif # ifndef FILENAME_CMP # define FILENAME_CMP strcmp /* case sensitive */ *** include/extern.h.orig Mon Nov 1 12:48:16 1999 --- include/extern.h Wed Nov 24 09:52:08 1999 *************** *** 601,607 **** --- 601,609 ---- /* ### files.c ### */ + #ifndef FILE_AREAS E FILE *FDECL(fopen_datafile, (const char *,const char *)); + #endif E boolean FDECL(uptodate, (int,const char *)); E void FDECL(store_version, (int)); #ifdef MFLOPPY *************** *** 631,640 **** E int NDECL(open_savefile); E int NDECL(delete_savefile); E int NDECL(restore_saved_game); ! E void FDECL(compress, (const char *)); ! E void FDECL(uncompress, (const char *)); E boolean FDECL(lock_file, (const char *,int)); E void FDECL(unlock_file, (const char *)); E void FDECL(read_config_file, (const char *)); E void FDECL(check_recordfile, (const char *)); --- 633,644 ---- E int NDECL(open_savefile); E int NDECL(delete_savefile); E int NDECL(restore_saved_game); ! E void FDECL(compress_area, (const char *, const char *)); ! E void FDECL(uncompress_area, (const char *, const char *)); ! #ifndef FILE_AREAS E boolean FDECL(lock_file, (const char *,int)); E void FDECL(unlock_file, (const char *)); + #endif E void FDECL(read_config_file, (const char *)); E void FDECL(check_recordfile, (const char *)); *************** *** 1928,1933 **** --- 1932,1947 ---- # if defined(SHELL) || defined(DEF_PAGER) || defined(DEF_MAILREADER) E int FDECL(child, (int)); # endif + #ifdef FILE_AREAS + E char *FDECL(make_file_name, (const char *, const char *)); + E FILE *FDECL(fopen_datafile_area, (const char *,const char *,const char *)); + E FILE *FDECL(freopen_area, (const char *,const char *,const char *, FILE *)); + E int FDECL(chmod_area, (const char *, const char *, int)); + E int FDECL(open_area, (const char *, const char *, int, int)); + E int FDECL(creat_area, (const char *, const char *, int)); + E boolean FDECL(lock_file_area, (const char *, const char *,int)); + E void FDECL(unlock_file_area, (const char *, const char *)); + #endif #endif /* UNIX */ /* ### vault.c ### */ *** include/global.h.orig Mon Nov 1 12:48:09 1999 --- include/global.h Tue Nov 23 18:09:43 1999 *************** *** 11,36 **** #define BETA /* if a beta-test copy [MRS] */ /* ! * Files expected to exist in the playground directory. */ #define RECORD "record" /* a file containing list of topscorers */ #define HELP "help" /* a file containing command descriptions */ #define SHELP "hh" /* abbreviated form of the same */ #define DEBUGHELP "wizhelp" /* a file containing debug mode cmds */ #define RUMORFILE "rumors" /* a file with fortune cookies */ #define ORACLEFILE "oracles" /* a file with oracular information */ #define DATAFILE "data" /* a file giving the meaning of symbols used */ #define CMDHELPFILE "cmdhelp" /* file telling what commands do */ #define HISTORY "history" /* a file giving nethack's history */ #define LICENSE "license" /* file with license information */ #define OPTIONFILE "opthelp" /* a file explaining runtime options */ #define OPTIONS_USED "options" /* compile-time options, for #version */ #ifdef SHORT_FILENAMES # define GUIDEBOOK "guideboo.txt" /* Nethack Guidebook*/ #else #define GUIDEBOOK "Guidebook.txt" /* Nethack Guidebook*/ #endif #define LEV_EXT ".lev" /* extension for special level files */ --- 11,50 ---- #define BETA /* if a beta-test copy [MRS] */ /* ! * Files expected to exist in the playground directory if file areas are not ! * enabled and in the named areas otherwise. */ #define RECORD "record" /* a file containing list of topscorers */ + #define RECORD_AREA FILE_AREA_VAR #define HELP "help" /* a file containing command descriptions */ + #define HELP_AREA FILE_AREA_SHARE #define SHELP "hh" /* abbreviated form of the same */ + #define SHELP_AREA FILE_AREA_SHARE #define DEBUGHELP "wizhelp" /* a file containing debug mode cmds */ + #define DEBUGHELP_AREA FILE_AREA_SHARE #define RUMORFILE "rumors" /* a file with fortune cookies */ + #define RUMORAREA FILE_AREA_SHARE #define ORACLEFILE "oracles" /* a file with oracular information */ + #define ORACLEAREA FILE_AREA_SHARE #define DATAFILE "data" /* a file giving the meaning of symbols used */ + #define DATAAREA FILE_AREA_SHARE #define CMDHELPFILE "cmdhelp" /* file telling what commands do */ + #define CMDHELPAREA FILE_AREA_SHARE #define HISTORY "history" /* a file giving nethack's history */ + #define HISTORY_AREA FILE_AREA_SHARE #define LICENSE "license" /* file with license information */ + #define LICENSE_AREA FILE_AREA_SHARE #define OPTIONFILE "opthelp" /* a file explaining runtime options */ + #define OPTIONAREA FILE_AREA_SHARE #define OPTIONS_USED "options" /* compile-time options, for #version */ + #define OPTIONS_USED_AREA FILE_AREA_SHARE #ifdef SHORT_FILENAMES # define GUIDEBOOK "guideboo.txt" /* Nethack Guidebook*/ #else #define GUIDEBOOK "Guidebook.txt" /* Nethack Guidebook*/ #endif + #define GUIDEBOOK_AREA FILE_AREA_SHARE #define LEV_EXT ".lev" /* extension for special level files */ *************** *** 179,184 **** --- 193,223 ---- #if defined(WIN32) && !defined(NTCONF_H) #include "ntconf.h" + #endif + + #ifndef FILE_AREAS + + #define fopen_datafile_area(area, filename, mode) fopen_datafile(filename, mode) + #define lock_file_area(area, filename, retryct) lock_file(filename, retryct) + #define unlock_file_area(area, filename) unlock_file(filename) + #define dlb_fopen_area(area, name, mode) dlb_fopen(name, mode) + + /* + * ALI + * + * By defining these, functions can pass them around even though they're + * not actually used. This can make the code easier to read at the cost + * of some efficiency. Given the high overhead of dealing with files anyway, + * this is often a good trade-off. + */ + + #define FILE_AREA_VAR NULL + #define FILE_AREA_SAVE NULL + #define FILE_AREA_LEVL NULL + #define FILE_AREA_BONES NULL + #define FILE_AREA_SHARE NULL + #define FILE_AREA_UNSHARE NULL + #endif /* Displayable name of this port; don't redefine if defined in *conf.h */ *** include/unixconf.h.orig Mon Nov 1 12:48:09 1999 --- include/unixconf.h Wed Nov 24 11:51:22 1999 *************** *** 75,80 **** --- 75,133 ---- /* #define VPIX_MUSIC /* Play real music through speaker on systems with built-in VPIX support */ + /* + * ALI + * + * File areas can be used to place different Slash'EM files in different + * directories. This is necessary to comply with Linux's FSSTD 1.2 and its + * replacement FS 2.0. Currently, these are only implemented for UNIX, but + * other ports could follow suit by including similar defines in their port + * specific config files and implementing the relevent functions. + * + * File areas are supposed to be opaque; that is the core system does not + * interpret them in any way, it simply passes them to the port specific + * functions to handle. This means that while the obvious mapping is onto + * directories, there is nothing in the core code that assumes this. Non-UNIX + * ports in particular may find that a more general mapping is desirable. + * + * The following file areas are supported: + * + * FILE_AREA_SAVE For save files (R/W) + * FILE_AREA_BONES For bones files (R/W) + * FILE_AREA_LEVL For level files (R/W) + * FILE_AREA_VAR For other files which may be modified by Slash'EM + * FILE_AREA_SHARE For read-only, architechure independent, files + * FILE_AREA_UNSHARE For read-only, architechure dependent, files + */ + + /* #define FILE_AREAS /* Use file areas */ + + #ifdef FILE_AREAS + + /* + * File areas compatible with Linux's FSSTND 1.2. + * Note: This has been superceeded by FHS 2.0, but is included because + * many systems still seem to use it. + */ + + /* #define FILE_AREA_VAR "/var/lib/games/slashem/" /* */ + /* #define FILE_AREA_SAVE "/var/lib/games/slashem/save/" /* */ + /* #define FILE_AREA_SHARE "/usr/lib/games/slashem/" /* */ + /* #define FILE_AREA_UNSHARE "/usr/lib/games/slashem/" /* */ + + /* + * File areas compatible with FHS 2.0 + */ + + #define FILE_AREA_VAR "/var/games/slashem/" /* */ + #define FILE_AREA_SAVE "/var/games/slashem/save/" /* */ + #define FILE_AREA_SHARE "/usr/share/games/slashem/" /* */ + #define FILE_AREA_UNSHARE "/usr/lib/games/slashem/" /* */ + + #define FILE_AREA_BONES FILE_AREA_VAR + #define FILE_AREA_LEVL FILE_AREA_VAR + + #endif /* FILE_AREAS */ /* * The next two defines are intended mainly for the Andrew File System, *************** *** 85,92 **** */ /* #define NO_FILE_LINKS /* if no hard links */ - /* #define LOCKDIR "/usr/games/lib/nethackdir" /* where to put locks */ /* * Define DEF_PAGER as your default pager, e.g. "/bin/cat" or "/usr/ucb/more" --- 138,151 ---- */ /* #define NO_FILE_LINKS /* if no hard links */ + #ifdef NO_FILE_LINKS + # ifdef FILE_AREAS + # define LOCKDIR FILE_AREA_VAR /* where to put locks */ + # else + # define LOCKDIR "/usr/games/lib/nethackdir" /* where to put locks */ + # endif + #endif /* * Define DEF_PAGER as your default pager, e.g. "/bin/cat" or "/usr/ucb/more" *************** *** 242,248 **** #include #endif ! #define HLOCK "perm" /* an empty file used for locking purposes */ #ifndef REDO #define Getchar nhgetch --- 301,308 ---- #include #endif ! #define HLOCK "perm" /* an empty file used for locking purposes */ ! #define HLOCK_AREA FILE_AREA_VAR #ifndef REDO #define Getchar nhgetch *** src/dlb.c.orig Mon Nov 1 12:47:57 1999 --- src/dlb.c Wed Nov 17 18:13:08 1999 *************** *** 38,49 **** long *sizep)); /* not static because shared with dlb_main.c */ ! boolean FDECL(open_library,(const char *lib_name, library *lp)); void FDECL(close_library,(library *lp)); /* without extern.h via hack.h, these haven't been declared for us */ extern char *FDECL(eos, (char *)); extern FILE *FDECL(fopen_datafile, (const char *,const char *)); /* * Read the directory out of the library. Return 1 if successful, --- 38,59 ---- long *sizep)); /* not static because shared with dlb_main.c */ ! boolean FDECL(open_library,(const char *lib_area, const char *lib_name, ! library *lp)); void FDECL(close_library,(library *lp)); /* without extern.h via hack.h, these haven't been declared for us */ extern char *FDECL(eos, (char *)); + #ifdef FILE_AREAS + extern FILE *FDECL(fopen_datafile_area, (const char *,const char *, + const char *)); + #else + /* + * If FILE_AREAS is not defined, then fopen_datafile_area + * is a macro defined in terms of fopen_datafile. + */ extern FILE *FDECL(fopen_datafile, (const char *,const char *)); + #endif /* * Read the directory out of the library. Return 1 if successful, *************** *** 165,177 **** * structure. Return TRUE if successful, FALSE otherwise. */ boolean ! open_library(lib_name, lp) ! const char *lib_name; library *lp; { boolean status = FALSE; ! lp->fdata = fopen_datafile(lib_name, RDBMODE); if (lp->fdata) { if (readlibdir(lp)) { status = TRUE; --- 175,187 ---- * structure. Return TRUE if successful, FALSE otherwise. */ boolean ! open_library(lib_area, lib_name, lp) ! const char *lib_area, *lib_name; library *lp; { boolean status = FALSE; ! lp->fdata = fopen_datafile_area(lib_area, lib_name, RDBMODE); if (lp->fdata) { if (readlibdir(lp)) { status = TRUE; *************** *** 207,215 **** (void) memset((char *)&dlb_libs[0], 0, sizeof(dlb_libs)); /* To open more than one library, add open library calls here. */ ! if (!open_library(DLBFILE, &dlb_libs[0])) return dlb_initialized; #ifdef DLBFILE2 ! if (!open_library(DLBFILE2, &dlb_libs[1])) return dlb_initialized; #endif dlb_initialized = TRUE; --- 217,225 ---- (void) memset((char *)&dlb_libs[0], 0, sizeof(dlb_libs)); /* To open more than one library, add open library calls here. */ ! if (!open_library(DLBAREA, DLBFILE, &dlb_libs[0])) return dlb_initialized; #ifdef DLBFILE2 ! if (!open_library(DLBAREA2, DLBFILE2, &dlb_libs[1])) return dlb_initialized; #endif dlb_initialized = TRUE; *************** *** 231,239 **** --- 241,255 ---- } } + dlb * + #ifndef FILE_AREAS dlb_fopen(name, mode) const char *name, *mode; + #else + dlb_fopen_area(area, name, mode) + const char *area, *name, *mode; + #endif { long start, size; library *lp; *************** *** 250,256 **** --- 266,276 ---- dp->start = start; dp->size = size; dp->mark = 0; + #ifndef FILE_AREAS } else if ((fp = fopen_datafile(name, mode)) != 0) { + #else + } else if ((fp = fopen_datafile_area(area, name, mode)) != 0) { + #endif /* use an external file */ dp = (dlb *) alloc(sizeof(dlb)); dp->fp = fp; *** src/dungeon.c.orig Mon Nov 1 12:47:57 1999 --- src/dungeon.c Wed Nov 17 18:30:34 1999 *************** *** 8,13 **** --- 8,14 ---- #ifdef OVL1 + #define DUNGEON_AREA FILE_AREA_UNSHARE #define DUNGEON_FILE "dungeon" /* KMH, ROLE_PATCH -- Modified so file names fit within 8 letters */ *************** *** 646,652 **** pd.n_levs = pd.n_brs = 0; ! dgn_file = dlb_fopen(DUNGEON_FILE, RDBMODE); if (!dgn_file) panic("Cannot open dungeon description file \"%s\"!", DUNGEON_FILE); --- 647,653 ---- pd.n_levs = pd.n_brs = 0; ! dgn_file = dlb_fopen_area(DUNGEON_AREA, DUNGEON_FILE, RDBMODE); if (!dgn_file) panic("Cannot open dungeon description file \"%s\"!", DUNGEON_FILE); *** src/files.c.orig Mon Nov 1 12:48:17 1999 --- src/files.c Thu Nov 18 17:08:52 1999 *************** *** 89,99 **** static int FDECL(get_uchars, (FILE *,char *,char *,uchar *,int,const char *)); int FDECL(parse_config_line, (FILE *,char *,char *,char *)); #ifdef COMPRESS ! void FDECL(redirect, (const char *, const char *, FILE *, BOOLEAN_P)); ! void FDECL(docompress_file, (const char *, BOOLEAN_P)); #endif /* fopen a file, with OS-dependent bells and whistles */ /* NOTE: a simpler version of this routine also exists in util/dlb_main.c */ FILE * --- 89,104 ---- static int FDECL(get_uchars, (FILE *,char *,char *,uchar *,int,const char *)); int FDECL(parse_config_line, (FILE *,char *,char *,char *)); #ifdef COMPRESS ! void FDECL(redirect, (const char *, const char *, const char *, FILE *, ! BOOLEAN_P)); ! void FDECL(docompress_file, (const char *, const char *, BOOLEAN_P)); #endif + /* + * When file areas are in use, fopen_datafile_area is used instead. + */ + #ifndef FILE_AREA /* fopen a file, with OS-dependent bells and whistles */ /* NOTE: a simpler version of this routine also exists in util/dlb_main.c */ FILE * *************** *** 116,121 **** --- 121,127 ---- #endif return fp; } + #endif /* FILE_AREA */ /* ---------- BEGIN LEVEL FILE HANDLING ----------- */ *************** *** 176,188 **** /* Use O_TRUNC to force the file to be shortened if it already * exists and is currently longer. */ fd = open(lock, O_WRONLY |O_CREAT | O_TRUNC | O_BINARY, FCMASK); ! #else ! # ifdef MAC ! fd = maccreat(lock, LEVL_TYPE); # else fd = creat(lock, FCMASK); ! # endif #endif /* MICRO */ if (fd >= 0) --- 182,203 ---- /* Use O_TRUNC to force the file to be shortened if it already * exists and is currently longer. */ + # ifdef FILE_AREAS + fd = open_area(FILE_AREA_LEVL, lock, + O_WRONLY |O_CREAT | O_TRUNC | O_BINARY, FCMASK); + # else fd = open(lock, O_WRONLY |O_CREAT | O_TRUNC | O_BINARY, FCMASK); ! # endif ! #else /* MICRO */ ! # ifdef FILE_AREAS ! fd = creat_area(FILE_AREA_LEVL, lock, FCMASK); # else + # ifdef MAC + fd = maccreat(lock, LEVL_TYPE); + # else fd = creat(lock, FCMASK); ! # endif ! # endif /* FILE_AREAS */ #endif /* MICRO */ if (fd >= 0) *************** *** 204,214 **** if (level_info[lev].where != ACTIVE) swapin_file(lev); #endif ! #ifdef MAC ! fd = macopen(lock, O_RDONLY | O_BINARY, LEVL_TYPE); #else fd = open(lock, O_RDONLY | O_BINARY, 0); ! #endif return fd; } --- 219,233 ---- if (level_info[lev].where != ACTIVE) swapin_file(lev); #endif ! #ifdef FILE_AREAS ! fd = open_area(FILE_AREA_LEVL, lock, O_RDONLY | O_BINARY, 0); #else + # ifdef MAC + fd = macopen(lock, O_RDONLY | O_BINARY, LEVL_TYPE); + # else fd = open(lock, O_RDONLY | O_BINARY, 0); ! # endif ! #endif /* FILE_AREAS */ return fd; } *************** *** 223,229 **** --- 242,252 ---- */ if (lev == 0 || (level_info[lev].flags & LFILE_EXISTS)) { set_levelfile_name(lock, lev); + #ifdef FILE_AREAS + (void) remove_area(FILE_AREA_LEVL, lock); + #else (void) unlink(lock); + #endif level_info[lev].flags &= ~LFILE_EXISTS; } } *************** *** 322,334 **** /* Use O_TRUNC to force the file to be shortened if it already * exists and is currently longer. */ fd = open(file, O_WRONLY |O_CREAT | O_TRUNC | O_BINARY, FCMASK); #else ! # ifdef MAC ! fd = maccreat(file, BONE_TYPE); # else fd = creat(file, FCMASK); ! # endif # if defined(VMS) && !defined(SECURE) /* Re-protect bones file with world:read+write+execute+delete access. --- 345,366 ---- /* Use O_TRUNC to force the file to be shortened if it already * exists and is currently longer. */ + # ifdef FILE_AREAS + fd = open_area(FILE_AREA_BONES, file, + O_WRONLY |O_CREAT | O_TRUNC | O_BINARY, FCMASK); + # else fd = open(file, O_WRONLY |O_CREAT | O_TRUNC | O_BINARY, FCMASK); + # endif #else ! # ifdef FILE_AREAS ! fd = creat_area(FILE_AREA_BONES, file, FCMASK); # else + # ifdef MAC + fd = maccreat(file, BONE_TYPE); + # else fd = creat(file, FCMASK); ! # endif ! # endif /* FILE_AREAS */ # if defined(VMS) && !defined(SECURE) /* Re-protect bones file with world:read+write+execute+delete access. *************** *** 338,344 **** --- 370,380 ---- ANDs the mask with the user's default protection, which usually denies some or all access to world. */ + # ifndef FILE_AREAS (void) chmod(file, FCMASK | 007); /* allow other users full access */ + # else + (void) chmod_area(FILE_AREA_BONES, file, FCMASK | 007); + # endif # endif /* VMS && !SECURE */ #endif /* MICRO */ *************** *** 353,359 **** --- 389,399 ---- char *tempname; tempname = set_bonestemp_name(); + # ifdef FILE_AREAS + (void) remove_area(FILE_AREA_BONES, tempname); + # else (void) unlink(tempname); + # endif } #endif /* MFLOPPY */ *************** *** 368,383 **** (void) set_bonesfile_name(bones, lev); tempname = set_bonestemp_name(); ! #if (defined(SYSV) && !defined(SVR4)) || defined(GENIX) /* old SYSVs don't have rename. Some SVR3's may, but since they * also have link/unlink, it doesn't matter. :-) */ (void) unlink(bones); ret = link(tempname, bones); ret += unlink(tempname); ! #else ret = rename(tempname, bones); ! #endif #ifdef WIZARD if (wizard && ret != 0) pline("couldn't rename %s to %s", tempname, bones); --- 408,427 ---- (void) set_bonesfile_name(bones, lev); tempname = set_bonestemp_name(); ! #ifdef FILE_AREAS ! ret = rename_area(FILE_AREA_BONES, tempname, bones); ! #else ! # if (defined(SYSV) && !defined(SVR4)) || defined(GENIX) /* old SYSVs don't have rename. Some SVR3's may, but since they * also have link/unlink, it doesn't matter. :-) */ (void) unlink(bones); ret = link(tempname, bones); ret += unlink(tempname); ! # else ret = rename(tempname, bones); ! # endif ! #endif /* FILE_AREAS */ #ifdef WIZARD if (wizard && ret != 0) pline("couldn't rename %s to %s", tempname, bones); *************** *** 393,404 **** int fd; *bonesid = set_bonesfile_name(bones, lev); ! uncompress(bones); /* no effect if nonexistent */ ! #ifdef MAC ! fd = macopen(bones, O_RDONLY | O_BINARY, BONE_TYPE); #else fd = open(bones, O_RDONLY | O_BINARY, 0); ! #endif return fd; } --- 437,452 ---- int fd; *bonesid = set_bonesfile_name(bones, lev); ! uncompress_area(FILE_AREA_BONES, bones); /* no effect if nonexistent */ ! #ifdef FILE_AREAS ! fd = open_area(FILE_AREA_BONES, bones, O_RDONLY | O_BINARY, 0); #else + # ifdef MAC + fd = macopen(bones, O_RDONLY | O_BINARY, BONE_TYPE); + # else fd = open(bones, O_RDONLY | O_BINARY, 0); ! # endif ! #endif /* FILE_AREAS */ return fd; } *************** *** 408,414 **** --- 456,466 ---- d_level *lev; { (void) set_bonesfile_name(bones, lev); + #ifdef FILE_AREAS + return !(remove_area(FILE_AREA_BONES, bones) < 0); + #else return !(unlink(bones) < 0); + #endif } *************** *** 417,423 **** void compress_bonesfile() { ! compress(bones); } /* ---------- END BONES FILE HANDLING ----------- */ --- 469,475 ---- void compress_bonesfile() { ! compress_area(FILE_AREA_BONES, bones); } /* ---------- END BONES FILE HANDLING ----------- */ *************** *** 431,438 **** --- 483,495 ---- set_savefile_name() { #ifdef VMS + #ifndef FILE_AREAS Sprintf(SAVEF, "[.save]%d%s", getuid(), plname); regularize(SAVEF+7); + #else + Sprintf(SAVEF, "%d%s", getuid(), plname); + regularize(SAVEF); + #endif Strcat(SAVEF, ";1"); #else # ifdef MICRO *************** *** 452,459 **** --- 509,521 ---- } Strcat(SAVEF, ".sav"); # else + # ifndef FILE_AREAS Sprintf(SAVEF, "save/%d%s", (int)getuid(), plname); regularize(SAVEF+5); /* avoid . or / in name */ + # else + Sprintf(SAVEF, "%d%s", (int)getuid(), plname); + regularize(SAVEF); /* avoid . or / in name */ + # endif # endif /* MICRO */ #endif /* VMS */ } *************** *** 495,524 **** create_savefile() { int fd; ! #ifdef AMIGA ! fd = ami_wbench_getsave(O_WRONLY | O_CREAT | O_TRUNC); ! #else # ifdef MICRO ! fd = open(SAVEF, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, FCMASK); # else ! # ifdef MAC ! fd = maccreat(SAVEF, SAVE_TYPE); # else fd = creat(SAVEF, FCMASK); ! # endif ! # if defined(VMS) && !defined(SECURE) /* Make sure the save file is owned by the current process. That's the default for non-privileged users, but for priv'd users the file will be owned by the directory's owner instead of the user. */ ! # ifdef getuid /*(see vmsunix.c)*/ ! # undef getuid ! # endif (void) chown(SAVEF, getuid(), getgid()); ! # endif /* VMS && !SECURE */ ! # endif /* MICRO */ ! #endif /* AMIGA */ return fd; } --- 557,600 ---- create_savefile() { int fd; ! #ifdef FILE_AREAS # ifdef MICRO ! fd = open_area(FILE_AREA_SAVE, SAVEF, ! O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, FCMASK); # else ! fd = creat_area(FILE_AREA_SAVE, SAVEF, FCMASK); ! # endif ! #else /* FILE_AREAS */ ! # ifdef AMIGA ! fd = ami_wbench_getsave(O_WRONLY | O_CREAT | O_TRUNC); ! # else ! # ifdef MICRO ! fd = open(SAVEF, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, FCMASK); # else + # ifdef MAC + fd = maccreat(SAVEF, SAVE_TYPE); + # else fd = creat(SAVEF, FCMASK); ! # endif ! # endif /* MICRO */ ! # endif /* AMIGA */ ! #endif /* FILE_AREAS */ ! ! #if defined(VMS) && !defined(SECURE) /* Make sure the save file is owned by the current process. That's the default for non-privileged users, but for priv'd users the file will be owned by the directory's owner instead of the user. */ ! # ifdef getuid /*(see vmsunix.c)*/ ! # undef getuid ! # endif ! # ifdef FILE_AREAS ! (void) chown_area(FILE_AREA_SAVE, SAVEF, getuid(), getgid()); ! # else (void) chown(SAVEF, getuid(), getgid()); ! # endif ! #endif return fd; } *************** *** 530,544 **** { int fd; ! #ifdef AMIGA ! fd = ami_wbench_getsave(O_RDONLY); #else ! # ifdef MAC ! fd = macopen(SAVEF, O_RDONLY | O_BINARY, SAVE_TYPE); # else fd = open(SAVEF, O_RDONLY | O_BINARY, 0); ! # endif ! #endif /* AMIGA */ return fd; } --- 606,624 ---- { int fd; ! #ifdef FILE_AREAS ! fd = open_area(FILE_AREA_SAVE, SAVEF, O_RDONLY | O_BINARY, 0); #else ! # ifdef AMIGA ! fd = ami_wbench_getsave(O_RDONLY); # else + # ifdef MAC + fd = macopen(SAVEF, O_RDONLY | O_BINARY, SAVE_TYPE); + # else fd = open(SAVEF, O_RDONLY | O_BINARY, 0); ! # endif ! # endif /* AMIGA */ ! #endif /* FILE_AREAS */ return fd; } *************** *** 558,567 **** } #endif ! #ifdef AMIGA ami_wbench_unlink(SAVEF); ! #endif (void) unlink(SAVEF); return 0; /* for restore_saved_game() (ex-xxxmain.c) test */ } --- 638,651 ---- } #endif ! #ifdef FILE_AREAS ! (void) remove_area(FILE_AREA_SAVE, SAVEF); ! #else ! # ifdef AMIGA ami_wbench_unlink(SAVEF); ! # endif (void) unlink(SAVEF); + #endif return 0; /* for restore_saved_game() (ex-xxxmain.c) test */ } *************** *** 583,589 **** ) return -1; #endif /* MFLOPPY */ ! uncompress(SAVEF); if ((fd = open_savefile()) < 0) return fd; if (!uptodate(fd, SAVEF)) { --- 667,673 ---- ) return -1; #endif /* MFLOPPY */ ! uncompress_area(FILE_AREA_SAVE, SAVEF); if ((fd = open_savefile()) < 0) return fd; if (!uptodate(fd, SAVEF)) { *************** *** 601,613 **** #ifdef COMPRESS void ! redirect(filename, mode, stream, uncomp) ! const char *filename, *mode; FILE *stream; boolean uncomp; { ! if (freopen(filename, mode, stream) == (FILE *)0) { ! (void) fprintf(stderr, "freopen of %s for %scompress failed\n", filename, uncomp ? "un" : ""); terminate(EXIT_FAILURE); } --- 685,701 ---- #ifdef COMPRESS void ! redirect(filearea, filename, mode, stream, uncomp) ! const char *filearea, *filename, *mode; FILE *stream; boolean uncomp; { ! #ifndef FILE_AREAS ! if (freopen(filename, mode, stream) == (FILE *)0) { ! #else ! if (freopen_area(filearea, filename, mode, stream) == (FILE *)0) { ! #endif ! (void) fprintf(stderr, "redirect of %s for %scompress failed\n", filename, uncomp ? "un" : ""); terminate(EXIT_FAILURE); } *************** *** 621,628 **** * cf. child() in unixunix.c. */ void ! docompress_file(filename, uncomp) ! const char *filename; boolean uncomp; { char cfn[80]; --- 705,712 ---- * cf. child() in unixunix.c. */ void ! docompress_file(filearea, filename, uncomp) ! const char *filearea, *filename; boolean uncomp; { char cfn[80]; *************** *** 640,646 **** # endif /* when compressing, we know the file exists */ if (uncomp) { ! if ((cf = fopen(cfn, RDBMODE)) == (FILE *)0) return; (void) fclose(cf); } --- 724,730 ---- # endif /* when compressing, we know the file exists */ if (uncomp) { ! if ((cf = fopen_datafile_area(filearea, cfn, RDBMODE)) == (FILE *)0) return; (void) fclose(cf); } *************** *** 682,692 **** * compress and gzip, those mentioned in config.h. */ if (uncomp) { ! redirect(cfn, RDBMODE, stdin, uncomp); ! redirect(filename, WRBMODE, stdout, uncomp); } else { ! redirect(filename, RDBMODE, stdin, uncomp); ! redirect(cfn, WRBMODE, stdout, uncomp); } (void) setgid(getgid()); (void) setuid(getuid()); --- 766,776 ---- * compress and gzip, those mentioned in config.h. */ if (uncomp) { ! redirect(filearea, cfn, RDBMODE, stdin, uncomp); ! redirect(filearea, filename, WRBMODE, stdout, uncomp); } else { ! redirect(filearea, filename, RDBMODE, stdin, uncomp); ! redirect(filearea, cfn, WRBMODE, stdout, uncomp); } (void) setgid(getgid()); (void) setuid(getuid()); *************** *** 714,755 **** # endif /* remove file left behind */ if (uncomp) ! (void) unlink(cfn); else ! (void) unlink(filename); } #endif /* COMPRESS */ /* compress file */ void ! compress(filename) ! const char *filename; #ifdef applec ! # pragma unused(filename) #endif { #ifdef COMPRESS ! docompress_file(filename, FALSE); #endif } /* uncompress file if it exists */ void ! uncompress(filename) ! const char *filename; #ifdef applec ! # pragma unused(filename) #endif { #ifdef COMPRESS ! docompress_file(filename, TRUE); #endif } /* ---------- END FILE COMPRESSION HANDLING ----------- */ /* ---------- BEGIN FILE LOCKING HANDLING ----------- */ static int nesting = 0; --- 798,853 ---- # endif /* remove file left behind */ if (uncomp) ! #ifndef FILE_AREAS ! (void) unlink(cfn); ! #else ! (void) remove_area(filearea, cfn); ! #endif else ! #ifndef FILE_AREAS ! (void) unlink(filename); ! #else ! (void) remove_area(filearea, filename); ! #endif } #endif /* COMPRESS */ /* compress file */ void ! compress_area(filearea, filename) ! const char *filearea, *filename; #ifdef applec ! # pragma unused(filearea,filename) #endif { #ifdef COMPRESS ! docompress_file(filearea, filename, FALSE); #endif } /* uncompress file if it exists */ void ! uncompress_area(filearea, filename) ! const char *filearea, *filename; #ifdef applec ! # pragma unused(filearea,filename) #endif { #ifdef COMPRESS ! docompress_file(filearea, filename, TRUE); #endif } /* ---------- END FILE COMPRESSION HANDLING ----------- */ + /* + * When file areas are in use, (un)lock_file_area are used instead. + */ + + #ifndef FILE_AREAS + /* ---------- BEGIN FILE LOCKING HANDLING ----------- */ static int nesting = 0; *************** *** 926,931 **** --- 1024,1030 ---- /* ---------- END FILE LOCKING HANDLING ----------- */ + #endif /* FILE_AREAS */ /* ---------- BEGIN CONFIG FILE HANDLING ----------- */ *** src/pager.c.orig Mon Nov 1 12:47:58 1999 --- src/pager.c Thu Nov 18 12:31:03 1999 *************** *** 179,185 **** int chk_skip; boolean found_in_file = FALSE, skipping_entry = FALSE; ! fp = dlb_fopen(DATAFILE, "r"); if (!fp) { pline("Cannot open data file!"); return; --- 179,185 ---- int chk_skip; boolean found_in_file = FALSE, skipping_entry = FALSE; ! fp = dlb_fopen_area(DATAAREA, DATAFILE, "r"); if (!fp) { pline("Cannot open data file!"); return; *************** *** 580,586 **** char bufr[BUFSZ+6]; register char *buf = &bufr[6], *ep, q, ctrl, meta; ! fp = dlb_fopen(CMDHELPFILE, "r"); if (!fp) { pline("Cannot open data file!"); return 0; --- 580,586 ---- char bufr[BUFSZ+6]; register char *buf = &bufr[6], *ep, q, ctrl, meta; ! fp = dlb_fopen_area(CMDHELPAREA, CMDHELPFILE, "r"); if (!fp) { pline("Cannot open data file!"); return 0; *** src/questpgr.c.orig Mon Nov 1 12:47:58 1999 --- src/questpgr.c Thu Nov 18 12:25:34 1999 *************** *** 9,14 **** --- 9,15 ---- #include "qtext.h" + #define QTEXT_AREA FILE_AREA_SHARE #define QTEXT_FILE "quest.dat" /* #define DEBUG */ *************** *** 97,103 **** char qt_classes[CATMAX][CATLEN]; long qt_offsets[CATMAX]; ! msg_file = dlb_fopen(QTEXT_FILE, RDBMODE); if (!msg_file) panic("\rCANNOT OPEN QUEST TEXT FILE %s.", QTEXT_FILE); --- 98,104 ---- char qt_classes[CATMAX][CATLEN]; long qt_offsets[CATMAX]; ! msg_file = dlb_fopen_area(QTEXT_AREA, QTEXT_FILE, RDBMODE); if (!msg_file) panic("\rCANNOT OPEN QUEST TEXT FILE %s.", QTEXT_FILE); *** src/rumors.c.orig Mon Nov 1 12:47:58 1999 --- src/rumors.c Thu Nov 18 12:24:06 1999 *************** *** 72,78 **** if (true_rumor_size < 0L) /* we couldn't open RUMORFILE */ return rumor_buf; ! rumors = dlb_fopen(RUMORFILE, "r"); if (rumors) { if (true_rumor_size == 0L) { /* if this is 1st outrumor() */ --- 72,78 ---- if (true_rumor_size < 0L) /* we couldn't open RUMORFILE */ return rumor_buf; ! rumors = dlb_fopen_area(RUMORAREA, RUMORFILE, "r"); if (rumors) { if (true_rumor_size == 0L) { /* if this is 1st outrumor() */ *************** *** 216,222 **** (oracle_flg > 0 && oracle_cnt == 0)) /* oracles already exhausted */ return; ! oracles = dlb_fopen(ORACLEFILE, "r"); if (oracles) { winid tmpwin; --- 216,222 ---- (oracle_flg > 0 && oracle_cnt == 0)) /* oracles already exhausted */ return; ! oracles = dlb_fopen_area(ORACLEAREA, ORACLEFILE, "r"); if (oracles) { winid tmpwin; *** src/save.c.orig Mon Nov 1 12:47:58 1999 --- src/save.c Thu Nov 18 16:34:23 1999 *************** *** 173,186 **** #endif HUP if (iflags.window_inited) { ! uncompress(SAVEF); fd = open_savefile(); if (fd > 0) { (void) close(fd); clear_nhwindow(WIN_MESSAGE); pline("There seems to be an old save file."); if (yn("Overwrite the old file?") == 'n') { ! compress(SAVEF); #ifdef KEEP_SAVE /*WAC don't restore if you didn't save*/ saverestore = FALSE; --- 173,186 ---- #endif HUP if (iflags.window_inited) { ! uncompress_area(FILE_AREA_SAVE, SAVEF); fd = open_savefile(); if (fd > 0) { (void) close(fd); clear_nhwindow(WIN_MESSAGE); pline("There seems to be an old save file."); if (yn("Overwrite the old file?") == 'n') { ! compress_area(FILE_AREA_SAVE, SAVEF); #ifdef KEEP_SAVE /*WAC don't restore if you didn't save*/ saverestore = FALSE; *************** *** 308,314 **** delete_levelfile(ledger_no(&u.uz)); delete_levelfile(0); ! compress(SAVEF); #ifdef AMIGA ami_wbench_iconwrite(SAVEF); #endif --- 308,314 ---- delete_levelfile(ledger_no(&u.uz)); delete_levelfile(0); ! compress_area(FILE_AREA_SAVE, SAVEF); #ifdef AMIGA ami_wbench_iconwrite(SAVEF); #endif *** src/sp_lev.c.orig Mon Nov 1 12:47:59 1999 --- src/sp_lev.c Thu Nov 18 12:21:53 1999 *************** *** 2607,2613 **** char c; struct version_info vers_info; ! fd = dlb_fopen(name, RDBMODE); if (!fd) return FALSE; Fread((genericptr_t) &vers_info, sizeof vers_info, 1, fd); --- 2607,2613 ---- char c; struct version_info vers_info; ! fd = dlb_fopen_area(FILE_AREA_UNSHARE, name, RDBMODE); if (!fd) return FALSE; Fread((genericptr_t) &vers_info, sizeof vers_info, 1, fd); *** src/topten.c.orig Mon Nov 1 12:47:59 1999 --- src/topten.c Thu Nov 18 14:50:07 1999 *************** *** 361,374 **** #endif #ifdef LOGFILE /* used for debugging (who dies of what, where) */ ! if (lock_file(LOGFILE, 10)) { ! if(!(lfile = fopen_datafile(LOGFILE,"a"))) { HUP raw_print("Cannot open log file!"); } else { writeentry(lfile, t0); (void) fclose(lfile); } ! unlock_file(LOGFILE); } #endif /* LOGFILE */ --- 361,374 ---- #endif #ifdef LOGFILE /* used for debugging (who dies of what, where) */ ! if (lock_file_area(LOGAREA, LOGFILE, 10)) { ! if(!(lfile = fopen_datafile_area(LOGAREA, LOGFILE, "a"))) { HUP raw_print("Cannot open log file!"); } else { writeentry(lfile, t0); (void) fclose(lfile); } ! unlock_file_area(LOGAREA, LOGFILE); } #endif /* LOGFILE */ *************** *** 384,401 **** goto showwin; } ! if (!lock_file(RECORD, 60)) goto destroywin; #ifdef UPDATE_RECORD_IN_PLACE ! rfile = fopen_datafile(RECORD, "r+"); #else ! rfile = fopen_datafile(RECORD, "r"); #endif if (!rfile) { HUP raw_print("Cannot open record file!"); ! unlock_file(RECORD); goto destroywin; } --- 384,401 ---- goto showwin; } ! if (!lock_file_area(RECORD_AREA, RECORD, 60)) goto destroywin; #ifdef UPDATE_RECORD_IN_PLACE ! rfile = fopen_datafile_area(FILE_AREA_VAR,RECORD, "r+"); #else ! rfile = fopen_datafile_area(FILE_AREA_VAR,RECORD, "r"); #endif if (!rfile) { HUP raw_print("Cannot open record file!"); ! unlock_file_area(RECORD_AREA, RECORD); goto destroywin; } *************** *** 471,479 **** t0->fpos : final_fpos), SEEK_SET); #else (void) fclose(rfile); ! if(!(rfile = fopen_datafile(RECORD,"w"))){ HUP raw_print("Cannot write record file"); ! unlock_file(RECORD); free_ttlist(tt_head); goto destroywin; } --- 471,479 ---- t0->fpos : final_fpos), SEEK_SET); #else (void) fclose(rfile); ! if(!(rfile = fopen_datafile_area(FILE_AREA_VAR,RECORD,"w"))){ HUP raw_print("Cannot write record file"); ! unlock_file_area(RECORD_AREA, RECORD); free_ttlist(tt_head); goto destroywin; } *************** *** 553,559 **** } #endif /* UPDATE_RECORD_IN_PLACE */ (void) fclose(rfile); ! unlock_file(RECORD); free_ttlist(tt_head); showwin: --- 553,559 ---- } #endif /* UPDATE_RECORD_IN_PLACE */ (void) fclose(rfile); ! unlock_file_area(RECORD_AREA, RECORD); free_ttlist(tt_head); showwin: *************** *** 784,790 **** return; } ! rfile = fopen_datafile(RECORD, "r"); if (!rfile) { raw_print("Cannot open record file!"); return; --- 784,790 ---- return; } ! rfile = fopen_datafile_area(FILE_AREA_VAR,RECORD, "r"); if (!rfile) { raw_print("Cannot open record file!"); return; *************** *** 981,987 **** if (!otmp) return((struct obj *) 0); ! rfile = fopen_datafile(RECORD, "r"); if (!rfile) { impossible("Cannot open record file!"); return (struct obj *)0; --- 981,987 ---- if (!otmp) return((struct obj *) 0); ! rfile = fopen_datafile_area(FILE_AREA_VAR,RECORD, "r"); if (!rfile) { impossible("Cannot open record file!"); return (struct obj *)0; *** sys/unix/Makefile.dat.orig Mon Nov 1 12:48:17 1999 --- sys/unix/Makefile.dat Wed Nov 24 11:22:04 1999 *************** *** 130,133 **** spotless: -rm -f spec_levs quest_levs *.lev $(VARDAT) dungeon dungeon.pdf ! -rm -f nhdat x11tiles pet_mark.xbm rip.xpm tiles.xpm --- 130,133 ---- spotless: -rm -f spec_levs quest_levs *.lev $(VARDAT) dungeon dungeon.pdf ! -rm -f nhshare nhunshare x11tiles pet_mark.xbm rip.xpm tiles.xpm *** sys/unix/Makefile.top.orig Mon Nov 1 12:48:17 1999 --- sys/unix/Makefile.top Wed Nov 24 11:21:49 1999 *************** *** 28,56 **** # GAMEDIR also appears in config.h as "HACKDIR". # ! # note that 'make install' believes in creating a nice tidy GAMEDIR for ! # installation, free of debris from previous NetHack versions -- ! # therefore there should not be anything in GAMEDIR that you want to keep # (if there is, you'll have to do the installation by hand or modify the # instructions) ! GAMEDIR = /usr/local/slashemdir ! SHELLDIR = /usr/local/bin ! # KDEDIR = /opt/kde # SHELLDIR = $(KDEDIR)/bin # per discussions in Install.X11 and Install.Qt ! VARQTND = tiles.xpm rip.xpm ! VARX11ND = x11tiles pet_mark.xbm ! # VARX11ND = x11tiles pet_mark.xbm rip.xpm ! # VARDATND = $(VARX11ND) ! # VARDATND = $(VARQTND) ! VARDATND = ! VARDATD = data oracles options quest.dat rumors ! VARDAT = $(VARDATD) $(VARDATND) # Some versions of make use the SHELL environment variable as the shell # for running commands. We need this to be a Bourne shell. --- 28,85 ---- # GAMEDIR also appears in config.h as "HACKDIR". # ! # note that 'make install' believes in creating nice tidy directories for ! # installation, free of debris from previous Slash'EM versions -- therefore ! # there should not be anything in these directories that you want to keep # (if there is, you'll have to do the installation by hand or modify the # instructions) ! # These must agree with the definitions in unixconf.h ! ! # Defs. for non file areas support. ! GAMEDIR = /usr/local/slashemdir ! FILE_AREA_VAR = $(GAMEDIR) ! FILE_AREA_SAVE = $(GAMEDIR)/save ! FILE_AREA_SHARE = $(GAMEDIR) ! FILE_AREA_UNSHARE = $(GAMEDIR) ! FILE_AREA_BONES = $(FILE_AREA_VAR) ! FILE_AREA_LEVL = $(FILE_AREA_VAR) ! SHELLDIR = /usr/local/bin ! ! # Defs. compatible with Linux's FSSTND 1.2 ! # FILE_AREA_VAR = /var/lib/games/slashem ! # FILE_AREA_SAVE = /var/lib/games/slashem/save ! # FILE_AREA_SHARE = /usr/lib/games/slashem ! # FILE_AREA_UNSHARE = /usr/lib/games/slashem ! # FILE_AREA_BONES = $(FILE_AREA_VAR) ! # FILE_AREA_LEVL = $(FILE_AREA_VAR) ! # SHELLDIR = /usr/games ! ! # Defs. compatible with FHS 2.0 ! # FILE_AREA_VAR = /var/games/slashem ! # FILE_AREA_SAVE = /var/games/slashem/save ! # FILE_AREA_SHARE = /usr/share/games/slashem ! # FILE_AREA_UNSHARE = /usr/lib/games/slashem ! # FILE_AREA_BONES = $(FILE_AREA_VAR) ! # FILE_AREA_LEVL = $(FILE_AREA_VAR) ! # SHELLDIR = /usr/games + # KDEDIR = /opt/kde # SHELLDIR = $(KDEDIR)/bin + # Shareable (architecture independent) data files which are not candidates + # for inclusion in DLB libraries (ND) and which are (D). Port specific files # per discussions in Install.X11 and Install.Qt ! CNF_SHARE_QTND = tiles.xpm rip.xpm ! CNF_SHARE_X11ND = x11tiles pet_mark.xbm ! # CNF_SHARE_X11ND = x11tiles pet_mark.xbm rip.xpm ! # CNF_SHARE_DATND = $(CNF_SHARE_X11ND) ! # CNF_SHARE_DATND = $(CNF_SHARE_QTND) ! CNF_SHARE_DATND = ! CNF_SHARE_DATD = data oracles options quest.dat rumors ! CNF_SHARE_DAT = $(CNF_SHARE_DATD) $(CNF_SHARE_DATND) # Some versions of make use the SHELL environment variable as the shell # for running commands. We need this to be a Bourne shell. *************** *** 86,99 **** #QUEST_LEVS = ?-goal.lev ?-fill?.lev ?-locate.lev ?-start.lev QUEST_LEVS = ???-goal.lev ???-fil?.lev ???-loca.lev ???-strt.lev ! DATNODLB = $(VARDATND) license ! DATDLB = $(DATHELP) dungeon $(SPEC_LEVS) $(QUEST_LEVS) $(VARDATD) ! DAT = $(DATNODLB) $(DATDLB) $(GAME): ( cd src ; $(MAKE) ) ! all: $(GAME) Guidebook $(VARDAT) dungeon spec_levs check-dlb @echo "Done." Guidebook: --- 115,131 ---- #QUEST_LEVS = ?-goal.lev ?-fill?.lev ?-locate.lev ?-start.lev QUEST_LEVS = ???-goal.lev ???-fil?.lev ???-loca.lev ???-strt.lev ! SHARE_DATNODLB = $(CNF_SHARE_DATND) license ! UNSHARE_DATNODLB = ! SHARE_DATDLB = $(DATHELP) $(CNF_SHARE_DATD) ! UNSHARE_DATDLB = dungeon $(SPEC_LEVS) $(QUEST_LEVS) ! SHARE_DAT = $(SHARE_DATNODLB) $(SHARE_DATDLB) ! UNSHARE_DAT = $(UNSHARE_DATNODLB) $(UNSHARE_DATDLB) $(GAME): ( cd src ; $(MAKE) ) ! all: $(GAME) Guidebook $(CNF_SHARE_DAT) dungeon spec_levs check-dlb @echo "Done." Guidebook: *************** *** 155,161 **** dlb: ( cd util ; $(MAKE) dlb ) ! ( cd dat ; ../util/dlb cf nhdat $(DATDLB) ) dofiles: --- 187,194 ---- dlb: ( cd util ; $(MAKE) dlb ) ! ( cd dat ; ../util/dlb cf nhshare $(SHARE_DATDLB) ) ! ( cd dat ; ../util/dlb cf nhunshare $(UNSHARE_DATDLB) ) dofiles: *************** *** 166,234 **** -e '}' \ -e '$$s/.*/nodlb/p' < dat/options` ; \ $(MAKE) dofiles-$${target-nodlb} ! cp src/$(GAME) $(GAMEDIR) ! cp doc/Guidebook.txt $(GAMEDIR) # cp win/Qt/KDE/kslashem.kdelnk $(KDEDIR)/share/applnk/Games -rm -f $(SHELLDIR)/$(GAME) ! sed -e 's;/usr/games/lib/nethackdir;$(GAMEDIR);' \ -e 's;HACKDIR/nethack;HACKDIR/$(GAME);' \ < sys/unix/nethack.sh \ > $(SHELLDIR)/$(GAME) # set up their permissions ! -( cd $(GAMEDIR) ; $(CHOWN) $(GAMEUID) $(GAME) ; \ $(CHGRP) $(GAMEGRP) $(GAME) ) ! chmod $(GAMEPERM) $(GAMEDIR)/$(GAME) ! $(CHOWN) $(GAMEUID) $(GAMEDIR)/Guidebook.txt ! $(CHGRP) $(GAMEGRP) $(GAMEDIR)/Guidebook.txt ! chmod $(FILEPERM) $(GAMEDIR)/Guidebook.txt -$(CHOWN) $(GAMEUID) $(SHELLDIR)/$(GAME) $(CHGRP) $(GAMEGRP) $(SHELLDIR)/$(GAME) chmod $(EXEPERM) $(SHELLDIR)/$(GAME) dofiles-dlb: check-dlb ! ( cd dat ; cp nhdat $(DATNODLB) $(GAMEDIR) ) # set up their permissions ! -( cd $(GAMEDIR) ; $(CHOWN) $(GAMEUID) nhdat $(DATNODLB) ; \ ! $(CHGRP) $(GAMEGRP) nhdat $(DATNODLB) ; \ ! chmod $(FILEPERM) nhdat $(DATNODLB) ) dofiles-nodlb: # copy over the game files ! ( cd dat ; cp $(DAT) $(GAMEDIR) ) # set up their permissions ! -( cd $(GAMEDIR) ; $(CHOWN) $(GAMEUID) $(DAT) ; \ ! $(CHGRP) $(GAMEGRP) $(DAT) ; \ ! chmod $(FILEPERM) $(DAT) ) ! update: $(GAME) $(VARDAT) dungeon spec_levs Guidebook.txt # (don't yank the old version out from under people who're playing it) ! -mv $(GAMEDIR)/$(GAME) $(GAMEDIR)/$(GAME).old # quest.dat is also kept open and has the same problems over NFS ! # (quest.dat may be inside nhdat if dlb is in use) ! -mv $(GAMEDIR)/quest.dat $(GAMEDIR)/quest.dat.old ! -mv $(GAMEDIR)/nhdat $(GAMEDIR)/nhdat.old # set up new versions of the game files ( $(MAKE) dofiles ) # touch time-sensitive files ! -touch -c $(GAMEDIR)/bones* $(GAMEDIR)/?lock* $(GAMEDIR)/wizard* ! -touch -c $(GAMEDIR)/save/* ! touch $(GAMEDIR)/perm $(GAMEDIR)/record # and a reminder @echo You may also want to install the man pages via the doc Makefile. ! install: $(GAME) $(VARDAT) dungeon spec_levs Guidebook.txt # set up the directories -mkdir $(SHELLDIR) ! -rm -rf $(GAMEDIR) ! -mkdir $(GAMEDIR) $(GAMEDIR)/save ! -$(CHOWN) $(GAMEUID) $(GAMEDIR) $(GAMEDIR)/save ! $(CHGRP) $(GAMEGRP) $(GAMEDIR) $(GAMEDIR)/save ! chmod $(DIRPERM) $(GAMEDIR) $(GAMEDIR)/save # set up the game files ( $(MAKE) dofiles ) # set up some additional files ! touch $(GAMEDIR)/perm $(GAMEDIR)/record $(GAMEDIR)/logfile ! -( cd $(GAMEDIR) ; $(CHOWN) $(GAMEUID) perm record logfile ; \ $(CHGRP) $(GAMEGRP) perm record logfile ; \ chmod $(FILEPERM) perm record logfile ) # and a reminder --- 199,282 ---- -e '}' \ -e '$$s/.*/nodlb/p' < dat/options` ; \ $(MAKE) dofiles-$${target-nodlb} ! cp src/$(GAME) $(FILE_AREA_UNSHARE) ! cp doc/Guidebook.txt $(FILE_AREA_SHARE) # cp win/Qt/KDE/kslashem.kdelnk $(KDEDIR)/share/applnk/Games -rm -f $(SHELLDIR)/$(GAME) ! sed -e 's;/usr/games/lib/nethackdir;$(FILE_AREA_UNSHARE);' \ -e 's;HACKDIR/nethack;HACKDIR/$(GAME);' \ < sys/unix/nethack.sh \ > $(SHELLDIR)/$(GAME) # set up their permissions ! -( cd $(FILE_AREA_UNSHARE) ; $(CHOWN) $(GAMEUID) $(GAME) ; \ $(CHGRP) $(GAMEGRP) $(GAME) ) ! chmod $(GAMEPERM) $(FILE_AREA_UNSHARE)/$(GAME) ! $(CHOWN) $(GAMEUID) $(FILE_AREA_SHARE)/Guidebook.txt ! $(CHGRP) $(GAMEGRP) $(FILE_AREA_SHARE)/Guidebook.txt ! chmod $(FILEPERM) $(FILE_AREA_SHARE)/Guidebook.txt -$(CHOWN) $(GAMEUID) $(SHELLDIR)/$(GAME) $(CHGRP) $(GAMEGRP) $(SHELLDIR)/$(GAME) chmod $(EXEPERM) $(SHELLDIR)/$(GAME) dofiles-dlb: check-dlb ! ( cd dat ; cp nhshare $(SHARE_DATNODLB) $(FILE_AREA_SHARE) ) ! ( cd dat ; cp nhunshare $(UNSHARE_DATNODLB) $(FILE_AREA_UNSHARE) ) # set up their permissions ! -( cd $(FILE_AREA_SHARE) ; \ ! $(CHOWN) $(GAMEUID) nhshare $(SHARE_DATNODLB) ; \ ! $(CHGRP) $(GAMEGRP) nhshare $(SHARE_DATNODLB) ; \ ! chmod $(FILEPERM) nhshare $(SHARE_DATNODLB) ) ! -( cd $(FILE_AREA_UNSHARE) ; \ ! $(CHOWN) $(GAMEUID) nhunshare $(UNSHARE_DATNODLB) ; \ ! $(CHGRP) $(GAMEGRP) nhunshare $(UNSHARE_DATNODLB) ; \ ! chmod $(FILEPERM) nhunshare $(UNSHARE_DATNODLB) ) dofiles-nodlb: # copy over the game files ! ( cd dat ; cp $(SHARE_DAT) $(FILE_AREA_SHARE) ) ! ( cd dat ; cp $(UNSHARE_DAT) $(FILE_AREA_UNSHARE) ) # set up their permissions ! -( cd $(FILE_AREA_SHARE) ; $(CHOWN) $(GAMEUID) $(SHARE_DAT) ; \ ! $(CHGRP) $(GAMEGRP) $(SHARE_DAT) ; \ ! chmod $(FILEPERM) $(SHARE_DAT) ) ! -( cd $(FILE_AREA_UNSHARE) ; $(CHOWN) $(GAMEUID) $(UNSHARE_DAT) ; \ ! $(CHGRP) $(GAMEGRP) $(UNSHARE_DAT) ; \ ! chmod $(FILEPERM) $(UNSHARE_DAT) ) ! update: $(GAME) $(CNF_SHARE_DAT) dungeon spec_levs Guidebook.txt # (don't yank the old version out from under people who're playing it) ! -mv $(FILE_AREA_UNSHARE)/$(GAME) $(FILE_AREA_UNSHARE)/$(GAME).old # quest.dat is also kept open and has the same problems over NFS ! # (quest.dat may be inside nhunshare if dlb is in use) ! -mv $(FILE_AREA_UNSHARE)/quest.dat $(FILE_AREA_UNSHARE)/quest.dat.old ! -mv $(FILE_AREA_UNSHARE)/nhunshare $(FILE_AREA_UNSHARE)/nhunshare.old # set up new versions of the game files ( $(MAKE) dofiles ) # touch time-sensitive files ! -touch -c $(FILE_AREA_BONES)/bones* $(FILE_AREA_VAR)/?lock* ! -touch -c $(FILE_AREA_VAR)/wizard* $(FILE_AREA_SAVE)/* ! touch $(FILE_AREA_VAR)/perm $(FILE_AREA_VAR)/record # and a reminder @echo You may also want to install the man pages via the doc Makefile. ! install: $(GAME) $(CNF_SHARE_DAT) dungeon spec_levs Guidebook.txt # set up the directories -mkdir $(SHELLDIR) ! -rm -rf $(FILE_AREA_VAR) $(FILE_AREA_BONES) $(FILE_AREA_SAVE) ! -rm -rf $(FILE_AREA_LEVL) $(FILE_AREA_SHARE) $(FILE_AREA_UNSHARE) ! -mkdir $(FILE_AREA_VAR) $(FILE_AREA_BONES) $(FILE_AREA_SAVE) ! -mkdir $(FILE_AREA_LEVL) $(FILE_AREA_SHARE) $(FILE_AREA_UNSHARE) ! -$(CHOWN) $(GAMEUID) $(FILE_AREA_VAR) $(FILE_AREA_BONES) $(FILE_AREA_SAVE) ! $(CHGRP) $(GAMEGRP) $(FILE_AREA_VAR) $(FILE_AREA_BONES) $(FILE_AREA_SAVE) ! chmod $(DIRPERM) $(FILE_AREA_VAR) $(FILE_AREA_BONES) $(FILE_AREA_SAVE) ! -$(CHOWN) $(GAMEUID) $(FILE_AREA_LEVL) $(FILE_AREA_SHARE) $(FILE_AREA_UNSHARE) ! $(CHGRP) $(GAMEGRP) $(FILE_AREA_LEVL) $(FILE_AREA_SHARE) $(FILE_AREA_UNSHARE) ! chmod $(DIRPERM) $(FILE_AREA_LEVL) $(FILE_AREA_SHARE) $(FILE_AREA_UNSHARE) # set up the game files ( $(MAKE) dofiles ) # set up some additional files ! touch $(FILE_AREA_VAR)/perm $(FILE_AREA_VAR)/record $(FILE_AREA_VAR)/logfile ! -( cd $(FILE_AREA_VAR) ; $(CHOWN) $(GAMEUID) perm record logfile ; \ $(CHGRP) $(GAMEGRP) perm record logfile ; \ chmod $(FILEPERM) perm record logfile ) # and a reminder *** sys/unix/unixmain.c.orig Mon Nov 1 12:48:03 1999 --- sys/unix/unixmain.c Thu Nov 18 16:43:59 1999 *************** *** 222,228 **** --- 222,232 ---- */ boolean remember_wiz_mode = wizard; #endif + #ifndef FILE_AREAS (void) chmod(SAVEF,0); /* disallow parallel restores */ + #else + (void) chmod_area(FILE_AREA_SAVE, SAVEF, 0); + #endif (void) signal(SIGINT, (SIG_RET_TYPE) done1); #ifdef NEWS if(iflags.news) { *************** *** 245,252 **** if(yn("Do you want to keep the save file?") == 'n') (void) delete_savefile(); else { (void) chmod(SAVEF,FCMASK); /* back to readable */ ! compress(SAVEF); } } flags.move = 0; --- 249,260 ---- if(yn("Do you want to keep the save file?") == 'n') (void) delete_savefile(); else { + #ifndef FILE_AREAS (void) chmod(SAVEF,FCMASK); /* back to readable */ ! #else ! (void) chmod_area(FILE_AREA_SAVE, SAVEF, FCMASK); ! #endif ! compress_area(FILE_AREA_SAVE, SAVEF); } } flags.move = 0; *** sys/unix/unixunix.c.orig Mon Nov 1 12:48:03 1999 --- sys/unix/unixunix.c Tue Nov 23 19:52:02 1999 *************** *** 184,190 **** #endif /* we ignore QUIT and INT at this point */ ! if (!lock_file(HLOCK, 10)) { wait_synch(); error("%s", ""); } --- 184,190 ---- #endif /* we ignore QUIT and INT at this point */ ! if (!lock_file_area(HLOCK_AREA, HLOCK, 10)) { wait_synch(); error("%s", ""); } *************** *** 198,207 **** do { lock[0] = 'a' + i++; ! if((fd = open(lock, 0)) == -1) { if(errno == ENOENT) goto gotlock; /* no such file */ perror(lock); ! unlock_file(HLOCK); error("Cannot open %s", lock); } --- 198,211 ---- do { lock[0] = 'a' + i++; ! #ifndef FILE_AREAS ! if((fd = open(lock, 0, 0)) == -1) { ! #else ! if((fd = open_area(FILE_AREA_LEVL, lock, 0, 0)) == -1) { ! #endif if(errno == ENOENT) goto gotlock; /* no such file */ perror(lock); ! unlock_file_area(HLOCK_AREA, HLOCK); error("Cannot open %s", lock); } *************** *** 211,223 **** (void) close(fd); } while(i < locknum); ! unlock_file(HLOCK); error("Too many hacks running now."); } else { ! if((fd = open(lock, 0)) == -1) { if(errno == ENOENT) goto gotlock; /* no such file */ perror(lock); ! unlock_file(HLOCK); error("Cannot open %s", lock); } --- 215,231 ---- (void) close(fd); } while(i < locknum); ! unlock_file_area(HLOCK_AREA, HLOCK); error("Too many hacks running now."); } else { ! #ifndef FILE_AREAS ! if((fd = open(lock, 0, 0)) == -1) { ! #else ! if((fd = open_area(FILE_AREA_LEVL, lock, 0, 0)) == -1) { ! #endif if(errno == ENOENT) goto gotlock; /* no such file */ perror(lock); ! unlock_file_area(HLOCK_AREA, HLOCK); error("Cannot open %s", lock); } *************** *** 240,257 **** if(eraseoldlocks()) goto gotlock; else { ! unlock_file(HLOCK); error("Couldn't destroy old game."); } else { ! unlock_file(HLOCK); error("%s", ""); } } gotlock: ! fd = creat(lock, FCMASK); ! unlock_file(HLOCK); if(fd == -1) { error("cannot creat lock file."); } else { --- 248,269 ---- if(eraseoldlocks()) goto gotlock; else { ! unlock_file_area(HLOCK_AREA, HLOCK); error("Couldn't destroy old game."); } else { ! unlock_file_area(HLOCK_AREA, HLOCK); error("%s", ""); } } gotlock: ! #ifndef FILE_AREAS ! fd = creat(lock, FCMASK); ! #else ! fd = creat_area(FILE_AREA_LEVL, lock, FCMASK); ! #endif ! unlock_file_area(HLOCK_AREA, HLOCK); if(fd == -1) { error("cannot creat lock file."); } else { *************** *** 360,362 **** --- 372,644 ---- return(0); } #endif + + #ifdef FILE_AREAS + + /* + * Unix file areas are directories with trailing slashes. + */ + + char *make_file_name(filearea, filename) + const char *filearea, *filename; + { + char *buf; + int lenarea; + if (filearea && filename[0]!='/') + { + lenarea = strlen(filearea); + buf = (char *)alloc(lenarea+strlen(filename)+1); + strcpy(buf, filearea); + strcpy(buf+lenarea, filename); + } + else + { + buf = (char *)alloc(strlen(filename)+1); + strcpy(buf, filename); + } + return buf; + } + + FILE * + fopen_datafile_area(filearea, filename, mode) + const char *filearea, *filename, *mode; + { + FILE *fp; + char *buf; + buf = make_file_name(filearea, filename); + fp = fopen(buf, mode); + return fp; + } + + int + chmod_area(filearea, filename, mode) + const char *filearea, *filename; + int mode; + { + int retval; + char *buf; + buf = make_file_name(filearea, filename); + retval = chmod(buf, mode); + free(buf); + return retval; + } + + int + open_area(filearea, filename, flags, mode) + const char *filearea, *filename; + int flags, mode; + { + int fd; + char *buf; + buf = make_file_name(filearea, filename); + fd = open(buf, flags, mode); + free(buf); + return fd; + } + + int + creat_area(filearea, filename, mode) + const char *filearea, *filename; + int mode; + { + int fd; + char *buf; + buf = make_file_name(filearea, filename); + fd = creat(buf, mode); + free(buf); + return fd; + } + + int + rename_area(filearea, oldfilename, newfilename) + const char *filearea, *oldfilename, *newfilename; + { + int retval; + char *oldpath,*newpath; + int lenarea; + oldpath = make_file_name(filearea, oldfilename); + newpath = make_file_name(filearea, newfilename); + retval = rename(oldpath, newpath); + free(oldpath); + free(newpath); + return retval; + } + + int + remove_area(filearea, filename) + const char *filearea, *filename; + { + int retval; + char *buf; + buf = make_file_name(filearea, filename); + retval = remove(buf); + free(buf); + return retval; + } + + FILE * + freopen_area(filearea, filename, mode, stream) + const char *filearea, *filename, *mode; + FILE *stream; + { + FILE *fp; + char *buf; + buf = make_file_name(filearea, filename); + fp = freopen(buf, mode, stream); + free(buf); + return fp; + } + + /* ---------- BEGIN FILE LOCKING HANDLING ----------- */ + + /* + * ALI + * + * We assume that filenames are unique and so locks + * don't need to take the filearea into account. Since + * these locks are only used for RECORD, LOGFILE and HLOCK, + * this assumption is currently valid. + */ + + static int nesting = 0; + + static int lockfd=-1; /* for lock_file_area() to pass to unlock_file_area() */ + + #define HUP if (!program_state.done_hup) + + static char * + make_lockname(filename, lockname) + const char *filename; + char *lockname; + { + # ifdef NO_FILE_LINKS + Strcpy(lockname, LOCKDIR); + if (LOCKDIR[sizeof(LOCKDIR)-2]!='/') + Strcat(lockname, "/"); + Strcat(lockname, filename); + # else + # ifdef FILE_AREAS + Strcpy(lockname, FILE_AREA_VAR); + Strcat(lockname, filename); + # else + Strcpy(lockname, filename); + # endif + # endif /* NO_FILE_LINKS */ + Strcat(lockname, "_lock"); + return lockname; + } + + static boolean + assert_lock(filename, lockname) + const char *filename, *lockname; + { + # ifdef NO_FILE_LINKS + return (lockfd = open(lockname, O_RDWR|O_CREAT|O_EXCL, 0666)) != -1; + # else + if (link(filename, lockname) == -1) + if (errno == EXDEV) + return (lockfd = open(lockname, O_RDWR|O_CREAT|O_EXCL, 0666)) != -1; + else + return FALSE; + else + { + lockfd=-1; + return TRUE; + } + # endif + } + + /* + * lock a file + * + * Note: The area says where the file is, not where the lock is. + */ + + boolean + lock_file_area(filearea, filename, retryct) + const char *filearea, *filename; + int retryct; + { + int retval=TRUE; + char *lockname, locknambuf[BUFSZ]; + char *buf; + + nesting++; + if (nesting > 1) { + impossible("TRIED TO NEST LOCKS"); + return TRUE; + } + + buf = make_file_name(filearea, filename); + lockname = make_lockname(filename, locknambuf); + + while (retval && !assert_lock(buf, lockname)) { + register int errnosv = errno; + + switch (errnosv) { /* George Barbanis */ + case EEXIST: + if (retryct--) { + HUP raw_printf( + "Waiting for access to %s. (%d retries left).", + filename, retryct); + # if defined(SYSV) || defined(ULTRIX) + (void) + # endif + sleep(1); + } else { + HUP (void) raw_print("I give up. Sorry."); + HUP raw_printf("Perhaps there is an old %s around?", + lockname); + nesting--; + retval = FALSE; + } + + break; + case ENOENT: + HUP raw_printf("Can't find file %s to lock!", filename); + nesting--; + retval = FALSE; + case EACCES: + HUP raw_printf("No write permission to lock %s!", filename); + nesting--; + retval = FALSE; + default: + HUP perror(lockname); + HUP raw_printf( + "Cannot lock %s for unknown reason (%d).", + filename, errnosv); + nesting--; + retval = FALSE; + } + + } + + free(buf); + return retval; + } + + /* unlock file, which must be currently locked by lock_file_area */ + void + unlock_file_area(filearea, filename) + const char *filearea, *filename; + { + char *lockname, locknambuf[BUFSZ]; + + if (nesting == 1) { + lockname = make_lockname(filename, locknambuf); + + if (unlink(lockname) < 0) + HUP raw_printf("Can't unlink %s.", lockname); + if (lockfd!=-1) + { + (void) close(lockfd); + lockfd=-1; + } + } + + nesting--; + } + + /* ---------- END FILE LOCKING HANDLING ----------- */ + + #endif /* FILE_AREAS */ *** util/dlb_main.c.orig Mon Nov 1 12:48:04 1999 --- util/dlb_main.c Wed Nov 17 18:09:14 1999 *************** *** 486,498 **** #define fopen vms_fopen #endif /* VMS */ ! /* open_library(dlb.c) needs this (which normally comes from src/files.c) */ FILE * fopen_datafile(filename, mode) const char *filename, *mode; { return fopen(filename, mode); } #endif /* DLB */ --- 486,529 ---- #define fopen vms_fopen #endif /* VMS */ ! /* ! * open_library(dlb.c) needs this (which normally comes from src/files.c, ! * or sys/unix/unixunix.c if file areas are enabled). As yet only the UNIX ! * port supports file areas so this works. We might need access to the ! * actual port functions, rather than duplicating them here, if other ports ! * follow suit. ! */ ! #ifdef FILE_AREAS ! #ifdef UNIX ! FILE * ! fopen_datafile_area(filearea, filename, mode) ! const char *filearea, *filename, *mode; ! { ! FILE *fp; ! char *buf; ! int lenarea; ! if (filearea && filename[0]!='/') ! { ! lenarea = strlen(filearea); ! buf = (char *)alloc(lenarea+strlen(filename)+1); ! strcpy(buf, filearea); ! strcpy(buf+lenarea, filename); ! fp = fopen(buf, mode); ! free(buf); ! } ! else ! fp = fopen(filename, mode); ! return fp; ! } ! #endif ! #else /* FILE_AREAS */ FILE * fopen_datafile(filename, mode) const char *filename, *mode; { return fopen(filename, mode); } + #endif /* FILE_AREAS */ #endif /* DLB */ *** win/Qt/audio.cpp.orig Sat Oct 30 15:04:07 1999 --- win/Qt/audio.cpp Wed Nov 24 10:40:34 1999 *************** *** 25,31 **** audio_mapping* cursor; if (!init) { ! FILE* f=fopen(AUDIOMAP_FILE, "r"); init=1; if (!f) { --- 25,31 ---- audio_mapping* cursor; if (!init) { ! FILE* f=fopen_datafile_area(FILE_AREA_SHARE, AUDIOMAP_FILE, "r"); init=1; if (!f) { *** win/Qt/qt_win.cpp.orig Sat Oct 30 19:20:17 1999 --- win/Qt/qt_win.cpp Wed Nov 24 10:50:10 1999 *************** *** 2190,2196 **** --- 2190,2202 ---- { if (!pixmap) { pixmap=new QPixmap; + #ifndef FILE_AREAS tryload(*pixmap, "rip.xpm"); + #else + char *rip_file=make_file_name(FILE_AREA_SHARE, "rip.xpm"); + tryload(*pixmap, rip_file); + free(rip_file); + #endif } resize(pixmap->width(),pixmap->height()); setFont(QFont("times",12)); // XXX may need to be configurable *************** *** 2950,2963 **** --- 2956,2978 ---- NetHackQtGlyphs::NetHackQtGlyphs() { + #ifndef FILE_AREAS const char* tile_file = "tiles.xpm"; + #else + char* tile_file = make_file_name (FILE_AREA_SHARE, "tiles.xpm"); + #endif int tw = TILEWBASE; int th = TILEHBASE; if (!img.load(tile_file)) { + #ifndef FILE_AREAS tile_file = "nhtiles.bmp"; + #else + free(tile_file); + tile_file = make_file_name (FILE_AREA_SHARE, "nhtiles.bmp"); + #endif if (!img.load(tile_file)) { QString msg; msg.sprintf("Cannot load tiles.xpm or nhtiles.bmp"); *************** *** 2972,2977 **** --- 2987,2995 ---- tile_file, img.height(), total_tiles_used); } } + #ifdef FILE_AREAS + free(tile_file); + #endif resize(tw, th); } *************** *** 3265,3271 **** char *cr; window->Clear(); ! f = dlb_fopen(filename, "r"); if (!f) { complain = must_exist; } else { --- 3283,3289 ---- char *cr; window->Clear(); ! f = dlb_fopen_area(FILE_AREA_SHARE, filename, "r"); if (!f) { complain = must_exist; } else { *************** *** 3282,3288 **** --- 3300,3312 ---- } } #else + #ifndef FILE_AREAS QFile file(filename); + #else + char *path; + path = make_file_name(FILE_AREA_SHARE, filename); + QFile file(path); + #endif if (file.open(IO_ReadOnly)) { char line[128]; *************** *** 3294,3299 **** --- 3318,3326 ---- } else { complain = must_exist; } + #ifdef FILE_AREAS + free(path); + #endif #endif if (complain) { *** win/X11/tile2x11.c.orig Mon Nov 1 12:48:17 1999 --- win/X11/tile2x11.c Wed Nov 24 10:05:51 1999 *************** *** 160,165 **** --- 160,196 ---- return fprintf(fp, "};\n")>=0; } + /* + * ALI + * + * Architecture independent tile file so that x11tiles can always be + * stored in FILE_AREA_SHARE, thus simplifying the configuration. + */ + + static boolean + fwrite_tile_header_item(item, fp) + long item; + FILE *fp; + { + putc((item>>24)&0xff,fp); + putc((item>>16)&0xff,fp); + putc((item>>8)&0xff,fp); + putc(item&0xff,fp); + return !ferror(fp); + } + + static boolean + fwrite_tile_header(header, fp) + x11_header *header; + FILE *fp; + { + return fwrite_tile_header_item(header->version,fp) && + fwrite_tile_header_item(header->ncolors,fp) && + fwrite_tile_header_item(header->tile_width,fp) && + fwrite_tile_header_item(header->tile_height,fp) && + fwrite_tile_header_item(header->ntiles,fp); + } + int main(argc, argv) int argc; *************** *** 209,216 **** exit(1); } } else { ! if (fwrite((char *)&header, sizeof(x11_header), 1, fp) == 0) { ! Fprintf(stderr, "can't open output header\n"); exit(1); } --- 240,247 ---- exit(1); } } else { ! if (fwrite_tile_header(&header, fp) == 0) { ! Fprintf(stderr, "can't write output header\n"); exit(1); } *** win/X11/winX.c.orig Mon Nov 1 12:48:07 1999 --- win/X11/winX.c Tue Nov 23 19:45:19 1999 *************** *** 1286,1292 **** int charcount; /* Use the port-independent file opener to see if the file exists. */ ! fp = dlb_fopen(str, RDTMODE); if (!fp) { if(complain) pline("Cannot open %s. Sorry.", str); --- 1286,1292 ---- int charcount; /* Use the port-independent file opener to see if the file exists. */ ! fp = dlb_fopen_area(FILE_AREA_SHARE, str, RDTMODE); if (!fp) { if(complain) pline("Cannot open %s. Sorry.", str); *************** *** 1320,1326 **** textlines = (char *) alloc((unsigned int) charcount); textlines[0] = '\0'; ! fp = dlb_fopen(str, RDTMODE); while (dlb_fgets(line, LLEN, fp)) { (void) strcat(textlines, line); --- 1320,1326 ---- textlines = (char *) alloc((unsigned int) charcount); textlines[0] = '\0'; ! fp = dlb_fopen_area(FILE_AREA_SHARE, str, RDTMODE); while (dlb_fgets(line, LLEN, fp)) { (void) strcat(textlines, line); *** win/X11/winmap.c.orig Mon Nov 1 12:48:07 1999 --- win/X11/winmap.c Wed Nov 24 10:16:19 1999 *************** *** 254,259 **** --- 254,260 ---- { Display *dpy = XtDisplay(toplevel); unsigned int width, height; + char *pet_mark_file; if (tile_image == 0) return; /* no tiles */ *************** *** 277,286 **** XDestroyImage(tile_image); /* data bytes free'd also */ tile_image = 0; ! init_annotation(&pet_annotation, ! appResources.pet_mark_bitmap, appResources.pet_mark_color); } /* * Open and read the tile file. Return TRUE if there were no problems. --- 278,329 ---- XDestroyImage(tile_image); /* data bytes free'd also */ tile_image = 0; ! #ifndef FILE_AREAS ! pet_mark_file = appResources.pet_mark_bitmap; ! #else ! pet_mark_file = make_file_name(FILE_AREA_SHARE, appResources.pet_mark_bitmap); ! #endif ! init_annotation(&pet_annotation, pet_mark_file, appResources.pet_mark_color); ! #ifdef FILE_AREAS ! free(pet_mark_file); ! #endif } + #ifndef USE_XPM + /* + * ALI + * + * Architecture independent tile file so that x11tiles can always be + * stored in FILE_AREA_SHARE, thus simplifying the configuration. + */ + + static boolean + fread_tile_header_item(item, fp) + long *item; + FILE *fp; + { + *item = (long)getc(fp)<<24; + *item |= (long)getc(fp)<<16; + *item |= (long)getc(fp)<<8; + *item |= (long)getc(fp); + #ifdef VERBOSE + fprintf(stderr, "fread_tile_header_item: 0x%lX\n",*item); + #endif + return !feof(fp) && !ferror(fp); + } + + static boolean + fread_tile_header(header, fp) + x11_header *header; + FILE *fp; + { + return fread_tile_header_item(&header->version,fp) && + fread_tile_header_item(&header->ncolors,fp) && + fread_tile_header_item(&header->tile_width,fp) && + fread_tile_header_item(&header->tile_height,fp) && + fread_tile_header_item(&header->ntiles,fp); + } + #endif /* * Open and read the tile file. Return TRUE if there were no problems. *************** *** 321,334 **** #ifdef USE_XPM { ! char buf[BUFSIZ]; XpmAttributes attributes; int errorcode; attributes.valuemask = XpmCloseness; attributes.closeness = 25000; ! errorcode=XpmReadFileToImage(dpy,appResources.tile_file,&tile_image,0,&attributes); if (errorcode == XpmColorFailed) { Sprintf(buf, "Insufficient colors available to load %s.",appResources.tile_file); --- 364,382 ---- #ifdef USE_XPM { ! char buf[BUFSIZ],*tile_file; XpmAttributes attributes; int errorcode; attributes.valuemask = XpmCloseness; attributes.closeness = 25000; ! #ifndef FILE_AREAS ! tile_file = appResources.tile_file; ! #else ! tile_file = make_file_name(FILE_AREA_SHARE, appResources.tile_file); ! #endif ! errorcode=XpmReadFileToImage(dpy,tile_file,&tile_image,0,&attributes); if (errorcode == XpmColorFailed) { Sprintf(buf, "Insufficient colors available to load %s.",appResources.tile_file); *************** *** 336,343 **** X11_raw_print("Try closing other colorful applications and restart."); X11_raw_print("Attempting to load with inferior colors."); attributes.closeness = 50000; ! errorcode=XpmReadFileToImage(dpy,appResources.tile_file,&tile_image,0,&attributes); } if (errorcode!=XpmSuccess) { if (errorcode == XpmColorFailed) { --- 384,394 ---- X11_raw_print("Try closing other colorful applications and restart."); X11_raw_print("Attempting to load with inferior colors."); attributes.closeness = 50000; ! errorcode=XpmReadFileToImage(dpy,tile_file,&tile_image,0,&attributes); } + #ifdef FILE_AREAS + free(tile_file); + #endif if (errorcode!=XpmSuccess) { if (errorcode == XpmColorFailed) { *************** *** 389,395 **** goto tiledone; } ! fp = fopen_datafile(appResources.tile_file, RDBMODE); if (!fp) { X11_raw_print("can't open tile file"); perror(appResources.tile_file); --- 440,446 ---- goto tiledone; } ! fp = fopen_datafile_area(FILE_AREA_SHARE, appResources.tile_file, RDBMODE); if (!fp) { X11_raw_print("can't open tile file"); perror(appResources.tile_file); *************** *** 397,403 **** goto tiledone; } ! if (fread((char *) &header, sizeof(header), 1, fp) != 1) { X11_raw_print("read of header failed"); result = FALSE; goto tiledone; --- 448,454 ---- goto tiledone; } ! if (!fread_tile_header(&header, fp)) { X11_raw_print("read of header failed"); result = FALSE; goto tiledone; *** win/X11/wintext.c.orig Mon Nov 1 12:48:07 1999 --- win/X11/wintext.c Wed Nov 24 10:12:25 1999 *************** *** 591,600 **** if (!rip_image) { XpmAttributes attributes; int errorcode; attributes.valuemask = XpmCloseness; attributes.closeness = 65535; /* Try anything */ ! errorcode = XpmReadFileToImage(XtDisplay(parent), appResources.tombstone, &rip_image, 0, &attributes); if (errorcode != XpmSuccess) { char buf[BUFSIZ]; Sprintf(buf, "Failed to load %s: %s", appResources.tombstone, --- 591,604 ---- if (!rip_image) { XpmAttributes attributes; int errorcode; + char *rip_file; attributes.valuemask = XpmCloseness; attributes.closeness = 65535; /* Try anything */ ! rip_file = make_file_name(FILE_AREA_SHARE, appResources.tombstone); ! errorcode = XpmReadFileToImage(XtDisplay(parent), rip_file, ! &rip_image, 0, &attributes); ! free(rip_file); if (errorcode != XpmSuccess) { char buf[BUFSIZ]; Sprintf(buf, "Failed to load %s: %s", appResources.tombstone, *** win/tty/wintty.c.orig Mon Nov 1 12:48:05 1999 --- win/tty/wintty.c Thu Nov 18 12:22:32 1999 *************** *** 1970,1976 **** char *cr; tty_clear_nhwindow(WIN_MESSAGE); ! f = dlb_fopen(fname, "r"); if (!f) { if(complain) { home(); tty_mark_synch(); tty_raw_print(""); --- 1970,1976 ---- char *cr; tty_clear_nhwindow(WIN_MESSAGE); ! f = dlb_fopen_area(FILE_AREA_SHARE, fname, "r"); if (!f) { if(complain) { home(); tty_mark_synch(); tty_raw_print("");