dumplog message history groundwork

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.
This commit is contained in:
PatR
2017-03-10 16:41:49 -08:00
parent 9623154bbc
commit 278b6d52eb
3 changed files with 52 additions and 28 deletions

View 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);

View 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);

View 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 */