some C99 changes

Instead of using index() macro defined to strchr, use C99 strchr.
Instead of using rindex() macro defined to strrchr, use C99 strrchr.

If you want to try building on a platform that doesn't offer those
two functions, these are available:
    define NOT_C99       /* to make some non-C99 code available */
    define NEED_INDEX    /* to define a macro for index()  */
    define NEED_RINDX    /* to define a macro for rindex() */
This commit is contained in:
nhmall
2022-10-29 10:54:25 -04:00
parent 943c1bc3c3
commit 99a93fe50b
99 changed files with 463 additions and 460 deletions

View File

@@ -149,7 +149,7 @@ char *path;
strncpy(fileName, path, sizeof(fileName) - 1);
fileName[31] = 0;
if (colon = index(fileName, ':'))
if (colon = strchr(fileName, ':'))
colon[1] = '\0';
else
fileName[0] = '\0';
@@ -511,6 +511,6 @@ register char *s;
{
register char *lp;
while ((lp = index(s, ':')) || (lp = index(s, '/')))
while ((lp = strchr(s, ':')) || (lp = strchr(s, '/')))
*lp = '_';
}

View File

@@ -476,7 +476,7 @@ amii_player_selection()
#if 0 /* OBSOLETE */
if( *g.pl_character ){
g.pl_character[ 0 ] = toupper( g.pl_character[ 0 ] );
if( index( pl_classes, g.pl_character[ 0 ] ) )
if( strchr( pl_classes, g.pl_character[ 0 ] ) )
return;
}
#endif
@@ -528,7 +528,7 @@ amii_player_selection()
switch( class )
{
case VANILLAKEY:
if( index( pl_classes, toupper( code ) ) )
if( strchr( pl_classes, toupper( code ) ) )
{
g.pl_character[0] = toupper( code );
aredone = 1;
@@ -1016,10 +1016,10 @@ char def;
if (resp) {
char *rb, respbuf[QBUFSZ];
allow_num = (index(resp, '#') != 0);
allow_num = (strchr(resp, '#') != 0);
Strcpy(respbuf, resp);
/* any acceptable responses that follow <esc> aren't displayed */
if ((rb = index(respbuf, '\033')) != 0)
if ((rb = strchr(respbuf, '\033')) != 0)
*rb = '\0';
(void) strncpy(prompt, query, QBUFSZ - 1);
prompt[QBUFSZ - 1] = '\0';
@@ -1062,18 +1062,18 @@ char def;
#endif /*0*/
digit_ok = allow_num && isdigit(q);
if (q == '\033') {
if (index(resp, 'q'))
if (strchr(resp, 'q'))
q = 'q';
else if (index(resp, 'n'))
else if (strchr(resp, 'n'))
q = 'n';
else
q = def;
break;
} else if (index(quitchars, q)) {
} else if (strchr(quitchars, q)) {
q = def;
break;
}
if (!index(resp, q) && !digit_ok) {
if (!strchr(resp, q) && !digit_ok) {
amii_bell();
q = (char) 0;
} else if (q == '#' || digit_ok) {
@@ -1099,7 +1099,7 @@ char def;
break; /* overflow: try again */
digit_string[0] = z;
amii_addtopl(digit_string), n_len++;
} else if (z == 'y' || index(quitchars, z)) {
} else if (z == 'y' || strchr(quitchars, z)) {
if (z == '\033')
value = -1; /* abort */
z = '\n'; /* break */
@@ -1176,7 +1176,7 @@ boolean complain;
cw->morestr = (char *) fn;
while (dlb_fgets(buf, sizeof(buf), fp) != NULL) {
if (t = index(buf, '\n'))
if (t = strchr(buf, '\n'))
*t = 0;
amii_putstr(win, 0, buf);
}
@@ -1362,9 +1362,9 @@ amii_player_selection()
cursor_on(WIN_MESSAGE);
pick4u = lowc(WindowGetchar());
cursor_off(WIN_MESSAGE);
if (index(quitchars, pick4u))
if (strchr(quitchars, pick4u))
pick4u = 'y';
} while (!index(ynqchars, pick4u));
} while (!strchr(ynqchars, pick4u));
pbuf[0] = pick4u;
pbuf[1] = 0;
amii_addtopl(pbuf);

View File

@@ -229,7 +229,7 @@ char *str;
char *ptr;
char drive;
if ((ptr = index(str, ':')) != (char *) 0) {
if ((ptr = strchr(str, ':')) != (char *) 0) {
drive = toupper(*(ptr - 1));
(void) Dsetdrv(drive - 'A');
}

View File

@@ -124,7 +124,7 @@ error VA_DECL(const char *, line)
{ /* opening brace for vprogerror(), nested block for USE_OLDARG error() */
char pbuf[BUFSZ];
if(index(line, '%')) {
if(strchr(line, '%')) {
Vsprintf(pbuf,line,VA_ARGS);
line = pbuf;
}

View File

@@ -298,7 +298,7 @@ char *str;
char *ptr;
char drive;
if ((ptr = index(str, ':')) != (char *) 0) {
if ((ptr = strchr(str, ':')) != (char *) 0) {
drive = toupper(*(ptr - 1));
#ifdef OS2_32BITAPI
DosSetDefaultDisk((ULONG)(drive - 'A' + 1));

View File

@@ -193,22 +193,22 @@ mswin_color_from_string(char *colorstring, HBRUSH *brushptr,
return;
red_value =
index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
strchr(hexadecimals, tolower(*colorstring++)) - hexadecimals;
red_value *= 16;
red_value +=
index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
strchr(hexadecimals, tolower(*colorstring++)) - hexadecimals;
green_value =
index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
strchr(hexadecimals, tolower(*colorstring++)) - hexadecimals;
green_value *= 16;
green_value +=
index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
strchr(hexadecimals, tolower(*colorstring++)) - hexadecimals;
blue_value =
index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
strchr(hexadecimals, tolower(*colorstring++)) - hexadecimals;
blue_value *= 16;
blue_value +=
index(hexadecimals, tolower(*colorstring++)) - hexadecimals;
strchr(hexadecimals, tolower(*colorstring++)) - hexadecimals;
*colorptr = RGB(red_value, blue_value, green_value);
} else {

View File

@@ -316,9 +316,9 @@ prompt_for_player_selection(void)
/* tty_putstr(BASE_WINDOW, 0, prompt); */
do {
/* pick4u = lowc(readchar()); */
if (index(quitchars, pick4u))
if (strchr(quitchars, pick4u))
pick4u = 'y';
} while (!index(ynqchars, pick4u));
} while (!strchr(ynqchars, pick4u));
if ((int) strlen(prompt) + 1 < CO) {
/* Echo choice and move back down line */
/* tty_putsym(BASE_WINDOW, (int)strlen(prompt)+1, echoline,
@@ -1377,7 +1377,7 @@ mswin_yn_function(const char *question, const char *choices, CHAR_P def)
if (choices) {
char *cb, choicebuf[QBUFSZ];
Strcpy(choicebuf, choices);
if ((cb = index(choicebuf, '\033')) != 0) {
if ((cb = strchr(choicebuf, '\033')) != 0) {
/* anything beyond <esc> is hidden */
*cb = '\0';
}
@@ -1389,7 +1389,7 @@ mswin_yn_function(const char *question, const char *choices, CHAR_P def)
Strcat(message, " ");
/* escape maps to 'q' or 'n' or default, in that order */
yn_esc_map =
(index(choices, 'q') ? 'q' : (index(choices, 'n') ? 'n' : def));
(strchr(choices, 'q') ? 'q' : (strchr(choices, 'n') ? 'n' : def));
} else {
Strcpy(message, question);
}
@@ -1399,7 +1399,7 @@ mswin_yn_function(const char *question, const char *choices, CHAR_P def)
char buf[BUFSZ];
ZeroMemory(buf, sizeof(buf));
if (choices) {
if (!index(choices, '\033'))
if (!strchr(choices, '\033'))
buf[0] = '\033'; /* make sure ESC is always available */
strncat(buf, choices, sizeof(buf) - 2);
NHSPhoneSetKeypadFromString(buf);
@@ -1431,7 +1431,7 @@ mswin_yn_function(const char *question, const char *choices, CHAR_P def)
ch = mswin_nhgetch();
if (ch == '\033') {
result = yn_esc_map;
} else if (choices && !index(choices, ch)) {
} else if (choices && !strchr(choices, ch)) {
/* FYI: ch==-115 is for KP_ENTER */
if (def
&& (ch == ' ' || ch == '\r' || ch == '\n' || ch == -115)) {

View File

@@ -4799,11 +4799,11 @@ void NetHackQtBind::qt_display_file(const char *filename, BOOLEAN_P must_exist)
complain = must_exist;
} else {
while (dlb_fgets(buf, BUFSZ, f)) {
if ((cr = index(buf, '\n')) != 0) *cr = 0;
if ((cr = strchr(buf, '\n')) != 0) *cr = 0;
#ifdef MSDOS
if ((cr = index(buf, '\r')) != 0) *cr = 0;
if ((cr = strchr(buf, '\r')) != 0) *cr = 0;
#endif
if (index(buf, '\t') != 0) (void) tabexpand(buf);
if (strchr(buf, '\t') != 0) (void) tabexpand(buf);
window->PutStr(ATR_NONE, buf);
}
window->Display(FALSE);
@@ -4981,7 +4981,7 @@ char NetHackQtBind::qt_yn_function(const char *question, const char *choices, CH
if (choices) {
char *cb, choicebuf[QBUFSZ];
Strcpy(choicebuf, choices);
if ((cb = index(choicebuf, '\033')) != 0) {
if ((cb = strchr(choicebuf, '\033')) != 0) {
// anything beyond <esc> is hidden
*cb = '\0';
}
@@ -4991,8 +4991,8 @@ char NetHackQtBind::qt_yn_function(const char *question, const char *choices, CH
if (def) Sprintf(eos(message), " (%c)", def);
Strcat(message, " ");
// escape maps to 'q' or 'n' or default, in that order
yn_esc_map = (index(choices, 'q') ? 'q' :
(index(choices, 'n') ? 'n' : def));
yn_esc_map = (strchr(choices, 'q') ? 'q' :
(strchr(choices, 'n') ? 'n' : def));
} else {
Strcpy(message, question);
}
@@ -5024,7 +5024,7 @@ char NetHackQtBind::qt_yn_function(const char *question, const char *choices, CH
char ch=NetHackQtBind::qt_nhgetch();
if (ch=='\033') {
result=yn_esc_map;
} else if (choices && !index(choices,ch)) {
} else if (choices && !strchr(choices,ch)) {
if (def && (ch==' ' || ch=='\r' || ch=='\n')) {
result=def;
} else {

View File

@@ -736,9 +736,9 @@ boolean complain;
datawin = Gem_create_nhwindow(NHW_TEXT);
while (dlb_fgets(buf, BUFSZ, f)) {
if ((cr = index(buf, '\n')) != 0)
if ((cr = strchr(buf, '\n')) != 0)
*cr = 0;
if (index(buf, '\t') != 0)
if (strchr(buf, '\t') != 0)
(void) tabexpand(buf);
Gem_putstr(datawin, 0, buf);
}

View File

@@ -1032,7 +1032,7 @@ gnome_yn_function(const char *question, const char *choices, CHAR_P def)
if (choices) {
char *cb, choicebuf[QBUFSZ];
Strcpy(choicebuf, choices);
if ((cb = index(choicebuf, '\033')) != 0) {
if ((cb = strchr(choicebuf, '\033')) != 0) {
/* anything beyond <esc> is hidden */
*cb = '\0';
}
@@ -1044,13 +1044,13 @@ gnome_yn_function(const char *question, const char *choices, CHAR_P def)
Strcat(message, " ");
/* escape maps to 'q' or 'n' or default, in that order */
yn_esc_map =
(index(choices, 'q') ? 'q' : (index(choices, 'n') ? 'n' : def));
(strchr(choices, 'q') ? 'q' : (strchr(choices, 'n') ? 'n' : def));
} else {
Strcpy(message, question);
}
gnome_putstr(WIN_MESSAGE, ATR_BOLD, message);
if (mainWnd != NULL && choices && !index(choices, ch)) {
if (mainWnd != NULL && choices && !strchr(choices, ch)) {
return (ghack_yes_no_dialog(question, choices, def));
}
@@ -1059,7 +1059,7 @@ gnome_yn_function(const char *question, const char *choices, CHAR_P def)
ch = gnome_nhgetch();
if (ch == '\033') {
result = yn_esc_map;
} else if (choices && !index(choices, ch)) {
} else if (choices && !strchr(choices, ch)) {
/* FYI: ch==-115 is for KP_ENTER */
if (def
&& (ch == ' ' || ch == '\r' || ch == '\n' || ch == -115)) {