From a03f968c09c49b8b4bf3b1d4dc32ad0662b6bc93 Mon Sep 17 00:00:00 2001 From: Gorilla Sapiens Date: Fri, 6 Feb 2026 18:17:56 -0700 Subject: [PATCH 1/2] get_rnd_text() equal odds for all lines Renames rumors.tru to rumors_t.txt and rumors.fal to rumors_f.txt. Splits rumors into rumors_t and rumors_f. Removes padding from engrave, epitaph, and bogusmon. Adds sidecar *.idx files for all of the above to guarantee all lines have the exact same odds of appearing, regardless of length. Removes kludgey get_rnd_line(). Adds new files to various Makefiles etc. --- Files | 5 +- dat/.gitignore | 8 +- dat/epitaph.txt | 3 +- dat/{rumors.fal => rumors_f.txt} | 0 dat/{rumors.tru => rumors_t.txt} | 0 include/extern.h | 3 +- include/global.h | 11 +- src/do_name.c | 2 +- src/engrave.c | 4 +- src/rumors.c | 339 ++++----------------- sys/msdos/Makefile.GCC | 24 +- sys/unix/Makefile.dat | 11 +- sys/unix/Makefile.top | 13 +- sys/unix/NetHack.xcodeproj/project.pbxproj | 32 +- sys/unix/hints/include/cross-pre2.370 | 3 +- sys/vms/Makefile.dat | 2 +- sys/vms/Makefile_dat.vms | 12 +- sys/vms/Makefile_top.vms | 13 +- sys/vms/install.com | 6 +- sys/windows/GNUmakefile | 23 +- sys/windows/Makefile.nmake | 57 +++- util/makedefs.c | 252 ++++----------- 22 files changed, 271 insertions(+), 552 deletions(-) rename dat/{rumors.fal => rumors_f.txt} (100%) rename dat/{rumors.tru => rumors_t.txt} (100%) diff --git a/Files b/Files index 7154e17c20..53dd92e784 100644 --- a/Files +++ b/Files @@ -56,7 +56,7 @@ medusa-3.lua medusa-4.lua minefill.lua minend-1.lua minend-2.lua minend-3.lua minetn-1.lua minetn-2.lua minetn-3.lua minetn-4.lua minetn-5.lua minetn-6.lua minetn-7.lua nhcore.lua nhlib.lua opthelp optmenu oracle.lua oracles.txt orcus.lua -quest.lua rumors.fal rumors.tru sanctum.lua soko1-1.lua +quest.lua rumors_f.txt rumors_t.txt sanctum.lua soko1-1.lua soko1-2.lua soko2-1.lua soko2-2.lua soko3-1.lua soko3-2.lua soko4-1.lua soko4-2.lua symbols themerms.lua tower1.lua tower2.lua tower3.lua tribute tut-1.lua tut-2.lua @@ -670,7 +670,8 @@ regenerated from the files in the distribution. dat: (files generated by makedefs at playground creation time) -data options oracles rumors +data options oracles rumors_t rumors_t.idx rumors_f rumors_f.idx +epitaphs epitaphs.idx engrave engrave.idx bogusmon bogusmon.idx (files generated for Qt interface on macOS) Info.plist nethack.icns diff --git a/dat/.gitignore b/dat/.gitignore index 748a8ffe17..fa09490166 100644 --- a/dat/.gitignore +++ b/dat/.gitignore @@ -5,10 +5,16 @@ rip.xpm pet_mark.xbm pilemark.xbm quest.dat -rumors +rumors_t +rumors_t.idx +rumors_f +rumors_f.idx bogusmon +bogusmon.idx engrave +engrave.idx epitaph +epitaph.idx x11tiles nhtiles.bmp *.lev diff --git a/dat/epitaph.txt b/dat/epitaph.txt index d559d1fb3d..730cc38dfd 100644 --- a/dat/epitaph.txt +++ b/dat/epitaph.txt @@ -279,8 +279,7 @@ I died laughing I disbelieved in reincarnation in my last life, too. I hacked myself to death I have all the time in the world -#"reached Mine's End": not necessarily true; sounds like "reached my end" -I have reached Mine's End +I have reached Mine's End ## not necessarily true; sounds like "reached my end" I knew I'd find a use for this gravestone! I know my mind. And it's around here someplace. I lied! I'll never be alright! diff --git a/dat/rumors.fal b/dat/rumors_f.txt similarity index 100% rename from dat/rumors.fal rename to dat/rumors_f.txt diff --git a/dat/rumors.tru b/dat/rumors_t.txt similarity index 100% rename from dat/rumors.tru rename to dat/rumors_t.txt diff --git a/include/extern.h b/include/extern.h index 899f72b4ab..e98ae5de33 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2772,8 +2772,7 @@ extern int genl_player_setup(int); /* ### rumors.c ### */ extern char *getrumor(int, char *, boolean) NONNULLARG2; -extern char *get_rnd_text(const char *, char *, int(*)(int), - unsigned) NONNULLPTRS; +extern char *get_rnd_text(const char *, char *, int(*)(int)) NONNULLPTRS; extern void outrumor(int, int); extern void outoracle(boolean, boolean); extern void save_oracles(NHFILE *) NONNULLARG1; diff --git a/include/global.h b/include/global.h index 6d785ac9aa..54ccdde589 100644 --- a/include/global.h +++ b/include/global.h @@ -16,7 +16,8 @@ #define SHELP "hh" /* abbreviated form of the same */ #define KEYHELP "keyhelp" /* explanatory text for 'whatdoes' command */ #define DEBUGHELP "wizhelp" /* file containing debug mode cmds */ -#define RUMORFILE "rumors" /* file with fortune cookies */ +#define RUMORSTFILE "rumors_t" /* file with true fortune cookies */ +#define RUMORSFFILE "rumors_f" /* file with false fortune cookies */ #define ORACLEFILE "oracles" /* file with oracular information */ #define DATAFILE "data" /* file giving the meaning of symbols used */ #define CMDHELPFILE "cmdhelp" /* file telling what commands do */ @@ -33,14 +34,6 @@ #define TRIBUTEFILE "tribute" /* 3.6 tribute to Terry Pratchett */ #define LEV_EXT ".lua" /* extension for special level files */ -/* padding amounts for files that have lines chosen by fseek to random spot, - advancing to the next line, and using that line; makedefs forces shorter - lines to be padded to these lengths; value of 0 will inhibit any padding, - avoiding an increase in files' sizes, but resulting in biased selection; - used by makedefs while building and by core's callers of get_rnd_text() */ -#define MD_PAD_RUMORS 60u /* for RUMORFILE, EPITAPHFILE, and ENGRAVEFILE */ -#define MD_PAD_BOGONS 20u /* for BOGUSMONFILE */ - /* Assorted definitions that may depend on selections in config.h. */ /* diff --git a/src/do_name.c b/src/do_name.c index c273963431..c1416657ce 100644 --- a/src/do_name.c +++ b/src/do_name.c @@ -1373,7 +1373,7 @@ bogusmon(char *buf, char *code) if (code) *code = '\0'; /* might fail (return empty buf[]) if the file isn't available */ - get_rnd_text(BOGUSMONFILE, buf, rn2_on_display_rng, MD_PAD_BOGONS); + get_rnd_text(BOGUSMONFILE, buf, rn2_on_display_rng); if (!*mnam) { Strcpy(buf, "bogon"); } else if (strchr(bogon_codes, *mnam)) { /* strip prefix if present */ diff --git a/src/engrave.c b/src/engrave.c index c84908cf13..6b17068e07 100644 --- a/src/engrave.c +++ b/src/engrave.c @@ -55,7 +55,7 @@ random_engraving(char *outbuf, char *pristine_copy) /* a random engraving may come from the "rumors" file, or from the "engrave" file (formerly in an array here) */ if (!rn2(4) || !(rumor = getrumor(0, pristine_copy, TRUE)) || !*rumor) - (void) get_rnd_text(ENGRAVEFILE, pristine_copy, rn2, MD_PAD_RUMORS); + (void) get_rnd_text(ENGRAVEFILE, pristine_copy, rn2); Strcpy(outbuf, pristine_copy); wipeout_text(outbuf, (int) (strlen(outbuf) / 4), 0); @@ -1696,7 +1696,7 @@ make_grave(coordxy x, coordxy y, const char *str) /* Engrave the headstone */ del_engr_at(x, y); if (!str) - str = get_rnd_text(EPITAPHFILE, buf, rn2, MD_PAD_RUMORS); + str = get_rnd_text(EPITAPHFILE, buf, rn2); make_engr_at(x, y, str, NULL, 0L, HEADSTONE); return; } diff --git a/src/rumors.c b/src/rumors.c index 5aac3bd40c..a191a408f5 100644 --- a/src/rumors.c +++ b/src/rumors.c @@ -6,6 +6,16 @@ #include "hack.h" #include "dlb.h" +/* 3.7 + * The files rumors, engrave, epitaph, and bogusmon now include an + * index file (*.idx) with 16 byte records, one per valid line in the + * file. Access now consists of randomly seeking the INDEX file, + * reading the record there, and then reading the real entry. This + * once and for all fixes "bias based on length" and removes the need + * for padding short entries. Additionally, we've split rumors into + * two files, rumorst and rumorsf, for ease of access. + */ + /* [Note: this comment is fairly old, but still accurate for 3.1; * it's no longer accurate for 3.7 but may still be of interest.] * Rumors have been entirely rewritten to speed up the access. This is @@ -42,10 +52,7 @@ */ #ifndef SFCTOOL -staticfn void unpadline(char *); staticfn void init_rumors(dlb *); -staticfn char *get_rnd_line(dlb *, char *, unsigned, int (*)(int), - long, long, unsigned); staticfn void init_oracles(dlb *); staticfn void others_check(const char *ftype, const char *, winid *); staticfn void couldnt_open_file(const char *); @@ -61,24 +68,6 @@ static const char **CapMons = 0; unique or always a particular gender; see dat/bogusmon.txt */ extern const char bogon_codes[]; /* from do_name.c */ -/* makedefs pads short rumors, epitaphs, engravings, and hallucinatory - monster names with trailing underscores; strip those off */ -staticfn void -unpadline(char *line) -{ - char *p = eos(line); - - /* remove newline if still present; caller should have stripped it */ - if (p > line && p[-1] == '\n') - --p; - - /* remove padding */ - while (p > line && p[-1] == '_') - --p; - - *p = '\0'; -} - DISABLE_WARNING_FORMAT_NONLITERAL staticfn void @@ -119,64 +108,37 @@ getrumor( char *rumor_buf, boolean exclude_cookie) { - dlb *rumors; - long beginning, ending; - char line[BUFSZ]; static const char *cookie_marker = "[cookie] "; const int marklen = strlen(cookie_marker); + int count = 0; + int adjtruth; + + *rumor_buf = 0; + + do { + switch(adjtruth = truth + rn2(2)) { + case 2: + case 1: + /* find a true rumor */ + get_rnd_text(RUMORSTFILE, rumor_buf, rn2); + break; + case 0: + case -1: + /* find a false rumor */ + get_rnd_text(RUMORSFFILE, rumor_buf, rn2); + break; + default: + impossible("strange truth value for rumor"); + return strcpy(rumor_buf, "Oops..."); + } + count++; + } while (count < 50 && exclude_cookie && !strncmp(rumor_buf, cookie_marker, marklen)); + + if (count >= 50) + impossible("Can't find non-cookie rumor?"); + else if (!gi.in_mklev) /* avoid exercising wisdom for graffiti */ + exercise(A_WIS, (adjtruth > 0)); - rumor_buf[0] = '\0'; - if (gt.true_rumor_size < 0L) /* a previous try failed to open RUMORFILE */ - return rumor_buf; - - rumors = dlb_fopen(RUMORFILE, "r"); - if (rumors) { - int count = 0; - int adjtruth; - - do { - rumor_buf[0] = '\0'; - if (gt.true_rumor_size == 0L) { /* if this is 1st outrumor() */ - init_rumors(rumors); - if (gt.true_rumor_size < 0L) { /* init failed */ - Sprintf(rumor_buf, "Error reading \"%.80s\".", RUMORFILE); - return rumor_buf; - } - } - /* - * input: 1 0 -1 - * rn2 \ +1 2=T 1=T 0=F - * adj./ +0 1=T 0=F -1=F - */ - switch (adjtruth = truth + rn2(2)) { - case 2: /*(might let a bogus input arg sneak thru)*/ - case 1: - beginning = (long) gt.true_rumor_start; - ending = gt.true_rumor_end; - break; - case 0: /* once here, 0 => false rather than "either"*/ - case -1: - beginning = (long) gf.false_rumor_start; - ending = gf.false_rumor_end; - break; - default: - impossible("strange truth value for rumor"); - return strcpy(rumor_buf, "Oops..."); - } - Strcpy(rumor_buf, - get_rnd_line(rumors, line, (unsigned) sizeof line, rn2, - beginning, ending, MD_PAD_RUMORS)); - } while (count++ < 50 && exclude_cookie - && !strncmp(rumor_buf, cookie_marker, marklen)); - (void) dlb_fclose(rumors); - if (count >= 50) - impossible("Can't find non-cookie rumor?"); - else if (!gi.in_mklev) /* avoid exercising wisdom for graffiti */ - exercise(A_WIS, (adjtruth > 0)); - } else { - couldnt_open_file(RUMORFILE); - gt.true_rumor_size = -1; /* don't try to open it again */ - } if (!exclude_cookie && !strncmp(rumor_buf, cookie_marker, marklen)) { /* remove cookie_marker from the string */ @@ -190,107 +152,17 @@ getrumor( return rumor_buf; } -/* test that the true/false rumor boundaries are valid and show the first - two and very last epitaphs, engravings, and bogus monsters */ +/* show the first two and very last rumors, epitaphs, engravings, and bogus monsters */ void rumor_check(void) { - dlb *rumors; winid tmpwin = WIN_ERR; - char *endp, line[BUFSZ], xbuf[BUFSZ], rumor_buf[BUFSZ]; - - rumors = (gt.true_rumor_size >= 0) ? dlb_fopen(RUMORFILE, "r") : 0; - if (rumors) { - long ftell_rumor_start = 0L; - - rumor_buf[0] = '\0'; - if (gt.true_rumor_size == 0L) { /* if this is 1st outrumor() */ - init_rumors(rumors); - if (gt.true_rumor_size < 0L) { - rumors = (dlb *) 0; /* init_rumors() closes it upon failure */ - goto no_rumors; /* init failed */ - } - } - tmpwin = create_nhwindow(NHW_TEXT); - - /* - * reveal the values. - */ - Sprintf(rumor_buf, - "T start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)", - (long) gt.true_rumor_start, gt.true_rumor_start, - gt.true_rumor_end, (unsigned long) gt.true_rumor_end, - gt.true_rumor_size,(unsigned long) gt.true_rumor_size); - putstr(tmpwin, 0, rumor_buf); - Sprintf(rumor_buf, - "F start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)", - (long) gf.false_rumor_start, gf.false_rumor_start, - gf.false_rumor_end, (unsigned long) gf.false_rumor_end, - gf.false_rumor_size, (unsigned long) gf.false_rumor_size); - putstr(tmpwin, 0, rumor_buf); - - /* - * check the first rumor (start of true rumors) by - * skipping the first two lines. - * - * Then seek to the start of the false rumors (based on - * the value read in rumors, and display it. - */ - rumor_buf[0] = '\0'; - (void) dlb_fseek(rumors, (long) gt.true_rumor_start, SEEK_SET); - ftell_rumor_start = dlb_ftell(rumors); - (void) dlb_fgets(line, sizeof line, rumors); - if ((endp = strchr(line, '\n')) != 0) - *endp = 0; - Sprintf(rumor_buf, "T %06ld %s", ftell_rumor_start, - xcrypt(line, xbuf)); - putstr(tmpwin, 0, rumor_buf); - /* find last true rumor */ - while (dlb_fgets(line, sizeof line, rumors) - && dlb_ftell(rumors) < gt.true_rumor_end) - continue; - if ((endp = strchr(line, '\n')) != 0) - *endp = 0; - Sprintf(rumor_buf, " %6s %s", "", xcrypt(line, xbuf)); - putstr(tmpwin, 0, rumor_buf); - - rumor_buf[0] = '\0'; - (void) dlb_fseek(rumors, (long) gf.false_rumor_start, SEEK_SET); - ftell_rumor_start = dlb_ftell(rumors); - (void) dlb_fgets(line, sizeof line, rumors); - if ((endp = strchr(line, '\n')) != 0) - *endp = 0; - Sprintf(rumor_buf, "F %06ld %s", ftell_rumor_start, - xcrypt(line, xbuf)); - putstr(tmpwin, 0, rumor_buf); - /* find last false rumor */ - while (dlb_fgets(line, sizeof line, rumors) - && dlb_ftell(rumors) < gf.false_rumor_end) - continue; - if ((endp = strchr(line, '\n')) != 0) - *endp = 0; - Sprintf(rumor_buf, " %6s %s", "", xcrypt(line, xbuf)); - putstr(tmpwin, 0, rumor_buf); - - (void) dlb_fclose(rumors); - - /* if a previous attempt couldn't open file or rejected its contents, - we didn't bother trying again this time */ - } else if (gt.true_rumor_size < 0L) { - no_rumors: /* file could be opened but init_rumors() didn't like it */ - pline("rumors not accessible."); - /* engravings, epitaphs, and bogus monsters will still be shown, - and in tmpwin rather than via additional pline() calls */ - display_nhwindow(WIN_MESSAGE, TRUE); /* --more-- */ - - /* first attempt to open file has just failed */ - } else { - couldnt_open_file(RUMORFILE); - gt.true_rumor_size = -1; /* don't try to open it again */ - } + tmpwin = create_nhwindow(NHW_TEXT); /* initial implementation of default epitaph/engraving/bogusmon contained an error; check those along with rumors */ + others_check("Tru Rumors:", RUMORSTFILE, &tmpwin); + others_check("Fal Rumors:", RUMORSFFILE, &tmpwin); others_check("Engravings:", ENGRAVEFILE, &tmpwin); others_check("Epitaphs:", EPITAPHFILE, &tmpwin); others_check("Bogus monsters:", BOGUSMONFILE, &tmpwin); @@ -409,119 +281,43 @@ others_check( RESTORE_WARNING_FORMAT_NONLITERAL -/* load one randomly chosen line from a section of a file; undoes - decryption and strips trailing underscore padding and final newline; - if padlength is non-zero, every line is expected to be at least that - long and every line in the file will have an equal chance of being - chosen; however, if padlength is 0, lines following long lines are - more likely than average to be picked, and lines after short lines - are less likely */ -staticfn char * -get_rnd_line( - dlb *fh, /* already opened file */ - char *buf, /* output buffer */ - unsigned bufsiz, /* (unsigned) sizeof buf */ - int (*rng)(int), /* random number routine; rn2(N) or similar, 0..N-1 */ - long startpos, /* location in file of first line of interest */ - long endpos, /* location one byte past last line of interest; - * if 0, end-of-file will be used */ - unsigned padlength) /* expected line length; 0 if no expectations */ -{ - char *newl, *xbufp, xbuf[BUFSZ]; - long filechunksize, chunkoffset; - int trylimit; - - *buf = '\0'; - if (!endpos) { - (void) dlb_fseek(fh, 0L, SEEK_END); - endpos = dlb_ftell(fh); - } - filechunksize = endpos - startpos; - - /* might be zero (only if file is empty); should complain in that - case but it could happen over and over, also the suggestion - that save and restore might fix the problem wouldn't be useful */ - if (filechunksize < 1L) - return buf; - /* 'rumors' is about 3/4 of the way to the limit on a 16-bit config - for the whole, roughly 3/8 of the way for either half; all active - configurations these days are at least 32-bits anyway */ - nhassert(filechunksize <= INT_MAX); /* essential for rn2() */ - - /* - * Position randomly which will probably be in the middle of a line. - * (Occasionally by chance it will happen to be at the very start of - * a line, but we'll have no way of knowing that so have to behave - * as if it were positioned in the middle.) - * Read the rest of that line, then use the next one. If there's no - * next line (ie, end of file), go back to beginning and use first. - * - * When short lines have been padded to length N, only accept long - * lines if we land within last N+1 characters (+1 is for newline - * which hasn't been stripped away yet), effectively shortening - * them to normal length. That yields even selection distribution. - */ - for (trylimit = 10; trylimit > 0; --trylimit) { - chunkoffset = (long) (*rng)((int) filechunksize); - (void) dlb_fseek(fh, startpos + chunkoffset, SEEK_SET); - (void) dlb_fgets(buf, bufsiz, fh); - /* if padlength is 0, accept any position; when non-zero, - padlength does not count the newline but strlen(buf) does */ - if (!padlength || (unsigned) strlen(buf) <= padlength + 1) - break; - } - /* use next line; for rumors, caller takes care of whether startpos - and endpos cover just true rumors or just false rumors; reaching - endpos is equivalent to end-of-file in order to avoid using the - first false rumor if fseek for a true one lands within the last one */ - if (dlb_ftell(fh) >= endpos || !dlb_fgets(buf, bufsiz, fh)) { - /* assume failure is due to end-of-file; go back to start */ - (void) dlb_fseek(fh, startpos, SEEK_SET); - (void) dlb_fgets(buf, bufsiz, fh); - } - if ((newl = strchr(buf, '\n')) != 0) - *newl = '\0'; - /* decrypt line; make sure that our intermediate buffer is big enough */ - xbufp = (strlen(buf) <= sizeof xbuf - 1) ? &xbuf[0] - : (char *) alloc((unsigned) strlen(buf) + 1); - Strcpy(buf, xcrypt(buf, xbufp)); - if (xbufp != &xbuf[0]) - free((genericptr_t) xbufp); - /* strip padding that makedefs adds to short lines */ - if (padlength) - unpadline(buf); - return buf; -} - /* Gets a random line of text from file 'fname', and returns it. rng is the random number generator to use, and should act like rn2 does. */ char * get_rnd_text( const char *fname, char *buf, - int (*rng)(int), - unsigned padlength) + int (*rng)(int)) { - dlb *fh = dlb_fopen(fname, "r"); + char tmp[BUFSZ] = { 0 }; buf[0] = '\0'; + + sprintf(tmp, "%s.idx", fname); + + dlb *fh = dlb_fopen(tmp, "r"); if (fh) { - long starttxt = 0L; - char line[BUFSZ]; - - /* skip "don't edit" comment */ - (void) dlb_fgets(line, sizeof line, fh); - /* obtain current file position */ - (void) dlb_fseek(fh, 0L, SEEK_CUR); - starttxt = dlb_ftell(fh); - - /* get a randomly chosen line; it comes back decrypted and unpadded */ - Strcpy(buf, get_rnd_line(fh, line, (unsigned) sizeof line, rng, - starttxt, 0L, padlength)); - (void) dlb_fclose(fh); + dlb_fseek(fh, 0, SEEK_END); + unsigned long size = dlb_ftell(fh); + dlb_fseek(fh, rng(size / 16) * 16, SEEK_SET); + (void) dlb_fgets(tmp, sizeof tmp, fh); + dlb_fclose(fh); + + fh = dlb_fopen(fname, "r"); + if (fh) { + dlb_fseek(fh, atoi(tmp), SEEK_SET); + (void) dlb_fgets(tmp, sizeof tmp, fh); + dlb_fclose(fh); + } else { + couldnt_open_file(fname); + } } else { - couldnt_open_file(fname); + couldnt_open_file(tmp); } + + (void) strip_newline(tmp); + (void) xcrypt(tmp, buf); + return buf; } @@ -880,7 +676,6 @@ init_CapMons(void) if ((endp = strchr(hline, '\n')) != 0) *endp = '\0'; /* strip newline */ (void) xcrypt(hline, xbuf); - unpadline(xbuf); if (!xbuf[0] || !strchr(bogon_codes, xbuf[0])) code = '\0', startp = &xbuf[0]; /* ordinary */ diff --git a/sys/msdos/Makefile.GCC b/sys/msdos/Makefile.GCC index bdf4391e38..9784fd5717 100644 --- a/sys/msdos/Makefile.GCC +++ b/sys/msdos/Makefile.GCC @@ -867,19 +867,19 @@ $(O)dat.tag: $(DAT)/nhdat $(DAT)/data: $(O)utility.tag $(DATABASE) @$(subst /,\,$(U)makedefs.exe -d) -$(DAT)/rumors: $(O)utility.tag $(DAT)/rumors.tru $(DAT)/rumors.fal +$(DAT)/rumors_f $(DAT)/rumors_f.idx $(DAT)/rumors_t $(DAT)/rumors_t.idx: $(O)utility.tag $(DAT)/rumors_t.txt $(DAT)/rumors_f.txt @$(subst /,\,$(U)makedefs.exe -r) $(DAT)/oracles: $(O)utility.tag $(DAT)/oracles.txt @$(subst /,\,$(U)makedefs.exe -h) -$(DAT)/bogusmon: $(O)utility.tag $(DAT)/bogusmon.txt +$(DAT)/bogusmon $(DAT)/bogusmon.idx: $(O)utility.tag $(DAT)/bogusmon.txt @$(subst /,\,$(U)makedefs.exe -s) -$(DAT)/engrave: $(O)utility.tag $(DAT)/engrave.txt +$(DAT)/engrave $(DAT)/engrave.idx: $(O)utility.tag $(DAT)/engrave.txt @$(subst /,\,$(U)makedefs.exe -s) -$(DAT)/epitaph: $(O)utility.tag $(DAT)/epitaph.txt +$(DAT)/epitaph $(DAT)/epitaph.idx: $(O)utility.tag $(DAT)/epitaph.txt @$(subst /,\,$(U)makedefs.exe -s) $(O)sp_lev.tag: $(O)utility.tag @@ -891,7 +891,9 @@ $(O)sp_lev.tag: $(O)utility.tag #note that dir below assumes bin/dir.exe from djgpp distribution # -$(DAT)/nhdat: $(U)dlb_main.exe $(DAT)/data $(DAT)/rumors \ +$(DAT)/nhdat: $(U)dlb_main.exe $(DAT)/data \ + $(DAT)/rumors_t $(DAT)/rumors_t.idx \ + $(DAT)/rumors_f $(DAT)/rumors_f.idx \ $(DAT)/oracles \ $(QUEST_DAT) \ $(O)sp_lev.tag \ @@ -899,9 +901,9 @@ $(DAT)/nhdat: $(U)dlb_main.exe $(DAT)/data $(DAT)/rumors \ @$(subst /,\,echo dat done >$(O)dat.tag) @$(subst /,\,cd $(DAT)) @$(subst /,\,copy $(MSYS)/msdoshlp.txt .) - @$(LS) data oracles options rumors help hh >dlb.lst + @$(LS) data oracles options rumors_t rumors_t.idx rumors_f rumors_f.idx help hh >dlb.lst @$(LS) cmdhelp history opthelp optmenu wizhelp license msdoshlp.txt >>dlb.lst - @$(LS) bogusmon engrave epitaph tribute >>dlb.lst + @$(LS) bogusmon bogusmon.idx engrave engrave.idx epitaph epitaph.idx tribute >>dlb.lst $(LS) $(subst /,\,*.lua) >>dlb.lst @$(subst /,\,$(U)dlb_main cvIf dlb.lst nhdat) @$(subst /,\,cd $(SRC)) @@ -978,14 +980,20 @@ spotless: clean $(subst /,\,if exist $(SRC)/tile.c del $(SRC)/tile.c) $(subst /,\,if exist $(DAT)/options del $(DAT)/options) $(subst /,\,if exist $(DAT)/data del $(DAT)/data) - $(subst /,\,if exist $(DAT)/rumors del $(DAT)/rumors) + $(subst /,\,if exist $(DAT)/rumors_t del $(DAT)/rumors_t) + $(subst /,\,if exist $(DAT)/rumors_t.idx del $(DAT)/rumors_t.idx) + $(subst /,\,if exist $(DAT)/rumors_f del $(DAT)/rumors_f) + $(subst /,\,if exist $(DAT)/rumors_f.idx del $(DAT)/rumors_f.idx) $(subst /,\,if exist $(DAT)/oracles del $(DAT)/oracles) ifndef LUA_QTEXT_FILE $(subst /,\,if exist $(DAT)/quest.dat del $(DAT)/quest.dat) endif $(subst /,\,if exist $(DAT)/bogusmon del $(DAT)/bogusmon) + $(subst /,\,if exist $(DAT)/bogusmon.idx del $(DAT)/bogusmon.idx) $(subst /,\,if exist $(DAT)/engrave del $(DAT)/engrave) + $(subst /,\,if exist $(DAT)/engrave.idx del $(DAT)/engrave.idx) $(subst /,\,if exist $(DAT)/epitaph del $(DAT)/epitaph) + $(subst /,\,if exist $(DAT)/epitaph.idx del $(DAT)/epitaph.idx) $(subst /,\,if exist $(DAT)/dlb.lst del $(DAT)/dlb.lst) $(subst /,\,if exist $(DAT)/nhdat del $(DAT)/nhdat) $(subst /,\,if exist $(TILE_BMP) del $(TILE_BMP)) diff --git a/sys/unix/Makefile.dat b/sys/unix/Makefile.dat index 43c61537dd..1b26f57529 100644 --- a/sys/unix/Makefile.dat +++ b/sys/unix/Makefile.dat @@ -9,7 +9,8 @@ NHSROOT=.. # SHELL=E:/GEMINI2/MUPFEL.TTP # UUDECODE=uudecode -VARDAT = bogusmon data engrave epitaph rumors oracles +VARDAT = bogusmon bogusmon.idx data engrave engrave.idx epitaph epitaph.idx \ + rumors_t rumors_t.idx rumors_f rumors_f.idx oracles all: $(VARDAT) spec_levs quest_levs @@ -97,19 +98,19 @@ GEM_RSC.RSC: data: data.base ../util/makedefs ../util/makedefs -d -rumors: rumors.tru rumors.fal ../util/makedefs +rumors_t rumors_t.idx rumors_f rumors_f.idx: rumors_t.txt rumors_f.txt ../util/makedefs ../util/makedefs -r oracles: oracles.txt ../util/makedefs ../util/makedefs -h -engrave: engrave.txt ../util/makedefs +engrave engrave.idx: engrave.txt ../util/makedefs ../util/makedefs -2 -epitaph: epitaph.txt ../util/makedefs +epitaph epitaph.idx: epitaph.txt ../util/makedefs ../util/makedefs -1 -bogusmon: bogusmon.txt ../util/makedefs +bogusmon bogusmon.idx: bogusmon.txt ../util/makedefs ../util/makedefs -3 options: ../util/makedefs diff --git a/sys/unix/Makefile.top b/sys/unix/Makefile.top index c108f35527..63a0389ba6 100644 --- a/sys/unix/Makefile.top +++ b/sys/unix/Makefile.top @@ -67,7 +67,8 @@ DIRPERM = 0755 # Qt without X11; assumes GRAPHIC_TOMBSTONE: # VARDATND = nhtiles.bmp pet_mark.xbm pilemark.xbm rip.xpm -VARDATD = bogusmon data engrave epitaph oracles options quest.lua rumors +VARDATD = bogusmon bogusmon.idx data engrave engrave.idx epitaph epitaph.idx oracles options quest.lua \ + rumors_t rumors_t.idx rumors_f rumors_f.idx VARDAT = $(VARDATD) $(VARDATND) # Some versions of make use the SHELL environment variable as the @@ -201,17 +202,17 @@ distrib: data: $(GAME) ( cd dat ; $(MAKE) data ) -engrave: $(GAME) +engrave engrave.idx: $(GAME) ( cd dat ; $(MAKE) engrave ) -bogusmon: $(GAME) +bogusmon bogusmon.idx: $(GAME) ( cd dat ; $(MAKE) bogusmon ) -epitaph: $(GAME) +epitaph epitaph.idx: $(GAME) ( cd dat ; $(MAKE) epitaph ) -rumors: $(GAME) - ( cd dat ; $(MAKE) rumors ) +rumors_t rumors_t.idx rumors_f rumors_f.idx: $(GAME) + ( cd dat ; $(MAKE) rumors_t ) oracles: $(GAME) ( cd dat ; $(MAKE) oracles ) diff --git a/sys/unix/NetHack.xcodeproj/project.pbxproj b/sys/unix/NetHack.xcodeproj/project.pbxproj index 3139be9b47..ad029f6b74 100644 --- a/sys/unix/NetHack.xcodeproj/project.pbxproj +++ b/sys/unix/NetHack.xcodeproj/project.pbxproj @@ -1178,9 +1178,9 @@ 317E7C4B21A35F0500F6E4E5 /* Copy makedefs */, 059660C02C80B07100398EDE /* Codesign makedefs */, 319CBA3821A3458100150830 /* Build data */, - 317E7C4521A3548F00F6E4E5 /* Build rumors */, + 317E7C4521A3548F00F6E4E5 /* Build rumors and index */, 317E7C4E21A3697300F6E4E5 /* Build options */, - 317E7C4F21A36A5700F6E4E5 /* Build engrave, epitaph and bogusmon */, + 317E7C4F21A36A5700F6E4E5 /* Build engrave, epitaph, bogusmon, and their indices */, 3192867F21A3AF8000325BEB /* Build oracles */, ); buildRules = ( @@ -1419,7 +1419,7 @@ shellPath = /bin/sh; shellScript = "codesign --force --deep -s - \"${NH_UTIL_DIR}\"/recover\n"; }; - 317E7C4521A3548F00F6E4E5 /* Build rumors */ = { + 317E7C4521A3548F00F6E4E5 /* Build rumors and index*/ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -1427,15 +1427,18 @@ inputFileListPaths = ( ); inputPaths = ( - "$(NH_DAT_DIR)/rumors.tru", - "$(NH_DAT_DIR)/rumors.fal", + "$(NH_DAT_DIR)/rumors_t.txt", + "$(NH_DAT_DIR)/rumors_f.txt "$(NH_UTIL_DIR)/makedefs", ); name = "Build rumors"; outputFileListPaths = ( ); outputPaths = ( - "$(NH_DAT_DIR)/rumors", + "$(NH_DAT_DIR)/rumors_t", + "$(NH_DAT_DIR)/rumors_t.idx", + "$(NH_DAT_DIR)/rumors_f", + "$(NH_DAT_DIR)/rumors_f.idx", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -1481,7 +1484,7 @@ shellPath = /bin/sh; shellScript = "cd \"${NH_DAT_DIR}\"\n\"${NH_UTIL_DIR}\"/makedefs -v\n"; }; - 317E7C4F21A36A5700F6E4E5 /* Build engrave, epitaph and bogusmon */ = { + 317E7C4F21A36A5700F6E4E5 /* Build engrave, epitaph, bogusmon, and their indices */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -1493,13 +1496,16 @@ "$(NH_DAT_DIR)/epitaph.txt", "$(NH_DAT_DIR)/bogusmon.txt", ); - name = "Build engrave, epitaph and bogusmon"; + name = "Build engrave, epitaph, bogusmon, and their indices"; outputFileListPaths = ( ); outputPaths = ( "$(NH_DAT_DIR)/engrave", + "$(NH_DAT_DIR)/engrave.idx", "$(NH_DAT_DIR)/epitaph", + "$(NH_DAT_DIR)/epitaph.idx", "$(NH_DAT_DIR)/bogusmon", + "$(NH_DAT_DIR)/bogusmon.idx", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -1537,10 +1543,13 @@ ); inputPaths = ( "$(NH_DAT_DIR)/bogusmon", + "$(NH_DAT_DIR)/bogusmon.idx", "$(NH_DAT_DIR)/cmdhelp", "$(NH_DAT_DIR)/data", "$(NH_DAT_DIR)/engrave", + "$(NH_DAT_DIR)/engrave.idx", "$(NH_DAT_DIR)/epitaph", + "$(NH_DAT_DIR)/epitaph.idx", "$(NH_DAT_DIR)/help", "$(NH_DAT_DIR)/hh", "$(NH_DAT_DIR)/history", @@ -1549,7 +1558,10 @@ "$(NH_DAT_DIR)/optmenu", "$(NH_DAT_DIR)/options", "$(NH_DAT_DIR)/oracles", - "$(NH_DAT_DIR)/rumors", + "$(NH_DAT_DIR)/rumors_t", + "$(NH_DAT_DIR)/rumors_t.idx", + "$(NH_DAT_DIR)/rumors_f", + "$(NH_DAT_DIR)/rumors_f.idx", "$(NH_DAT_DIR)/tribute", "$(NH_DAT_DIR)/wizhelp", "$(NH_DAT_DIR)/air.lua", @@ -1692,7 +1704,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "cd \"${NH_DAT_DIR}\"\n\"${NH_UTIL_DIR}\"/dlb cf nhdat help hh cmdhelp keyhelp history opthelp optmenu wizhelp dungeon.lua tribute asmodeus.lua baalz.lua bigrm-*.lua castle.lua fakewiz?.lua juiblex.lua knox.lua medusa-?.lua minend-?.lua minefill.lua minetn-?.lua oracle.lua orcus.lua sanctum.lua soko?-?.lua tower?.lua tut-?.lua valley.lua wizard?.lua nhcore.lua nhlib.lua themerms.lua hellfill.lua astral.lua air.lua earth.lua fire.lua water.lua ???-goal.lua ???-fil?.lua ???-loca.lua ???-strt.lua bogusmon data engrave epitaph oracles options quest.lua rumors\n"; + shellScript = "cd \"${NH_DAT_DIR}\"\n\"${NH_UTIL_DIR}\"/dlb cf nhdat help hh cmdhelp keyhelp history opthelp optmenu wizhelp dungeon.lua tribute asmodeus.lua baalz.lua bigrm-*.lua castle.lua fakewiz?.lua juiblex.lua knox.lua medusa-?.lua minend-?.lua minefill.lua minetn-?.lua oracle.lua orcus.lua sanctum.lua soko?-?.lua tower?.lua tut-?.lua valley.lua wizard?.lua nhcore.lua nhlib.lua themerms.lua hellfill.lua astral.lua air.lua earth.lua fire.lua water.lua ???-goal.lua ???-fil?.lua ???-loca.lua ???-strt.lua bogusmon bogusmon.idx data engrave engrave.idx epitaph epitaph.idx oracles options quest.lua rumors_t rumors_t.idx rumors_f rumors_f.idx\n"; }; 3192867021A39F6A00325BEB /* Install */ = { isa = PBXShellScriptBuildPhase; diff --git a/sys/unix/hints/include/cross-pre2.370 b/sys/unix/hints/include/cross-pre2.370 index d0cdf513a0..77e37f9e72 100644 --- a/sys/unix/hints/include/cross-pre2.370 +++ b/sys/unix/hints/include/cross-pre2.370 @@ -366,7 +366,8 @@ override WINOBJ= # don't bother Making regular NetHack executable override GAME= # the real VARDAT hasn't been defined yet for use in ALLDEP override -WASM_DAT = bogusmon data engrave epitaph oracles quest.lua rumors +WASM_DAT = bogusmon bogusmon.idx data engrave engrave.idx epitaph epitaph.idx oracles quest.lua \ + rumors_t rumors_t.idx rumors_f rumors_f.idx WASMDEP = include/nhlua.h $(WASM_DAT) spec_levs check-dlb override ALLDEP = $(WASMDEP) wasm override PREGAME += mkdir -p $(TARGETDIR)/wasm-data ; diff --git a/sys/vms/Makefile.dat b/sys/vms/Makefile.dat index efe3632979..fcad7644fe 100644 --- a/sys/vms/Makefile.dat +++ b/sys/vms/Makefile.dat @@ -107,7 +107,7 @@ rip.xpm : $(WINX11)rip.xpm data.; : data.base $(MAKEDEFS) $(RUN) $(MAKEDEFS) -d -rumors.; : rumors.tru rumors.fal $(MAKEDEFS) +rumors.; : rumors_t.txt rumors_f.txt $(MAKEDEFS) $(RUN) $(MAKEDEFS) -r engrave.; epitaph.; bogusmon.; : engrave.txt epitaph.txt bogusmon.txt diff --git a/sys/vms/Makefile_dat.vms b/sys/vms/Makefile_dat.vms index 09979bb63c..1f0aa2f929 100644 --- a/sys/vms/Makefile_dat.vms +++ b/sys/vms/Makefile_dat.vms @@ -67,7 +67,9 @@ MOCPATH ?= $(QTDIR)/bin/$(MOC) # The default is for the TARGET_* variables to match the defaults. # If we're cross-compiling these will get overridden elsewhere, likely via -VARDAT = bogusmon data engrave epitaph rumors oracles options +VARDAT = bogusmon bogusmon.idx data engrave engrave.idx epitaph epitaph.idx \ + rumors_t rumors_f oracles options \ + rumors_t.idx rumors_f.idx all: $(VARDAT) spec_levs quest_levs @@ -119,19 +121,19 @@ nethack.icns: $(WINSHR)nhicns.uu data: data.base $(UTIL)makedefs.exe mcr $(UTIL)makedefs.exe -d -rumors: rumors.tru rumors.fal $(UTIL)makedefs.exe +rumors_t rumors_f rumors_t.idx rumors_f.idx: rumors_t.txt rumors_f.txt $(UTIL)makedefs.exe mcr $(UTIL)makedefs.exe -r oracles: oracles.txt $(UTIL)makedefs.exe mcr $(UTIL)makedefs.exe -h -engrave: engrave.txt $(UTIL)makedefs.exe +engrave engrave.idx: engrave.txt $(UTIL)makedefs.exe mcr $(UTIL)makedefs.exe -s -epitaph: epitaph.txt $(UTIL)makedefs.exe +epitaph epitaph.idx: epitaph.txt $(UTIL)makedefs.exe mcr $(UTIL)makedefs.exe -s -bogusmon: bogusmon.txt $(UTIL)makedefs.exe +bogusmon bogusmon.idx: bogusmon.txt $(UTIL)makedefs.exe mcr $(UTIL)makedefs.exe -s # note: 'options' should have already been made when include/date.h was created diff --git a/sys/vms/Makefile_top.vms b/sys/vms/Makefile_top.vms index 47028c80d6..8ea24e5dc7 100644 --- a/sys/vms/Makefile_top.vms +++ b/sys/vms/Makefile_top.vms @@ -111,7 +111,8 @@ DIRPERM = 0755 # Qt without X11; assumes GRAPHIC_TOMBSTONE: # VARDATND = nhtiles.bmp pet_mark.xbm pilemark.xbm rip.xpm -VARDATD = bogusmon data engrave epitaph oracles options quest.lua rumors +VARDATD = bogusmon bogusmon.idx data engrave engrave.idx epitaph epitaph.idx oracles options quest.lua \ + rumors_t rumors_t.idx rumors_f rumors_f.idx VARDAT = $(VARDATD) $(VARDATND) # Some versions of make use the SHELL environment variable as the @@ -177,17 +178,17 @@ manpages: data: $(GAME) pipe set def $(DAT) && $(MAKE) data && set def [-] -engrave: $(GAME) +engrave engrave.idx: $(GAME) pipe set def $(DAT) && $(MAKE) engrave && set def [-] -bogusmon: $(GAME) +bogusmon bogusmon.idx: $(GAME) pipe set def $(DAT) && $(MAKE) bogusmon && set def [-] -epitaph: $(GAME) +epitaph epitaph.idx: $(GAME) pipe set def $(DAT) && $(MAKE) epitaph && set def [-] -rumors: $(GAME) - pipe set def $(DAT) && $(MAKE) rumors && set def [-] +rumors_t rumors_t.idx rumors_f rumors_f.idx: $(GAME) + pipe set def $(DAT) && $(MAKE) rumors_t && set def [-] oracles: $(GAME) pipe set def $(DAT) && $(MAKE) oracles && set def [-] diff --git a/sys/vms/install.com b/sys/vms/install.com index 867e5bd94e..69ff93aedd 100755 --- a/sys/vms/install.com +++ b/sys/vms/install.com @@ -29,8 +29,8 @@ $ ! to avoid inadvertent logical name interaction $ play_files = "PERM.,RECORD.,LOGFILE.,XLOGFILE.,PANICLOG." $ help_files = "HELP.,HH.,CMDHELP.,KEYHELP.,WIZHELP.,OPTHELP.," - + "HISTORY.,LICENSE." -$ data_files = "DATA.,RUMORS.,ORACLES.,OPTIONS.,TRIBUTE.," - - + "ENGRAVE.,EPITAPH.,BOGUSMON." +$ data_files = "DATA.,RUMORS_T.,RUMORS_T.IDX,RUMORS_F.,RUMORS_F.IDX,ORACLES.,OPTIONS.,TRIBUTE.," - + + "ENGRAVE.,ENGRAVE.IDX,EPITAPH.,EPITAPH.IDX,BOGUSMON.,BOGUSMON.IDX" $ sysconf_file = "[.sys.vms]sysconf" $ guidebook = "[.doc]Guidebook.txt" $ invoc_proc = "[.sys.vms]nethack.com" @@ -97,7 +97,7 @@ $ set default [-.-.dat] !move to data directory $ milestone "(data)" $ makedefs -d !data.base -> data $ milestone "(rumors)" -$ makedefs -r !rumors.tru + rumors.fal -> rumors +$ makedefs -r !rumors_t.txt + rumors_f.txt -> rumors $ milestone "(oracles)" $ makedefs -h !oracles.txt -> oracles $ milestone "(dungeon preprocess)" diff --git a/sys/windows/GNUmakefile b/sys/windows/GNUmakefile index 6f282c6326..8558107de5 100644 --- a/sys/windows/GNUmakefile +++ b/sys/windows/GNUmakefile @@ -974,9 +974,12 @@ CLEAN_FILE += $(SFCTARGETS) $(SFCTOOLOBJS) $(U)sf.tags $(U)sfdata.c $(INCL)/sfpr #========================================== ODLB = $(O)dlb DLBOBJS = $(addprefix $(ODLB)/, alloc.o dlb.o dlb_main.o panic.o) -DAT_CLEAN = $(addprefix $(DAT)/, data oracles options porthelp rumors engrave epitaph bogusmon) +DAT_CLEAN = $(addprefix $(DAT)/, data oracles options porthelp \ + rumors_t rumors_f \ + rumors_t.idx rumors_f.idx \ + engrave engrave.idx epitaph epitaph.idx bogusmon bogusmon.idx) DAT_NOCLEAN = $(addprefix $(DAT)/, help hh cmdhelp keyhelp history opthelp optmenu \ - wizhelp license engrave epitaph bogusmon tribute) + wizhelp license engrave engrave.idx epitaph epitaph.idx bogusmon bogusmon.idx tribute) DLBLST = $(DAT)/dlb.lst DLB = $(GAMEDIR)/nhdat$(NHV) DTARGETS = $(U)dlb.exe $(DAT_CLEAN) $(DLBLST) $(DLB) @@ -1007,14 +1010,14 @@ $(DAT)/options $(INCL)/date.h: $(U)makedefs.exe $(DAT)/porthelp: $(MSWSYS)/porthelp cp $< $@ -$(DAT)/rumors: $(U)makedefs.exe $(DAT)/rumors.tru $(DAT)/rumors.fal +$(DAT)/rumors_t $(DAT)/rumors_f $(DAT)/rumors_t.idx $(DAT)/rumors_f.idx : $(U)makedefs.exe $(DAT)/rumors_t.txt $(DAT)/rumors_f.txt $< -r -$(DAT)/engrave: $(DAT)/bogusmon +$(DAT)/engrave $DAT/engrave.idx: $(DAT)/bogusmon -$(DAT)/epitaph: $(DAT)/bogusmon +$(DAT)/epitaph $DAT/epitaph.idx: $(DAT)/bogusmon -$(DAT)/bogusmon: $(U)makedefs.exe $(DAT)/bogusmon.txt $(DAT)/engrave.txt $(DAT)/epitaph.txt +$(DAT)/bogusmon $DAT/bogusmon.idx: $(U)makedefs.exe $(DAT)/bogusmon.txt $(DAT)/engrave.txt $(DAT)/epitaph.txt $< -s $(DLBLST): $(LUAFILES) | $(DAT_CLEAN) $(DAT_NOCLEAN) @@ -1024,7 +1027,10 @@ $(DLBLST): $(LUAFILES) | $(DAT_CLEAN) $(DAT_NOCLEAN) if [ -f $(DAT)/ttyoptions ] ; then echo ttyoptions >> $(DLBLST) ; fi if [ -f $(DAT)/guioptions ] ; then echo guioptions >> $(DLBLST) ; fi echo porthelp >> $(DLBLST) - echo rumors >> $(DLBLST) + echo rumors_t >> $(DLBLST) + echo rumors_t.idx >> $(DLBLST) + echo rumors_f >> $(DLBLST) + echo rumors_f.idx >> $(DLBLST) echo help >> $(DLBLST) echo hh >> $(DLBLST) echo cmdhelp >> $(DLBLST) @@ -1035,8 +1041,11 @@ $(DLBLST): $(LUAFILES) | $(DAT_CLEAN) $(DAT_NOCLEAN) echo wizhelp >> $(DLBLST) echo license >> $(DLBLST) echo engrave >> $(DLBLST) + echo engrave.idx >> $(DLBLST) echo epitaph >> $(DLBLST) + echo epitaph.idx >> $(DLBLST) echo bogusmon >> $(DLBLST) + echo bogusmon.idx >> $(DLBLST) echo tribute >> $(DLBLST) cd $(DAT) ; ls -1 *.lua >> $(DLBLST) diff --git a/sys/windows/Makefile.nmake b/sys/windows/Makefile.nmake index aa713f1c7f..489ef50e31 100644 --- a/sys/windows/Makefile.nmake +++ b/sys/windows/Makefile.nmake @@ -1725,7 +1725,10 @@ $(GAMEDIR)NetHackW.exe : gamedir.tag $(OGUI)tile.o \ # install #-------- # -binary.tag: $(DAT)data $(DAT)rumors $(DAT)oracles $(DLB) \ +binary.tag: $(DAT)data \ + $(DAT)rumors_t $(DAT)rumors_t.idx \ + $(DAT)rumors_f $(DAT)rumors_f.idx \ + $(DAT)oracles $(DLB) \ $(HACKCSRC) $(SOUNDSRCS) copy nhdat$(NHV) $(GAMEDIR) copy $(DAT)license $(GAMEDIR) @@ -1743,17 +1746,23 @@ binary.tag: $(DAT)data $(DAT)rumors $(DAT)oracles $(DLB) \ copy /Y nhdat$(NHV) $(GAMEDIR) ! ELSE copy $(DAT)bogusmon $(GAMEDIR) + copy $(DAT)bogusmon.idx $(GAMEDIR) copy $(DAT)cmdhelp $(GAMEDIR) copy $(DAT)data $(GAMEDIR) copy $(DAT)engrave $(GAMEDIR) + copy $(DAT)engrave.idx $(GAMEDIR) copy $(DAT)epitaph $(GAMEDIR) + copy $(DAT)epitaph.idx $(GAMEDIR) copy $(DAT)help $(GAMEDIR) copy $(DAT)hh $(GAMEDIR) copy $(DAT)history $(GAMEDIR) copy $(DAT)license $(GAMEDIR) copy $(DAT)optmenu $(GAMEDIR) copy $(DAT)oracles $(GAMEDIR) - copy $(DAT)rumors $(GAMEDIR) + copy $(DAT)rumors_t $(GAMEDIR) + copy $(DAT)rumors_t.idx $(GAMEDIR) + copy $(DAT)rumors_f $(GAMEDIR) + copy $(DAT)rumors_f.idx $(GAMEDIR) copy $(DAT)symbols $(GAMEDIR) copy $(DAT)tribute $(GAMEDIR) copy $(DAT)wizhelp $(GAMEDIR) @@ -2157,9 +2166,11 @@ $(DAT)porthelp: $(MSWSYS)porthelp !IF ("$(USE_DLB)"=="Y") nhdat$(NHV): $(U)dlb.exe $(DAT)data $(DAT)oracles $(OPTIONS_FILE) $(LUA_FILES) \ - $(DAT)rumors $(DAT)help $(DAT)hh $(DAT)cmdhelp $(DAT)keyhelp \ + $(DAT)rumors_t $(DAT)rumors_t.idx $(DAT)rumors_f $(DAT)rumors_f.idx \ + $(DAT)help $(DAT)hh $(DAT)cmdhelp $(DAT)keyhelp \ $(DAT)history $(DAT)opthelp $(DAT)optmenu $(DAT)wizhelp $(DAT)porthelp \ - $(DAT)license $(DAT)engrave $(DAT)epitaph $(DAT)bogusmon $(DAT)tribute + $(DAT)license $(DAT)engrave $(DAT)epitaph $(DAT)bogusmon $(DAT)tribute \ + $(DAT)engrave.idx $(DAT)epitaph.idx $(DAT)bogusmon.idx @echo Building $@ @cd $(DAT) @echo data >dlb.lst @@ -2168,7 +2179,10 @@ nhdat$(NHV): $(U)dlb.exe $(DAT)data $(DAT)oracles $(OPTIONS_FILE) $(LUA_FILES) \ @if exist ttyoptions @echo ttyoptions >>dlb.lst @if exist guioptions @echo guioptions >>dlb.lst @if exist porthelp @echo porthelp >>dlb.lst - @echo rumors >>dlb.lst + @echo rumors_t >>dlb.lst + @echo rumors_t.idx >>dlb.lst + @echo rumors_f >>dlb.lst + @echo rumors_f.idx >>dlb.lst @echo help >>dlb.lst @echo hh >>dlb.lst @echo cmdhelp >>dlb.lst @@ -2179,8 +2193,11 @@ nhdat$(NHV): $(U)dlb.exe $(DAT)data $(DAT)oracles $(OPTIONS_FILE) $(LUA_FILES) \ @echo wizhelp >>dlb.lst @echo license >>dlb.lst @echo engrave >>dlb.lst + @echo engrave.idx >>dlb.lst @echo epitaph >>dlb.lst + @echo epitaph.idx >>dlb.lst @echo bogusmon >>dlb.lst + @echo bogusmon.idx >>dlb.lst @echo tribute >>dlb.lst # @for %%N in ($(luawildcards)) do dir /b %%N >>dlb.lst @for %%N in (*.lua) do @echo %%N >>dlb.lst @@ -2519,19 +2536,19 @@ $(OUTL)alloc.o: alloc.c $(CONFIG_H) $(DAT)data: $(U)makedefs.exe $(DATABASE) $(U)makedefs -d -$(DAT)rumors: $(U)makedefs.exe $(DAT)rumors.tru $(DAT)rumors.fal +$(DAT)rumors_t $(DAT)rumors_t.idx $(DAT)rumors_f $(DAT)rumors_f.idx: $(U)makedefs.exe $(DAT)rumors_t.txt $(DAT)rumors_f.txt $(U)makedefs -r $(DAT)oracles: $(U)makedefs.exe $(DAT)oracles.txt $(U)makedefs -h -$(DAT)engrave: $(U)makedefs.exe $(DAT)engrave.txt +$(DAT)engrave $(DAT)engrave.idx: $(U)makedefs.exe $(DAT)engrave.txt $(U)makedefs -2 -$(DAT)epitaph: $(U)makedefs.exe $(DAT)epitaph.txt +$(DAT)epitaph $(DAT)epitaph.idx: $(U)makedefs.exe $(DAT)epitaph.txt $(U)makedefs -1 -$(DAT)bogusmon: $(U)makedefs.exe $(DAT)bogusmon.txt +$(DAT)bogusmon $(DAT)bogusmon.idx: $(U)makedefs.exe $(DAT)bogusmon.txt $(U)makedefs -3 # This is the universal ctags utility which produces the tags in the @@ -2812,8 +2829,13 @@ binary: envchk.tag libdir.tag ottydir$(TARGET_CPU).tag \ opdccdir$(TARGET_CPU).tag opdcgdir$(TARGET_CPU).tag \ $(LUASRC)lua.h $(PDCDEP) \ $(INCL)nhlua.h $(OUTL)utility.tag \ - $(DAT)data $(DAT)rumors $(DAT)oracles $(DAT)engrave \ - $(DAT)epitaph $(DAT)bogusmon $(GAMEDIR)NetHack.exe \ + $(DAT)data \ + $(DAT)rumors_t $(DAT)rumors_t.idx \ + $(DAT)rumors_f $(DAT)rumors_f.idx \ + $(DAT)oracles $(DAT)engrave $(DAT)engrave.idx \ + $(DAT)epitaph $(DAT)bogusmon \ + $(DAT)epitaph.idx $(DAT)bogusmon.idx \ + $(GAMEDIR)NetHack.exe \ $(GAMEDIR)NetHackW.exe $(SFCTOOLPKG) $(GAMEDIRDLLS) binary.tag @echo NetHack is up to date. @@ -2832,10 +2854,16 @@ spotless: clean if exist $(U)*.lnk del $(U)*.lnk if exist $(U)*.map del $(U)*.map if exist $(DAT)data del $(DAT)data - if exist $(DAT)rumors del $(DAT)rumors + if exist $(DAT)rumors_t del $(DAT)rumors_t + if exist $(DAT)rumors_t.idx del $(DAT)rumors_t.idx + if exist $(DAT)rumors_f del $(DAT)rumors_f + if exist $(DAT)rumors_f.idx del $(DAT)rumors_f.idx if exist $(DAT)engrave del $(DAT)engrave + if exist $(DAT)engrave.idx del $(DAT)engrave.idx if exist $(DAT)epitaph del $(DAT)epitaph + if exist $(DAT)epitaph.idx del $(DAT)epitaph.idx if exist $(DAT)bogusmon del $(DAT)bogusmon + if exist $(DAT)bogusmon.idx del $(DAT)bogusmon.idx if exist $(DAT)porthelp del $(DAT)porthelp if exist nhdat$(NHV). del nhdat$(NHV). if exist outldirx86.tag del outldirx86.tag @@ -2881,7 +2909,10 @@ spotless: clean !ENDIF if exist $(LUALIB) del $(LUALIB) if exist $(DAT)oracles del $(DAT)oracles - if exist $(DAT)rumors del $(DAT)rumors + if exist $(DAT)rumors_t del $(DAT)rumors_t + if exist $(DAT)rumors_t.idx del $(DAT)rumors_t.idx + if exist $(DAT)rumors_f del $(DAT)rumors_f + if exist $(DAT)rumors_f.idx del $(DAT)rumors_f.idx if exist $(DAT)options del $(DAT)options if exist $(DAT)ttyoptions del $(DAT)ttyoptions if exist $(DAT)guioptions del $(DAT)guioptions diff --git a/util/makedefs.c b/util/makedefs.c index 53c90c1512..e848ed8ceb 100644 --- a/util/makedefs.c +++ b/util/makedefs.c @@ -165,12 +165,9 @@ extern void objects_globals_init(void); /* objects.c */ static char *name_file(const char *, const char *); static FILE *getfp(const char *, const char *, const char *, int); static void do_ext_makedefs(int, char **); -static char *padline(char *, unsigned); -static unsigned long read_rumors_file(const char *, int *, - long *, unsigned long, unsigned); static void rafile(int); static void do_rnd_access_file(const char *, const char *, - const char *, unsigned); + const char *); static boolean d_filter(char *); static boolean h_filter(char *); static void opt_out_words(char *, int *); @@ -196,7 +193,7 @@ struct ascii_filter { }; static struct ascii_filter ascii_ctx; -/* input, output, tmp */ +/* input, output, tmp, index */ static FILE *ifp, *ofp, *tfp; #if defined(__BORLANDC__) && !defined(_WIN32) @@ -331,10 +328,14 @@ do_makedefs(char *options) rafile('1'); rafile('2'); rafile('3'); + rafile('4'); + rafile('5'); break; case '1': case '2': case '3': + case '4': + case '5': rafile(*options); break; #if defined(OLD_MAKEDEFS_OPTIONS) @@ -420,21 +421,29 @@ rafile(int whichone) case '1': do_rnd_access_file(EPITAPHFILE, "epitaph", /* default epitaph: parody of the default engraving */ - "No matter where I went, here I am.", - MD_PAD_RUMORS); /* '_RUMORS' is correct here */ + "No matter where I went, here I am."); break; case '2': do_rnd_access_file(ENGRAVEFILE, "engrave", /* default engraving: popularized by "The Adventures of Buckaroo Bonzai Across the 8th Dimension" but predates that 1984 movie; some attribute it to Confucius */ - "No matter where you go, there you are.", - MD_PAD_RUMORS); /* '_RUMORS' used here too */ + "No matter where you go, there you are."); break; case '3': do_rnd_access_file(BOGUSMONFILE, "bogusmon", /* default bogusmon: iconic monster that isn't in nethack */ - "grue", MD_PAD_BOGONS); + "grue"); + break; + case '4': + do_rnd_access_file(RUMORSTFILE, "rumors_t", + /* default true rumor: based on classic logic puzzle */ + "This rumor is true"); + break; + case '5': + do_rnd_access_file(RUMORSFFILE, "rumors_f", + /* default false rumoe: based on classic logic puzzle */ + "This rumor is false"); break; } } @@ -996,94 +1005,17 @@ grep0(FILE *inputfp0, FILE* outputfp0, int flg) return; } -static char * -padline(char *line, unsigned padlength) -{ - /* - * Rumor selection is accomplished by seeking to a random - * position in the file, advancing to newline, and taking - * the next line. Therefore, rumors which follow long-line - * rumors are most likely to be chosen and rumors which - * follow short-line rumors are least likely to be chosen. - * We ameliorate the latter by padding the shortest lines, - * increasing the chance of the random seek landing in them. - * The core's get_rnd_text() handles long lines in a way - * that results in even selection distribution. - * - * Random epitaphs, engravings, and hallucinatory monster - * names are in the same boat. - */ - char *endp; - unsigned len = (unsigned) strlen(line); /* includes newline */ - - if (len <= padlength) { - endp = strchr(line, '\n'); /* fgetline() guarantees a newline even if - * the input file's last line lacks one */ - - /* this is safe provided that padlength+1 is less than the allocation - amount used in fgetline(); currently 144 (BUFSZ/2+16) */ - while (len++ < padlength) { - *endp++ = '_'; - } - *endp++ = '\n'; - *endp = '\0'; - } - return line; -} - -/* common code for do_rumors(). Return 0 on error. */ -static unsigned long -read_rumors_file( - const char *file_ext, - int *rumor_count, - long *rumor_size, - unsigned long old_rumor_offset, - unsigned padlength) -{ - char infile[MAXFNAMELEN], xbuf[BUFSZ]; - char *line; - unsigned long rumor_offset; - - Sprintf(infile, DATA_IN_TEMPLATE, RUMOR_FILE); - Strcat(infile, file_ext); - if (!(ifp = fopen(infile, RDTMODE))) { - perror(infile); - return 0L; - } - set_fgetline_context(infile, TRUE, FALSE); - - /* copy the rumors */ - while ((line = fgetline(ifp)) != 0) { - (void) padline(line, padlength); /* make shortest lines be longer */ - - (*rumor_count)++; -#if 0 - /*[if we forced binary output, this would be sufficient]*/ - *rumor_size += strlen(line); /* includes newline */ -#endif - (void) fputs(xcrypt(line, xbuf), tfp); - free((genericptr_t) line); - } - /* record the current position; next rumors section will start here */ - rumor_offset = (unsigned long) ftell(tfp); - Fclose(ifp); /* all done with rumors.file_ext */ - - /* the calculated value for *_rumor_count assumes that - a single-byte line terminator is in use; for platforms - which use two byte CR+LF, we need to override that value - [it's much simpler to do so unconditionally, rendering - the loop's accumulation above obsolete] */ - *rumor_size = (long) (rumor_offset - old_rumor_offset); - return rumor_offset; -} - static void do_rnd_access_file( const char *fname, const char *basefname, - const char *deflt_content, - unsigned padlength) + const char *deflt_content) { + FILE *idxfp; /* TODO why is ifp global? should this be global too??? */ + unsigned long offset; + char deflt_wnl[BUFSZ]; /* default with newline */ + char *comment; + char *line, buf[BUFSZ], xbuf[BUFSZ], greptmp[8 + 1 + 3 + 1]; @@ -1105,15 +1037,24 @@ do_rnd_access_file( makedefs_exit(EXIT_FAILURE); /*NOTREACHED*/ } + Strcat(filename, ".idx"); + if (!(idxfp = fopen(filename, WRTMODE))) { + perror(filename); + makedefs_exit(EXIT_FAILURE); + /*NOTREACHED*/ + } Fprintf(ofp, "%s", Dont_Edit_Data); /* write out the default content entry unconditionally instead of - waiting to see whether there are no regular output lines; if it - matches a regular entry (bogusmon "grue"), that entry will become - more likely to be picked than normal but it's nothing to worry about */ + waiting to see whether there are no regular output lines */ + offset = (unsigned long) ftell(ofp); + Fprintf(idxfp, "%15ld\n", offset); /* 16 chars total */ Strcpy(buf, deflt_content); - if (!strchr(buf, '\n')) /* lines from the file include trailing newline +*/ + Strcpy(deflt_wnl, deflt_content); + if (!strchr(buf, '\n')) { /* lines from the file include trailing newline +*/ Strcat(buf, "\n"); /* so make sure that the default one does too */ - (void) fputs(xcrypt(padline(buf, padlength), xbuf), ofp); + Strcat(deflt_wnl, "\n"); + } + (void) fputs(xcrypt(buf, xbuf), ofp); tfp = getfp(DATA_TEMPLATE, greptmp, WRTMODE, FLG_TEMPFILE); grep0(ifp, tfp, FLG_TEMPFILE); @@ -1125,14 +1066,26 @@ do_rnd_access_file( set_fgetline_context(NULL, FALSE, FALSE); while ((line = fgetline(ifp)) != 0) { - if (line[0] != '#' && line[0] != '\n') { - (void) padline(line, padlength); - (void) fputs(xcrypt(line, xbuf), ofp); + /* allow "##" to begin a midline comment */ + if ((comment = /* ASSIGNMENT */ strstr(line, "##")) != NULL) { + while (comment > line && (comment[-1] == ' ' || comment[-1] == '\t')) { + comment--; + } + comment[0] = '\n'; + comment[1] = 0; + } + if (line[0] && line[0] != '#' && line[0] != '\n') { + if (strcmp(line, deflt_wnl)) { /* don't duplicate deflt_content */ + offset = (unsigned long) ftell(ofp); + Fprintf(idxfp, "%15ld\n", offset); /* 16 chars total */ + (void) fputs(xcrypt(line, xbuf), ofp); + } } free((genericptr_t) line); } Fclose(ifp); Fclose(ofp); + Fclose(idxfp); #ifdef HAS_NO_MKSTEMP delete_file(DATA_TEMPLATE, greptmp); @@ -1145,101 +1098,8 @@ DISABLE_WARNING_FORMAT_NONLITERAL void do_rumors(void) { - char *line; - static const char rumors_header[] = - "%s%04d,%06ld,%06lx;%04d,%06ld,%06lx;0,0,%06lx\n"; - char tempfile[MAXFNAMELEN]; - int true_rumor_count, false_rumor_count; - long true_rumor_size, false_rumor_size; - unsigned long true_rumor_offset, false_rumor_offset, eof_offset; - - Sprintf(tempfile, DATA_TEMPLATE, "rumors.tmp"); - filename[0] = '\0'; -#ifdef FILE_PREFIX - Strcat(filename, file_prefix); -#endif - Sprintf(eos(filename), DATA_TEMPLATE, RUMOR_FILE); - if (!(ofp = fopen(filename, WRTMODE))) { - perror(filename); - makedefs_exit(EXIT_FAILURE); - /*NOTREACHED*/ - } - if (!(tfp = fopen(tempfile, WRTMODE))) { - perror(tempfile); - Fclose(ofp); - makedefs_exit(EXIT_FAILURE); - /*NOTREACHED*/ - } - - true_rumor_count = false_rumor_count = 0; - true_rumor_size = false_rumor_size = 0L; - true_rumor_offset = false_rumor_offset = eof_offset = 0L; - - /* output a dummy header record; we'll replace it in final output */ - Fprintf(tfp, rumors_header, Dont_Edit_Data, true_rumor_count, - true_rumor_size, true_rumor_offset, false_rumor_count, - false_rumor_size, false_rumor_offset, eof_offset); - /* record the current position; true rumors will start here */ - true_rumor_offset = (unsigned long) ftell(tfp); - - false_rumor_offset - = (unsigned long) read_rumors_file(".tru", &true_rumor_count, - &true_rumor_size, true_rumor_offset, - MD_PAD_RUMORS); - if (!false_rumor_offset) - goto rumors_failure; - - eof_offset = read_rumors_file(".fal", &false_rumor_count, - &false_rumor_size, false_rumor_offset, - MD_PAD_RUMORS); - if (!eof_offset) - goto rumors_failure; - - /* get ready to transfer the contents of temp file to output file */ - line = (char *) alloc(BUFSZ + MAXFNAMELEN); - Sprintf(line, "rewind of \"%s\"", tempfile); - if (rewind(tfp) != 0) { - perror(line); - free((genericptr_t) line); - goto rumors_failure; - } - free((genericptr_t) line); - - /* output the header record */ - Fprintf(ofp, rumors_header, Dont_Edit_Data, true_rumor_count, - true_rumor_size, true_rumor_offset, false_rumor_count, - false_rumor_size, false_rumor_offset, eof_offset); - - set_fgetline_context(NULL, FALSE, FALSE); - /* skip the temp file's dummy header */ - if (!(line = fgetline(tfp))) { /* "Don't Edit" */ - perror(tempfile); - goto rumors_failure; - } - free((genericptr_t) line); - if (!(line = fgetline(tfp))) { /* count,size,offset */ - perror(tempfile); - goto rumors_failure; - } - free((genericptr_t) line); - /* copy the rest of the temp file into the final output file */ - while ((line = fgetline(tfp)) != 0) { - (void) fputs(line, ofp); - free((genericptr_t) line); - } - /* all done; delete temp file */ - Fclose(tfp); - Unlink(tempfile); - Fclose(ofp); - return; - - rumors_failure: - Fclose(ofp); - Unlink(filename); /* kill empty or incomplete output file */ - Fclose(tfp); - Unlink(tempfile); /* and temporary file */ - makedefs_exit(EXIT_FAILURE); - /*NOTREACHED*/ + rafile('4'); + rafile('5'); } RESTORE_WARNING_FORMAT_NONLITERAL From 75272a78865a172f01fd3a8bd9dc7d2ac04bc8a2 Mon Sep 17 00:00:00 2001 From: Gorilla Sapiens Date: Fri, 6 Feb 2026 22:08:14 -0700 Subject: [PATCH 2/2] fixed comment --- src/rumors.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rumors.c b/src/rumors.c index a191a408f5..9bc54b5210 100644 --- a/src/rumors.c +++ b/src/rumors.c @@ -13,7 +13,7 @@ * reading the record there, and then reading the real entry. This * once and for all fixes "bias based on length" and removes the need * for padding short entries. Additionally, we've split rumors into - * two files, rumorst and rumorsf, for ease of access. + * two files, rumors_t and rumors_f, for ease of access. */ /* [Note: this comment is fairly old, but still accurate for 3.1;