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
+7 -7
View File
@@ -815,7 +815,7 @@ load_default_resources(void)
++numdefs;
}
linelen += strlen(inbuf);
if (!index(inbuf, '\n'))
if (!strchr(inbuf, '\n'))
continue;
if (linelen > longlen)
longlen = linelen;
@@ -2128,7 +2128,7 @@ yn_key(Widget w, XEvent *event, String *params, Cardinal *num_params)
}
if (!yn_choices /* accept any input */
|| (yn_no_default && (ch == '\033' || index(yn_quitchars, ch)))) {
|| (yn_no_default && (ch == '\033' || strchr(yn_quitchars, ch)))) {
yn_return = ch;
} else {
if (!yn_preserve_case)
@@ -2137,9 +2137,9 @@ yn_key(Widget w, XEvent *event, String *params, Cardinal *num_params)
if (ch == '\033') {
yn_getting_num = FALSE;
yn_return = yn_esc_map;
} else if (index(yn_quitchars, ch)) {
} else if (strchr(yn_quitchars, ch)) {
yn_return = yn_def;
} else if (index(yn_choices, ch)) {
} else if (strchr(yn_choices, ch)) {
if (ch == '#') {
if (yn_getting_num) { /* don't select again */
X11_nhbell();
@@ -2235,7 +2235,7 @@ X11_yn_function_core(
yn_preserve_case = TRUE;
break;
}
if ((cb = index(choicebuf, '\033')) != 0)
if ((cb = strchr(choicebuf, '\033')) != 0)
*cb = '\0';
/* ques [choices] (def) */
int ln = ((int) strlen(ques) /* prompt text */
@@ -2252,8 +2252,8 @@ X11_yn_function_core(
Strcat(buf, " ");
/* escape maps to 'q' or 'n' or default, in that order */
yn_esc_map = (index(choices, 'q') ? 'q'
: index(choices, 'n') ? 'n'
yn_esc_map = (strchr(choices, 'q') ? 'q'
: strchr(choices, 'n') ? 'n'
: def);
} else {
int ln = ((int) strlen(ques) /* prompt text */
+5 -5
View File
@@ -275,7 +275,7 @@ menu_key(Widget w, XEvent *event, String *params, Cardinal *num_params)
some menus use digits as potential group accelerators
but their entries don't rely on counts */
if (!menu_info->counting
&& index(menu_info->curr_menu.gacc, ch))
&& strchr(menu_info->curr_menu.gacc, ch))
goto group_accel;
menu_info->menu_count *= 10L;
menu_info->menu_count += (long) (ch - '0');
@@ -338,7 +338,7 @@ menu_key(Widget w, XEvent *event, String *params, Cardinal *num_params)
XtCallCallbacks(hbar, XtNjumpProc, &left);
}
return;
} else if (index(menu_info->curr_menu.gacc, ch)) {
} else if (strchr(menu_info->curr_menu.gacc, ch)) {
group_accel:
/* matched a group accelerator */
if (menu_info->how == PICK_ANY || menu_info->how == PICK_ONE) {
@@ -758,7 +758,7 @@ x11_scroll_perminv(int arg UNUSED) /* arg is always 1 */
this loop, so handle only one character at a time for !slow */
if (!appResources.slow)
break;
} while (ch && !index(quitchars, ch));
} while (ch && !strchr(quitchars, ch));
return;
}
@@ -940,11 +940,11 @@ X11_select_menu(winid window, int how, menu_item **menu_list)
if (n > 0) /* at least one group accelerator found */
for (ap = gacc, curr = menu_info->new_menu.base; curr;
curr = curr->next)
if (curr->gselector && !index(gacc, curr->gselector)
if (curr->gselector && !strchr(gacc, curr->gselector)
&& (menu_info->how == PICK_ANY
|| gcnt[GSELIDX(curr->gselector)] == 1)) {
*ap++ = curr->gselector;
*ap = '\0'; /* re-terminate for index() */
*ap = '\0'; /* re-terminate for strchr() */
}
}
menu_info->new_menu.gacc = copy_of(gacc);
+25 -25
View File
@@ -24,7 +24,7 @@
#include <X11/Xaw/Viewport.h>
#include <X11/Xaw/Cardinals.h>
#include <X11/Xaw/List.h>
#include <X11/Xos.h> /* for index() */
#include <X11/Xos.h> /* for strchr() */
#include <X11/Xatom.h>
#ifdef PRESERVE_NO_SYSV
@@ -181,13 +181,13 @@ ps_key(Widget w, XEvent *event, String *params, Cardinal *num_params)
nhUse(params);
nhUse(num_params);
(void) memset(rolechars, '\0', sizeof rolechars); /* for index() */
(void) memset(rolechars, '\0', sizeof rolechars); /* for strchr() */
for (i = 0; roles[i].name.m; ++i) {
ch = lowc(*roles[i].name.m);
/* if (flags.female && roles[i].name.f) ch = lowc(*roles[i].name.f);
*/
/* this supports at most two roles with the same first letter */
if (index(rolechars, ch))
if (strchr(rolechars, ch))
ch = highc(ch);
rolechars[i] = ch;
}
@@ -196,15 +196,15 @@ ps_key(Widget w, XEvent *event, String *params, Cardinal *num_params)
/* don't beep */
return;
}
mark = index(rolechars, ch);
mark = strchr(rolechars, ch);
if (!mark)
mark = index(rolechars, lowc(ch));
mark = strchr(rolechars, lowc(ch));
if (!mark)
mark = index(rolechars, highc(ch));
mark = strchr(rolechars, highc(ch));
if (!mark) {
if (index(ps_randchars, ch))
if (strchr(ps_randchars, ch))
ps_selected = PS_RANDOM;
else if (index(ps_quitchars, ch))
else if (strchr(ps_quitchars, ch))
ps_selected = PS_QUIT;
else {
X11_nhbell(); /* no such class */
@@ -227,11 +227,11 @@ race_key(Widget w, XEvent *event, String *params, Cardinal *num_params)
nhUse(params);
nhUse(num_params);
(void) memset(racechars, '\0', sizeof racechars); /* for index() */
(void) memset(racechars, '\0', sizeof racechars); /* for strchr() */
for (i = 0; races[i].noun; ++i) {
ch = lowc(*races[i].noun);
/* this supports at most two races with the same first letter */
if (index(racechars, ch))
if (strchr(racechars, ch))
ch = highc(ch);
racechars[i] = ch;
}
@@ -240,15 +240,15 @@ race_key(Widget w, XEvent *event, String *params, Cardinal *num_params)
/* don't beep */
return;
}
mark = index(racechars, ch);
mark = strchr(racechars, ch);
if (!mark)
mark = index(racechars, lowc(ch));
mark = strchr(racechars, lowc(ch));
if (!mark)
mark = index(racechars, highc(ch));
mark = strchr(racechars, highc(ch));
if (!mark) {
if (index(ps_randchars, ch))
if (strchr(ps_randchars, ch))
ps_selected = PS_RANDOM;
else if (index(ps_quitchars, ch))
else if (strchr(ps_quitchars, ch))
ps_selected = PS_QUIT;
else {
X11_nhbell(); /* no such race */
@@ -275,13 +275,13 @@ gend_key(Widget w, XEvent *event, String *params, Cardinal *num_params)
/* don't beep */
return;
}
mark = index(gendchars, ch);
mark = strchr(gendchars, ch);
if (!mark)
mark = index(gendchars, lowc(ch));
mark = strchr(gendchars, lowc(ch));
if (!mark) {
if (index(ps_randchars, ch))
if (strchr(ps_randchars, ch))
ps_selected = PS_RANDOM;
else if (index(ps_quitchars, ch))
else if (strchr(ps_quitchars, ch))
ps_selected = PS_QUIT;
else {
X11_nhbell(); /* no such gender */
@@ -308,13 +308,13 @@ algn_key(Widget w, XEvent *event, String *params, Cardinal *num_params)
/* don't beep */
return;
}
mark = index(algnchars, ch);
mark = strchr(algnchars, ch);
if (!mark)
mark = index(algnchars, highc(ch));
mark = strchr(algnchars, highc(ch));
if (!mark) {
if (index(ps_randchars, ch))
if (strchr(ps_randchars, ch))
ps_selected = PS_RANDOM;
else if (index(ps_quitchars, ch))
else if (strchr(ps_quitchars, ch))
ps_selected = PS_QUIT;
else {
X11_nhbell(); /* no such alignment */
@@ -1787,7 +1787,7 @@ ec_key(Widget w, XEvent *event, String *params, Cardinal *num_params)
} else if (ch == '?') {
extend_help((Widget) 0, (XtPointer) 0, (XtPointer) 0);
return;
} else if (index("\033\n\r", ch)) {
} else if (strchr("\033\n\r", ch)) {
if (ch == '\033') {
/* unselect while still visible */
if (extended_cmd_selected >= 0)
@@ -2191,7 +2191,7 @@ make_menu(const char *popup_name, const char *popup_label,
XSetWMProtocols(XtDisplay(popup), XtWindow(popup), &wm_delete_window, 1);
/* during role selection, highlight "random" as pre-selected choice */
if (right_callback == ps_random && index(ps_randchars, '\n'))
if (right_callback == ps_random && strchr(ps_randchars, '\n'))
swap_fg_bg(right);
return popup;
+2 -2
View File
@@ -384,7 +384,7 @@ append_text_buffer(struct text_buffer *tb, const char *str, boolean concat)
if (tb->num_lines) { /* not first --- append a newline */
char appchar = '\n';
if (concat && !index("!.?'\")", tb->text[tb->text_last - 1])) {
if (concat && !strchr("!.?'\")", tb->text[tb->text_last - 1])) {
appchar = ' ';
tb->num_lines--; /* offset increment at end of function */
}
@@ -398,7 +398,7 @@ append_text_buffer(struct text_buffer *tb, const char *str, boolean concat)
if (length) {
/* Remove all newlines. Otherwise we have a confused line count. */
copy = (tb->text + tb->text_last);
while ((copy = index(copy, '\n')) != (char *) 0)
while ((copy = strchr(copy, '\n')) != (char *) 0)
*copy = ' ';
}