From 376f9ba047e70a7da6190658703c56baf928f8f3 Mon Sep 17 00:00:00 2001 From: "nethack.allison" Date: Mon, 1 May 2006 01:49:18 +0000 Subject: [PATCH] debug mode #wizrumorcheck Provide a command to easily verify that the rumor true/false boundary offsets are correct for the rumors file. If the boundary is pointing mid-line, the rumor at the boundary won't decrypt properly. --- include/extern.h | 3 +++ src/cmd.c | 11 +++++++++ src/rumors.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/include/extern.h b/include/extern.h index 72d3b9c8c..700bff092 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1877,6 +1877,9 @@ E void FDECL(outoracle, (BOOLEAN_P, BOOLEAN_P)); E void FDECL(save_oracles, (int,int)); E void FDECL(restore_oracles, (int)); E int FDECL(doconsult, (struct monst *)); +#ifdef WIZARD +E void NDECL(rumor_check); +#endif /* ### save.c ### */ diff --git a/src/cmd.c b/src/cmd.c index e95615fcf..76028a6e2 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -149,6 +149,7 @@ STATIC_PTR int NDECL(wiz_show_stats); # ifdef PORT_DEBUG STATIC_DCL int NDECL(wiz_port_debug); # endif +STATIC_PTR int NDECL(wiz_rumor_check); # endif STATIC_PTR int NDECL(enter_explore_mode); STATIC_PTR int NDECL(doattributes); @@ -942,6 +943,14 @@ wiz_smell() } while (TRUE); return 0; } + +/* #wizrumorcheck command - verify each rumor access */ +STATIC_PTR int +wiz_rumor_check() +{ + rumor_check(); + return 0; +} #endif /* WIZARD */ @@ -1754,6 +1763,7 @@ struct ext_func_tab extcmdlist[] = { {(char *)0, (char *)0, donull, TRUE}, #endif {(char *)0, (char *)0, donull, TRUE}, + {(char *)0, (char *)0, donull, TRUE}, #endif {(char *)0, (char *)0, donull, TRUE} /* sentinel */ }; @@ -1780,6 +1790,7 @@ static const struct ext_func_tab debug_extcmdlist[] = { #ifdef DEBUG {"wizdebug", "wizard debug command", wiz_debug_cmd, TRUE}, #endif + {"wizrumorcheck", "verify rumor boundaries", wiz_rumor_check, TRUE}, {"wmode", "show wall modes", wiz_show_wmodes, TRUE}, {(char *)0, (char *)0, donull, TRUE} }; diff --git a/src/rumors.c b/src/rumors.c index 3478354ff..fab6f5ac6 100644 --- a/src/rumors.c +++ b/src/rumors.c @@ -134,6 +134,66 @@ boolean exclude_cookie; return rumor_buf; } +#ifdef WIZARD +/* + * test that the true/false rumor boundaries are valid. + */ +void +rumor_check() +{ + dlb *rumors; + winid tmpwin; + char *endp, line[BUFSZ], xbuf[BUFSZ], rumor_buf[BUFSZ]; + + if (true_rumor_size < 0L) /* we couldn't open RUMORFILE */ + return; + + rumors = dlb_fopen(RUMORFILE, "r"); + + if (rumors) { + long rumor_start = 0L; + rumor_buf[0] = '\0'; + if (true_rumor_size == 0L) { /* if this is 1st outrumor() */ + init_rumors(rumors); + if (true_rumor_size < 0L) /* init failed */ + return; + } + tmpwin = create_nhwindow(NHW_TEXT); + /* + * 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, true_rumor_start, SEEK_SET); + rumor_start = dlb_ftell(rumors); + (void) dlb_fgets(line, sizeof line, rumors); + if ((endp = index(line, '\n')) != 0) *endp = 0; + Sprintf(rumor_buf, "T %06ld %s", rumor_start, + xcrypt(line, xbuf)); + putstr(tmpwin, 0, rumor_buf); + + rumor_buf[0] = '\0'; + (void) dlb_fseek(rumors, false_rumor_start, SEEK_SET); + rumor_start = dlb_ftell(rumors); + (void) dlb_fgets(line, sizeof line, rumors); + if ((endp = index(line, '\n')) != 0) *endp = 0; + Sprintf(rumor_buf, "F %06ld %s", rumor_start, + xcrypt(line, xbuf)); + putstr(tmpwin, 0, rumor_buf); + + (void) dlb_fclose(rumors); + display_nhwindow(tmpwin, TRUE); + destroy_nhwindow(tmpwin); + } else { + impossible("Can't open rumors file!"); + true_rumor_size = -1; /* don't try to open it again */ + } +} +#endif + void outrumor(truth, mechanism) int truth; /* 1=true, -1=false, 0=either */ -- 2.40.0