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

@@ -5285,6 +5285,8 @@ struct window_procs Qt_procs = {
genl_outrip,
#endif
genl_preference_update,
genl_getmsghistory,
genl_putmsghistory,
};
extern "C" void play_usersound(const char* filename, int volume)

View File

@@ -157,6 +157,8 @@ struct window_procs X11_procs = {
genl_outrip,
#endif
X11_preference_update,
genl_getmsghistory,
genl_putmsghistory,
};
/*

View File

@@ -97,7 +97,9 @@ struct window_procs Gem_procs = {
Gem_start_screen,
Gem_end_screen,
Gem_outrip,
Gem_preference_update
Gem_preference_update,
genl_getmsghistory,
genl_putmsghistory
};
#ifdef MAC

View File

@@ -73,6 +73,8 @@ struct window_procs Gnome_procs = {
gnome_end_screen,
gnome_outrip,
genl_preference_update,
genl_getmsghistory,
genl_putmsghistory,
};
/*

View File

@@ -1,4 +1,4 @@
/* SCCS Id: @(#)topl.c 3.4 1996/10/24 */
/* SCCS Id: @(#)topl.c 3.4 2003/10/05 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -443,6 +443,73 @@ char def;
return q;
}
/*
* This is called by the core save routines.
* Each time we are called, we return one string from the
* message history starting with the oldest message first. each time
* we are called. Each time after that, we return a more recent message,
* until there are no more messages to return. Then we return a final
* null string.
*/
char *
tty_getmsghistory(init)
boolean init;
{
static int idx = 0, state = 0;
static boolean doneinit = FALSE;
register struct WinDesc *cw = wins[WIN_MESSAGE];
char *retstr = (char *)0;
/*
* state 0 = normal return with string from msg history.
* state 1 = finished with recall data, return toplines.
* state 2 = completely finished, return null string.
*/
if (init) {
doneinit = TRUE;
state = 0;
idx = cw->maxrow;
}
if (doneinit && state < 2) {
if (state == 1) {
++state;
return toplines;
}
do {
if(cw->data[idx] && strcmp(cw->data[idx], "") )
retstr = cw->data[idx];
idx = (idx + 1) % cw->rows;
} while (idx != cw->maxrow && !retstr);
if (idx == cw->maxrow) ++state;
}
return retstr;
}
/*
* This is called by the core savefile restore routines.
* Each time we are called, we stuff the string into our message
* history recall buffer. The core will send the oldest message
* first (actually it sends them in the order they exist in the
* save file, but that is supposed to be the oldest first).
*/
void
tty_putmsghistory(msg)
const char *msg;
{
register struct WinDesc *cw = wins[WIN_MESSAGE];
int idx = cw->maxrow;
unsigned len = strlen(msg) + 1;
if (len > (unsigned)cw->datlen[idx]) {
if (cw->data[idx]) free(cw->data[idx]);
len += (8 - (len & 7)); /* pad up to next multiple of 8 */
cw->data[idx] = (char *)alloc(len);
cw->datlen[idx] = (short)len;
}
Strcpy(cw->data[idx], msg);
cw->maxcol = cw->maxrow = (idx + 1) % cw->rows;
}
#endif /* TTY_GRAPHICS */
/*topl.c*/

View File

@@ -109,6 +109,8 @@ struct window_procs tty_procs = {
#else
genl_preference_update,
#endif
tty_getmsghistory,
tty_putmsghistory,
};
static int maxwin = 0; /* number of windows in use */

View File

@@ -121,6 +121,8 @@ struct window_procs mswin_procs = {
mswin_end_screen,
mswin_outrip,
mswin_preference_update,
genl_getmsghistory,
genl_putmsghistory,
};