saving message history (trunk only)

On September 11, 2003 "<Someone>" wrote:
> When we're going to have a different save file format, could
> the last messages in the message history be saved as well, so
> ^P would work the same before and after saving (possibly
> including a few less messages to make room for the startup
> messages?).

This seemed like a reasonable request. This patch:
- adds the core support required.
- adds the tty supporting routines.
This commit is contained in:
nethack.allison
2003-10-05 13:43:16 +00:00
parent a5c8b517d2
commit f6f6c1f0d5
19 changed files with 228 additions and 5 deletions

View File

@@ -452,6 +452,7 @@ unsigned int *stuckid, *steedid; /* STEED */
restnames(fd);
restore_waterlevel(fd);
restore_msghistory(fd);
/* must come after all mons & objs are restored */
relink_timers(FALSE);
relink_light_sources(FALSE);
@@ -910,6 +911,26 @@ boolean ghostly;
clear_id_mapping();
}
restore_msghistory(fd)
register int fd;
{
int msgsize, k, msgcount = 0;
char msg[BUFSZ];
while(1) {
mread(fd, (genericptr_t) &msgsize, sizeof(msgsize));
if(msgsize == -1) break;
if (msgsize > (BUFSZ - 1))
panic("restore_msghistory: msg too big (%d)", msgsize);
mread(fd, (genericptr_t)msg, msgsize);
msg[msgsize] = '\0';
putmsghistory(msg);
++msgcount;
}
#ifdef DEBUG_MSGCOUNT
pline("Read %d messages from savefile.", msgcount);
#endif
}
/* Clear all structures for object and monster ID mapping. */
STATIC_OVL void

View File

@@ -339,6 +339,7 @@ register int fd, mode;
savefruitchn(fd, mode);
savenames(fd, mode);
save_waterlevel(fd, mode);
save_msghistory(fd, mode);
bflush(fd);
}
@@ -984,6 +985,36 @@ register int fd, mode;
ffruit = 0;
}
save_msghistory(fd, mode)
register int fd, mode;
{
char *msg, buf[BUFSZ];
int msgcount = 0, msglen = 0;
int minusone = -1;
boolean init = TRUE;
/* Ask window port for each message in sequence */
while ((msg = getmsghistory(init)) != 0) {
init = FALSE;
msglen = strlen(msg);
if (msglen < (BUFSZ-1))
Strcpy(buf, msg);
else {
/* impossible */
(void)strncpy(buf, msg, (BUFSZ - 1));
buf[BUFSZ-1] = '\0';
msglen = strlen(buf);
}
bwrite(fd, (genericptr_t)&msglen, sizeof(msglen));
bwrite(fd, (genericptr_t)msg, msglen);
++msgcount;
}
bwrite(fd, (genericptr_t) &minusone, sizeof(int));
#ifdef DEBUG_MSGCOUNT
pline("Stored %d messages into savefile.", msgcount);
#endif
}
/* also called by prscore(); this probably belongs in dungeon.c... */
void
free_dungeons()

View File

@@ -143,4 +143,47 @@ const char *pref;
they support.
Just return in this genl one. */
}
char *
genl_getmsghistory(init)
boolean init;
{
/* window ports can provide
their own getmsghistory() routine to
preserve message history between games.
The routine is called repeatedly from
the core save routine, and the window
port is expected to successively return
each message that it wants saved, starting
with the oldest message first, finishing
with the most recent.
Return null pointer when finished.
*/
return (char *)0;
}
/*ARGSUSED*/
void
genl_putmsghistory(msg)
const char *msg;
{
/* window ports can provide
their own putmsghistory() routine to
load message history from a saved game.
The routine is called repeatedly from
the core restore routine, starting with
the oldest saved message first, and
finishing with the latest.
The window port routine is expected to
load the message recall buffers in such
a way that the ordering is preserved.
The window port routine should make no
assumptions about how many messages are
forthcoming, nor should it assume that
another message will follow this one,
so it should keep all pointers/indexes
intact at the end of each call.
*/
}
/*windows.c*/