]> granicus.if.org Git - nethack/commitdiff
debug mode #wizrumorcheck
authornethack.allison <nethack.allison>
Mon, 1 May 2006 01:49:18 +0000 (01:49 +0000)
committernethack.allison <nethack.allison>
Mon, 1 May 2006 01:49:18 +0000 (01:49 +0000)
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
src/cmd.c
src/rumors.c

index 72d3b9c8c255664c948fbe05e2be6a8664186503..700bff0926d4e40ed73ac0ffa3594edb231a12f0 100644 (file)
@@ -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 ### */
 
index e95615fcf59affeaa66628bf8e10a6ef4788f3f8..76028a6e2c4d93d8f0aa37d56175130987106529 100644 (file)
--- 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}
 };
index 3478354ff3948f232dcd2f5f7b610c6bdff125a0..fab6f5ac64dea892c45fa014b231f0d98609e098 100644 (file)
@@ -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 */