贴点代码:
/* NetHack 3.6topl.c$NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.32 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
#ifdef TTY_GRAPHICS
#include "tcap.h"
#include "wintty.h"
#include <ctype.h>
#ifndef C /* this matches src/cmd.c */
#define C(c) (0x1f & (c))
#endif
STATIC_DCL void FDECL(redotoplin, (const char *));
STATIC_DCL void FDECL(topl_putsym, (CHAR_P));
STATIC_DCL void NDECL(remember_topl);
STATIC_DCL void FDECL(removetopl, (int));
STATIC_DCL void FDECL(msghistory_snapshot, (BOOLEAN_P));
STATIC_DCL void FDECL(free_msghistory_snapshot, (BOOLEAN_P));
int
tty_doprev_message()
{
register struct WinDesc *cw = wins[WIN_MESSAGE];
winid prevmsg_win;
int i;
if ((iflags.prevmsg_window != 's')
&& !ttyDisplay->inread) { /* not single */
if (iflags.prevmsg_window == 'f') { /* full */
prevmsg_win = create_nhwindow(NHW_MENU);
putstr(prevmsg_win, 0, "Message History");
putstr(prevmsg_win, 0, "");
cw->maxcol = cw->maxrow;
i = cw->maxcol;
do {
if (cw->data[i] && strcmp(cw->data[i], ""))
putstr(prevmsg_win, 0, cw->data[i]);
i = (i + 1) % cw->rows;
} while (i != cw->maxcol);
putstr(prevmsg_win, 0, toplines);
display_nhwindow(prevmsg_win, TRUE);
destroy_nhwindow(prevmsg_win);
} else if (iflags.prevmsg_window == 'c') { /* combination */
do {
morc = 0;
if (cw->maxcol == cw->maxrow) {
ttyDisplay->dismiss_more =
C('p'); /* <ctrl/P> allowed at --More-- */
redotoplin(toplines);
cw->maxcol--;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
if (!cw->data[cw->maxcol])
cw->maxcol = cw->maxrow;
} else if (cw->maxcol == (cw->maxrow - 1)) {
ttyDisplay->dismiss_more =
C('p'); /* <ctrl/P> allowed at --More-- */
redotoplin(cw->data[cw->maxcol]);
cw->maxcol--;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
if (!cw->data[cw->maxcol])
cw->maxcol = cw->maxrow;
} else {
prevmsg_win = create_nhwindow(NHW_MENU);
putstr(prevmsg_win, 0, "Message History");
putstr(prevmsg_win, 0, "");
cw->maxcol = cw->maxrow;
i = cw->maxcol;
do {
if (cw->data[i] && strcmp(cw->data[i], ""))
putstr(prevmsg_win, 0, cw->data[i]);
i = (i + 1) % cw->rows;
} while (i != cw->maxcol);
putstr(prevmsg_win, 0, toplines);
display_nhwindow(prevmsg_win, TRUE);
destroy_nhwindow(prevmsg_win);
}
} while (morc == C('p'));
ttyDisplay->dismiss_more = 0;
} else { /* reversed */
morc = 0;
prevmsg_win = create_nhwindow(NHW_MENU);
putstr(prevmsg_win, 0, "Message History");
putstr(prevmsg_win, 0, "");
putstr(prevmsg_win, 0, toplines);
cw->maxcol = cw->maxrow - 1;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
do {
putstr(prevmsg_win, 0, cw->data[cw->maxcol]);
cw->maxcol--;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
if (!cw->data[cw->maxcol])
cw->maxcol = cw->maxrow;
} while (cw->maxcol != cw->maxrow);
display_nhwindow(prevmsg_win, TRUE);
destroy_nhwindow(prevmsg_win);
cw->maxcol = cw->maxrow;
ttyDisplay->dismiss_more = 0;
}
} else if (iflags.prevmsg_window == 's') { /* single */
ttyDisplay->dismiss_more = C('p'); /* <ctrl/P> allowed at --More-- */
do {
morc = 0;
if (cw->maxcol == cw->maxrow)
redotoplin(toplines);
else if (cw->data[cw->maxcol])
redotoplin(cw->data[cw->maxcol]);
cw->maxcol--;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
if (!cw->data[cw->maxcol])
cw->maxcol = cw->maxrow;
} while (morc == C('p'));
ttyDisplay->dismiss_more = 0;
}
return 0;
}
STATIC_OVL void
redotoplin(str)
const char *str;
{
int otoplin = ttyDisplay->toplin;
home();
if (*str & 0x80) {
/* kludge for the / command, the only time we ever want a */
/* graphics character on the top line */
g_putch((int) *str++);
ttyDisplay->curx++;
}
end_glyphout(); /* in case message printed during graphics output */
putsyms(str);
cl_end();
ttyDisplay->toplin = 1;
if (ttyDisplay->cury && otoplin != 3)
more();
}
STATIC_OVL void
remember_topl()
{
/* NetHack 3.6topl.c$NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.32 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
#ifdef TTY_GRAPHICS
#include "tcap.h"
#include "wintty.h"
#include <ctype.h>
#ifndef C /* this matches src/cmd.c */
#define C(c) (0x1f & (c))
#endif
STATIC_DCL void FDECL(redotoplin, (const char *));
STATIC_DCL void FDECL(topl_putsym, (CHAR_P));
STATIC_DCL void NDECL(remember_topl);
STATIC_DCL void FDECL(removetopl, (int));
STATIC_DCL void FDECL(msghistory_snapshot, (BOOLEAN_P));
STATIC_DCL void FDECL(free_msghistory_snapshot, (BOOLEAN_P));
int
tty_doprev_message()
{
register struct WinDesc *cw = wins[WIN_MESSAGE];
winid prevmsg_win;
int i;
if ((iflags.prevmsg_window != 's')
&& !ttyDisplay->inread) { /* not single */
if (iflags.prevmsg_window == 'f') { /* full */
prevmsg_win = create_nhwindow(NHW_MENU);
putstr(prevmsg_win, 0, "Message History");
putstr(prevmsg_win, 0, "");
cw->maxcol = cw->maxrow;
i = cw->maxcol;
do {
if (cw->data[i] && strcmp(cw->data[i], ""))
putstr(prevmsg_win, 0, cw->data[i]);
i = (i + 1) % cw->rows;
} while (i != cw->maxcol);
putstr(prevmsg_win, 0, toplines);
display_nhwindow(prevmsg_win, TRUE);
destroy_nhwindow(prevmsg_win);
} else if (iflags.prevmsg_window == 'c') { /* combination */
do {
morc = 0;
if (cw->maxcol == cw->maxrow) {
ttyDisplay->dismiss_more =
C('p'); /* <ctrl/P> allowed at --More-- */
redotoplin(toplines);
cw->maxcol--;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
if (!cw->data[cw->maxcol])
cw->maxcol = cw->maxrow;
} else if (cw->maxcol == (cw->maxrow - 1)) {
ttyDisplay->dismiss_more =
C('p'); /* <ctrl/P> allowed at --More-- */
redotoplin(cw->data[cw->maxcol]);
cw->maxcol--;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
if (!cw->data[cw->maxcol])
cw->maxcol = cw->maxrow;
} else {
prevmsg_win = create_nhwindow(NHW_MENU);
putstr(prevmsg_win, 0, "Message History");
putstr(prevmsg_win, 0, "");
cw->maxcol = cw->maxrow;
i = cw->maxcol;
do {
if (cw->data[i] && strcmp(cw->data[i], ""))
putstr(prevmsg_win, 0, cw->data[i]);
i = (i + 1) % cw->rows;
} while (i != cw->maxcol);
putstr(prevmsg_win, 0, toplines);
display_nhwindow(prevmsg_win, TRUE);
destroy_nhwindow(prevmsg_win);
}
} while (morc == C('p'));
ttyDisplay->dismiss_more = 0;
} else { /* reversed */
morc = 0;
prevmsg_win = create_nhwindow(NHW_MENU);
putstr(prevmsg_win, 0, "Message History");
putstr(prevmsg_win, 0, "");
putstr(prevmsg_win, 0, toplines);
cw->maxcol = cw->maxrow - 1;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
do {
putstr(prevmsg_win, 0, cw->data[cw->maxcol]);
cw->maxcol--;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
if (!cw->data[cw->maxcol])
cw->maxcol = cw->maxrow;
} while (cw->maxcol != cw->maxrow);
display_nhwindow(prevmsg_win, TRUE);
destroy_nhwindow(prevmsg_win);
cw->maxcol = cw->maxrow;
ttyDisplay->dismiss_more = 0;
}
} else if (iflags.prevmsg_window == 's') { /* single */
ttyDisplay->dismiss_more = C('p'); /* <ctrl/P> allowed at --More-- */
do {
morc = 0;
if (cw->maxcol == cw->maxrow)
redotoplin(toplines);
else if (cw->data[cw->maxcol])
redotoplin(cw->data[cw->maxcol]);
cw->maxcol--;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
if (!cw->data[cw->maxcol])
cw->maxcol = cw->maxrow;
} while (morc == C('p'));
ttyDisplay->dismiss_more = 0;
}
return 0;
}
STATIC_OVL void
redotoplin(str)
const char *str;
{
int otoplin = ttyDisplay->toplin;
home();
if (*str & 0x80) {
/* kludge for the / command, the only time we ever want a */
/* graphics character on the top line */
g_putch((int) *str++);
ttyDisplay->curx++;
}
end_glyphout(); /* in case message printed during graphics output */
putsyms(str);
cl_end();
ttyDisplay->toplin = 1;
if (ttyDisplay->cury && otoplin != 3)
more();
}
STATIC_OVL void
remember_topl()
{