-/* NetHack 3.6 rumors.c $NHDT-Date: 1545132266 2018/12/18 11:24:26 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.34 $ */
+/* NetHack 3.6 rumors.c $NHDT-Date: 1583445339 2020/03/05 21:55:39 $ $NHDT-Branch: NetHack-3.6-Mar2020 $:$NHDT-Revision: 1.38 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
/* JNetHack Copyright */
/* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000 */
-/* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2019 */
+/* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2020 */
/* JNetHack may be freely redistributed. See license for details. */
#include "hack.h"
couldnt_open_file(RUMORFILE);
true_rumor_size = -1; /* don't try to open it again */
}
-/* this is safe either way, so do it always since we can't get the definition
- * out of makedefs.c
- */
+
+ /* this is safe either way, so do it always since we can't get the
+ * definition out of makedefs.c
+ */
#define PAD_RUMORS_TO
#ifdef PAD_RUMORS_TO
/* remove padding */
char *endp, line[BUFSZ], xbuf[BUFSZ], rumor_buf[BUFSZ];
if (true_rumor_size < 0L) { /* we couldn't open RUMORFILE */
- no_rumors:
+ no_rumors:
pline("rumors not accessible.");
- if (rumors)
- (void) dlb_fclose(rumors);
return;
}
rumor_buf[0] = '\0';
if (true_rumor_size == 0L) { /* if this is 1st outrumor() */
init_rumors(rumors);
- if (true_rumor_size < 0L)
+ if (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) true_rumor_start, true_rumor_start, true_rumor_end,
- (unsigned long) true_rumor_end, true_rumor_size,
- (unsigned long) true_rumor_size);
+ Sprintf(rumor_buf,
+ "T start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)",
+ (long) true_rumor_start, true_rumor_start,
+ true_rumor_end, (unsigned long) true_rumor_end,
+ true_rumor_size, (unsigned long) true_rumor_size);
putstr(tmpwin, 0, rumor_buf);
-
- Sprintf(
- rumor_buf,
- "F start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)",
- (long) false_rumor_start, false_rumor_start, false_rumor_end,
- (unsigned long) false_rumor_end, false_rumor_size,
- (unsigned long) false_rumor_size);
+ Sprintf(rumor_buf,
+ "F start=%06ld (%06lx), end=%06ld (%06lx), size=%06ld (%06lx)",
+ (long) false_rumor_start, false_rumor_start,
+ false_rumor_end, (unsigned long) false_rumor_end,
+ false_rumor_size, (unsigned long) false_rumor_size);
putstr(tmpwin, 0, rumor_buf);
/*
dlb *fh;
buf[0] = '\0';
-
fh = dlb_fopen(fname, "r");
-
if (fh) {
- /* TODO: cache sizetxt, starttxt, endtxt. maybe cache file contents?
- */
- long sizetxt = 0, starttxt = 0, endtxt = 0, tidbit = 0;
+ /* TODO: cache sizetxt, starttxt, endtxt. maybe cache file contents? */
+ long sizetxt = 0L, starttxt = 0L, endtxt = 0L, tidbit = 0L;
char *endp, line[BUFSZ], xbuf[BUFSZ];
- (void) dlb_fgets(line, sizeof line,
- fh); /* skip "don't edit" comment */
+
+ /* skip "don't edit" comment */
+ (void) dlb_fgets(line, sizeof line, fh);
(void) dlb_fseek(fh, 0L, SEEK_CUR);
starttxt = dlb_ftell(fh);
(void) dlb_fseek(fh, 0L, SEEK_END);
endtxt = dlb_ftell(fh);
sizetxt = endtxt - starttxt;
- tidbit = rng(sizetxt);
+ /* might be zero (only if file is empty); should complain in that
+ case but if could happen over and over, also the suggestion
+ that save and restore might fix the problem wouldn't be useful */
+ if (sizetxt < 1L)
+ return buf;
+ tidbit = (*rng)(sizetxt);
(void) dlb_fseek(fh, starttxt + tidbit, SEEK_SET);
(void) dlb_fgets(line, sizeof line, fh);
switch (mechanism) {
case BY_ORACLE:
/* Oracle delivers the rumor */
-#if 0 /*JP*/
+#if 0 /*JP:T*/
pline("True to her word, the Oracle %ssays: ",
(!rn2(4) ? "offhandedly "
: (!rn2(3) ? "casually "
if (perform_bwrite(mode)) {
bwrite(fd, (genericptr_t) &oracle_cnt, sizeof oracle_cnt);
if (oracle_cnt)
- bwrite(fd, (genericptr_t) oracle_loc, oracle_cnt * sizeof(long));
+ bwrite(fd, (genericptr_t) oracle_loc,
+ oracle_cnt * sizeof(long));
}
if (release_data(mode)) {
if (oracle_cnt) {