]> granicus.if.org Git - nethack/commitdiff
dumplog message history groundwork
authorPatR <rankin@nethack.org>
Sat, 11 Mar 2017 00:41:49 +0000 (16:41 -0800)
committerPatR <rankin@nethack.org>
Sat, 11 Mar 2017 00:41:49 +0000 (16:41 -0800)
Separate the message logging out of pline so that other things (for
instance, one-line summary for quest block messages) can be logged.
The code that utilizes this isn't ready for prime time yet.

For FREE_ALL_MEMORY, release DUMPLOG message history when saving.
(Actually, this frees it unconditionally rather just doing so for
FREE_ALL_MEMORY.)  It was being freed when logged at end of game,
but not during save.  If dumplog message history and interface
message history get integrated, the existing message history
save/restore handling should become applicable instead.

include/extern.h
src/pline.c
src/save.c

index 800969d6f8d7167281a03797539752dede8cc858..3f5b3497147c1d659b79a31d41f6ea8c559daf95 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 extern.h        $NHDT-Date: 1488075978 2017/02/26 02:26:18 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.582 $ */
+/* NetHack 3.6 extern.h        $NHDT-Date: 1489192904 2017/03/11 00:41:44 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.583 $ */
 /* Copyright (c) Steve Creps, 1988.                              */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -1801,6 +1801,10 @@ E boolean FDECL(is_autopickup_exception, (struct obj *, BOOLEAN_P));
 
 /* ### pline.c ### */
 
+#ifdef DUMPLOG
+E void FDECL(dumplogmsg, (const char *));
+E void NDECL(dumplogfreemessages);
+#endif
 E void VDECL(pline, (const char *, ...)) PRINTF_F(1, 2);
 E void VDECL(Norep, (const char *, ...)) PRINTF_F(1, 2);
 E void NDECL(free_youbuf);
index 6103d29cfd9c10988d3fe12e71a617ce6ce66013..2a473625b5357b6e992ccafeba1592eb250e24f7 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 pline.c $NHDT-Date: 1461437814 2016/04/23 18:56:54 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.51 $ */
+/* NetHack 3.6 pline.c $NHDT-Date: 1489192905 2017/03/11 00:41:45 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.57 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -18,6 +18,47 @@ static void FDECL(execplinehandler, (const char *));
 /* also used in end.c */
 unsigned saved_pline_index = 0; /* slot in saved_plines[] to use next */
 char *saved_plines[DUMPLOG_MSG_COUNT] = { (char *) 0 };
+
+/* keep the most recent DUMPLOG_MSG_COUNT messages */
+void
+dumplogmsg(line)
+const char *line;
+{
+    /*
+     * TODO:
+     *  This essentially duplicates message history, which is
+     *  currently implemented in an interface-specific manner.
+     *  The core should take responsibility for that and have
+     *  this share it.
+     */
+    unsigned indx = saved_pline_index; /* next slot to use */
+    char *oldest = saved_plines[indx]; /* current content of that slot */
+
+    if (oldest && strlen(oldest) >= strlen(line)) {
+        /* this buffer will gradually shrink until the 'else' is needed;
+           there's no pressing need to track allocation size instead */
+        Strcpy(oldest, line);
+    } else {
+        if (oldest)
+            free((genericptr_t) oldest);
+        saved_plines[indx] = dupstr(line);
+    }
+    saved_pline_index = (indx + 1) % DUMPLOG_MSG_COUNT;
+}
+
+/* called during save (unlike the interface-specific message history,
+   this data isn't saved and restored); end-of-game releases saved_pline[]
+   while writing its contents to the final dump log */
+void
+dumplogfreemessages()
+{
+    unsigned indx;
+
+    for (indx = 0; indx < DUMPLOG_MSG_COUNT; ++indx)
+        if (saved_plines[indx])
+            free((genericptr_t) saved_plines[indx]), saved_plines[indx] = 0;
+    saved_pline_index = 0;
+}
 #endif
 
 /*VARARGS1*/
@@ -86,7 +127,6 @@ VA_DECL(const char *, line)
         pbuf[BUFSZ - 1 - 1] = line[ln - 1];
         pbuf[BUFSZ - 1] = '\0';
         line = pbuf;
-        ln = BUFSZ - 1;
     }
     if (!iflags.window_inited) {
         raw_print(line);
@@ -99,30 +139,7 @@ VA_DECL(const char *, line)
      * Unfortunately, that means Norep() isn't honored (general issue) and
      * that short lines aren't combined into one longer one (tty behavior).
      */
-    {
-        /*
-         * TODO:
-         *  This essentially duplicates message history, which is
-         *  currently implemented in an interface-specific manner.
-         *  The core should take responsibility for that and have
-         *  this share it.
-         *  Ideally history for prompt lines should be augmented
-         *  with the player's response once that has been specified.
-         */
-        unsigned indx = saved_pline_index; /* next slot to use */
-        char *oldest = saved_plines[indx]; /* current content of that slot */
-
-        if (oldest && (int) strlen(oldest) >= ln) { /* ln==strlen(line) */
-            /* this buffer will gradually shrink until the 'else' is needed;
-               there's no pressing need to track allocation size instead */
-            Strcpy(oldest, line);
-        } else {
-            if (oldest)
-                free((genericptr_t) oldest);
-            saved_plines[indx] = dupstr(line);
-        }
-        saved_pline_index = (indx + 1) % DUMPLOG_MSG_COUNT;
-    }
+    dumplogmsg(line);
 #endif
 
     msgtyp = msgtype_type(line, no_repeat);
index 078f276afebd984dae8a64aa02360bb2ffbca1c0..5270cc657af1bd2322b2e9aa807ec43cc9cdce1b 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 save.c  $NHDT-Date: 1450231175 2015/12/16 01:59:35 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.98 $ */
+/* NetHack 3.6 save.c  $NHDT-Date: 1489192905 2017/03/11 00:41:45 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.101 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -1410,6 +1410,9 @@ freedynamicdata()
 #ifdef STATUS_VIA_WINDOWPORT
     status_finish();
 #endif
+#ifdef DUMPLOG
+    dumplogfreemessages();
+#endif
 
     /* last, because it frees data that might be used by panic() to provide
        feedback to the user; conceivably other freeing might trigger panic */