tty_getlin cleanup (trunk only)
The presence of conditional code for both UNICODE_WIDEWINPORT and
NEWAUTOCOMP in hooked_tty_getlin() was making it be pretty hard to read.
This simplifies the UNICODE_WIDEWINPORT parts similar to what was done in
topl.c a year or two back. The NEWAUTOCOMP parts are still cluttered.
This compiles successfully with UNICODE_WIDEWINPORT enabled but that
configuration is otherwise untested.
This commit is contained in:
+32
-59
@@ -1,5 +1,4 @@
|
|||||||
/* NetHack 3.5 getline.c $Date$ $Revision$ */
|
/* NetHack 3.5 getline.c $Date$ $Revision$ */
|
||||||
/* SCCS Id: @(#)getline.c 3.5 2007/01/31 */
|
|
||||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
|
|
||||||
@@ -24,11 +23,24 @@ extern int NDECL(extcmd_via_menu); /* cmd.c */
|
|||||||
|
|
||||||
extern char erase_char, kill_char; /* from appropriate tty.c file */
|
extern char erase_char, kill_char; /* from appropriate tty.c file */
|
||||||
|
|
||||||
|
/* cloned from topl.c, but not identical
|
||||||
|
*/
|
||||||
#ifdef UNICODE_WIDEWINPORT
|
#ifdef UNICODE_WIDEWINPORT
|
||||||
|
/* nhwchar is wchar; data from core needs narrow-to-wide conversion;
|
||||||
|
data going back to core needs wide-to-narrow conversion; data
|
||||||
|
used within tty routines typically needs wide-to-wide awareness */
|
||||||
|
STATIC_VAR nhwchar getl_wbuf[BUFSZ];
|
||||||
|
STATIC_VAR char getl_nbuf[BUFSZ];
|
||||||
#define T(x) L##x
|
#define T(x) L##x
|
||||||
#else
|
#define Waddtopl(str) addtopl(nhwstrcpy(getl_wbuf,str))
|
||||||
|
#define Wputsyms(str) putsyms(nhwstrcpy(getl_wbuf,str))
|
||||||
|
#define NWstrcpy(wdst,src) nhwstrcpy(wdst,src) /* narrow-to-wide */
|
||||||
|
#else /*!UNICODE_WIDEWINPORT*/
|
||||||
|
/* nhwchar is char; no conversions needed */
|
||||||
#define T(x) x
|
#define T(x) x
|
||||||
#endif
|
#define Waddtopl(str) addtopl(str)
|
||||||
|
#define Wputsyms(str) putsyms(str)
|
||||||
|
#endif /*?UNICODE_WIDEWINPORT*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read a line closed with '\n' into the array char bufp[BUFSZ].
|
* Read a line closed with '\n' into the array char bufp[BUFSZ].
|
||||||
@@ -54,9 +66,6 @@ getlin_hook_proc hook;
|
|||||||
register int c;
|
register int c;
|
||||||
struct WinDesc *cw = wins[WIN_MESSAGE];
|
struct WinDesc *cw = wins[WIN_MESSAGE];
|
||||||
boolean doprev = 0;
|
boolean doprev = 0;
|
||||||
#ifdef UNICODE_WIDEWINPORT
|
|
||||||
nhwchar wbuf[BUFSZ];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) more();
|
if(ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) more();
|
||||||
cw->flags &= ~WIN_STOP;
|
cw->flags &= ~WIN_STOP;
|
||||||
@@ -65,23 +74,18 @@ getlin_hook_proc hook;
|
|||||||
pline("%s ", query);
|
pline("%s ", query);
|
||||||
*obufp = 0;
|
*obufp = 0;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
|
(void) fflush(stdout);
|
||||||
#ifdef UNICODE_WIDEWINPORT
|
#ifdef UNICODE_WIDEWINPORT
|
||||||
char buf[BUFSZ];
|
Strcat(strcat(strcpy(getl_nbuf, query), " "), obufp);
|
||||||
(void) fflush(stdout);
|
(void)NWstrcpy(toplines, getl_nbuf);
|
||||||
Sprintf(buf, "%s ", query);
|
|
||||||
Strcat(buf, obufp);
|
|
||||||
nhwstrcpy(wbuf, buf);
|
|
||||||
(void)nhwcpy(toplines, wbuf);
|
|
||||||
#else
|
#else
|
||||||
(void) fflush(stdout);
|
Strcat(strcat(strcpy(toplines, query), " "), obufp);
|
||||||
Sprintf(toplines, "%s ", query);
|
|
||||||
Strcat(toplines, obufp);
|
|
||||||
#endif
|
#endif
|
||||||
if((c = Getchar()) == EOF) c = '\033';
|
c = Getchar();
|
||||||
if(c == '\033') {
|
if (c == '\033' || c == EOF) {
|
||||||
*obufp = c;
|
obufp[0] = '\033';
|
||||||
obufp[1] = 0;
|
obufp[1] = '\0';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (ttyDisplay->intr) {
|
if (ttyDisplay->intr) {
|
||||||
ttyDisplay->intr--;
|
ttyDisplay->intr--;
|
||||||
@@ -95,19 +99,10 @@ getlin_hook_proc hook;
|
|||||||
ttyDisplay->inread = sav;
|
ttyDisplay->inread = sav;
|
||||||
tty_clear_nhwindow(WIN_MESSAGE);
|
tty_clear_nhwindow(WIN_MESSAGE);
|
||||||
cw->maxcol = cw->maxrow;
|
cw->maxcol = cw->maxrow;
|
||||||
#ifdef UNICODE_WIDEWINPORT
|
Waddtopl(query);
|
||||||
nhwstrcpy(wbuf, query);
|
Waddtopl(T(" "));
|
||||||
addtopl(wbuf);
|
|
||||||
addtopl(L" ");
|
|
||||||
*bufp = 0;
|
*bufp = 0;
|
||||||
nhwstrcpy(wbuf, obufp);
|
Waddtopl(obufp);
|
||||||
addtopl(wbuf);
|
|
||||||
#else
|
|
||||||
addtopl(query);
|
|
||||||
addtopl(" ");
|
|
||||||
*bufp = 0;
|
|
||||||
addtopl(obufp);
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
if (!doprev)
|
if (!doprev)
|
||||||
(void) tty_doprev_message();/* need two initially */
|
(void) tty_doprev_message();/* need two initially */
|
||||||
@@ -119,22 +114,10 @@ getlin_hook_proc hook;
|
|||||||
tty_clear_nhwindow(WIN_MESSAGE);
|
tty_clear_nhwindow(WIN_MESSAGE);
|
||||||
cw->maxcol = cw->maxrow;
|
cw->maxcol = cw->maxrow;
|
||||||
doprev = 0;
|
doprev = 0;
|
||||||
#ifdef UNICODE_WIDEWINPORT
|
Waddtopl(query);
|
||||||
nhwstrcpy(wbuf, query);
|
Waddtopl(T(" "));
|
||||||
addtopl(wbuf);
|
|
||||||
addtopl(L" ");
|
|
||||||
#else
|
|
||||||
addtopl(query);
|
|
||||||
addtopl(" ");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
*bufp = 0;
|
*bufp = 0;
|
||||||
#ifdef UNICODE_WIDEWINPORT
|
Waddtopl(obufp);
|
||||||
nhwstrcpy(wbuf, obufp);
|
|
||||||
addtopl(wbuf);
|
|
||||||
#else
|
|
||||||
addtopl(obufp);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
if(c == erase_char || c == '\b') {
|
if(c == erase_char || c == '\b') {
|
||||||
if(bufp != obufp) {
|
if(bufp != obufp) {
|
||||||
@@ -171,20 +154,10 @@ getlin_hook_proc hook;
|
|||||||
#endif /* NEWAUTOCOMP */
|
#endif /* NEWAUTOCOMP */
|
||||||
*bufp = c;
|
*bufp = c;
|
||||||
bufp[1] = 0;
|
bufp[1] = 0;
|
||||||
#ifdef UNICODE_WIDEWINPORT
|
Wputsyms(bufp);
|
||||||
nhwstrcpy(wbuf, bufp);
|
|
||||||
putsyms(wbuf);
|
|
||||||
#else
|
|
||||||
putsyms(bufp);
|
|
||||||
#endif
|
|
||||||
bufp++;
|
bufp++;
|
||||||
if (hook && (*hook)(obufp)) {
|
if (hook && (*hook)(obufp)) {
|
||||||
#ifdef UNICODE_WIDEWINPORT
|
Wputsyms(bufp);
|
||||||
nhwstrcpy(wbuf, bufp);
|
|
||||||
putsyms(wbuf);
|
|
||||||
#else
|
|
||||||
putsyms(bufp);
|
|
||||||
#endif
|
|
||||||
#ifndef NEWAUTOCOMP
|
#ifndef NEWAUTOCOMP
|
||||||
bufp = eos(bufp);
|
bufp = eos(bufp);
|
||||||
#else /* NEWAUTOCOMP */
|
#else /* NEWAUTOCOMP */
|
||||||
|
|||||||
Reference in New Issue
Block a user