add some unicode support (trunk only)
This patch attempts to add some levels of unicode support to NetHack. The master on/off switch for any Unicode support is defining UNICODE_SUPPORT in config.h. Currently there is code support for two subsets of unicode support: UNICODE_DRAWING If UNICODE_DRAWING is defined, then the data structures used to house drawing symbols are expanded to the size of wchar_t, big enough to hold unicode characters. A typdef called `nhsym' is involved and if UNICODE_DRAWING is defined, it is wchar_t, otherwise it is uchar. UNICODE_WIDEWINPORT If UNICODE_WIDEWINPORT is defined, then the data structures inside the window port are expanded to the size of wchar_t, big enough to hold unicode characters. Both map symbols and text within the window port are expanded, in order for potential support for displaying multinational characters some day, but this patch only provides viewing of map symbols. A typdef called `nhwchar' is involved and if UNICODE_WIDEWINPORT is defined, it is wchar_t, otherwise it is char. The only window port with code support for UNICODE_WIDEWINPORT currently is the TTY port. Don't enable UNICODE_WIDEWINPORT unless: - it is a TTY port - the underlying platform specific routines can handle the larger data structures. Don't enable UNICODE_SUPPORT unless: - your compiler can handle wchar_t. - your compiler can accept L'a' characters. - your compiler can accept L"wide" strings. Note that if your compiler can handle the above, you could enable the larger data structures (currently if TTY) even if your platform can't actually display unicode or UTF-8, by messing with u_putch() in win/tty/wintty.c to only deal regular chars. That should be the only function that actually pushes wide characters out to the display. If you enable UNICODE_SUPPORT, and your platform is capable you will need to turn on the unicode run-time option to be able to load unicode character sets from the symbol file, to be able to push unicode characters to the display. You'll also want to load a unicode symbol set once the unicode option is toggled on. In a config file you would do that via these two lines: OPTIONS=unicode OPTIONS=symset:Unicode_non_US The repository was stamped with NETHACK_PRE_UNICODE prior to applying this patch, and stamped with NETHACK_POST_UNICODE afterwards. The code differences between those two tagged versions are this patch.
This commit is contained in:
@@ -23,6 +23,12 @@ extern int NDECL(extcmd_via_menu); /* cmd.c */
|
||||
|
||||
extern char erase_char, kill_char; /* from appropriate tty.c file */
|
||||
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
#define T(x) L##x
|
||||
#else
|
||||
#define T(x) x
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Read a line closed with '\n' into the array char bufp[BUFSZ].
|
||||
* (The '\n' is not stored. The string is closed with a '\0'.)
|
||||
@@ -47,6 +53,9 @@ getlin_hook_proc hook;
|
||||
register int c;
|
||||
struct WinDesc *cw = wins[WIN_MESSAGE];
|
||||
boolean doprev = 0;
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
nhwchar wbuf[BUFSZ];
|
||||
#endif
|
||||
|
||||
if(ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) more();
|
||||
cw->flags &= ~WIN_STOP;
|
||||
@@ -55,9 +64,18 @@ getlin_hook_proc hook;
|
||||
pline("%s ", query);
|
||||
*obufp = 0;
|
||||
for(;;) {
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
char buf[BUFSZ];
|
||||
(void) fflush(stdout);
|
||||
Sprintf(buf, "%s ", query);
|
||||
Strcat(buf, obufp);
|
||||
nhwstrcpy(wbuf, buf);
|
||||
(void)nhwcpy(toplines, wbuf);
|
||||
#else
|
||||
(void) fflush(stdout);
|
||||
Sprintf(toplines, "%s ", query);
|
||||
Strcat(toplines, obufp);
|
||||
#endif
|
||||
if((c = Getchar()) == EOF) c = '\033';
|
||||
if(c == '\033') {
|
||||
*obufp = c;
|
||||
@@ -76,10 +94,19 @@ getlin_hook_proc hook;
|
||||
ttyDisplay->inread = sav;
|
||||
tty_clear_nhwindow(WIN_MESSAGE);
|
||||
cw->maxcol = cw->maxrow;
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
nhwstrcpy(wbuf, query);
|
||||
addtopl(wbuf);
|
||||
addtopl(L" ");
|
||||
*bufp = 0;
|
||||
nhwstrcpy(wbuf, obufp);
|
||||
addtopl(wbuf);
|
||||
#else
|
||||
addtopl(query);
|
||||
addtopl(" ");
|
||||
*bufp = 0;
|
||||
addtopl(obufp);
|
||||
#endif
|
||||
} else {
|
||||
if (!doprev)
|
||||
(void) tty_doprev_message();/* need two initially */
|
||||
@@ -91,10 +118,22 @@ getlin_hook_proc hook;
|
||||
tty_clear_nhwindow(WIN_MESSAGE);
|
||||
cw->maxcol = cw->maxrow;
|
||||
doprev = 0;
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
nhwstrcpy(wbuf, query);
|
||||
addtopl(wbuf);
|
||||
addtopl(L" ");
|
||||
#else
|
||||
addtopl(query);
|
||||
addtopl(" ");
|
||||
#endif
|
||||
|
||||
*bufp = 0;
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
nhwstrcpy(wbuf, obufp);
|
||||
addtopl(wbuf);
|
||||
#else
|
||||
addtopl(obufp);
|
||||
#endif
|
||||
}
|
||||
if(c == erase_char || c == '\b') {
|
||||
if(bufp != obufp) {
|
||||
@@ -104,11 +143,11 @@ getlin_hook_proc hook;
|
||||
#endif /* NEWAUTOCOMP */
|
||||
bufp--;
|
||||
#ifndef NEWAUTOCOMP
|
||||
putsyms("\b \b");/* putsym converts \b */
|
||||
putsyms(T("\b \b"));/* putsym converts \b */
|
||||
#else /* NEWAUTOCOMP */
|
||||
putsyms("\b");
|
||||
for (i = bufp; *i; ++i) putsyms(" ");
|
||||
for (; i > bufp; --i) putsyms("\b");
|
||||
putsyms(T("\b"));
|
||||
for (i = bufp; *i; ++i) putsyms(T(" "));
|
||||
for (; i > bufp; --i) putsyms(T("\b"));
|
||||
*bufp = 0;
|
||||
#endif /* NEWAUTOCOMP */
|
||||
} else tty_nhbell();
|
||||
@@ -131,21 +170,31 @@ getlin_hook_proc hook;
|
||||
#endif /* NEWAUTOCOMP */
|
||||
*bufp = c;
|
||||
bufp[1] = 0;
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
nhwstrcpy(wbuf, bufp);
|
||||
putsyms(wbuf);
|
||||
#else
|
||||
putsyms(bufp);
|
||||
#endif
|
||||
bufp++;
|
||||
if (hook && (*hook)(obufp)) {
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
nhwstrcpy(wbuf, bufp);
|
||||
putsyms(wbuf);
|
||||
#else
|
||||
putsyms(bufp);
|
||||
#endif
|
||||
#ifndef NEWAUTOCOMP
|
||||
bufp = eos(bufp);
|
||||
#else /* NEWAUTOCOMP */
|
||||
/* pointer and cursor left where they were */
|
||||
for (i = bufp; *i; ++i) putsyms("\b");
|
||||
for (i = bufp; *i; ++i) putsyms(T("\b"));
|
||||
} else if (i > bufp) {
|
||||
char *s = i;
|
||||
|
||||
/* erase rest of prior guess */
|
||||
for (; i > bufp; --i) putsyms(" ");
|
||||
for (; s > bufp; --s) putsyms("\b");
|
||||
for (; i > bufp; --i) putsyms(T(" "));
|
||||
for (; s > bufp; --s) putsyms(T("\b"));
|
||||
#endif /* NEWAUTOCOMP */
|
||||
}
|
||||
} else if(c == kill_char || c == '\177') { /* Robert Viduya */
|
||||
@@ -153,11 +202,11 @@ getlin_hook_proc hook;
|
||||
#ifndef NEWAUTOCOMP
|
||||
while(bufp != obufp) {
|
||||
bufp--;
|
||||
putsyms("\b \b");
|
||||
putsyms(T("\b \b"));
|
||||
}
|
||||
#else /* NEWAUTOCOMP */
|
||||
for (; *bufp; ++bufp) putsyms(" ");
|
||||
for (; bufp != obufp; --bufp) putsyms("\b \b");
|
||||
for (; *bufp; ++bufp) putsyms(T(" "));
|
||||
for (; bufp != obufp; --bufp) putsyms(T("\b \b"));
|
||||
*bufp = 0;
|
||||
#endif /* NEWAUTOCOMP */
|
||||
} else
|
||||
@@ -168,6 +217,8 @@ getlin_hook_proc hook;
|
||||
clear_nhwindow(WIN_MESSAGE); /* clean up after ourselves */
|
||||
}
|
||||
|
||||
#undef T
|
||||
|
||||
void
|
||||
xwaitforspace(s)
|
||||
register const char *s; /* chars allowed besides return */
|
||||
|
||||
194
win/tty/topl.c
194
win/tty/topl.c
@@ -14,11 +14,13 @@
|
||||
#define C(c) (0x1f & (c))
|
||||
#endif
|
||||
|
||||
STATIC_DCL void FDECL(redotoplin, (const char*));
|
||||
STATIC_DCL void FDECL(topl_putsym, (CHAR_P));
|
||||
STATIC_DCL void FDECL(redotoplin, (const nhwchar*));
|
||||
STATIC_DCL void FDECL(topl_putsym, (NHWCHAR_P));
|
||||
STATIC_DCL void NDECL(remember_topl);
|
||||
STATIC_DCL void FDECL(removetopl, (int));
|
||||
|
||||
extern nhwchar emptysym[];
|
||||
|
||||
int
|
||||
tty_doprev_message()
|
||||
{
|
||||
@@ -26,6 +28,9 @@ tty_doprev_message()
|
||||
|
||||
winid prevmsg_win;
|
||||
int i;
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
char buf[BUFSZ];
|
||||
#endif
|
||||
if ((iflags.prevmsg_window != 's') && !ttyDisplay->inread) { /* not single */
|
||||
if(iflags.prevmsg_window == 'f') { /* full */
|
||||
prevmsg_win = create_nhwindow(NHW_MENU);
|
||||
@@ -34,11 +39,23 @@ tty_doprev_message()
|
||||
cw->maxcol = cw->maxrow;
|
||||
i = cw->maxcol;
|
||||
do {
|
||||
if(cw->data[i] && strcmp(cw->data[i], "") )
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
if(cw->data[i] && nhwstrcmp(cw->data[i], "") ) {
|
||||
strnhwcpy(buf, cw->data[i]);
|
||||
putstr(prevmsg_win, 0, buf);
|
||||
#else
|
||||
if(cw->data[i] && strcmp(cw->data[i], "") ) {
|
||||
putstr(prevmsg_win, 0, cw->data[i]);
|
||||
#endif
|
||||
}
|
||||
i = (i + 1) % cw->rows;
|
||||
} while (i != cw->maxcol);
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
strnhwcpy(buf, toplines);
|
||||
putstr(prevmsg_win, 0, buf);
|
||||
#else
|
||||
putstr(prevmsg_win, 0, toplines);
|
||||
#endif
|
||||
display_nhwindow(prevmsg_win, TRUE);
|
||||
destroy_nhwindow(prevmsg_win);
|
||||
} else if (iflags.prevmsg_window == 'c') { /* combination */
|
||||
@@ -65,11 +82,24 @@ tty_doprev_message()
|
||||
cw->maxcol = cw->maxrow;
|
||||
i = cw->maxcol;
|
||||
do {
|
||||
if(cw->data[i] && strcmp(cw->data[i], "") )
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
if(cw->data[i] && nhwstrcmp(cw->data[i], "") ) {
|
||||
strnhwcpy(buf, cw->data[i]);
|
||||
putstr(prevmsg_win, 0, buf);
|
||||
#else
|
||||
if(cw->data[i] && strcmp(cw->data[i], "") ) {
|
||||
putstr(prevmsg_win, 0, cw->data[i]);
|
||||
#endif
|
||||
}
|
||||
i = (i + 1) % cw->rows;
|
||||
} while (i != cw->maxcol);
|
||||
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
strnhwcpy(buf, toplines);
|
||||
putstr(prevmsg_win, 0, buf);
|
||||
#else
|
||||
putstr(prevmsg_win, 0, toplines);
|
||||
#endif
|
||||
display_nhwindow(prevmsg_win, TRUE);
|
||||
destroy_nhwindow(prevmsg_win);
|
||||
}
|
||||
@@ -81,11 +111,22 @@ tty_doprev_message()
|
||||
prevmsg_win = create_nhwindow(NHW_MENU);
|
||||
putstr(prevmsg_win, 0, "Message History");
|
||||
putstr(prevmsg_win, 0, "");
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
strnhwcpy(buf, toplines);
|
||||
putstr(prevmsg_win, 0, buf);
|
||||
#else
|
||||
putstr(prevmsg_win, 0, toplines);
|
||||
#endif
|
||||
cw->maxcol=cw->maxrow-1;
|
||||
if(cw->maxcol < 0) cw->maxcol = cw->rows-1;
|
||||
do {
|
||||
putstr(prevmsg_win, 0, cw->data[cw->maxcol]);
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
strnhwcpy(buf, cw->data[cw->maxcol]);
|
||||
putstr(prevmsg_win, 0, buf);
|
||||
#else
|
||||
putstr(prevmsg_win, 0, cw->data[cw->maxcol]);
|
||||
|
||||
#endif
|
||||
cw->maxcol--;
|
||||
if (cw->maxcol < 0) cw->maxcol = cw->rows-1;
|
||||
if (!cw->data[cw->maxcol])
|
||||
@@ -116,19 +157,23 @@ tty_doprev_message()
|
||||
}
|
||||
|
||||
STATIC_OVL void
|
||||
redotoplin(str)
|
||||
const char *str;
|
||||
redotoplin(symstr)
|
||||
const nhwchar *symstr;
|
||||
{
|
||||
int otoplin = ttyDisplay->toplin;
|
||||
home();
|
||||
if(*str & 0x80) {
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
if(*symstr >= 0x80) {
|
||||
#else
|
||||
if(*symstr & 0x80) {
|
||||
#endif
|
||||
/* kludge for the / command, the only time we ever want a */
|
||||
/* graphics character on the top line */
|
||||
g_putch((int)*str++);
|
||||
g_putch((int)*symstr++);
|
||||
ttyDisplay->curx++;
|
||||
}
|
||||
end_glyphout(); /* in case message printed during graphics output */
|
||||
putsyms(str);
|
||||
putsyms(symstr);
|
||||
cl_end();
|
||||
ttyDisplay->toplin = 1;
|
||||
if(ttyDisplay->cury && otoplin != 3)
|
||||
@@ -140,21 +185,29 @@ remember_topl()
|
||||
{
|
||||
register struct WinDesc *cw = wins[WIN_MESSAGE];
|
||||
int idx = cw->maxrow;
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
unsigned len = nhwlen(toplines) + 1;
|
||||
#else
|
||||
unsigned len = strlen(toplines) + 1;
|
||||
#endif
|
||||
|
||||
if (len > (unsigned)cw->datlen[idx]) {
|
||||
if (cw->data[idx]) free(cw->data[idx]);
|
||||
len += (8 - (len & 7)); /* pad up to next multiple of 8 */
|
||||
cw->data[idx] = (char *)alloc(len);
|
||||
cw->data[idx] = (nhwchar *)alloc(sizeof(nhwchar) * len);
|
||||
cw->datlen[idx] = (short)len;
|
||||
}
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
(void)nhwcpy(cw->data[idx], toplines);
|
||||
#else
|
||||
Strcpy(cw->data[idx], toplines);
|
||||
#endif
|
||||
cw->maxcol = cw->maxrow = (idx + 1) % cw->rows;
|
||||
}
|
||||
|
||||
void
|
||||
addtopl(s)
|
||||
const char *s;
|
||||
const nhwchar *s;
|
||||
{
|
||||
register struct WinDesc *cw = wins[WIN_MESSAGE];
|
||||
|
||||
@@ -175,7 +228,12 @@ more()
|
||||
|
||||
if(ttyDisplay->toplin) {
|
||||
tty_curs(BASE_WINDOW, cw->curx+1, cw->cury);
|
||||
if(cw->curx >= CO - 8) topl_putsym('\n');
|
||||
if(cw->curx >= CO - 8)
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
topl_putsym(L'\n');
|
||||
#else
|
||||
topl_putsym('\n');
|
||||
#endif
|
||||
}
|
||||
|
||||
if(flags.standout)
|
||||
@@ -204,22 +262,33 @@ more()
|
||||
|
||||
void
|
||||
update_topl(bp)
|
||||
register const char *bp;
|
||||
register const nhwchar *bp;
|
||||
{
|
||||
register char *tl, *otl;
|
||||
register nhwchar *tl, *otl;
|
||||
register int n0;
|
||||
int notdied = 1;
|
||||
struct WinDesc *cw = wins[WIN_MESSAGE];
|
||||
|
||||
/* If there is room on the line, print message on same line */
|
||||
/* But messages like "You die..." deserve their own line */
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
n0 = nhwlen(bp);
|
||||
#else
|
||||
n0 = strlen(bp);
|
||||
#endif
|
||||
if ((ttyDisplay->toplin == 1 || (cw->flags & WIN_STOP)) &&
|
||||
cw->cury == 0 &&
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
n0 + (int)nhwlen(toplines) + 3 < CO-8 && /* room for --More-- */
|
||||
(notdied = nhwncmp(bp, L"You die", 7))) {
|
||||
(void)nhwcat(toplines, L" ");
|
||||
(void)nhwcat(toplines, bp);
|
||||
#else
|
||||
n0 + (int)strlen(toplines) + 3 < CO-8 && /* room for --More-- */
|
||||
(notdied = strncmp(bp, "You die", 7))) {
|
||||
Strcat(toplines, " ");
|
||||
Strcat(toplines, bp);
|
||||
#endif
|
||||
cw->curx += 2;
|
||||
if(!(cw->flags & WIN_STOP))
|
||||
addtopl(bp);
|
||||
@@ -232,7 +301,11 @@ update_topl(bp)
|
||||
}
|
||||
}
|
||||
remember_topl();
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
(void) nhwncpy(toplines, bp, TBUFSZ);
|
||||
#else
|
||||
(void) strncpy(toplines, bp, TBUFSZ);
|
||||
#endif
|
||||
toplines[TBUFSZ - 1] = 0;
|
||||
|
||||
for(tl = toplines; n0 >= CO; ){
|
||||
@@ -240,34 +313,49 @@ update_topl(bp)
|
||||
for(tl+=CO-1; tl != otl && !isspace(*tl); --tl) ;
|
||||
if(tl == otl) {
|
||||
/* Eek! A huge token. Try splitting after it. */
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
tl = nhwindex(otl, ' ');
|
||||
#else
|
||||
tl = index(otl, ' ');
|
||||
#endif
|
||||
if (!tl) break; /* No choice but to spit it out whole. */
|
||||
}
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
*tl++ = (nhwchar)'\n';
|
||||
n0 = nhwlen(tl);
|
||||
#else
|
||||
*tl++ = '\n';
|
||||
n0 = strlen(tl);
|
||||
#endif
|
||||
}
|
||||
if(!notdied) cw->flags &= ~WIN_STOP;
|
||||
if(!(cw->flags & WIN_STOP)) redotoplin(toplines);
|
||||
}
|
||||
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
#define T(x) L##x
|
||||
#else
|
||||
#define T(x) x
|
||||
#endif
|
||||
|
||||
STATIC_OVL
|
||||
void
|
||||
topl_putsym(c)
|
||||
char c;
|
||||
nhwchar c;
|
||||
{
|
||||
register struct WinDesc *cw = wins[WIN_MESSAGE];
|
||||
|
||||
if(cw == (struct WinDesc *) 0) panic("Putsym window MESSAGE nonexistant");
|
||||
|
||||
switch(c) {
|
||||
case '\b':
|
||||
case T('\b'):
|
||||
if(ttyDisplay->curx == 0 && ttyDisplay->cury > 0)
|
||||
tty_curs(BASE_WINDOW, CO, (int)ttyDisplay->cury-1);
|
||||
backsp();
|
||||
ttyDisplay->curx--;
|
||||
cw->curx = ttyDisplay->curx;
|
||||
return;
|
||||
case '\n':
|
||||
case T('\n'):
|
||||
cl_end();
|
||||
ttyDisplay->curx = 0;
|
||||
ttyDisplay->cury++;
|
||||
@@ -278,7 +366,7 @@ topl_putsym(c)
|
||||
break;
|
||||
default:
|
||||
if(ttyDisplay->curx == CO-1)
|
||||
topl_putsym('\n'); /* 1 <= curx <= CO; avoid CO */
|
||||
topl_putsym(T('\n')); /* 1 <= curx <= CO; avoid CO */
|
||||
#ifdef WIN32CON
|
||||
(void) putchar(c);
|
||||
#endif
|
||||
@@ -291,12 +379,14 @@ topl_putsym(c)
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef T
|
||||
|
||||
void
|
||||
putsyms(str)
|
||||
const char *str;
|
||||
putsyms(symstr)
|
||||
const nhwchar *symstr;
|
||||
{
|
||||
while(*str)
|
||||
topl_putsym(*str++);
|
||||
while(*symstr)
|
||||
topl_putsym(*symstr++);
|
||||
}
|
||||
|
||||
STATIC_OVL void
|
||||
@@ -304,7 +394,12 @@ removetopl(n)
|
||||
register int n;
|
||||
{
|
||||
/* assume addtopl() has been done, so ttyDisplay->toplin is already set */
|
||||
while (n-- > 0) putsyms("\b \b");
|
||||
while (n-- > 0)
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
putsyms(L"\b \b");
|
||||
#else
|
||||
putsyms("\b \b");
|
||||
#endif
|
||||
}
|
||||
|
||||
extern char erase_char; /* from xxxtty.c; don't need kill_char */
|
||||
@@ -331,6 +426,9 @@ char def;
|
||||
struct WinDesc *cw = wins[WIN_MESSAGE];
|
||||
boolean doprev = 0;
|
||||
char prompt[QBUFSZ];
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
nhwchar wprompt[QBUFSZ];
|
||||
#endif
|
||||
|
||||
if(ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) more();
|
||||
cw->flags &= ~WIN_STOP;
|
||||
@@ -362,7 +460,12 @@ char def;
|
||||
ttyDisplay->inread = sav;
|
||||
tty_clear_nhwindow(WIN_MESSAGE);
|
||||
cw->maxcol = cw->maxrow;
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
nhwstrcpy(wprompt, prompt);
|
||||
addtopl(wprompt);
|
||||
#else
|
||||
addtopl(prompt);
|
||||
#endif
|
||||
} else {
|
||||
if(!doprev)
|
||||
(void) tty_doprev_message(); /* need two initially */
|
||||
@@ -378,7 +481,12 @@ char def;
|
||||
tty_clear_nhwindow(WIN_MESSAGE);
|
||||
cw->maxcol = cw->maxrow;
|
||||
doprev = 0;
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
nhwstrcpy(wprompt, prompt);
|
||||
addtopl(wprompt);
|
||||
#else
|
||||
addtopl(prompt);
|
||||
#endif
|
||||
q = '\0'; /* force another loop iteration */
|
||||
continue;
|
||||
}
|
||||
@@ -399,13 +507,18 @@ char def;
|
||||
tty_nhbell();
|
||||
q = (char)0;
|
||||
} else if (q == '#' || digit_ok) {
|
||||
char z, digit_string[2];
|
||||
char z;
|
||||
nhwchar digit_string[2];
|
||||
int n_len = 0;
|
||||
long value = 0;
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
addtopl(L"#"), n_len++;
|
||||
#else
|
||||
addtopl("#"), n_len++;
|
||||
digit_string[1] = '\0';
|
||||
#endif
|
||||
digit_string[1] = (nhwchar)0;
|
||||
if (q != '#') {
|
||||
digit_string[0] = q;
|
||||
digit_string[0] = (nhwchar)q;
|
||||
addtopl(digit_string), n_len++;
|
||||
value = q - '0';
|
||||
q = '#';
|
||||
@@ -415,7 +528,7 @@ char def;
|
||||
if (digit(z)) {
|
||||
value = (10 * value) + (z - '0');
|
||||
if (value < 0) break; /* overflow: try again */
|
||||
digit_string[0] = z;
|
||||
digit_string[0] = (nhwchar)z;
|
||||
addtopl(digit_string), n_len++;
|
||||
} else if (z == 'y' || index(quitchars, z)) {
|
||||
if (z == '\033') value = -1; /* abort */
|
||||
@@ -440,7 +553,12 @@ char def;
|
||||
|
||||
if (q != '#') {
|
||||
Sprintf(rtmp, "%c", q);
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
nhwstrcpy(wprompt, rtmp); /* rtmp[40] -> wprompt[128] ok */
|
||||
addtopl(wprompt);
|
||||
#else
|
||||
addtopl(rtmp);
|
||||
#endif
|
||||
}
|
||||
clean_up:
|
||||
ttyDisplay->inread--;
|
||||
@@ -468,6 +586,7 @@ boolean init;
|
||||
static boolean doneinit = FALSE;
|
||||
register struct WinDesc *cw = wins[WIN_MESSAGE];
|
||||
char *retstr = (char *)0;
|
||||
static char buf[BUFSZ];
|
||||
|
||||
if (!cw) return (char *)0; /* bail */
|
||||
/*
|
||||
@@ -483,11 +602,24 @@ boolean init;
|
||||
if (doneinit && state < 2) {
|
||||
if (state == 1) {
|
||||
++state;
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
strnhwcpy(buf,toplines);
|
||||
return buf;
|
||||
#else
|
||||
return toplines;
|
||||
#endif
|
||||
}
|
||||
do {
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
if(cw->data[idx] && nhwcmp(cw->data[idx], emptysym) ) {
|
||||
strnhwcpy(buf, cw->data[idx]);
|
||||
retstr = buf;
|
||||
}
|
||||
#else
|
||||
if(cw->data[idx] && strcmp(cw->data[idx], "") )
|
||||
retstr = cw->data[idx];
|
||||
|
||||
#endif
|
||||
idx = (idx + 1) % cw->rows;
|
||||
} while (idx != cw->maxrow && !retstr);
|
||||
if (idx == cw->maxrow) ++state;
|
||||
@@ -513,10 +645,14 @@ const char *msg;
|
||||
if (len > (unsigned)cw->datlen[idx]) {
|
||||
if (cw->data[idx]) free(cw->data[idx]);
|
||||
len += (8 - (len & 7)); /* pad up to next multiple of 8 */
|
||||
cw->data[idx] = (char *)alloc(len);
|
||||
cw->data[idx] = (nhwchar *)alloc(sizeof(nhwchar) * len);
|
||||
cw->datlen[idx] = (short)len;
|
||||
}
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
(void)nhwstrcpy(cw->data[idx], msg);
|
||||
#else
|
||||
Strcpy(cw->data[idx], msg);
|
||||
#endif
|
||||
cw->maxcol = cw->maxrow = (idx + 1) % cw->rows;
|
||||
}
|
||||
#endif /* TTY_GRAPHICS */
|
||||
|
||||
340
win/tty/wintty.c
340
win/tty/wintty.c
@@ -43,6 +43,11 @@ extern char mapped_menu_cmds[]; /* from options.c */
|
||||
/* this is only needed until tty_status_* routines are written */
|
||||
extern NEARDATA winid WIN_STATUS;
|
||||
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
void FDECL(tty_putmixed,(winid,int,const char *));
|
||||
void FDECL(tty_putstr_core,(winid,int,const nhwchar *));
|
||||
#endif
|
||||
|
||||
/* Interface definition, for windows.c */
|
||||
struct window_procs tty_procs = {
|
||||
"tty",
|
||||
@@ -70,7 +75,11 @@ struct window_procs tty_procs = {
|
||||
tty_destroy_nhwindow,
|
||||
tty_curs,
|
||||
tty_putstr,
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
tty_putmixed,
|
||||
#else
|
||||
genl_putmixed,
|
||||
#endif
|
||||
tty_display_file,
|
||||
tty_start_menu,
|
||||
tty_add_menu,
|
||||
@@ -141,7 +150,12 @@ static char obuf[BUFSIZ]; /* BUFSIZ is defined in stdio.h */
|
||||
#endif
|
||||
|
||||
static char winpanicstr[] = "Bad window id %d";
|
||||
char defmorestr[] = "--More--";
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
nhwchar defmorestr[] = L"--More--";
|
||||
#else
|
||||
nhwchar defmorestr[] = "--More--";
|
||||
#endif
|
||||
nhwchar emptysym[1] = {0};
|
||||
|
||||
#ifdef CLIPPING
|
||||
# if defined(USE_TILES) && defined(MSDOS)
|
||||
@@ -181,8 +195,9 @@ STATIC_DCL void FDECL(process_menu_window, (winid,struct WinDesc *));
|
||||
STATIC_DCL void FDECL(process_text_window, (winid,struct WinDesc *));
|
||||
STATIC_DCL tty_menu_item *FDECL(reverse, (tty_menu_item *));
|
||||
STATIC_DCL const char * FDECL(compress_str, (const char *));
|
||||
STATIC_DCL void FDECL(tty_putsym, (winid, int, int, CHAR_P));
|
||||
STATIC_DCL void FDECL(tty_putsym, (winid, int, int, NHWCHAR_P));
|
||||
static char *FDECL(copy_of, (const char *));
|
||||
static nhwchar *FDECL(nhwchar_copy_of, (const nhwchar *));
|
||||
STATIC_DCL void FDECL(bail, (const char *)); /* __attribute__((noreturn)) */
|
||||
|
||||
/*
|
||||
@@ -260,7 +275,11 @@ winch()
|
||||
for(i=WIN_INVEN; i < MAXWIN; i++)
|
||||
if(wins[i] && wins[i]->active) {
|
||||
/* cop-out */
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
addtopl(L"Press Return to continue: ");
|
||||
#else
|
||||
addtopl("Press Return to continue: ");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
(void) fflush(stdout);
|
||||
@@ -953,24 +972,24 @@ tty_create_nhwindow(type)
|
||||
|
||||
if(newwin->maxrow) {
|
||||
newwin->data =
|
||||
(char **) alloc(sizeof(char *) * (unsigned)newwin->maxrow);
|
||||
(nhwchar **) alloc(sizeof(nhwchar *) * (unsigned)newwin->maxrow);
|
||||
newwin->datlen =
|
||||
(short *) alloc(sizeof(short) * (unsigned)newwin->maxrow);
|
||||
if(newwin->maxcol) {
|
||||
for (i = 0; i < newwin->maxrow; i++) {
|
||||
newwin->data[i] = (char *) alloc((unsigned)newwin->maxcol);
|
||||
newwin->data[i] = (nhwchar *) alloc(sizeof(nhwchar) * (unsigned)newwin->maxcol);
|
||||
newwin->datlen[i] = newwin->maxcol;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < newwin->maxrow; i++) {
|
||||
newwin->data[i] = (char *) 0;
|
||||
newwin->data[i] = (nhwchar *) 0;
|
||||
newwin->datlen[i] = 0;
|
||||
}
|
||||
}
|
||||
if(newwin->type == NHW_MESSAGE)
|
||||
newwin->maxrow = 0;
|
||||
} else {
|
||||
newwin->data = (char **)0;
|
||||
newwin->data = (nhwchar **)0;
|
||||
newwin->datlen = (short *)0;
|
||||
}
|
||||
|
||||
@@ -1008,12 +1027,12 @@ free_window_info(cw, free_data)
|
||||
for(i=0; i<cw->maxrow; i++)
|
||||
if(cw->data[i]) {
|
||||
free((genericptr_t)cw->data[i]);
|
||||
cw->data[i] = (char *)0;
|
||||
cw->data[i] = (nhwchar *)0;
|
||||
if (cw->datlen) cw->datlen[i] = 0;
|
||||
}
|
||||
if (free_data) {
|
||||
free((genericptr_t)cw->data);
|
||||
cw->data = (char **)0;
|
||||
cw->data = (nhwchar **)0;
|
||||
if (cw->datlen) free((genericptr_t)cw->datlen);
|
||||
cw->datlen = (short *)0;
|
||||
cw->rows = 0;
|
||||
@@ -1087,15 +1106,25 @@ dmore(cw, s)
|
||||
register struct WinDesc *cw;
|
||||
const char *s; /* valid responses */
|
||||
{
|
||||
const char *prompt = cw->morestr ? cw->morestr : defmorestr;
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
char buf[BUFSZ];
|
||||
#endif
|
||||
const nhwchar *prompt = cw->morestr ? cw->morestr : defmorestr;
|
||||
|
||||
int offset = (cw->type == NHW_TEXT) ? 1 : 2;
|
||||
|
||||
tty_curs(BASE_WINDOW,
|
||||
(int)ttyDisplay->curx + offset, (int)ttyDisplay->cury);
|
||||
if(flags.standout)
|
||||
standoutbeg();
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
strnhwcpy(buf, prompt);
|
||||
xputs(buf);
|
||||
ttyDisplay->curx += strlen(buf);
|
||||
#else
|
||||
xputs(prompt);
|
||||
ttyDisplay->curx += strlen(prompt);
|
||||
#endif
|
||||
if(flags.standout)
|
||||
standoutend();
|
||||
|
||||
@@ -1210,13 +1239,13 @@ struct WinDesc *cw;
|
||||
long count;
|
||||
int n, curr_page, page_lines;
|
||||
boolean finished, counting, reset_count;
|
||||
char *cp, *rp, resp[QBUFSZ], gacc[QBUFSZ],
|
||||
*msave, *morestr;
|
||||
char *cp, *rp, resp[QBUFSZ], gacc[QBUFSZ];
|
||||
nhwchar *msave, *morestr;
|
||||
|
||||
curr_page = page_lines = 0;
|
||||
page_start = page_end = 0;
|
||||
msave = cw->morestr; /* save the morestr */
|
||||
cw->morestr = morestr = (char*) alloc((unsigned) QBUFSZ);
|
||||
cw->morestr = morestr = (nhwchar*) alloc(sizeof(nhwchar) * (unsigned) QBUFSZ);
|
||||
counting = FALSE;
|
||||
count = 0L;
|
||||
reset_count = TRUE;
|
||||
@@ -1332,20 +1361,41 @@ struct WinDesc *cw;
|
||||
Strcat(resp, gacc); /* group accelerators */
|
||||
Strcat(resp, mapped_menu_cmds);
|
||||
|
||||
if (cw->npages > 1)
|
||||
if (cw->npages > 1) {
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
char buf[BUFSZ];
|
||||
Sprintf(buf, "(%d of %d)",
|
||||
curr_page + 1, (int) cw->npages);
|
||||
(void)nhwstrcpy(cw->morestr, buf);
|
||||
#else
|
||||
Sprintf(cw->morestr, "(%d of %d)",
|
||||
curr_page + 1, (int) cw->npages);
|
||||
else if (msave)
|
||||
#endif
|
||||
} else if (msave) {
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
(void)nhwcpy(cw->morestr, msave);
|
||||
#else
|
||||
Strcpy(cw->morestr, msave);
|
||||
else
|
||||
#endif
|
||||
} else {
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
(void)nhwcpy(cw->morestr, defmorestr);
|
||||
#else
|
||||
Strcpy(cw->morestr, defmorestr);
|
||||
|
||||
#endif
|
||||
}
|
||||
tty_curs(window, 1, page_lines);
|
||||
cl_end();
|
||||
dmore(cw, resp);
|
||||
} else {
|
||||
/* just put the cursor back... */
|
||||
tty_curs(window, (int) strlen(cw->morestr) + 2, page_lines);
|
||||
tty_curs(window,
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
(int) nhwlen(cw->morestr) + 2,
|
||||
#else
|
||||
(int) strlen(cw->morestr) + 2,
|
||||
#endif
|
||||
page_lines);
|
||||
xwaitforspace(resp);
|
||||
}
|
||||
|
||||
@@ -1509,7 +1559,7 @@ winid window;
|
||||
struct WinDesc *cw;
|
||||
{
|
||||
int i, n, attr;
|
||||
register char *cp;
|
||||
register nhwchar *cp;
|
||||
|
||||
for (n = 0, i = 0; i < cw->maxrow; i++) {
|
||||
if (!cw->offx && (n + cw->offy == ttyDisplay->rows - 1)) {
|
||||
@@ -1543,7 +1593,11 @@ struct WinDesc *cw;
|
||||
*cp && (int) ttyDisplay->curx < (int) ttyDisplay->cols;
|
||||
cp++, ttyDisplay->curx++)
|
||||
#endif
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
u_putch(*cp);
|
||||
#else
|
||||
(void) putchar(*cp);
|
||||
#endif
|
||||
term_end_attr(attr);
|
||||
}
|
||||
}
|
||||
@@ -1772,7 +1826,7 @@ STATIC_OVL void
|
||||
tty_putsym(window, x, y, ch)
|
||||
winid window;
|
||||
int x, y;
|
||||
char ch;
|
||||
nhwchar ch;
|
||||
{
|
||||
register struct WinDesc *cw = 0;
|
||||
|
||||
@@ -1784,7 +1838,11 @@ tty_putsym(window, x, y, ch)
|
||||
case NHW_MAP:
|
||||
case NHW_BASE:
|
||||
tty_curs(window, x, y);
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
u_putch(ch);
|
||||
#else
|
||||
(void) putchar(ch);
|
||||
#endif
|
||||
ttyDisplay->curx++;
|
||||
cw->curx++;
|
||||
break;
|
||||
@@ -1827,9 +1885,14 @@ tty_putstr(window, attr, str)
|
||||
const char *str;
|
||||
{
|
||||
register struct WinDesc *cw = 0;
|
||||
register char *ob;
|
||||
register const char *nb;
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
nhwchar symbuf[BUFSZ];
|
||||
register const nhwchar *symstr = symbuf;
|
||||
#else
|
||||
register const nhwchar *nb;
|
||||
register nhwchar *ob;
|
||||
register int i, j, n0;
|
||||
#endif
|
||||
|
||||
/* Assume there's a real problem if the window is missing --
|
||||
* probably a panic message
|
||||
@@ -1844,21 +1907,52 @@ tty_putstr(window, attr, str)
|
||||
return;
|
||||
if(cw->type != NHW_MESSAGE)
|
||||
str = compress_str(str);
|
||||
#if defined(USER_SOUNDS) && defined(WIN32CON)
|
||||
else
|
||||
play_sound_for_message(str);
|
||||
#endif
|
||||
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
nhwstrcpy(symbuf, str);
|
||||
tty_putstr_core(window, attr, symstr);
|
||||
}
|
||||
|
||||
void
|
||||
tty_putstr_core(window, attr, symstr)
|
||||
winid window;
|
||||
int attr;
|
||||
const nhwchar *symstr;
|
||||
{
|
||||
register struct WinDesc *cw = wins[window];
|
||||
register const nhwchar *nb;
|
||||
register nhwchar *ob;
|
||||
register int i, j, n0;
|
||||
#endif
|
||||
|
||||
ttyDisplay->lastwin = window;
|
||||
|
||||
switch(cw->type) {
|
||||
case NHW_MESSAGE:
|
||||
/* really do this later */
|
||||
#if defined(USER_SOUNDS) && defined(WIN32CON)
|
||||
play_sound_for_message(str);
|
||||
#endif
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
update_topl(symstr);
|
||||
#else
|
||||
update_topl(str);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case NHW_STATUS:
|
||||
ob = &cw->data[cw->cury][j = cw->curx];
|
||||
if(context.botlx) *ob = 0;
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
if(!cw->cury && (int)nhwlen(symstr) >= CO) {
|
||||
/* the characters before "St:" are unnecessary */
|
||||
nb = nhwindex(symstr, L':');
|
||||
if(nb && nb > symstr+2)
|
||||
symstr = nb - 2;
|
||||
}
|
||||
nb = symstr;
|
||||
#else
|
||||
if(!cw->cury && (int)strlen(str) >= CO) {
|
||||
/* the characters before "St:" are unnecessary */
|
||||
nb = index(str, ':');
|
||||
@@ -1866,6 +1960,8 @@ tty_putstr(window, attr, str)
|
||||
str = nb - 2;
|
||||
}
|
||||
nb = str;
|
||||
#endif
|
||||
|
||||
for(i = cw->curx+1, n0 = cw->cols; i < n0; i++, nb++) {
|
||||
if(!*nb) {
|
||||
if(*ob || context.botlx) {
|
||||
@@ -1880,19 +1976,31 @@ tty_putstr(window, attr, str)
|
||||
if(*ob) ob++;
|
||||
}
|
||||
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
(void) nhwncpy(&cw->data[cw->cury][j], symstr, cw->cols - j - 1);
|
||||
#else
|
||||
(void) strncpy(&cw->data[cw->cury][j], str, cw->cols - j - 1);
|
||||
cw->data[cw->cury][cw->cols-1] = '\0'; /* null terminate */
|
||||
#endif
|
||||
cw->data[cw->cury][cw->cols-1] = (nhwchar)0; /* null terminate */
|
||||
cw->cury = (cw->cury+1) % 2;
|
||||
cw->curx = 0;
|
||||
break;
|
||||
case NHW_MAP:
|
||||
tty_curs(window, cw->curx+1, cw->cury);
|
||||
term_start_attr(attr);
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
while(*symstr && (int) ttyDisplay->curx < (int) ttyDisplay->cols-1) {
|
||||
u_putch(*symstr);
|
||||
symstr++;
|
||||
ttyDisplay->curx++;
|
||||
}
|
||||
#else
|
||||
while(*str && (int) ttyDisplay->curx < (int) ttyDisplay->cols-1) {
|
||||
(void) putchar(*str);
|
||||
str++;
|
||||
ttyDisplay->curx++;
|
||||
}
|
||||
#endif
|
||||
cw->curx = 0;
|
||||
cw->cury++;
|
||||
term_end_attr(attr);
|
||||
@@ -1900,14 +2008,23 @@ tty_putstr(window, attr, str)
|
||||
case NHW_BASE:
|
||||
tty_curs(window, cw->curx+1, cw->cury);
|
||||
term_start_attr(attr);
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
while (*symstr) {
|
||||
#else
|
||||
while (*str) {
|
||||
#endif
|
||||
if ((int) ttyDisplay->curx >= (int) ttyDisplay->cols-1) {
|
||||
cw->curx = 0;
|
||||
cw->cury++;
|
||||
tty_curs(window, cw->curx+1, cw->cury);
|
||||
}
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
u_putch(*symstr);
|
||||
symstr++;
|
||||
#else
|
||||
(void) putchar(*str);
|
||||
str++;
|
||||
#endif
|
||||
ttyDisplay->curx++;
|
||||
}
|
||||
cw->curx = 0;
|
||||
@@ -1929,10 +2046,10 @@ tty_putstr(window, attr, str)
|
||||
}
|
||||
/* always grows one at a time, but alloc 12 at a time */
|
||||
if(cw->cury >= cw->rows) {
|
||||
char **tmp;
|
||||
nhwchar **tmp;
|
||||
|
||||
cw->rows += 12;
|
||||
tmp = (char **) alloc(sizeof(char *) * (unsigned)cw->rows);
|
||||
tmp = (nhwchar **) alloc(sizeof(nhwchar *) * (unsigned)cw->rows);
|
||||
for(i=0; i<cw->maxrow; i++)
|
||||
tmp[i] = cw->data[i];
|
||||
if(cw->data)
|
||||
@@ -1944,10 +2061,19 @@ tty_putstr(window, attr, str)
|
||||
}
|
||||
if(cw->data[cw->cury])
|
||||
free((genericptr_t)cw->data[cw->cury]);
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
n0 = nhwlen(symstr) + 1;
|
||||
#else
|
||||
n0 = strlen(str) + 1;
|
||||
ob = cw->data[cw->cury] = (char *)alloc((unsigned)n0 + 1);
|
||||
*ob++ = (char)(attr + 1); /* avoid nuls, for convenience */
|
||||
#endif
|
||||
|
||||
ob = cw->data[cw->cury] = (nhwchar *)alloc(sizeof(nhwchar) * (unsigned)n0 + 1);
|
||||
*ob++ = (nhwchar)(attr + 1); /* avoid nuls, for convenience */
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
(void)nhwcpy(ob, symstr);
|
||||
#else
|
||||
Strcpy(ob, str);
|
||||
#endif
|
||||
|
||||
if(n0 > cw->maxcol)
|
||||
cw->maxcol = n0;
|
||||
@@ -1955,11 +2081,19 @@ tty_putstr(window, attr, str)
|
||||
cw->maxrow = cw->cury;
|
||||
if(n0 > CO) {
|
||||
/* attempt to break the line */
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
for(i = CO-1; i && symstr[i] != L' ' && symstr[i] != L'\n';)
|
||||
#else
|
||||
for(i = CO-1; i && str[i] != ' ' && str[i] != '\n';)
|
||||
#endif
|
||||
i--;
|
||||
if(i) {
|
||||
cw->data[cw->cury-1][++i] = '\0';
|
||||
cw->data[cw->cury-1][++i] = (nhwchar)0;
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
tty_putstr_core(window, attr, &symstr[i]);
|
||||
#else
|
||||
tty_putstr(window, attr, &str[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1967,6 +2101,60 @@ tty_putstr(window, attr, str)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
/*
|
||||
* This differs from putstr() because the str parameter can
|
||||
* contain a sequence of characters representing:
|
||||
* \GXXXXNNNN a glyph value, encoded by encglyph().
|
||||
*
|
||||
*/
|
||||
void
|
||||
tty_putmixed(window, attr, str)
|
||||
winid window;
|
||||
int attr;
|
||||
const char *str;
|
||||
{
|
||||
nhwchar wbuf[BUFSZ];
|
||||
const char *cp = str;
|
||||
nhwchar *put = wbuf;
|
||||
while (*cp) {
|
||||
if (*cp == '\\') {
|
||||
int rndchk = 0, so = 0, gv = 0, ch, oc, dcount;
|
||||
unsigned os;
|
||||
const char *dp, *hex = "00112233445566778899aAbBcCdDeEfF";
|
||||
const char *save_cp = cp;
|
||||
|
||||
cp++;
|
||||
switch(*cp) {
|
||||
case 'G': /* glyph value \GXXXXNNNN*/
|
||||
dcount = 0;
|
||||
for (++cp; *cp && (dp = index(hex, *cp)) && (dcount++ < 4); cp++)
|
||||
rndchk = (int)((rndchk * 16) + ((int)(dp - hex) / 2));
|
||||
|
||||
if (rndchk == context.rndencode) {
|
||||
dcount = 0;
|
||||
for (; *cp && (dp = index(hex, *cp)) && (dcount++ < 4); cp++)
|
||||
gv = (int)((gv * 16) + ((int)(dp - hex) / 2));
|
||||
so = mapglyph(gv, &ch, &oc, &os, 0, 0);
|
||||
*put++ = (nhwchar)showsyms[so];
|
||||
continue;
|
||||
} else {
|
||||
/* possible forgery - leave it the way it is */
|
||||
cp = save_cp;
|
||||
}
|
||||
break;
|
||||
case '\\':
|
||||
break;
|
||||
}
|
||||
}
|
||||
*put++ = (nhwchar)*cp++;
|
||||
}
|
||||
*put = (nhwchar)0;
|
||||
/* now send it to tty_putstr_core() */
|
||||
tty_putstr_core(window, attr, wbuf);
|
||||
}
|
||||
#endif /*UNICODE_WIDEWINPORT*/
|
||||
|
||||
void
|
||||
tty_display_file(fname, complain)
|
||||
const char *fname;
|
||||
@@ -2149,7 +2337,7 @@ tty_end_menu(window, prompt)
|
||||
/* Reverse the list so that items are in correct order. */
|
||||
cw->mlist = reverse(cw->mlist);
|
||||
|
||||
/* Put the promt at the beginning of the menu. */
|
||||
/* Put the prompt at the beginning of the menu. */
|
||||
if (prompt) {
|
||||
anything any;
|
||||
|
||||
@@ -2200,10 +2388,19 @@ tty_end_menu(window, prompt)
|
||||
/* produce the largest demo string */
|
||||
Sprintf(buf, "(%d of %d) ", cw->npages, cw->npages);
|
||||
len = strlen(buf);
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
cw->morestr = nhwchar_copy_of(emptysym);
|
||||
#else
|
||||
cw->morestr = copy_of("");
|
||||
#endif
|
||||
} else {
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
cw->morestr = nhwchar_copy_of(L"(end) ");
|
||||
len = nhwlen(cw->morestr);
|
||||
#else
|
||||
cw->morestr = copy_of("(end) ");
|
||||
len = strlen(cw->morestr);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (len > (int)ttyDisplay->cols) {
|
||||
@@ -2323,7 +2520,11 @@ tty_wait_synch()
|
||||
} else {
|
||||
tty_display_nhwindow(WIN_MAP, FALSE);
|
||||
if(ttyDisplay->inmore) {
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
addtopl(L"--More--");
|
||||
#else
|
||||
addtopl("--More--");
|
||||
#endif
|
||||
(void) fflush(stdout);
|
||||
} else if(ttyDisplay->inread > program_state.gameover) {
|
||||
/* this can only happen if we were reading and got interrupted */
|
||||
@@ -2395,6 +2596,58 @@ end_glyphout()
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
/*
|
||||
* Parts of u_putch() were contributed by Adam Wozniak, 2005.
|
||||
*/
|
||||
void
|
||||
u_putch(sym)
|
||||
nhwchar sym;
|
||||
{
|
||||
unsigned long unicode = sym;
|
||||
if (!iflags.unicodedisp)
|
||||
putchar((char)sym);
|
||||
else {
|
||||
#if defined(UNIX) || defined(VMS)
|
||||
/* send utf8 to display */
|
||||
if (unicode < 0x80) {
|
||||
(void) putchar(unicode);
|
||||
} else if (unicode < 0x00000800) {
|
||||
(void) putchar(0xC0 | (unicode >> 6));
|
||||
(void) putchar(0x80 | (unicode & 0x3F));
|
||||
} else if (unicode < 0x00010000) {
|
||||
(void) putchar(0xE0 | (unicode >> 12));
|
||||
(void) putchar(0x80 | ((unicode >> 6) & 0x3F));
|
||||
(void) putchar(0x80 | (unicode & 0x3F));
|
||||
} else if (unicode < 0x00200000) {
|
||||
(void) putchar(0xF0 | (unicode >> 18));
|
||||
(void) putchar(0x80 | ((unicode >> 12) & 0x3F));
|
||||
(void) putchar(0x80 | ((unicode >> 6) & 0x3F));
|
||||
(void) putchar(0x80 | (unicode & 0x3F));
|
||||
} else if (unicode < 0x04000000) {
|
||||
(void) putchar(0xF8 | (unicode >> 24));
|
||||
(void) putchar(0x80 | ((unicode >> 18) & 0x3F));
|
||||
(void) putchar(0x80 | ((unicode >> 12) & 0x3F));
|
||||
(void) putchar(0x80 | ((unicode >> 6) & 0x3F));
|
||||
(void) putchar(0x80 | (unicode & 0x3F));
|
||||
} else {
|
||||
(void) putchar(0xFC | (unicode >> 30));
|
||||
(void) putchar(0x80 | ((unicode >> 24) & 0x3F));
|
||||
(void) putchar(0x80 | ((unicode >> 18) & 0x3F));
|
||||
(void) putchar(0x80 | ((unicode >> 12) & 0x3F));
|
||||
(void) putchar(0x80 | ((unicode >> 6) & 0x3F));
|
||||
(void) putchar(0x80 | (unicode & 0x3F));
|
||||
}
|
||||
#else
|
||||
/* it is assumed that whatever is being substituted for
|
||||
putchar() can handle unicode characters directly at
|
||||
this point (nttty's xputc() for example) */
|
||||
(void) putchar(sym);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif /*UNICODE_WIDEWINPORT*/
|
||||
|
||||
#ifndef WIN32
|
||||
void
|
||||
g_putch(in_ch)
|
||||
@@ -2403,6 +2656,11 @@ int in_ch;
|
||||
register char ch = (char)in_ch;
|
||||
|
||||
# if defined(ASCIIGRAPH) && !defined(NO_TERMS)
|
||||
# if defined(UNICODE_WIDEWINPORT) && defined(UNICODE_DRAWING)
|
||||
if (iflags.unicodedisp && symset[currentgraphics].name) {
|
||||
u_putch(in_ch);
|
||||
} else
|
||||
# endif
|
||||
if (SYMHANDLING(H_IBM) || iflags.eight_bit_tty) {
|
||||
/* IBM-compatible displays don't need other stuff */
|
||||
(void) putchar(ch);
|
||||
@@ -2486,9 +2744,9 @@ tty_print_glyph(window, x, y, glyph)
|
||||
xchar x, y;
|
||||
int glyph;
|
||||
{
|
||||
int ch;
|
||||
int ch, idx;
|
||||
boolean reverse_on = FALSE;
|
||||
int color;
|
||||
int color;
|
||||
unsigned special;
|
||||
|
||||
#ifdef CLIPPING
|
||||
@@ -2498,7 +2756,7 @@ tty_print_glyph(window, x, y, glyph)
|
||||
}
|
||||
#endif
|
||||
/* map glyph to character and color */
|
||||
(void)mapglyph(glyph, &ch, &color, &special, x, y);
|
||||
idx = mapglyph(glyph, &ch, &color, &special, x, y);
|
||||
|
||||
/* Move the cursor. */
|
||||
tty_curs(window, x,y);
|
||||
@@ -2531,6 +2789,11 @@ tty_print_glyph(window, x, y, glyph)
|
||||
if (iflags.grmode && iflags.tile_view)
|
||||
xputg(glyph,ch,special);
|
||||
else
|
||||
#endif
|
||||
#if defined(UNICODE_WIDEWINPORT) && defined(UNICODE_DRAWING)
|
||||
if (iflags.unicodedisp && symset[currentgraphics].name)
|
||||
g_putch(showsyms[idx]); /* use the unicode symset */
|
||||
else
|
||||
#endif
|
||||
g_putch(ch); /* print the character */
|
||||
|
||||
@@ -2683,6 +2946,15 @@ copy_of(s)
|
||||
return strcpy((char *) alloc((unsigned) (strlen(s) + 1)), s);
|
||||
}
|
||||
|
||||
# ifdef UNICODE_WIDEWINPORT
|
||||
static nhwchar *
|
||||
nhwchar_copy_of(s)
|
||||
const nhwchar *s;
|
||||
{
|
||||
if (!s) s = emptysym;
|
||||
return nhwcpy((nhwchar *) alloc(sizeof(nhwchar) * (unsigned) (nhwlen(s) + 1)), s);
|
||||
}
|
||||
# endif /*UNICODE_WIDEWINPORT*/
|
||||
#endif /* TTY_GRAPHICS */
|
||||
|
||||
/*wintty.c*/
|
||||
|
||||
Reference in New Issue
Block a user