From e83fcd0353b03ce3ed6ff5b33e2d4576c11dac79 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 14 Jul 2019 21:28:40 -0700 Subject: [PATCH] Revert "Improved readability of topline state management." This reverts commit 08a19108678e772ab52ee195be74101b2792accb. --- include/decl.h | 6 ------ win/tty/getline.c | 6 +++--- win/tty/topl.c | 24 ++++++++++++------------ win/tty/wintty.c | 48 +++++++++++++++++++++-------------------------- 4 files changed, 36 insertions(+), 48 deletions(-) diff --git a/include/decl.h b/include/decl.h index 6c0f9721c..5ebaa326e 100644 --- a/include/decl.h +++ b/include/decl.h @@ -455,12 +455,6 @@ struct early_opt { boolean valallowed; }; -/* topline states */ -#define TOPLINE_EMPTY 0 /* empty */ -#define TOPLINE_NEED_MORE 1 /* non-empty, need --More-- */ -#define TOPLINE_NON_EMPTY 2 /* non-empty, no --More-- required */ -#define TOPLINE_SPECIAL_PROMPT 3 /* special prompt state */ - #undef E #endif /* DECL_H */ diff --git a/win/tty/getline.c b/win/tty/getline.c index a3abfcc53..f4894a950 100644 --- a/win/tty/getline.c +++ b/win/tty/getline.c @@ -52,10 +52,10 @@ getlin_hook_proc hook; struct WinDesc *cw = wins[WIN_MESSAGE]; boolean doprev = 0; - if (ttyDisplay->toplin == TOPLINE_NEED_MORE && !(cw->flags & WIN_STOP)) + if (ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) more(); cw->flags &= ~WIN_STOP; - ttyDisplay->toplin = TOPLINE_SPECIAL_PROMPT; + ttyDisplay->toplin = 3; /* special prompt state */ ttyDisplay->inread++; /* issue the prompt */ @@ -193,7 +193,7 @@ getlin_hook_proc hook; } else tty_nhbell(); } - ttyDisplay->toplin = TOPLINE_NON_EMPTY; + ttyDisplay->toplin = 2; /* nonempty, no --More-- required */ ttyDisplay->inread--; clear_nhwindow(WIN_MESSAGE); /* clean up after ourselves */ diff --git a/win/tty/topl.c b/win/tty/topl.c index d2a889cc9..62fb3eb53 100644 --- a/win/tty/topl.c +++ b/win/tty/topl.c @@ -138,7 +138,7 @@ const char *str; end_glyphout(); /* in case message printed during graphics output */ putsyms(str); cl_end(); - ttyDisplay->toplin = TOPLINE_NEED_MORE; + ttyDisplay->toplin = 1; if (ttyDisplay->cury && otoplin != 3) more(); } @@ -151,7 +151,7 @@ const char *str; struct WinDesc *cw = wins[WIN_MESSAGE]; if (!(cw->flags & WIN_STOP)) { - if (ttyDisplay->cury && ttyDisplay->toplin == TOPLINE_NON_EMPTY) + if (ttyDisplay->cury && ttyDisplay->toplin == 2) tty_clear_nhwindow(WIN_MESSAGE); cw->curx = cw->cury = 0; @@ -159,8 +159,8 @@ const char *str; cl_end(); addtopl(str); - if (ttyDisplay->cury && ttyDisplay->toplin != TOPLINE_SPECIAL_PROMPT) - ttyDisplay->toplin = TOPLINE_NON_EMPTY; + if (ttyDisplay->cury && ttyDisplay->toplin != 3) + ttyDisplay->toplin = 2; } } @@ -196,7 +196,7 @@ const char *s; tty_curs(BASE_WINDOW, cw->curx + 1, cw->cury); putsyms(s); cl_end(); - ttyDisplay->toplin = TOPLINE_NEED_MORE; + ttyDisplay->toplin = 1; } void @@ -236,7 +236,7 @@ more() home(); cl_end(); } - ttyDisplay->toplin = TOPLINE_EMPTY; + ttyDisplay->toplin = 0; ttyDisplay->inmore = 0; } @@ -252,7 +252,7 @@ register const char *bp; /* If there is room on the line, print message on same line */ /* But messages like "You die..." deserve their own line */ n0 = strlen(bp); - if ((ttyDisplay->toplin == TOPLINE_NEED_MORE || (cw->flags & WIN_STOP)) + if ((ttyDisplay->toplin == 1 || (cw->flags & WIN_STOP)) && cw->cury == 0 && n0 + (int) strlen(toplines) + 3 < CO - 8 /* room for --More-- */ && (notdied = strncmp(bp, "You die", 7)) != 0) { @@ -263,9 +263,9 @@ register const char *bp; addtopl(bp); return; } else if (!(cw->flags & WIN_STOP)) { - if (ttyDisplay->toplin == TOPLINE_NEED_MORE) { + if (ttyDisplay->toplin == 1) { more(); - } else if (cw->cury) { /* for toplin == TOPLINE_NON_EMPTY && cury > 1 */ + } else if (cw->cury) { /* for when flags.toplin == 2 && cury > 1 */ docorner(1, cw->cury + 1); /* reset cury = 0 if redraw screen */ cw->curx = cw->cury = 0; /* from home--cls() & docorner(1,n) */ } @@ -381,10 +381,10 @@ char def; char prompt[BUFSZ]; yn_number = 0L; - if (ttyDisplay->toplin == TOPLINE_NEED_MORE && !(cw->flags & WIN_STOP)) + if (ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) more(); cw->flags &= ~WIN_STOP; - ttyDisplay->toplin = TOPLINE_SPECIAL_PROMPT; + ttyDisplay->toplin = 3; /* special prompt state */ ttyDisplay->inread++; if (resp) { char *rb, respbuf[QBUFSZ]; @@ -531,7 +531,7 @@ char def; dumplogmsg(toplines); #endif ttyDisplay->inread--; - ttyDisplay->toplin = TOPLINE_NON_EMPTY; + ttyDisplay->toplin = 2; if (ttyDisplay->intr) ttyDisplay->intr--; if (wins[WIN_MESSAGE]->cury) diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 6d5042f8e..b4e22ae02 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -332,7 +332,7 @@ int sig_unused UNUSED; new_status_window(); if (u.ux) { i = ttyDisplay->toplin; - ttyDisplay->toplin = TOPLINE_EMPTY; + ttyDisplay->toplin = 0; docrt(); bot(); ttyDisplay->toplin = i; @@ -420,7 +420,7 @@ char **argv UNUSED; /* set up tty descriptor */ ttyDisplay = (struct DisplayDesc *) alloc(sizeof (struct DisplayDesc)); - ttyDisplay->toplin = TOPLINE_EMPTY; + ttyDisplay->toplin = 0; ttyDisplay->rows = hgt; ttyDisplay->cols = wid; ttyDisplay->curx = ttyDisplay->cury = 0; @@ -1621,12 +1621,12 @@ winid window; switch (cw->type) { case NHW_MESSAGE: - if (ttyDisplay->toplin != TOPLINE_EMPTY) { + if (ttyDisplay->toplin) { home(); cl_end(); if (cw->cury) docorner(1, cw->cury + 1); - ttyDisplay->toplin = TOPLINE_EMPTY; + ttyDisplay->toplin = 0; } break; case NHW_STATUS: @@ -2317,13 +2317,12 @@ boolean blocking; /* with ttys, all windows are blocking */ switch (cw->type) { case NHW_MESSAGE: - if (ttyDisplay->toplin == TOPLINE_NEED_MORE) { + if (ttyDisplay->toplin == 1) { more(); - ttyDisplay->toplin = TOPLINE_NEED_MORE; /* more resets this */ + ttyDisplay->toplin = 1; /* more resets this */ tty_clear_nhwindow(window); - /* nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); */ } else - ttyDisplay->toplin = TOPLINE_EMPTY; + ttyDisplay->toplin = 0; cw->curx = cw->cury = 0; if (!cw->active) iflags.window_inited = TRUE; @@ -2331,8 +2330,8 @@ boolean blocking; /* with ttys, all windows are blocking */ case NHW_MAP: end_glyphout(); if (blocking) { - if (ttyDisplay->toplin != TOPLINE_EMPTY) - ttyDisplay->toplin = TOPLINE_NEED_MORE; + if (!ttyDisplay->toplin) + ttyDisplay->toplin = 1; tty_display_nhwindow(WIN_MESSAGE, TRUE); return; } @@ -2362,7 +2361,7 @@ boolean blocking; /* with ttys, all windows are blocking */ cw->offx = 0; if (cw->type == NHW_MENU) cw->offy = 0; - if (ttyDisplay->toplin == TOPLINE_NEED_MORE) + if (ttyDisplay->toplin == 1) tty_display_nhwindow(WIN_MESSAGE, TRUE); #ifdef H2344_BROKEN if (cw->maxrow >= (int) ttyDisplay->rows @@ -2378,7 +2377,7 @@ boolean blocking; /* with ttys, all windows are blocking */ cl_eos(); } else clear_screen(); - ttyDisplay->toplin = TOPLINE_EMPTY; + ttyDisplay->toplin = 0; } else { if (WIN_MESSAGE != WIN_ERR) tty_clear_nhwindow(WIN_MESSAGE); @@ -2407,9 +2406,8 @@ winid window; switch (cw->type) { case NHW_MESSAGE: - if (ttyDisplay->toplin != TOPLINE_EMPTY) + if (ttyDisplay->toplin) tty_display_nhwindow(WIN_MESSAGE, TRUE); - /* nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); */ /*FALLTHRU*/ case NHW_STATUS: case NHW_BASE: @@ -3160,11 +3158,10 @@ const char *mesg; response to a prompt, we'll assume that the display is up to date */ tty_putstr(WIN_MESSAGE, 0, mesg); /* if `mesg' didn't wrap (triggering --More--), force --More-- now */ - if (ttyDisplay->toplin == TOPLINE_NEED_MORE) { + if (ttyDisplay->toplin == 1) { more(); - ttyDisplay->toplin = TOPLINE_NEED_MORE; /* more resets this */ + ttyDisplay->toplin = 1; /* more resets this */ tty_clear_nhwindow(WIN_MESSAGE); - /* nhassert(ttyDisplay->toplin == TOPLINE_EMPTY); */ } /* normally means skip further messages, but in this case it means cancel the current prompt; any other messages should @@ -3204,7 +3201,7 @@ tty_wait_synch() (void) fflush(stdout); } else if (ttyDisplay->inread > program_state.gameover) { /* this can only happen if we were reading and got interrupted */ - ttyDisplay->toplin = TOPLINE_SPECIAL_PROMPT; + ttyDisplay->toplin = 3; /* do this twice; 1st time gets the Quit? message again */ (void) tty_doprev_message(); (void) tty_doprev_message(); @@ -3533,9 +3530,8 @@ tty_nhgetch() i = '\033'; /* map NUL to ESC since nethack doesn't expect NUL */ else if (i == EOF) i = '\033'; /* same for EOF */ - /* topline has been seen - we can clear need for more */ - if (ttyDisplay && ttyDisplay->toplin == TOPLINE_NEED_MORE) - ttyDisplay->toplin = TOPLINE_NON_EMPTY; + if (ttyDisplay && ttyDisplay->toplin == 1) + ttyDisplay->toplin = 2; #ifdef TTY_TILES_ESCCODES { /* hack to force output of the window select code */ @@ -3614,9 +3610,8 @@ tty_nhgetch() i = '\033'; /* map NUL to ESC since nethack doesn't expect NUL */ else if (i == EOF) i = '\033'; /* same for EOF */ - /* topline has been seen - we can clear need for more */ - if (ttyDisplay && ttyDisplay->toplin == TOPLINE_NEED_MORE) - ttyDisplay->toplin = TOPLINE_NON_EMPTY; + if (ttyDisplay && ttyDisplay->toplin == 1) + ttyDisplay->toplin = 2; #ifdef TTY_TILES_ESCCODES { /* hack to force output of the window select code */ @@ -3661,9 +3656,8 @@ int *x, *y, *mod; i = ntposkey(x, y, mod); if (!i && mod && (*mod == 0 || *mod == EOF)) i = '\033'; /* map NUL or EOF to ESC, nethack doesn't expect either */ - /* topline has been seen - we can clear need for more */ - if (ttyDisplay && ttyDisplay->toplin == TOPLINE_NEED_MORE) - ttyDisplay->toplin = TOPLINE_NON_EMPTY; + if (ttyDisplay && ttyDisplay->toplin == 1) + ttyDisplay->toplin = 2; #else /* !WIN32CON */ nhUse(x); nhUse(y); -- 2.40.0