Merge branch 'master' into NetHack-3.7
This commit is contained in:
142
win/tty/topl.c
142
win/tty/topl.c
@@ -259,7 +259,7 @@ register const char *bp;
|
||||
&& cw->cury == 0
|
||||
&& n0 + (int) strlen(g.toplines) + 3 < CO - 8 /* room for --More-- */
|
||||
&& (notdied = strncmp(bp, "You die", 7)) != 0) {
|
||||
nhassert((long) strlen(g.toplines) == cw->curx);
|
||||
/* nhassert((long) strlen(g.toplines) == cw->curx); */
|
||||
Strcat(g.toplines, " ");
|
||||
Strcat(g.toplines, bp);
|
||||
cw->curx += 2;
|
||||
@@ -617,6 +617,66 @@ boolean purged; /* True: took history's pointers, False: just cloned them */
|
||||
}
|
||||
}
|
||||
|
||||
STATIC_OVL ptr_array_t *
|
||||
get_message_history()
|
||||
{
|
||||
char *mesg;
|
||||
int i;
|
||||
struct WinDesc *cw;
|
||||
size_t max_length;
|
||||
ptr_array_t * a;
|
||||
|
||||
nhassert(WIN_MESSAGE != WIN_ERR);
|
||||
nhassert(wins[WIN_MESSAGE] != NULL);
|
||||
|
||||
/* paranoia (too early or too late panic save attempt?) */
|
||||
if (WIN_MESSAGE == WIN_ERR || !wins[WIN_MESSAGE])
|
||||
return NULL;
|
||||
|
||||
cw = wins[WIN_MESSAGE];
|
||||
|
||||
max_length = cw->rows;
|
||||
|
||||
if (*g.toplines) max_length++;
|
||||
|
||||
a = ptr_array_new(max_length);
|
||||
|
||||
nhassert(cw->maxrow <= cw->rows);
|
||||
for (i = 0; i < cw->rows; ++i) {
|
||||
mesg = cw->data[(i + cw->maxrow) % cw->rows];
|
||||
if (mesg && *mesg)
|
||||
a->elements[a->length++] = strdup(mesg);
|
||||
}
|
||||
if (*g.toplines)
|
||||
a->elements[a->length++] = strdup(g.toplines);
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
STATIC_OVL void
|
||||
purge_message_history()
|
||||
{
|
||||
int i;
|
||||
struct WinDesc *cw;
|
||||
|
||||
nhassert(WIN_MESSAGE != WIN_ERR);
|
||||
nhassert(wins[WIN_MESSAGE] != NULL);
|
||||
|
||||
cw = wins[WIN_MESSAGE];
|
||||
|
||||
*g.toplines = '\0';
|
||||
|
||||
for (i = 0; i < cw->rows; ++i) {
|
||||
if (cw->data[i]) {
|
||||
free(cw->data[i]);
|
||||
cw->data[i] = (char *) 0;
|
||||
cw->datlen[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
cw->maxcol = cw->maxrow = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is called by the core save routines.
|
||||
* Each time we are called, we return one string from the
|
||||
@@ -631,21 +691,25 @@ char *
|
||||
tty_getmsghistory(init)
|
||||
boolean init;
|
||||
{
|
||||
static int nxtidx;
|
||||
char *nextmesg;
|
||||
char *result = 0;
|
||||
static size_t nxtidx;
|
||||
static ptr_array_t * saved_messages = NULL;
|
||||
char *result = NULL;
|
||||
|
||||
if (init) {
|
||||
msghistory_snapshot(FALSE);
|
||||
nhassert(saved_messages == NULL);
|
||||
saved_messages = get_message_history();
|
||||
nxtidx = 0;
|
||||
wins[WIN_MESSAGE]->flags |= WIN_LOCKHISTORY;
|
||||
}
|
||||
|
||||
if (snapshot_mesgs) {
|
||||
nextmesg = snapshot_mesgs[nxtidx++];
|
||||
if (nextmesg) {
|
||||
result = (char *) nextmesg;
|
||||
} else {
|
||||
free_msghistory_snapshot(FALSE);
|
||||
if (saved_messages) {
|
||||
if (nxtidx < saved_messages->length)
|
||||
result = saved_messages->elements[nxtidx++];
|
||||
|
||||
if (result == NULL) {
|
||||
ptr_array_free(saved_messages);
|
||||
saved_messages = NULL;
|
||||
wins[WIN_MESSAGE]->flags &= ~WIN_LOCKHISTORY;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -674,7 +738,10 @@ const char *msg;
|
||||
boolean restoring_msghist;
|
||||
{
|
||||
static boolean initd = FALSE;
|
||||
int idx;
|
||||
static ptr_array_t * saved_messages = NULL;
|
||||
size_t i;
|
||||
|
||||
nhassert(!(wins[WIN_MESSAGE]->flags & WIN_LOCKHISTORY));
|
||||
|
||||
if (restoring_msghist && !initd) {
|
||||
/* we're restoring history from the previous session, but new
|
||||
@@ -682,7 +749,9 @@ boolean restoring_msghist;
|
||||
for instance); collect current history (ie, those new messages),
|
||||
and also clear it out so that nothing will be present when the
|
||||
restored ones are being put into place */
|
||||
msghistory_snapshot(TRUE);
|
||||
nhassert(saved_messages == NULL);
|
||||
saved_messages = get_message_history();
|
||||
purge_message_history();
|
||||
initd = TRUE;
|
||||
#ifdef DUMPLOG
|
||||
/* this suffices; there's no need to scrub saved_pline[] pointers */
|
||||
@@ -704,22 +773,39 @@ boolean restoring_msghist;
|
||||
#ifdef DUMPLOG
|
||||
dumplogmsg(g.toplines);
|
||||
#endif
|
||||
} else if (snapshot_mesgs) {
|
||||
nhassert(ttyDisplay == NULL ||
|
||||
ttyDisplay->toplin != TOPLINE_NEED_MORE);
|
||||
|
||||
/* done putting arbitrary messages in; put the snapshot ones back */
|
||||
for (idx = 0; snapshot_mesgs[idx]; ++idx) {
|
||||
remember_topl();
|
||||
Strcpy(g.toplines, snapshot_mesgs[idx]);
|
||||
#ifdef DUMPLOG
|
||||
dumplogmsg(g.toplines);
|
||||
#endif
|
||||
}
|
||||
/* now release the snapshot */
|
||||
free_msghistory_snapshot(TRUE);
|
||||
initd = FALSE; /* reset */
|
||||
return;
|
||||
}
|
||||
|
||||
/* tty_putmsghistory() is called with msg==NULL to indidate that
|
||||
* we are finished restoring the message history. If we saved
|
||||
* some message history when we started, its time now to appened
|
||||
* those saved messages.
|
||||
*
|
||||
* We don't otherwise expect to get called with msg==NULL.
|
||||
*
|
||||
*/
|
||||
nhassert(restoring_msghist && initd);
|
||||
|
||||
if (initd && restoring_msghist) {
|
||||
if (saved_messages) {
|
||||
nhassert(ttyDisplay == NULL ||
|
||||
ttyDisplay->toplin != TOPLINE_NEED_MORE);
|
||||
|
||||
for (i = 0; i < saved_messages->length; i++) {
|
||||
const char * mesg = saved_messages->elements[i];
|
||||
remember_topl();
|
||||
nhassert(mesg);
|
||||
Strcpy(g.toplines, mesg);
|
||||
#ifdef DUMPLOG
|
||||
dumplogmsg(g.toplines);
|
||||
#endif
|
||||
}
|
||||
ptr_array_free(saved_messages);
|
||||
saved_messages = NULL;
|
||||
}
|
||||
initd = FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif /* TTY_GRAPHICS */
|
||||
|
||||
Reference in New Issue
Block a user