get rid of warnings when building tty interface

My guess about NCURSES_CONST was right; it expands to nothing in the
/usr/include/term.h on my old OSX system.  There aren't any levers or
knobs available to avoid that so this adds casts of string literals
to avoid warnings about passing a literal to something that expects
non-const.

There's a lot of conditional code in termcap.c and the nhStr("foo")
(hidden cast) changes only got tested for my default configuraiton.
I tried to avoid typos but I attempt such all the time and we know
how that tends to go.

Are we sure that systems which need to install a curses development
package have term.h without that?  A tty-only build shouldn't require
that.
This commit is contained in:
PatR
2023-04-06 01:18:39 -07:00
parent 697ef9760c
commit 4927527493
+46 -45
View File
@@ -184,16 +184,16 @@ tty_startup(int *wid, int *hgt)
buf[BUFSZ - 1] = '\0'; buf[BUFSZ - 1] = '\0';
error("Unknown terminal type: %s.", term); error("Unknown terminal type: %s.", term);
} }
if ((pc = Tgetstr("pc")) != 0) if ((pc = Tgetstr(nhStr("pc"))) != 0)
PC = *pc; PC = *pc;
if (!(BC = Tgetstr("le"))) /* both termcap and terminfo use le */ if (!(BC = Tgetstr(nhStr("le")))) { /* both termcap and terminfo use le */
#ifdef TERMINFO #ifdef TERMINFO
error("Terminal must backspace."); error("Terminal must backspace.");
#else #else
if (!(BC = Tgetstr("bc"))) { /* termcap also uses bc/bs */ if (!(BC = Tgetstr(nhStr("bc")))) { /* termcap also uses bc/bs */
#ifndef MINIMAL_TERM #ifndef MINIMAL_TERM
if (!tgetflag("bs")) if (!tgetflag(nhStr("bs")))
error("Terminal must backspace."); error("Terminal must backspace.");
#endif #endif
BC = tbufptr; BC = tbufptr;
@@ -201,11 +201,12 @@ tty_startup(int *wid, int *hgt)
*BC = '\b'; *BC = '\b';
} }
#endif #endif
}
#ifdef MINIMAL_TERM #ifdef MINIMAL_TERM
HO = (char *) 0; HO = (char *) 0;
#else #else
HO = Tgetstr("ho"); HO = Tgetstr(nhStr("ho"));
#endif #endif
/* /*
* LI and CO are set in ioctl.c via a TIOCGWINSZ if available. If * LI and CO are set in ioctl.c via a TIOCGWINSZ if available. If
@@ -214,9 +215,9 @@ tty_startup(int *wid, int *hgt)
*/ */
#ifndef MICRO #ifndef MICRO
if (!CO) if (!CO)
CO = tgetnum("co"); CO = tgetnum(nhStr("co"));
if (!LI) if (!LI)
LI = tgetnum("li"); LI = tgetnum(nhStr("li"));
#else #else
#if defined(TOS) && defined(__GNUC__) #if defined(TOS) && defined(__GNUC__)
if (!strcmp(term, "builtin")) { if (!strcmp(term, "builtin")) {
@@ -224,8 +225,8 @@ tty_startup(int *wid, int *hgt)
} else } else
#endif #endif
{ {
CO = tgetnum("co"); CO = tgetnum(nhStr("co"));
LI = tgetnum("li"); LI = tgetnum(nhStr("li"));
if (!LI || !CO) /* if we don't override it */ if (!LI || !CO) /* if we don't override it */
get_scr_size(); get_scr_size();
} }
@@ -234,49 +235,49 @@ tty_startup(int *wid, int *hgt)
if (CO < COLNO || LI < ROWNO + 3) if (CO < COLNO || LI < ROWNO + 3)
setclipped(); setclipped();
#endif #endif
nh_ND = Tgetstr("nd"); /* move cursor right 1 column */ nh_ND = Tgetstr(nhStr("nd")); /* move cursor right 1 column */
if (tgetflag("os")) /* term can overstrike */ if (tgetflag(nhStr("os"))) /* term can overstrike */
error("NetHack can't have OS."); error("NetHack can't have OS.");
if (tgetflag("ul")) /* underline by overstrike w/ underscore */ if (tgetflag(nhStr("ul"))) /* underline by overstrike w/ underscore */
ul_hack = TRUE; ul_hack = TRUE;
CE = Tgetstr("ce"); /* clear line from cursor to eol */ CE = Tgetstr(nhStr("ce")); /* clear line from cursor to eol */
UP = Tgetstr("up"); /* move cursor up 1 line */ UP = Tgetstr(nhStr("up")); /* move cursor up 1 line */
/* It seems that xd is no longer supported, and we should use /* It seems that xd is no longer supported, and we should use
a linefeed instead; unfortunately this requires resetting a linefeed instead; unfortunately this requires resetting
CRMOD, and many output routines will have to be modified CRMOD, and many output routines will have to be modified
slightly. Let's leave that till the next release. */ slightly. Let's leave that till the next release. */
XD = Tgetstr("xd"); XD = Tgetstr(nhStr("xd"));
/* not: XD = Tgetstr("do"); */ /* not: XD = Tgetstr("do"); */
if (!(nh_CM = Tgetstr("cm"))) { /* cm: move cursor */ if (!(nh_CM = Tgetstr(nhStr("cm")))) { /* cm: move cursor */
if (!UP && !HO) if (!UP && !HO)
error("NetHack needs CM or UP or HO."); error("NetHack needs CM or UP or HO.");
tty_raw_print("Playing NetHack on terminals without CM is suspect."); tty_raw_print("Playing NetHack on terminals without CM is suspect.");
tty_wait_synch(); tty_wait_synch();
} }
SO = Tgetstr("so"); /* standout start */ SO = Tgetstr(nhStr("so")); /* standout start */
SE = Tgetstr("se"); /* standout end */ SE = Tgetstr(nhStr("se")); /* standout end */
nh_US = Tgetstr("us"); /* underline start */ nh_US = Tgetstr(nhStr("us")); /* underline start */
nh_UE = Tgetstr("ue"); /* underline end */ nh_UE = Tgetstr(nhStr("ue")); /* underline end */
ZH = Tgetstr("ZH"); /* italic start */ ZH = Tgetstr(nhStr("ZH")); /* italic start */
ZR = Tgetstr("ZR"); /* italic end */ ZR = Tgetstr(nhStr("ZR")); /* italic end */
SG = tgetnum("sg"); /* -1: not fnd; else # of spaces left by so */ SG = tgetnum(nhStr("sg")); /* -1: not fnd; else # of spaces left by so */
if (!SO || !SE || (SG > 0)) if (!SO || !SE || (SG > 0))
SO = SE = nh_US = nh_UE = nullstr; SO = SE = nh_US = nh_UE = nullstr;
TI = Tgetstr("ti"); /* nonconsequential cursor movement start */ TI = Tgetstr(nhStr("ti")); /* nonconsequential cursor movement start */
TE = Tgetstr("te"); /* nonconsequential cursor movement end */ TE = Tgetstr(nhStr("te")); /* nonconsequential cursor movement end */
VS = VE = nullstr; VS = VE = nullstr;
#ifdef TERMINFO #ifdef TERMINFO
VS = Tgetstr("eA"); /* enable graphics */ VS = Tgetstr(nhStr("eA")); /* enable graphics */
#endif #endif
KS = Tgetstr("ks"); /* keypad start (special mode) */ KS = Tgetstr(nhStr("ks")); /* keypad start (special mode) */
KE = Tgetstr("ke"); /* keypad end (ordinary mode [ie, digits]) */ KE = Tgetstr(nhStr("ke")); /* keypad end (ordinary mode [ie, digits]) */
MR = Tgetstr("mr"); /* reverse */ MR = Tgetstr(nhStr("mr")); /* reverse */
MB = Tgetstr("mb"); /* blink */ MB = Tgetstr(nhStr("mb")); /* blink */
MD = Tgetstr("md"); /* boldface */ MD = Tgetstr(nhStr("md")); /* boldface */
if (!SO) if (!SO)
SO = MD; SO = MD;
MH = Tgetstr("mh"); /* dim */ MH = Tgetstr(nhStr("mh")); /* dim */
ME = Tgetstr("me"); /* turn off all attributes */ ME = Tgetstr(nhStr("me")); /* turn off all attributes */
if (!ME) if (!ME)
ME = SE ? SE : nullstr; /* default to SE value */ ME = SE ? SE : nullstr; /* default to SE value */
@@ -293,9 +294,9 @@ tty_startup(int *wid, int *hgt)
nh_HE = dupstr(&ME[i]); nh_HE = dupstr(&ME[i]);
dynamic_HIHE = TRUE; dynamic_HIHE = TRUE;
AS = Tgetstr("as"); /* alt charset start */ AS = Tgetstr(nhStr("as")); /* alt charset start */
AE = Tgetstr("ae"); /* alt charset end */ AE = Tgetstr(nhStr("ae")); /* alt charset end */
nh_CD = Tgetstr("cd"); /* clear lines from cursor and down */ nh_CD = Tgetstr(nhStr("cd")); /* clear lines from cursor and down */
#ifdef TEXTCOLOR #ifdef TEXTCOLOR
#if defined(TOS) && defined(__GNUC__) #if defined(TOS) && defined(__GNUC__)
if (!strcmp(term, "builtin") || !strcmp(term, "tw52") if (!strcmp(term, "builtin") || !strcmp(term, "tw52")
@@ -309,7 +310,7 @@ tty_startup(int *wid, int *hgt)
*wid = CO; *wid = CO;
*hgt = LI; *hgt = LI;
/* cl: clear screen, set cursor to upper left */ /* cl: clear screen, set cursor to upper left */
if (!(CL = Tgetstr("cl"))) /* last thing set */ if (!(CL = Tgetstr(nhStr("cl")))) /* last thing set */
error("NetHack needs CL."); error("NetHack needs CL.");
if ((int) (tbufptr - tbuf) > (int) (sizeof tbuf)) if ((int) (tbufptr - tbuf) > (int) (sizeof tbuf))
error("TERMCAP entry too big...\n"); error("TERMCAP entry too big...\n");
@@ -451,10 +452,10 @@ tty_ascgraphics_hilite_fixup(void)
for (c = 0; c < CLR_MAX / 2; c++) for (c = 0; c < CLR_MAX / 2; c++)
if (c != CLR_BLACK) { if (c != CLR_BLACK) {
hilites[c | BRIGHT] = (char *) alloc(sizeof("\033[1;3%dm")); hilites[c | BRIGHT] = (char *) alloc(sizeof "\033[1;3%dm");
Sprintf(hilites[c | BRIGHT], "\033[1;3%dm", c); Sprintf(hilites[c | BRIGHT], "\033[1;3%dm", c);
if (c != CLR_GRAY) { if (c != CLR_GRAY) {
hilites[c] = (char *) alloc(sizeof("\033[0;3%dm")); hilites[c] = (char *) alloc(sizeof "\033[0;3%dm");
Sprintf(hilites[c], "\033[0;3%dm", c); Sprintf(hilites[c], "\033[0;3%dm", c);
} }
} }
@@ -893,13 +894,13 @@ init_hilite(void)
int c, colors; int c, colors;
char *setf, *scratch; char *setf, *scratch;
colors = tgetnum("Co"); colors = tgetnum(nhStr("Co"));
iflags.colorcount = colors; iflags.colorcount = colors;
int md_len = 0; int md_len = 0;
if (colors < 8 || (MD == NULL) || (strlen(MD) == 0) if (colors < 8 || (MD == NULL) || (strlen(MD) == 0)
|| ((setf = tgetstr("AF", (char **) 0)) == (char *) 0 || ((setf = tgetstr(nhStr("AF"), (char **) 0)) == (char *) 0
&& (setf = tgetstr("Sf", (char **) 0)) == (char *) 0)) { && (setf = tgetstr(nhStr("Sf"), (char **) 0)) == (char *) 0)) {
/* Fallback when colors not available /* Fallback when colors not available
* It's arbitrary to collapse all colors except gray * It's arbitrary to collapse all colors except gray
* together, but that's what the previous code did. * together, but that's what the previous code did.
@@ -1009,7 +1010,7 @@ kill_hilite(void)
if (hilites[CLR_BLACK] != hilites[CLR_BLUE]) if (hilites[CLR_BLACK] != hilites[CLR_BLUE])
free(hilites[CLR_BLACK]); free(hilites[CLR_BLACK]);
} }
if (tgetnum("Co") >= 16) { if (tgetnum(nhStr("Co")) >= 16) {
if (hilites[CLR_BLUE]) if (hilites[CLR_BLUE])
free(hilites[CLR_BLUE]); free(hilites[CLR_BLUE]);
if (hilites[CLR_GREEN]) if (hilites[CLR_GREEN])
@@ -1135,7 +1136,7 @@ init_hilite(void)
hilites[0] = NOCOL; hilites[0] = NOCOL;
for (c = 1; c < SIZE(hilites); c++) { for (c = 1; c < SIZE(hilites); c++) {
char *foo; char *foo;
foo = (char *) alloc(sizeof("\033b0")); foo = (char *) alloc(sizeof "\033b0");
if (tos_numcolors > 4) if (tos_numcolors > 4)
Sprintf(foo, "\033b%c", (c & ~BRIGHT) + '0'); Sprintf(foo, "\033b%c", (c & ~BRIGHT) + '0');
else else
@@ -1181,7 +1182,7 @@ init_hilite(void)
if (c == foreg) if (c == foreg)
hilites[c] = (char *) 0; hilites[c] = (char *) 0;
else if (c != hi_foreg || backg != hi_backg) { else if (c != hi_foreg || backg != hi_backg) {
hilites[c] = (char *) alloc(sizeof("\033[%d;3%d;4%dm")); hilites[c] = (char *) alloc(sizeof "\033[%d;3%d;4%dm");
Sprintf(hilites[c], "\033[%d", !!(c & BRIGHT)); Sprintf(hilites[c], "\033[%d", !!(c & BRIGHT));
if ((c | BRIGHT) != (foreg | BRIGHT)) if ((c | BRIGHT) != (foreg | BRIGHT))
Sprintf(eos(hilites[c]), ";3%d", c & ~BRIGHT); Sprintf(eos(hilites[c]), ";3%d", c & ~BRIGHT);