-/* NetHack 3.6 wintty.c $NHDT-Date: 1544842261 2018/12/15 02:51:01 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.188 $ */
+/* NetHack 3.6 wintty.c $NHDT-Date: 1544919891 2018/12/16 00:24:51 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.189 $ */
/* Copyright (c) David Cohrs, 1991 */
/* NetHack may be freely redistributed. See license for details. */
#define AVTC_INLINE_SYNC 3
#endif
+#ifdef HANGUP_HANDLING
+/*
+ * NetHack's core switches to a dummy windowing interface when it
+ * detects SIGHUP, but that's no help for any interface routine which
+ * is already in progress at the time, and there have been reports of
+ * runaway disconnected processes which use up all available CPU time.
+ * HUPSKIP() and HUPSKIP_RETURN(x) are used to try to cut them off so
+ * that they return to the core instead attempting more terminal I/O.
+ */
+#define HUPSKIP() \
+ do { \
+ if (program_state.done_hup) { \
+ morc = '\033'; \
+ return; \
+ } \
+ } while (0)
+ /* morc=ESC - in case we bypass xwaitforspace() which sets that */
+#define HUPSKIP_RESULT(RES) \
+ do { \
+ if (program_state.done_hup) \
+ return (RES); \
+ } while (0)
+#else /* !HANGUP_HANDLING */
+#define HUPSKIP() /*empty*/
+#define HUPSKIP_RESULT(RES) /*empty*/
+#endif /* ?HANGUP_HANDLING */
+
extern char mapped_menu_cmds[]; /* from options.c */
/* this is only needed until tty_status_* routines are written */
print_vt_code(i, c, d)
int i, c, d;
{
+ HUPSKIP();
if (iflags.vt_tiledata) {
if (c >= 0) {
if (i == AVTC_SELECT_WINDOW) {
bail("Giving up after 10 tries.\n");
tty_curs(BASE_WINDOW, 1, wins[BASE_WINDOW]->cury - 1);
tty_putstr(BASE_WINDOW, 0, "Enter a name for your character...");
- /* erase previous prompt (in case of ESC after partial response)
- */
+ /* erase previous prompt (in case of ESC after partial response) */
tty_curs(BASE_WINDOW, 1, wins[BASE_WINDOW]->cury), cl_end();
}
tty_putstr(BASE_WINDOW, 0, who_are_you);
STATIC_OVL void
getret()
{
+ HUPSKIP();
xputs("\n");
if (flags.standout)
standoutbeg();
{
register struct WinDesc *cw = 0;
+ HUPSKIP();
if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0)
panic(winpanicstr, window);
ttyDisplay->lastwin = window;
const char *prompt = cw->morestr ? cw->morestr : defmorestr;
int offset = (cw->type == NHW_TEXT) ? 1 : 2;
+ HUPSKIP();
tty_curs(BASE_WINDOW, (int) ttyDisplay->curx + offset,
(int) ttyDisplay->cury);
if (flags.standout)
{
char ch = item->selected ? (item->count == -1L ? '+' : '#') : '-';
+ HUPSKIP();
tty_curs(window, 4, lineno);
term_start_attr(item->attr);
(void) putchar(ch);
/* loop until finished */
while (!finished) {
+ HUPSKIP();
if (reset_count) {
counting = FALSE;
count = 0;
register char *cp;
for (n = 0, i = 0; i < cw->maxrow; i++) {
+ HUPSKIP();
if (!cw->offx && (n + cw->offy == ttyDisplay->rows - 1)) {
tty_curs(window, 1, n);
cl_end();
register struct WinDesc *cw = 0;
short s_maxcol;
+ HUPSKIP();
if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0)
panic(winpanicstr, window);
if (cw->flags & WIN_CANCELLED)
{
register struct WinDesc *cw = 0;
+ HUPSKIP();
if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0)
panic(winpanicstr, window);
int cx = ttyDisplay->curx;
int cy = ttyDisplay->cury;
+ HUPSKIP();
if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0)
panic(winpanicstr, window);
ttyDisplay->lastwin = window;
#ifdef DEBUG
if (x < 0 || y < 0 || y >= cw->rows || x > cw->cols) {
const char *s = "[unknown type]";
+
switch (cw->type) {
case NHW_MESSAGE:
s = "[topl window]";
{
register struct WinDesc *cw = 0;
+ HUPSKIP();
if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0)
panic(winpanicstr, window);
register long j;
#endif
+ HUPSKIP();
/* Assume there's a real problem if the window is missing --
* probably a panic message
*/
const char *newstr;
char buf[4 + BUFSZ];
+ HUPSKIP();
if (str == (const char *) 0)
return;
int how;
const char *mesg;
{
+ HUPSKIP();
/* "menu" without selection; use ordinary pline, no more() */
if (how == PICK_NONE) {
pline("%s", mesg);
void
tty_mark_synch()
{
+ HUPSKIP();
(void) fflush(stdout);
}
void
tty_wait_synch()
{
+ HUPSKIP();
/* we just need to make sure all windows are synch'd */
if (!ttyDisplay || ttyDisplay->rawprint) {
getret();
register int y;
register struct WinDesc *cw = wins[WIN_MAP];
+ HUPSKIP();
#if 0 /* this optimization is not valuable enough to justify
abusing core internals... */
if (u.uswallow) { /* Can be done more efficiently */
void
end_glyphout()
{
+ HUPSKIP();
#if defined(ASCIIGRAPH) && !defined(NO_TERMS)
if (GFlag) {
GFlag = FALSE;
{
register char ch = (char) in_ch;
+ HUPSKIP();
#if defined(ASCIIGRAPH) && !defined(NO_TERMS)
if (SYMHANDLING(H_IBM) || iflags.eight_bit_tty) {
/* IBM-compatible displays don't need other stuff */
extern boolean restoring;
int oldx = clipx, oldy = clipy;
+ HUPSKIP();
if (!clipping)
return;
if (x < clipx + 5) {
int color;
unsigned special;
+ HUPSKIP();
#ifdef CLIPPING
if (clipping) {
if (x <= clipx || y < clipy || x >= clipxmax || y >= clipymax)
tty_raw_print(str)
const char *str;
{
+ HUPSKIP();
if (ttyDisplay)
ttyDisplay->rawprint++;
print_vt_code2(AVTC_SELECT_WINDOW, NHW_BASE);
tty_raw_print_bold(str)
const char *str;
{
+ HUPSKIP();
if (ttyDisplay)
ttyDisplay->rawprint++;
print_vt_code2(AVTC_SELECT_WINDOW, NHW_BASE);
char nestbuf;
#endif
+ HUPSKIP_RESULT('\033');
print_vt_code1(AVTC_INLINE_SYNC);
(void) fflush(stdout);
/* Note: if raw_print() and wait_synch() get called to report terminal
{
/* hack to force output of the window select code */
int tmp = vt_tile_current_window;
+
vt_tile_current_window++;
print_vt_code2(AVTC_SELECT_WINDOW, tmp);
}
tty_nh_poskey(x, y, mod)
int *x, *y, *mod;
{
-#if defined(WIN32CON)
int i;
+
+ HUPSKIP_RESULT('\033');
+#if defined(WIN32CON)
(void) fflush(stdout);
/* Note: if raw_print() and wait_synch() get called to report terminal
* initialization problems, then wins[] and ttyDisplay might not be
i = '\033'; /* map NUL or EOF to ESC, nethack doesn't expect either */
if (ttyDisplay && ttyDisplay->toplin == 1)
ttyDisplay->toplin = 2;
- return i;
#else /* !WIN32CON */
nhUse(x);
nhUse(y);
nhUse(mod);
- return tty_nhgetch();
+ i = tty_nhgetch();
#endif /* ?WIN32CON */
+ return i;
}
void
}
for (row = 0; row < 2; ++row) {
+ HUPSKIP();
curs(WIN_STATUS, 1, row);
for (i = 0; fieldorder[row][i] != BL_FLUSH; ++i) {
int idx = fieldorder[row][i];
tty_putstatusfield(nullfield, " ", x++, y);
}
}
- /* reset .redraw, .dirty, .padright now that they've been rendered */
+ /* reset .redraw, .dirty, .padright now that they're rendered */
tty_status[NOW][idx].dirty = FALSE;
tty_status[NOW][idx].redraw = FALSE;
tty_status[NOW][idx].last_on_row = FALSE;