From: PatR Date: Sat, 22 Feb 2020 20:32:00 +0000 (-0800) Subject: more #302 - empty {bogusmon,engrave,epitaph}.txt X-Git-Tag: NetHack-3.6.6_Released~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7220c9d2d2353ed9c9625bbb7f86df1d0af5ed37;p=nethack more #302 - empty {bogusmon,engrave,epitaph}.txt Have makedefs add a real data line to the output for the files that caused trouble when empty. --- diff --git a/util/makedefs.c b/util/makedefs.c index 6243c5dfa..cd971bcc0 100644 --- a/util/makedefs.c +++ b/util/makedefs.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 makedefs.c $NHDT-Date: 1562180226 2019/07/03 18:57:06 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.149 $ */ +/* NetHack 3.6 makedefs.c $NHDT-Date: 1582403492 2020/02/22 20:31:32 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.177 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Kenneth Lorber, Kensington, Maryland, 2015. */ /* Copyright (c) M. Stephenson, 1990, 1991. */ @@ -182,7 +182,7 @@ static char *FDECL(xcrypt, (const char *)); static unsigned long FDECL(read_rumors_file, (const char *, int *, long *, unsigned long)); static boolean FDECL(get_gitinfo, (char *, char *)); -static void FDECL(do_rnd_access_file, (const char *)); +static void FDECL(do_rnd_access_file, (const char *, const char *)); static boolean FDECL(d_filter, (char *)); static boolean FDECL(h_filter, (char *)); static void NDECL(build_savebones_compat_string); @@ -362,9 +362,22 @@ char *options; break; case 's': case 'S': - do_rnd_access_file(EPITAPHFILE); - do_rnd_access_file(ENGRAVEFILE); - do_rnd_access_file(BOGUSMONFILE); + /* + * post-3.6.5: + * File must not be empty to avoid divide by 0 + * in core's rn2(), so provide a default entry. + */ + do_rnd_access_file(EPITAPHFILE, + /* default epitaph: parody of the default engraving */ + "No matter where I went, here I am."); + do_rnd_access_file(ENGRAVEFILE, + /* default engraving: popularized by "The Adventures of + Buckaroo Bonzai Across the 8th Dimenstion" but predates + that 1984 movie; some attribute it to Confucius */ + "No matter where you go, there you are."); + do_rnd_access_file(BOGUSMONFILE, + /* default bogusmon: iconic monster that isn't in nethack */ + "grue"); break; case 'h': case 'H': @@ -952,8 +965,9 @@ unsigned long old_rumor_offset; } static void -do_rnd_access_file(fname) +do_rnd_access_file(fname, deflt_content) const char *fname; +const char *deflt_content; { char *line; @@ -973,6 +987,11 @@ const char *fname; exit(EXIT_FAILURE); } 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 */ + (void) fputs(xcrypt(deflt_content), ofp); tfp = getfp(DATA_TEMPLATE, "grep.tmp", WRTMODE); grep0(ifp, tfp); @@ -981,7 +1000,7 @@ const char *fname; while ((line = fgetline(ifp)) != 0) { if (line[0] != '#' && line[0] != '\n') (void) fputs(xcrypt(line), ofp); - free(line); + free((genericptr_t) line); } Fclose(ifp); Fclose(ofp);