Skip to content

Commit

Permalink
debug mode #wizrumorcheck
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nethack.allison committed May 1, 2006
1 parent 10066ff commit 376f9ba
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ### */

Expand Down
11 changes: 11 additions & 0 deletions src/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 */


Expand Down Expand Up @@ -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 */
};
Expand All @@ -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}
};
Expand Down
60 changes: 60 additions & 0 deletions src/rumors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 376f9ba

Please sign in to comment.