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() */
#define HLOCK "NHPERM"
#endif
-#ifndef index
-#define index strchr
-#endif
-#ifndef rindex
-#define rindex strrchr
-#endif
-
#ifndef AMIGA
#include <time.h>
#endif
#ifndef SYSTEM_H
#define SYSTEM_H
+#ifdef NOT_C99
+#ifdef NEED_INDEX
+#define strchr index
+#endif
+#ifdef NEED_RINDX
+#define strrchr rindex
+#endif
+#endif /* NOT_C99 */
+
#if !defined(WIN32)
#if !defined(__cplusplus) && !defined(__GO32__)
#define E extern
E char *strncat(char *, const char *, size_t);
E char *strpbrk(const char *, const char *);
+#ifdef NOT_C99
#if defined(SYSV) || defined(MICRO) || defined(MAC) || defined(VMS) \
|| defined(HPUX)
E char *strchr(const char *, int);
E char *index(const char *, int);
E char *rindex(const char *, int);
#endif
+#endif
E int strcmp(const char *, const char *);
E int strncmp(const char *, const char *, size_t);
#endif /* !_XtIntrinsic_h_ && !POSIX_TYPES */
+#ifdef NOT_C99
#if defined(ULTRIX) && defined(__GNUC__)
E char *index(const char *, int);
E char *rindex(const char *, int);
#endif
+#endif
/* Old varieties of BSD have char *sprintf().
* Newer varieties of BSD have int sprintf() but allow for the old char *.
#include <memory.h>
#endif
#else /* therefore SYSV */
+#ifdef NOT_C99
#ifndef index /* some systems seem to do this for you */
#define index strchr
#endif
#ifndef rindex
#define rindex strrchr
#endif
-#endif
+#endif /* NOT_C99 */
+#endif /* SYSV */
/* Use the high quality random number routines. */
/* the high quality random number routines */
#include "system.h"
-#define index strchr
-#define rindex strrchr
-
/* Use the high quality random number routines. */
#ifndef USE_ISAAC64
# if defined(RANDOM)
#endif
#define NO_SIGNAL
-#define index strchr
-#define rindex strrchr
/* Time stuff */
#include <time.h>
strncpy(fileName, path, sizeof(fileName) - 1);
fileName[31] = 0;
- if (colon = index(fileName, ':'))
+ if (colon = strchr(fileName, ':'))
colon[1] = '\0';
else
fileName[0] = '\0';
{
register char *lp;
- while ((lp = index(s, ':')) || (lp = index(s, '/')))
+ while ((lp = strchr(s, ':')) || (lp = strchr(s, '/')))
*lp = '_';
}
#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
switch( class )
{
case VANILLAKEY:
- if( index( pl_classes, toupper( code ) ) )
+ if( strchr( pl_classes, toupper( code ) ) )
{
g.pl_character[0] = toupper( code );
aredone = 1;
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';
#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) {
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 */
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);
}
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);
char *ptr;
char drive;
- if ((ptr = index(str, ':')) != (char *) 0) {
+ if ((ptr = strchr(str, ':')) != (char *) 0) {
drive = toupper(*(ptr - 1));
(void) Dsetdrv(drive - 'A');
}
{ /* 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;
}
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));
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 {
/* 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,
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';
}
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);
}
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);
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)) {
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);
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';
}
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);
}
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 {
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);
}
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';
}
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));
}
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)) {
}
if (match) {
- const char *extended_opt = index(userea, ':');
+ const char *extended_opt = strchr(userea, ':');
if (!extended_opt)
- extended_opt = index(userea, '=');
+ extended_opt = strchr(userea, '=');
switch(e_arg) {
case ARG_DEBUG:
if (extended_opt) {
char *op;
boolean negated = FALSE;
- while ((op = index(opts, ',')) != 0) {
+ while ((op = strchr(opts, ',')) != 0) {
*op++ = 0;
/* recurse */
debug_fields(op);
const char *s = str;
while (*s) {
- if (!index("<>=-+0123456789%", *s))
+ if (!strchr("<>=-+0123456789%", *s))
return FALSE;
s++;
}
maxsf = (maxsf == 0) ? MAX_SUBFIELDS : min(maxsf, MAX_SUBFIELDS);
- if (index(str, '+') || index(str, '&')) {
+ if (strchr(str, '+') || strchr(str, '&')) {
char *c = str;
sf = 0;
goto choose_value;
}
/* restore suffix for use in color and attribute prompts */
- if (!index(numstart, '%'))
+ if (!strchr(numstart, '%'))
Strcat(numstart, "%");
/* reject negative values except for AC and >-1; reject 0 for < */
if (wizard) {
char c = yn_function(prmpt, choices, '\0', TRUE);
- if (c && index(choices, c)) {
+ if (c && strchr(choices, c)) {
c -= '0';
if (!c)
register char *autoc;
/* break off first autocomplete from the rest; parse the rest */
- if ((autoc = index(autocomplete, ',')) != 0
- || (autoc = index(autocomplete, ':')) != 0) {
+ if ((autoc = strchr(autocomplete, ',')) != 0
+ || (autoc = strchr(autocomplete, ':')) != 0) {
*autoc++ = '\0';
parseautocomplete(autoc, condition);
}
} else if (!(is_mov = movecmd(dirsym, MV_ANY)) && !u.dz) {
boolean did_help = FALSE, help_requested;
- if (!index(quitchars, dirsym)) {
+ if (!strchr(quitchars, dirsym)) {
help_requested = (dirsym == g.Cmd.spkeys[NHKF_GETDIR_HELP]);
if (help_requested || iflags.cmdassist) {
did_help = help_dir((s && *s == '^') ? dirsym : '\0',
sym = highc(sym); /* @A-Z[ (note: letter() accepts '@') */
ctrl = (sym - 'A') + 1; /* 0-27 (note: 28-31 aren't applicable) */
if ((explain = dowhatdoes_core(ctrl, buf2)) != 0
- && (!index(wiz_only_list, sym) || wizard)) {
+ && (!strchr(wiz_only_list, sym) || wizard)) {
Sprintf(buf, "Are you trying to use ^%c%s?", sym,
- index(wiz_only_list, sym) ? ""
+ strchr(wiz_only_list, sym) ? ""
: " as specified in the Guidebook");
putstr(win, 0, buf);
putstr(win, 0, "");
backspaced = TRUE;
} else if (key == g.Cmd.spkeys[NHKF_ESC]) {
break;
- } else if (!allowchars || index(allowchars, key)) {
+ } else if (!allowchars || strchr(allowchars, key)) {
*count = (cmdcount_nht) cnt;
if ((long) *count != cnt)
impossible("get_count: cmdcount_nht");
You("may look for an object, monster, or special map symbol.");
ch = yn_function("What do you look for?", (char *) 0, '\0', TRUE);
/* Don't filter out ' ' here; it has a use */
- if ((ch != def_monsyms[S_GHOST].sym) && index(quitchars, ch)) {
+ if ((ch != def_monsyms[S_GHOST].sym) && strchr(quitchars, ch)) {
if (Verbose(0, use_crystal_ball2))
pline1(Never_mind);
return;
*bp = '\0';
#if defined(MSDOS) || defined(WIN32)
- if ((bp = index(buf, '\r')) != 0) {
+ if ((bp = strchr(buf, '\r')) != 0) {
*bp++ = '\n';
*bp = '\0';
}
mesg = halu_fam_msgs[which];
else
mesg = fam_msgs[which];
- if (mesg && index(mesg, '%')) {
+ if (mesg && strchr(mesg, '%')) {
Sprintf(buf, mesg, !Blind ? "looks" : "seems");
mesg = buf;
}
cy = ty;
break;
}
- if ((cp = index(pick_chars, c)) != 0) {
+ if ((cp = strchr(pick_chars, c)) != 0) {
/* '.' => 0, ',' => 1, ';' => 2, ':' => 3 */
result = pick_chars_def[(int) (cp - pick_chars)].ret;
break;
iflags.getloc_moveskip ? "S" : "Not s");
msg_given = TRUE;
goto nxtc;
- } else if ((cp = index(mMoOdDxX, c)) != 0) { /* 'm|M', 'o|O', &c */
+ } else if ((cp = strchr(mMoOdDxX, c)) != 0) { /* 'm|M', 'o|O', &c */
/* nearest or farthest monster or object or door or unexplored */
int gtmp = (int) (cp - mMoOdDxX), /* 0..7 */
gloc = gtmp >> 1; /* 0..3 */
cy = garr[gloc][gidx[gloc]].y;
goto nxtc;
} else {
- if (!index(quitchars, c)) {
+ if (!strchr(quitchars, c)) {
char matching[MAXPCHARS];
int pass, lo_x, lo_y, hi_x, hi_y, k = 0;
get_rnd_text(BOGUSMONFILE, buf, rn2_on_display_rng, MD_PAD_BOGONS);
if (!*mnam) {
Strcpy(buf, "bogon");
- } else if (index(bogon_codes, *mnam)) { /* strip prefix if present */
+ } else if (strchr(bogon_codes, *mnam)) { /* strip prefix if present */
if (code)
*code = *mnam;
++mnam;
{
if (!code)
return FALSE;
- return index("-+=", code) ? TRUE : FALSE;
+ return strchr("-+=", code) ? TRUE : FALSE;
}
/* name of a Rogue player */
for (i = opts; *i; i++)
if (!strncmp("name=", i, 5)) {
char *j;
- if ((j = index(i + 5, ',')) != 0)
+ if ((j = strchr(i + 5, ',')) != 0)
*j = (char) 0;
return i + 5;
}
}
} else {
if ((obj = g.level.objects[omx][omy]) != 0
- && !index(nofetch, obj->oclass)
+ && !strchr(nofetch, obj->oclass)
#ifdef MAIL_STRUCTURES
&& obj->otyp != SCR_MAIL
#endif
obj_extract_self(g.kickedobj);
newsym(x, y);
if (costly && (!costly_spot(u.ux, u.uy)
- || !index(u.urooms, *in_rooms(x, y, SHOPBASE))))
+ || !strchr(u.urooms, *in_rooms(x, y, SHOPBASE))))
addtobill(g.kickedobj, FALSE, FALSE, FALSE);
if (!flooreffects(g.kickedobj, u.ux, u.uy, "fall")) {
place_object(g.kickedobj, u.ux, u.uy);
if (costly) {
price += stolen_value(obj, x, y,
(costly_spot(u.ux, u.uy)
- && index(u.urooms,
+ && strchr(u.urooms,
*in_rooms(x, y, SHOPBASE))),
TRUE);
/* set obj->no_charge to 0 */
(void) stolen_value(
otmp, ox, oy,
(costly_spot(u.ux, u.uy)
- && index(u.urooms, *in_rooms(ox, oy, SHOPBASE))),
+ && strchr(u.urooms, *in_rooms(ox, oy, SHOPBASE))),
FALSE);
}
/* set otmp->no_charge to 0 */
/* [perhaps this should be moved into thitmonst or hmon] */
if (mon && mon->isshk
&& (!inside_shop(u.ux, u.uy)
- || !index(in_rooms(mon->mx, mon->my, SHOPBASE), *u.ushops)))
+ || !strchr(in_rooms(mon->mx, mon->my, SHOPBASE), *u.ushops)))
hot_pursuit(mon);
if (obj_gone)
return "no";
/* an() returns too much. index is ok in this case */
case 1:
- return index(vowels, *obj) ? "an" : "a";
+ return strchr(vowels, *obj) ? "an" : "a";
case 2:
return "some";
case 3:
*/
if (sscanf(g.multireasonbuf, "%u:%c", &reasonmid, &reasondummy) == 2
&& mtmp->m_id == reasonmid) {
- if ((p = index(g.multireasonbuf, ' ')) != 0)
+ if ((p = strchr(g.multireasonbuf, ' ')) != 0)
*p = '\0';
}
}
char disclose, *dop;
*defquery = 'n';
- if ((dop = index(disclosure_options, category)) != 0) {
+ if ((dop = strchr(disclosure_options, category)) != 0) {
idx = (int) (dop - disclosure_options);
if (idx < 0 || idx >= NUM_DISCLOSURE_OPTIONS) {
impossible(
continue;
/* rub out unreadable & small punctuation marks */
- if (index("?.,'`-|_", *s)) {
+ if (strchr("?.,'`-|_", *s)) {
*s = ' ';
continue;
}
if (*sp == ' ')
len -= 1;
- if (len == 0 || index(ebuf, '\033')) {
+ if (len == 0 || strchr(ebuf, '\033')) {
if (zapwand) {
if (!Blind)
pline("%s, then %s.", Tobjnam(otmp, "glow"),
}
/* A single `x' is the traditional signature of an illiterate person */
- if (len != 1 || (!index(ebuf, 'x') && !index(ebuf, 'X')))
+ if (len != 1 || (!strchr(ebuf, 'x') && !strchr(ebuf, 'X')))
if (!u.uconduct.literate++)
livelog_printf(LL_CONDUCT, "became literate by engraving \"%s\"",
ebuf);
}
if (!flooreffects(stmp->obj, x, y, "land")) {
if (obj_left_shop
- && index(u.urooms, *in_rooms(u.ux, u.uy, SHOPBASE))) {
+ && strchr(u.urooms, *in_rooms(u.ux, u.uy, SHOPBASE))) {
/* At the moment this only takes on gold. While it is
simple enough to call addtobill for other items that
leave the shop due to scatter(), by default the hero
(void) sprintf(op, "%c%02X", quotechar, *sp);
op += 3;
cnt += 3;
- } else if ((index(legal, *sp) != 0) || (index(hexdigits, *sp) != 0)) {
+ } else if ((strchr(legal, *sp) != 0) || (strchr(hexdigits, *sp) != 0)) {
*op++ = *sp;
*op = '\0';
cnt++;
{
char *tf;
- tf = rindex(file, '.');
+ tf = strrchr(file, '.');
if (!tf)
tf = eos(file);
Sprintf(tf, ".%d", lev);
{
char *tf;
- tf = rindex(g.lock, '.');
+ tf = strrchr(g.lock, '.');
if (!tf)
tf = eos(g.lock);
Sprintf(tf, ".bn");
{
#ifdef VMS
{
- char *semi_colon = rindex(g.SAVEF, ';');
+ char *semi_colon = strrchr(g.SAVEF, ';');
if (semi_colon)
*semi_colon = '\0';
#endif
#ifdef VMS
{
- char *semi_colon = rindex(lockname, ';');
+ char *semi_colon = strrchr(lockname, ';');
if (semi_colon)
*semi_colon = '\0';
}
Strcpy(tmp_config, "NetHack.cnf");
else
Sprintf(tmp_config, "%s%s%s", envp,
- !index(":]>/", envp[strlen(envp) - 1]) ? "/" : "",
+ !strchr(":]>/", envp[strlen(envp) - 1]) ? "/" : "",
"NetHack.cnf");
set_configfile_name(tmp_config);
if ((fp = fopen(configfile, "r")) != (FILE *) 0)
return;
#endif
/* Backward compatibility, ignore trailing ;n */
- if ((ptr = index(bufp, ';')) != 0)
+ if ((ptr = strchr(bufp, ';')) != 0)
*ptr = '\0';
if (strlen(bufp) > 0) {
g.fqn_prefix[prefixid] = (char *) alloc(strlen(bufp) + 2);
if (*a++ != '[')
return (char *) 0;
/* last character should be close bracket, ignoring any comment */
- z = index(a, ']');
+ z = strchr(a, ']');
if (!z)
return (char *) 0;
/* comment, if present, can be preceded by spaces */
{
char *bufp, *altp;
- bufp = index(buf, '=');
- altp = index(buf, ':');
+ bufp = strchr(buf, '=');
+ altp = strchr(buf, ':');
if (!bufp || (altp && altp < bufp))
bufp = altp;
} else if (match_varname(buf, "SAVE", 4)) {
char *ptr;
- if ((ptr = index(bufp, ';')) != 0) {
+ if ((ptr = strchr(bufp, ';')) != 0) {
*ptr = '\0';
}
/* if buf[] doesn't end in a period, exclamation point, or question mark,
we'll include a period (in the message, not appended to buf[]) */
punct = eos((char *) buf) - 1; /* eos(buf)-1 is valid; cast away const */
- punct = index(".!?", *punct) ? "" : ".";
+ punct = strchr(".!?", *punct) ? "" : ".";
if (!g.program_state.config_error_ready) {
/* either very early, where pline() will use raw_print(), or
{
p->cont = FALSE;
p->pbreak = FALSE;
- p->ep = index(p->inbuf, '\n');
+ p->ep = strchr(p->inbuf, '\n');
if (p->skip) { /* in case previous line was too long */
if (p->ep)
p->skip = FALSE; /* found newline; next line is normal */
if (!filenm)
return;
Strcpy(fnbuf, filenm);
- if (index(fnbuf, '.') == 0)
+ if (strchr(fnbuf, '.') == 0)
Strcat(fnbuf, ".log");
lfile = fopen_datafile(fnbuf, "a", TROUBLEPREFIX);
if (lfile) {
/* strip filename's path if present */
#ifdef UNIX
- if ((p = rindex(filename, '/')) != 0)
+ if ((p = strrchr(filename, '/')) != 0)
filename = p + 1;
#endif
#ifdef VMS
char *st = &line[7]; /* 7 from "%title " */
char *p1, *p2;
- if ((p1 = index(st, '(')) != 0) {
+ if ((p1 = strchr(st, '(')) != 0) {
*p1++ = '\0';
(void) mungspaces(st);
- if ((p2 = index(p1, ')')) != 0) {
+ if ((p2 = strchr(p1, ')')) != 0) {
*p2 = '\0';
passagecnt = atoi(p1);
scope = TITLESCOPE;
display_nhwindow(tribwin, FALSE);
/* put the final attribution line into message history,
analogous to the summary line from long quest messages */
- if (index(lastline, '['))
+ if (strchr(lastline, '['))
mungspaces(lastline); /* to remove leading spaces */
else /* construct one if necessary */
Sprintf(lastline, "[%s, by Terry Pratchett]", tribtitle);
- if ((p = rindex(lastline, ']')) != 0)
+ if ((p = strrchr(lastline, ']')) != 0)
Sprintf(p, "; passage #%d]", targetpassage);
putmsghistory(lastline, FALSE);
grasped = TRUE;
if (DEADMONSTER(mtmp))
continue;
if (mtmp->data == mdat
- && index(in_rooms(mtmp->mx, mtmp->my, 0), roomno + ROOMOFFSET))
+ && strchr(in_rooms(mtmp->mx, mtmp->my, 0), roomno + ROOMOFFSET))
return mtmp;
}
return (struct monst *) 0;
for (x = min_x; x <= max_x; x += step) {
lev = &levl[x][min_y];
y = 0;
- if ((rno = lev[y].roomno) >= ROOMOFFSET && !index(ptr, rno)
+ if ((rno = lev[y].roomno) >= ROOMOFFSET && !strchr(ptr, rno)
&& goodtype(rno))
*(--ptr) = rno;
y += step;
if (y > max_y_offset)
continue;
- if ((rno = lev[y].roomno) >= ROOMOFFSET && !index(ptr, rno)
+ if ((rno = lev[y].roomno) >= ROOMOFFSET && !strchr(ptr, rno)
&& goodtype(rno))
*(--ptr) = rno;
y += step;
if (y > max_y_offset)
continue;
- if ((rno = lev[y].roomno) >= ROOMOFFSET && !index(ptr, rno)
+ if ((rno = lev[y].roomno) >= ROOMOFFSET && !strchr(ptr, rno)
&& goodtype(rno))
*(--ptr) = rno;
}
for (ptr1 = u.urooms, ptr2 = u.uentered,
ptr3 = u.ushops, ptr4 = u.ushops_entered; *ptr1; ptr1++) {
c = *ptr1;
- if (!index(u.urooms0, c))
+ if (!strchr(u.urooms0, c))
*ptr2++ = c;
if (IS_SHOP(c - ROOMOFFSET)) {
*ptr3++ = c;
- if (!index(u.ushops0, c))
+ if (!strchr(u.ushops0, c))
*ptr4++ = c;
}
}
/* filter u.ushops0 -> u.ushops_left */
for (ptr1 = u.ushops0, ptr2 = u.ushops_left; *ptr1; ptr1++)
- if (!index(u.ushops, *ptr1))
+ if (!strchr(u.ushops, *ptr1))
*ptr2++ = *ptr1;
*ptr2 = '\0';
}
char *
strip_newline(char *str)
{
- char *p = rindex(str, '\n');
+ char *p = strrchr(str, '\n');
if (p) {
if (p > str && *(p - 1) == '\r')
s1 = str;
while (s1 && *s1) {
- s2 = index(s1, '\n');
+ s2 = strchr(s1, '\n');
if (s2) {
len = (int) (s2 - s1);
s1 = s2 + 1;
if ((p >= &buf[3] && !strcmpi(p - 3, " on"))
|| (p >= &buf[4] && !strcmpi(p - 4, " off"))
|| (p >= &buf[5] && !strcmpi(p - 5, " with"))) {
- p = rindex(buf, ' ');
+ p = strrchr(buf, ' ');
Strcpy(onoff, p);
*p = '\0';
}
if (p >= &buf[2] && !strcmpi(p - 2, "er")) { /* slither + ing */
/* nothing here */
- } else if (p >= &buf[3] && !index(vowel, *(p - 1))
- && index(vowel, *(p - 2)) && !index(vowel, *(p - 3))) {
+ } else if (p >= &buf[3] && !strchr(vowel, *(p - 1))
+ && strchr(vowel, *(p - 2)) && !strchr(vowel, *(p - 3))) {
/* tip -> tipp + ing */
*p = *(p - 1);
*(p + 1) = '\0';
if (s) {
while (*orig && i < (BUFSZ - 1)) {
- if (!index(stuff_to_strip, *orig)) {
+ if (!strchr(stuff_to_strip, *orig)) {
*s++ = *orig;
i++;
}
/* fuzzy match variant of pmatch; particular characters are ignored */
do {
s = *strng++;
- } while (index(sk, s));
+ } while (strchr(sk, s));
do {
p = *patrn++;
- } while (index(sk, p));
+ } while (strchr(sk, p));
}
if (!p) /* end of pattern */
return (boolean) (s == '\0'); /* matches iff end of string too */
register char c1, c2;
do {
- while ((c1 = *s1++) != '\0' && index(ignore_chars, c1) != 0)
+ while ((c1 = *s1++) != '\0' && strchr(ignore_chars, c1) != 0)
continue;
- while ((c2 = *s2++) != '\0' && index(ignore_chars, c2) != 0)
+ while ((c2 = *s2++) != '\0' && strchr(ignore_chars, c2) != 0)
continue;
if (!c1 || !c2)
break; /* stop when end of either string is reached */
S_LIZARD, S_EEL, S_GOLEM, S_GHOST, S_DEMON, S_HUMAN, '\0'
};
- if ((punct = index(punctclasses, mcls1)) != 0)
+ if ((punct = strchr(punctclasses, mcls1)) != 0)
mcls1 = (schar) (S_ZOMBIE + 1 + (int) (punct - punctclasses));
- if ((punct = index(punctclasses, mcls2)) != 0)
+ if ((punct = strchr(punctclasses, mcls2)) != 0)
mcls2 = (schar) (S_ZOMBIE + 1 + (int) (punct - punctclasses));
}
res = mcls1 - mcls2; /* class */
seen = obj->dknown ? TRUE : FALSE,
/* class order */
classorder = flags.sortpack ? flags.inv_order : def_srt_order;
- p = index(classorder, oclass);
+ p = strchr(classorder, oclass);
if (p)
k = 1 + (int) (p - classorder);
else
cntgiven = TRUE;
}
}
- if (index(quitchars, ilet)) {
+ if (strchr(quitchars, ilet)) {
if (Verbose(1, getobj1))
pline1(Never_mind);
return (struct obj *) 0;
getlin(qbuf, buf);
if (buf[0] == '\033')
return 0;
- if (index(buf, 'i')) {
+ if (strchr(buf, 'i')) {
char ailets[1+26+26+1+5+1]; /* $ + a-z + A-Z + # + slop + \0 */
struct obj *otmp;
ailets[0] = '\0';
if (ofilter)
for (otmp = g.invent; otmp; otmp = otmp->nobj)
- /* index() check: limit overflow items to one '#' */
- if ((*ofilter)(otmp) && !index(ailets, otmp->invlet))
+ /* strchr() check: limit overflow items to one '#' */
+ if ((*ofilter)(otmp) && !strchr(ailets, otmp->invlet))
(void) strkitten(ailets, otmp->invlet);
if (display_inventory(ailets, TRUE) == '\033')
return 0;
continue;
oc_of_sym = def_char_to_objclass(sym);
if (takeoff && oc_of_sym != MAXOCLASSES) {
- if (index(extra_removeables, oc_of_sym)) {
+ if (strchr(extra_removeables, oc_of_sym)) {
; /* skip rest of takeoff checks */
- } else if (!index(removeables, oc_of_sym)) {
+ } else if (!strchr(removeables, oc_of_sym)) {
pline("Not applicable.");
return 0;
} else if (oc_of_sym == ARMOR_CLASS && !wearing_armor()) {
} else if (sym == 'u') {
add_valid_menu_class('u');
ckfn = ckunpaid;
- } else if (index("BUCXP", sym)) {
+ } else if (strchr("BUCXP", sym)) {
add_valid_menu_class(sym); /* 'B','U','C','X', or 'P' */
ckfn = ckvalidcat;
} else if (sym == 'm') {
} else if (oc_of_sym == MAXOCLASSES) {
You("don't have any %c's.", sym);
} else {
- if (!index(olets, oc_of_sym)) {
+ if (!strchr(olets, oc_of_sym)) {
add_valid_menu_class(oc_of_sym);
olets[oletct++] = oc_of_sym;
olets[oletct] = '\0';
int tmpglyph;
glyph_info tmpglyphinfo = nul_glyphinfo;
- if (lets && !index(lets, otmp->invlet))
+ if (lets && !strchr(lets, otmp->invlet))
continue;
if (!flags.sortpack || otmp->oclass == *invlet) {
if (wizid && !not_fully_identified(otmp))
for (otmp = g.invent; otmp; otmp = otmp->nobj)
if (otmp->invlet == cmdq->key
&& (!lets || !*lets
- || index(lets, def_oc_syms[(int)otmp->oclass].sym))) {
+ || strchr(lets, def_oc_syms[(int)otmp->oclass].sym))) {
free(cmdq);
return otmp->invlet;
}
} else if (obj->oclass == COIN_CLASS) {
/* if filtering by bless/curse state, gold is classified as
either unknown or uncursed based on user option setting */
- if (g.this_type && index("BUCX", g.this_type))
+ if (g.this_type && strchr("BUCX", g.this_type))
res = (g.this_type == (flags.goldX ? 'X' : 'U'));
} else {
switch (g.this_type) {
*extra_types++ = 'X';
if (!jcnt)
*extra_types++ = 'P';
- *extra_types = '\0'; /* for index() */
+ *extra_types = '\0'; /* for strchr() */
for (i = 0; i < MAXOCLASSES; i++)
- if (!index(types, def_oc_syms[i].sym)) {
+ if (!strchr(types, def_oc_syms[i].sym)) {
*extra_types++ = def_oc_syms[i].sym;
*extra_types = '\0';
}
goto doI_done;
}
- if (index("BUCXP", c))
+ if (strchr("BUCXP", c))
oclass = c; /* not a class but understood by this_type_only() */
else
oclass = def_char_to_objclass(c); /* change to object class */
}
if (traditional) {
- if (index(types, c) > index(types, '\033')) {
+ if (strchr(types, c) > strchr(types, '\033')) {
You("have no %sobjects%s.", before, after);
goto doI_done;
}
g.this_type = oclass; /* extra input for this_type_only() */
}
- if (index("BUCXP", c)) {
+ if (strchr("BUCXP", c)) {
/* the before and after phrases for "you have no..." can both be
treated as mutually-exclusive suffices when creating a title */
Sprintf(title, "Items %s", (before && *before) ? before : after);
else
otmp = obj;
if (costly_spot(otmp->ox, otmp->oy)) {
- if (index(u.urooms, *in_rooms(otmp->ox, otmp->oy, 0)))
+ if (strchr(u.urooms, *in_rooms(otmp->ox, otmp->oy, 0)))
addtobill(otmp, FALSE, FALSE, FALSE);
else
(void) stolen_value(otmp, otmp->ox, otmp->oy, FALSE, FALSE);
if (oclass)
class_name = names[oclass];
- else if ((pos = index(oth_symbols, let)) != 0)
+ else if ((pos = strchr(oth_symbols, let)) != 0)
class_name = oth_names[pos - oth_symbols];
else
class_name = names[0];
GC_ECHOFIRST | GC_CONDHIST);
/* \033 is in quitchars[] so we need to check for it separately
in order to treat it as cancel rather than as accept */
- if (!let || let == '\033' || !index(quitchars, let)) {
+ if (!let || let == '\033' || !strchr(quitchars, let)) {
pline1(Never_mind);
return ECMD_CANCEL;
}
if (let == '\033')
goto noadjust;
}
- if (index(quitchars, let)
+ if (strchr(quitchars, let)
/* adjusting to same slot is meaningful since all
compatible stacks get collected along the way,
but splitting to same slot is not */
goto noadjust;
}
/* letter() classifies '@' as one; compactify() can put '-' in lets;
- the only thing of interest that index() might find is '$' or '#'
+ the only thing of interest that strchr() might find is '$' or '#'
since letter() catches everything else that we put into lets[] */
- if ((letter(let) && let != '@') || (index(lets, let) && let != '-'))
+ if ((letter(let) && let != '@') || (strchr(lets, let) && let != '-'))
break; /* got one */
if (trycnt == 5)
goto noadjust;
const char *const it_reads = "It reads: \"";
i = rn2(SIZE(junk_templates));
- if (index(junk_templates[i], '%')) {
+ if (strchr(junk_templates[i], '%')) {
if (i == 0) {
recipient = DEVTEAM_EMAIL;
delivery = subst_delivery;
/* supply ending punctuation only if the message doesn't have any */
endpunct = "";
- if (!index(".!?", msg[msglen - 2]))
+ if (!strchr(".!?", msg[msglen - 2]))
endpunct = ".";
if (adminmsg) {
char *word;
while (*str) {
- word = index(str, ' ');
+ word = strchr(str, ' ');
#if 0
/* treat " (" as unbreakable space */
if (word && *(word + 1) == '(')
- word = index(word + 1, ' ');
+ word = strchr(word + 1, ' ');
#endif
if (word)
*word = '\0';
if (wizard && *protofile && sp && sp->rndlevs) {
char *ep = getenv("SPLEVTYPE"); /* not nh_getenv */
if (ep) {
- /* rindex always succeeds due to code in prior block */
- int len = (int) ((rindex(protofile, '-') - protofile) + 1);
+ /* strrchr always succeeds due to code in prior block */
+ int len = (int) ((strrchr(protofile, '-') - protofile) + 1);
while (ep && *ep) {
if (!strncmp(ep, protofile, len)) {
Sprintf(protofile + len, "%d", pick);
break;
} else {
- ep = index(ep, ',');
+ ep = strchr(ep, ',');
if (ep)
++ep;
}
void
clear_dknown(struct obj *obj)
{
- obj->dknown = index(dknowns, obj->oclass) ? 0 : 1;
+ obj->dknown = strchr(dknowns, obj->oclass) ? 0 : 1;
if ((obj->otyp >= ELVEN_SHIELD && obj->otyp <= ORCISH_SHIELD)
|| obj->otyp == SHIELD_OF_REFLECTION
|| objects[obj->otyp].oc_merge)
/* Nymphs take everything. Most monsters don't pick up corpses. */
if (!str ? searches_for_item(mtmp, otmp)
- : !!(index(str, otmp->oclass))) {
+ : !!(strchr(str, otmp->oclass))) {
if (otmp->otyp == CORPSE && mtmp->data->mlet != S_NYMPH
/* let a handful of corpse types thru to can_carry() */
&& !touch_petrifies(&mons[otmp->corpsenm])
}
if (((likegold && otmp->oclass == COIN_CLASS)
- || (likeobjs && index(practical, otmp->oclass)
+ || (likeobjs && strchr(practical, otmp->oclass)
&& (otmp->otyp != CORPSE
|| (ptr->mlet == S_NYMPH
&& !is_rider(&mons[otmp->corpsenm]))))
- || (likemagic && index(magical, otmp->oclass))
+ || (likemagic && strchr(magical, otmp->oclass))
|| (uses_items && searches_for_item(mtmp, otmp))
|| (likerock && otmp->otyp == BOULDER)
|| (likegems && otmp->oclass == GEM_CLASS
&& objects[otmp->otyp].oc_material != MINERAL)
|| (conceals && !cansee(otmp->ox, otmp->oy))
|| (ptr == &mons[PM_GELATINOUS_CUBE]
- && !index(indigestion, otmp->oclass)
+ && !strchr(indigestion, otmp->oclass)
&& !(otmp->otyp == CORPSE
&& touch_petrifies(&mons[otmp->corpsenm]))))
&& touch_artifact(otmp, mtmp)) {
bufin -= ct, cnt += ct, ct = 0;
while (cnt > 0) {
- if ((nl = index(bufin, '\n')) != 0) {
+ if ((nl = strchr(bufin, '\n')) != 0) {
/* normal case, newline is present */
ct = (long) (nl - bufin + 1L); /* +1: keep the newline */
for (p = bufin; p <= nl; ++p)
long sortindx; // should be ptrdiff_t, but we don't require that exists
boolean alphabetized, alphabyclass, lootsort;
- if (!flags.discosort || !(p = index(disco_order_let, flags.discosort)))
+ if (!flags.discosort || !(p = strchr(disco_order_let, flags.discosort)))
flags.discosort = 'o';
if (iflags.menu_requested) {
alphabyclass = (flags.discosort == 'c');
alphabetized = (flags.discosort == 'a' || alphabyclass);
lootsort = (flags.discosort == 's');
- sortindx = index(disco_order_let, flags.discosort) - disco_order_let;
+ sortindx = strchr(disco_order_let, flags.discosort) - disco_order_let;
tmpwin = create_nhwindow(NHW_MENU);
Sprintf(buf, "Discoveries, %s", disco_orders_descr[sortindx]);
/* several classes are omitted from packorder; one is of interest here */
Strcpy(classes, flags.inv_order);
- if (!index(classes, VENOM_CLASS))
+ if (!strchr(classes, VENOM_CLASS))
(void) strkitten(classes, VENOM_CLASS); /* append char to string */
ct = uniq_ct + arti_ct;
boolean traditional, alphabetized, lootsort;
int clr = 0;
- if (!flags.discosort || !(p = index(disco_order_let, flags.discosort)))
+ if (!flags.discosort || !(p = strchr(disco_order_let, flags.discosort)))
flags.discosort = 'o';
if (iflags.menu_requested) {
/* collect classes with discoveries, in packorder ordering; several
classes are omitted from packorder and one is of interest here */
Strcpy(allclasses, flags.inv_order);
- if (!index(allclasses, VENOM_CLASS))
+ if (!strchr(allclasses, VENOM_CLASS))
(void) strkitten(allclasses, VENOM_CLASS); /* append char to string */
/* construct discosyms[] */
for (s = allclasses; *s; ++s) {
for (i = g.bases[(int) oclass];
i < NUM_OBJECTS && objects[i].oc_class == oclass; ++i)
if ((dis = g.disco[i]) != 0 && interesting_to_discover(dis)) {
- if (!index(discosyms, c)) {
+ if (!strchr(discosyms, c)) {
Sprintf(eos(discosyms), "%c", c);
if (!traditional) {
any.a_int = c;
Sprintf(allclasses_plustwo, "%s%c%c", allclasses, 'u', 'a');
for (s = allclasses_plustwo, xtras = 0; *s; ++s) {
c = (*s == 'u' || *s == 'a') ? *s : def_oc_syms[(int) *s].sym;
- if (!index(discosyms, c)) {
+ if (!strchr(discosyms, c)) {
if (!xtras++)
(void) strkitten(discosyms, '\033');
(void) strkitten(discosyms, c);
compromise and use 'fname_k >= k' instead of '>',
accepting 1 char length discrepancy without risking
false match (I hope...) */
- if (fname_k >= k && (p = index(&fnamebuf[k], ' ')) != 0) {
+ if (fname_k >= k && (p = strchr(&fnamebuf[k], ' ')) != 0) {
*p = '\0'; /* truncate at 1st space past length of f->fname */
altfname = makesingular(fnamebuf);
k = Strlen(altfname); /* actually revised 'fname_k' */
are described as slippery when hero has slippery fingers */
if (obj == uarmg && Glib) /* just appended "(something)",
* change to "(something; slippery)" */
- Strcpy(rindex(bp, ')'), "; slippery)");
+ Strcpy(strrchr(bp, ')'), "; slippery)");
else if (!Blind && obj->lamplit && artifact_light(obj))
- Sprintf(rindex(bp, ')'), ", %s lit)",
+ Sprintf(strrchr(bp, ')'), ", %s lit)",
arti_light_description(obj));
}
/*FALLTHRU*/
c0 = lowc(*str);
if (!str[1] || str[1] == ' ') {
/* single letter; might be used for named fruit or a musical note */
- Strcpy(outbuf, index("aefhilmnosx", c0) ? "an " : "a ");
+ Strcpy(outbuf, strchr("aefhilmnosx", c0) ? "an " : "a ");
} else if (!strncmpi(str, "the ", 4) || !strcmpi(str, "molten lava")
|| !strcmpi(str, "iron bars") || !strcmpi(str, "ice")) {
; /* no article */
} else {
/* normal case is "an <vowel>" or "a <consonant>" */
- if ((index(vowels, c0) /* some exceptions warranting "a <vowel>" */
+ if ((strchr(vowels, c0) /* some exceptions warranting "a <vowel>" */
/* 'wun' initial sound */
- && (strncmpi(str, "one", 3) || (str[3] && !index("-_ ", str[3])))
+ && (strncmpi(str, "one", 3) || (str[3] && !strchr("-_ ", str[3])))
/* long 'u' initial sound */
&& strncmpi(str, "eu", 2) /* "eucalyptus leaf" */
&& strncmpi(str, "uke", 3) && strncmpi(str, "ukulele", 7)
&& strncmpi(str, "unicorn", 7) && strncmpi(str, "uranium", 7)
&& strncmpi(str, "useful", 6)) /* "useful tool" */
- || (c0 == 'x' && !index(vowels, lowc(str[1]))))
+ || (c0 == 'x' && !strchr(vowels, lowc(str[1]))))
Strcpy(outbuf, "an ");
else
Strcpy(outbuf, "a ");
int l;
/* some objects have capitalized adjectives in their names */
- if (((tmp = rindex(str, ' ')) != 0 || (tmp = rindex(str, '-')) != 0)
+ if (((tmp = strrchr(str, ' ')) != 0 || (tmp = strrchr(str, '-')) != 0)
&& (tmp[1] < 'A' || tmp[1] > 'Z')) {
/* insert "the" unless we have an apostrophe (where we assume
we're dealing with "Unique's corpse" when "Unique" wasn't
caught by CapitalMon() above) */
- insert_the = !index(str, '\'');
- } else if (tmp && index(str, ' ') < tmp) { /* has spaces */
+ insert_the = !strchr(str, '\'');
+ } else if (tmp && strchr(str, ' ') < tmp) { /* has spaces */
/* it needs an article if the name contains "of" */
tmp = strstri(str, " of ");
named = strstri(str, " named ");
if (!strncmpi(subj, "a ", 2) || !strncmpi(subj, "an ", 3))
goto sing;
spot = (const char *) 0;
- for (sp = subj; (sp = index(sp, ' ')) != 0; ++sp) {
+ for (sp = subj; (sp = strchr(sp, ' ')) != 0; ++sp) {
if (!strncmpi(sp, " of ", 4) || !strncmpi(sp, " from ", 6)
|| !strncmpi(sp, " called ", 8) || !strncmpi(sp, " named ", 7)
|| !strncmpi(sp, " labeled ", 9)) {
* Guess at a few other special cases that makeplural creates.
*/
if ((lowc(*spot) == 's' && spot != subj
- && !index("us", lowc(*(spot - 1))))
+ && !strchr("us", lowc(*(spot - 1))))
|| !BSTRNCMPI(subj, spot - 3, "eeth", 4)
|| !BSTRNCMPI(subj, spot - 3, "feet", 4)
|| !BSTRNCMPI(subj, spot - 1, "ia", 2)
Strcasecpy(buf, "is");
} else if (!strcmpi(buf, "have")) {
Strcasecpy(bspot - 1, "s");
- } else if (index("zxs", lowc(*bspot))
+ } else if (strchr("zxs", lowc(*bspot))
|| (len >= 2 && lowc(*bspot) == 'h'
- && index("cs", lowc(*(bspot - 1))))
+ && strchr("cs", lowc(*(bspot - 1))))
|| (len == 2 && lowc(*bspot) == 'o')) {
/* Ends in z, x, s, ch, sh; add an "es" */
Strcasecpy(bspot + 1, "es");
- } else if (lowc(*bspot) == 'y' && !index(vowels, lowc(*(bspot - 1)))) {
+ } else if (lowc(*bspot) == 'y' && !strchr(vowels, lowc(*(bspot - 1)))) {
/* like "y" case in makeplural */
Strcasecpy(bspot, "ies");
} else {
for (p = str; *p; ++p) {
/* substring starting at p can only match if *p is found
within compound_start[] */
- if (!index(compound_start, *p))
+ if (!strchr(compound_start, *p))
continue;
/* check current substring against all words in the compound[] list */
if (len >= 3 && !strcmpi(spot - 2, "erf")) {
/* avoid "nerf" -> "nerves", "serf" -> "serves" */
; /* fall through to default (append 's') */
- } else if (index("lr", lo_c) || index(vowels, lo_c)) {
+ } else if (strchr("lr", lo_c) || strchr(vowels, lo_c)) {
/* [aeioulr]f to [aeioulr]ves */
Strcasecpy(spot, "ves");
goto bottom;
goto bottom;
}
/* Ends in z, x, s, ch, sh; add an "es" */
- if (index("zxs", lo_c)
- || (len >= 2 && lo_c == 'h' && index("cs", lowc(*(spot - 1)))
+ if (strchr("zxs", lo_c)
+ || (len >= 2 && lo_c == 'h' && strchr("cs", lowc(*(spot - 1)))
/* 21st century k-sound */
&& !(len >= 4 && lowc(*(spot - 1)) == 'c' && ch_ksound(str)))
/* Kludge to get "tomatoes" and "potatoes" right */
goto bottom;
}
/* Ends in y preceded by consonant (note: also "qu") change to "ies" */
- if (lo_c == 'y' && !index(vowels, lowc(*(spot - 1)))) {
+ if (lo_c == 'y' && !strchr(vowels, lowc(*(spot - 1)))) {
Strcasecpy(spot, "ies"); /* y -> ies */
goto bottom;
}
goto bottom;
}
/* wolves, but f to ves isn't fully reversible */
- if (p - 4 >= bp && (index("lr", lowc(*(p - 4)))
- || index(vowels, lowc(*(p - 4))))
+ if (p - 4 >= bp && (strchr("lr", lowc(*(p - 4)))
+ || strchr(vowels, lowc(*(p - 4))))
&& !BSTRCMPI(bp, p - 3, "ves")) {
if (!BSTRCMPI(bp, p - 6, "cloves")
|| !BSTRCMPI(bp, p - 6, "nerves"))
}
/* balactheria -> balactherium */
if (p - 4 >= bp && !strcmpi(p - 2, "ia")
- && index("lr", lowc(*(p - 3))) && lowc(*(p - 4)) == 'e') {
+ && strchr("lr", lowc(*(p - 3))) && lowc(*(p - 4)) == 'e') {
Strcasecpy(p - 1, "um"); /* a -> um */
}
static void
readobjnam_parse_charges(struct _readobjnam_data *d)
{
- if (strlen(d->bp) > 1 && (d->p = rindex(d->bp, '(')) != 0) {
+ if (strlen(d->bp) > 1 && (d->p = strrchr(d->bp, '(')) != 0) {
boolean keeptrailingchars = TRUE;
int idx = 0;
using_alias = FALSE;
g.opt_initial = tinitial;
g.opt_from_file = tfrom_file;
- if ((op = index(opts, ',')) != 0) {
+ if ((op = strchr(opts, ',')) != 0) {
*op++ = 0;
if (!parseoptions(op, g.opt_initial, g.opt_from_file))
retval = FALSE;
if (opts) {
Snprintf(pfxbuf, sizeof pfxbuf, "%s", opts);
- if ((pfxp = index(pfxbuf, ':')) != 0)
+ if ((pfxp = strchr(pfxbuf, ':')) != 0)
*pfxp = '\0';
config_error_add("bad option suffix variation '%s'", pfxbuf);
}
return optn_ok;
}
newflags = 0;
- sep = index(op, '+') ? '+' : ' ';
+ sep = strchr(op, '+') ? '+' : ' ';
while (op) {
boolean matched = FALSE;
op = trimspaces(op); /* might have leading space */
- if ((nxt = index(op, sep)) != 0) {
+ if ((nxt = strchr(op, sep)) != 0) {
*nxt++ = '\0';
op = trimspaces(op); /* might have trailing space after
* plus sign removal */
c = 'v'; /* killed -> vanquished */
if (c == 'd')
c = 'o'; /* dungeon -> overview */
- dop = index(disclosure_options, c);
+ dop = strchr(disclosure_options, c);
if (dop) {
idx = (int) (dop - disclosure_options);
if (idx < 0 || idx > NUM_DISCLOSURE_OPTIONS - 1) {
prefix_val = -1;
} else
flags.end_disclose[idx] = DISCLOSE_YES_WITHOUT_PROMPT;
- } else if (index(valid_settings, c)) {
+ } else if (strchr(valid_settings, c)) {
prefix_val = c;
} else if (c == ' ') {
; /* do nothing */
"paranoid_confirm:whichone wheretwo whothree"
and "paranoid_confirm:" prefix has already
been stripped off by the time we get here */
- pp = index(op, ' ');
+ pp = strchr(op, ' ');
if (pp)
*pp = '\0';
/* we aren't matching option names but match_optname()
the old value (above) as a default action */
}
if (use_menu) {
- if (wizard && !index(ocl, VENOM_SYM))
+ if (wizard && !strchr(ocl, VENOM_SYM))
strkitten(ocl, VENOM_SYM);
(void) choose_classes_menu("Autopickup what?", 1, TRUE, ocl,
tbuf);
oc_sym = def_char_to_objclass(*op);
/* make sure all are valid obj symbols occurring once */
if (oc_sym != MAXOCLASSES
- && !index(flags.pickup_types, oc_sym)) {
+ && !strchr(flags.pickup_types, oc_sym)) {
flags.pickup_types[num] = (char) oc_sym;
flags.pickup_types[++num] = '\0';
} else
if (req == get_val || req == get_cnf_val) {
extern const char *const disco_orders_descr[]; /* o_init.c */
extern const char disco_order_let[];
- const char *p = index(disco_order_let, flags.discosort);
+ const char *p = strchr(disco_order_let, flags.discosort);
if (!p)
flags.discosort = 'o', p = disco_order_let;
GPCOORDS_SCREEN, '\0' };
char c = lowc(*op);
- if (c && index(gpcoords, c))
+ if (c && strchr(gpcoords, c))
iflags.getpos_coords = c;
else {
config_error_add("Unknown %s parameter '%s'",
if (req == do_set) {
if (opts) {
if (!strncmp(opts, "verbose", 7)) {
- p = index("01234", *(opts + 7));
+ p = strchr("01234", *(opts + 7));
if (p && *p == '\0') /* plain verbose, not verboseN */
param_optional = TRUE;
if ((op = string_for_opt(opts, param_optional)) != empty_optstr) {
{
char *colon, *equals;
- colon = index(opts, ':');
- equals = index(opts, '=');
+ colon = strchr(opts, ':');
+ equals = strchr(opts, '=');
if (!colon || (equals && equals < colon))
colon = equals;
static int
length_without_val(const char *user_string, int len)
{
- const char *p = index(user_string, ':'),
- *q = index(user_string, '=');
+ const char *p = strchr(user_string, ':'),
+ *q = strchr(user_string, '=');
if (!p || (q && q < p))
p = q;
++cp;
/* remaining cases are all for backslash; we know cp[1] is not \0 */
- } else if (index(dec, cp[1])) {
+ } else if (strchr(dec, cp[1])) {
++cp; /* move past backslash to first digit */
do {
cval = (cval * 10) + (*cp - '0');
- } while (*++cp && index(dec, *cp) && ++dcount < 3);
+ } while (*++cp && strchr(dec, *cp) && ++dcount < 3);
} else if ((cp[1] == 'o' || cp[1] == 'O') && cp[2]
- && index(oct, cp[2])) {
+ && strchr(oct, cp[2])) {
cp += 2; /* move past backslash and 'O' */
do {
cval = (cval * 8) + (*cp - '0');
- } while (*++cp && index(oct, *cp) && ++dcount < 3);
+ } while (*++cp && strchr(oct, *cp) && ++dcount < 3);
} else if ((cp[1] == 'x' || cp[1] == 'X') && cp[2]
- && (dp = index(hex, cp[2])) != 0) {
+ && (dp = strchr(hex, cp[2])) != 0) {
cp += 2; /* move past backslash and 'X' */
do {
cval = (cval * 16) + ((int) (dp - hex) / 2);
- } while (*++cp && (dp = index(hex, *cp)) != 0 && ++dcount < 2);
+ } while (*++cp && (dp = strchr(hex, *cp)) != 0 && ++dcount < 2);
} else { /* C-style character escapes */
switch (*++cp) {
case '\\':
if ((opts = nh_getenv("TERM"))
/* [could also check "xterm" which emulates vtXXX by default] */
&& !strncmpi(opts, "vt", 2)
- && AS && AE && index(AS, '\016') && index(AE, '\017')) {
+ && AS && AE && strchr(AS, '\016') && strchr(AE, '\017')) {
if (!g.symset[PRIMARYSET].explicitly)
load_symset("DECGraphics", PRIMARYSET);
switch_symbols(TRUE);
int retval = 1;
num = 0;
- if (!index(op, GOLD_SYM))
+ if (!strchr(op, GOLD_SYM))
buf[num++] = COIN_CLASS;
for (sp = op; *sp; sp++) {
config_error_add("Not an object class '%c'", *sp);
retval = 0;
fail = TRUE;
- } else if (!index(flags.inv_order, oc_sym)) {
+ } else if (!strchr(flags.inv_order, oc_sym)) {
/* VENOM_CLASS, RANDOM_CLASS, and ILLOBJ_CLASS are excluded
because they aren't in def_inv_order[] so don't make it
- into flags.inv_order, hence always fail this index() test */
+ into flags.inv_order, hence always fail this strchr() test */
config_error_add("Object class '%c' not allowed", *sp);
retval = 0;
fail = TRUE;
- } else if (index(sp + 1, *sp)) {
+ } else if (strchr(sp + 1, *sp)) {
config_error_add("Duplicate object class '%c'", *sp);
retval = 0;
fail = TRUE;
/* fill in any omitted classes, using previous ordering */
for (sp = flags.inv_order; *sp; sp++)
- if (!index(buf, *sp))
+ if (!strchr(buf, *sp))
(void) strkitten(&buf[num++], *sp);
buf[MAXOCLASSES - 1] = '\0';
/* look for first comma, then decide whether it is the key being bound
or a list element separator; if it's a key, find separator beyond it */
- if ((bind = index(bindings, ',')) != 0) {
+ if ((bind = strchr(bindings, ',')) != 0) {
/* at start so it represents a key */
if (bind == bindings)
- bind = index(bind + 1, ',');
+ bind = strchr(bind + 1, ',');
/* to get here, bind is non-Null and not equal to bindings,
so it is greater than bindings and bind[-1] is valid; check
whether current comma happens to be for "\,:cmd" or "',':cmd"
(":cmd" part is assumed if the comma has expected quoting) */
else if (bind[-1] == '\\' || (bind[-1] == '\'' && bind[1] == '\''))
- bind = index(bind + 2, ',');
+ bind = strchr(bind + 2, ',');
}
/* if a comma separator has been found, break off first binding from rest;
parse the rest and then handle this first one when recursion returns */
}
/* parse a single binding: first split around : */
- if (! (bind = index(bindings, ':')))
+ if (! (bind = strchr(bindings, ':')))
return FALSE; /* it's not a binding */
*bind++ = 0;
(void) strncpy(str, tmpstr, sizeof str - 1);
str[sizeof str - 1] = '\0';
- if ((cs = index(str, '=')) == 0) {
+ if ((cs = strchr(str, '=')) == 0) {
config_error_add("Malformed MENUCOLOR");
return FALSE;
}
tmps = cs + 1; /* advance past '=' */
mungspaces(tmps);
- if ((amp = index(tmps, '&')) != 0)
+ if ((amp = strchr(tmps, '&')) != 0)
*amp = '\0';
c = match_str2clr(tmps);
char
get_menu_cmd_key(char ch)
{
- char *found = index(g.mapped_menu_op, ch);
+ char *found = strchr(g.mapped_menu_op, ch);
if (found) {
int idx = (int) (found - g.mapped_menu_op);
char
map_menu_cmd(char ch)
{
- char *found = index(g.mapped_menu_cmds, ch);
+ char *found = strchr(g.mapped_menu_cmds, ch);
if (found) {
int idx = (int) (found - g.mapped_menu_cmds);
/* if backslash, handle single or double quote or second backslash */
} else if (strval[1] == '\\' && strval[2] && strval[3] == '\''
- && index("'\"\\", strval[2]) && !strval[4]) {
+ && strchr("'\"\\", strval[2]) && !strval[4]) {
buf[0] = strval[2];
/* not simple quote or basic backslash;
/* +1: skip opening single quote */
(void) strncpy(tmp, strval + 1, sizeof tmp - 1);
tmp[sizeof tmp - 1] = '\0';
- if ((p = rindex(tmp, '\'')) != 0) {
+ if ((p = strrchr(tmp, '\'')) != 0) {
*p = '\0';
escapes(tmp, buf);
} /* else buf[0] stays '\0' */
impossible("choose_classes_menu: invalid category %d", category);
}
if (way && *class_select) { /* Selections there already */
- if (index(class_select, *class_list)) {
+ if (strchr(class_select, *class_list)) {
selected = TRUE;
}
}
/* remove enchantment ("+0 aklys"); [for 3.6.0 and earlier, this wasn't
needed because looking at items on the map used xname() rather than
doname() hence known enchantment was implicitly suppressed] */
- if (*dbase_str && index("+-", dbase_str[0]) && digit(dbase_str[1])) {
+ if (*dbase_str && strchr("+-", dbase_str[0]) && digit(dbase_str[1])) {
++dbase_str; /* skip sign */
while (digit(*dbase_str))
++dbase_str;
if (alt && (!strncmpi(alt, "a ", 2)
|| !strncmpi(alt, "an ", 3)
|| !strncmpi(alt, "the ", 4)))
- alt = index(alt, ' ') + 1;
+ alt = strchr(alt, ' ') + 1;
/* remove charges or "(lit)" or wizmode "(N aum)" */
if ((ep = strstri(dbase_str, " (")) != 0 && ep > dbase_str)
*ep = '\0';
/* a number indicates the end of current entry */
skipping_entry = FALSE;
} else if (!skipping_entry) {
- if (!(ep = index(buf, '\n')))
+ if (!(ep = strchr(buf, '\n')))
goto bad_data_file;
(void) strip_newline((ep > buf) ? ep - 1 : ep);
/* if we match a key that begins with "~", skip
if (!dlb_fgets(tabbuf, BUFSZ, fp))
goto bad_data_file;
tp = tabbuf;
- if (!index(tp, '\n'))
+ if (!strchr(tp, '\n'))
goto bad_data_file;
(void) strip_newline(tp);
/* text in this file is indented with one tab but
/* if a tab after the leading one is found,
convert tabs into spaces; the attributions
at the end of quotes typically have them */
- if (index(tp, '\t') != 0)
+ if (strchr(tp, '\t') != 0)
(void) tabexpand(tp);
putstr(datawin, 0, tp);
}
if ((neg = (*buf == '!')) != 0)
if (*++buf == ' ')
++buf;
- p = index(buf, '='), q = index(buf, ':');
+ p = strchr(buf, '='), q = strchr(buf, ':');
if (!p || (q && q < p))
p = q;
if (p) { /* we have a value specified */
: (-1 * iflags.num_pad_mode); /* -1..0 */
newcond = FALSE;
for (; p; p = q) {
- q = index(p, ',');
+ q = strchr(p, ',');
if (q)
*q++ = '\0';
if (atoi(p) == np) {
cond = stack[0].active = 1;
while (dlb_fgets(buf, sizeof buf, fp)) {
++lnum;
- if (buf[0] == '&' && buf[1] && index("?:.#", buf[1])) {
+ if (buf[0] == '&' && buf[1] && strchr("?:.#", buf[1])) {
cond = whatdoes_cond(buf, stack, &depth, lnum);
continue;
}
: (ctrl ? buf[0] == '^' && highc(buf[1]) == q
: buf[0] == q)) {
(void) strip_newline(buf);
- if (index(buf, '\t'))
+ if (strchr(buf, '\t'))
(void) tabexpand(buf);
if (meta && ctrl && buf[4] == ' ') {
(void) strncpy(buf, "M-^? ", 8);
#endif
reslt = dowhatdoes_core(q, bufr);
if (reslt) {
- char *p = index(reslt, '\n'); /* 'm' prefix has two lines of output */
+ char *p = strchr(reslt, '\n'); /* 'm' prefix has two lines of output */
if (q == '&' || q == '?')
whatdoes_help();
register char c;
*itemcount = 0;
- ilets[iletct] = '\0'; /* terminate ilets so that index() will work */
+ ilets[iletct] = '\0'; /* terminate ilets so that strchr() will work */
while (otmp) {
c = def_oc_syms[(int) otmp->oclass].sym;
- if (!index(ilets, c) && (!filter || (*filter)(otmp)))
+ if (!strchr(ilets, c) && (!filter || (*filter)(otmp)))
ilets[iletct++] = c, ilets[iletct] = '\0';
*itemcount += 1;
otmp = here ? otmp->nexthere : otmp->nobj;
goto ask_again;
} else if (sym == 'm') {
m_seen = TRUE;
- } else if (index("uBUCXP", sym)) {
+ } else if (strchr("uBUCXP", sym)) {
add_valid_menu_class(sym); /* 'u' or 'B','U','C','X','P' */
filtered = TRUE;
} else {
oc_of_sym = def_char_to_objclass(sym);
- if (index(ilets, sym)) {
+ if (strchr(ilets, sym)) {
add_valid_menu_class(oc_of_sym);
oclasses[oclassct++] = oc_of_sym;
oclasses[oclassct] = '\0';
boolean
menu_class_present(int c)
{
- return (c && index(g.valid_menu_classes, c)) ? TRUE : FALSE;
+ return (c && strchr(g.valid_menu_classes, c)) ? TRUE : FALSE;
}
void
* is also specified since player has explicitly requested coins.
*/
if (obj->oclass == COIN_CLASS && g.class_filter)
- return index(g.valid_menu_classes, COIN_CLASS) ? TRUE : FALSE;
+ return strchr(g.valid_menu_classes, COIN_CLASS) ? TRUE : FALSE;
if (Role_if(PM_CLERIC) && !obj->bknown)
set_bknown(obj, 1);
*/
/* if class is expected but obj's class is not in the list, reject */
- if (g.class_filter && !index(g.valid_menu_classes, obj->oclass))
+ if (g.class_filter && !strchr(g.valid_menu_classes, obj->oclass))
return FALSE;
/* if unpaid is expected and obj isn't unpaid, reject (treat a container
holding any unpaid object as unpaid even if isn't unpaid itself) */
}
/* if its category is not in the list, reject */
- if (!index(g.valid_menu_classes, bucx))
+ if (!strchr(g.valid_menu_classes, bucx))
return FALSE;
}
if (g.picked_filter && !obj->pickup_prev)
allow_cat_no_uchain(struct obj *obj)
{
if (obj != uchain
- && ((index(g.valid_menu_classes, 'u') && obj->unpaid)
- || index(g.valid_menu_classes, obj->oclass)))
+ && ((strchr(g.valid_menu_classes, 'u') && obj->unpaid)
+ || strchr(g.valid_menu_classes, obj->oclass)))
return TRUE;
return FALSE;
}
obj2 = FOLLOW(obj, traverse_how);
if (bycat ? !allow_category(obj)
: (!selective && oclasses[0]
- && !index(oclasses, obj->oclass)))
+ && !strchr(oclasses, obj->oclass)))
continue;
lcount = -1L;
return FALSE;
/* check for pickup_types */
- pickit = (!*otypes || index(otypes, otmp->oclass));
+ pickit = (!*otypes || strchr(otypes, otmp->oclass));
/* check for autopickup exceptions */
ape = check_autopickup_exceptions(otmp);
/* sets obj->unpaid if necessary */
addtobill(otmp, TRUE, FALSE, FALSE);
Strcpy(u.ushops, saveushops);
- robshop = otmp->unpaid && !index(u.ushops, *fakeshop);
+ robshop = otmp->unpaid && !strchr(u.ushops, *fakeshop);
}
result = addinv(otmp);
if (g.program_state.wizkit_wishing)
return;
- if (index(line, '%')) {
+ if (strchr(line, '%')) {
#if !defined(NO_VSNPRINTF)
vlen = vsnprintf(pbuf, sizeof(pbuf), line, the_args);
#if (NH_DEVEL_STATUS != NH_STATUS_RELEASED) && defined(DEBUG)
{
char pbuf[BIGBUFSZ]; /* will be chopped down to BUFSZ-1 if longer */
- if (index(line, '%')) {
+ if (strchr(line, '%')) {
#if !defined(NO_VSNPRINTF)
(void) vsnprintf(pbuf, sizeof(pbuf), line, the_args);
#else
}
if ((part == HAND || part == HANDED)
&& (humanoid(mptr) && attacktype(mptr, AT_CLAW)
- && !index(not_claws, mptr->mlet) && mptr != &mons[PM_STONE_GOLEM]
+ && !strchr(not_claws, mptr->mlet) && mptr != &mons[PM_STONE_GOLEM]
&& mptr != &mons[PM_AMOROUS_DEMON]))
return (part == HAND) ? "claw" : "clawed";
if ((mptr == &mons[PM_MUMAK] || mptr == &mons[PM_MASTODON])
Your("displaced image doesn't fool %s!", mon_nam(priest));
(void) mattacku(priest);
return 0;
- } else if (index(u.urooms, temple)) {
+ } else if (strchr(u.urooms, temple)) {
/* chase player if inside temple & can see him */
if (priest->mcansee && m_canseeu(priest)) {
gx = u.ux;
case 'I':
case 'j': /* his/her */
case 'J':
- if (index("dlno", lowc(*(c - 1))))
+ if (strchr("dlno", lowc(*(c - 1))))
qtext_pronoun(*(c - 1), *c);
else
--c; /* default action */
/* switch from by_pline to by_window if line has multiple segments or
is unreasonably long (the latter ought to checked after formatting
conversions rather than before...) */
- if (output == 0 && (index(text, '\n') || strlen(text) >= BUFSZ - 1)) {
+ if (output == 0 && (strchr(text, '\n') || strlen(text) >= BUFSZ - 1)) {
output = 2;
/*
int ln = (int) strlen(mesg);
/* we will be displaying a sentence; need ending punctuation */
- if (ln > 0 && !index(".!?", mesg[ln - 1]))
+ if (ln > 0 && !strchr(".!?", mesg[ln - 1]))
endpunct = ".";
pline("It reads:");
}
/* Look for tokens delimited by '-' */
sptr = g.plname + g.plnamelen;
- if ((eptr = index(sptr, '-')) != (char *) 0)
+ if ((eptr = strchr(sptr, '-')) != (char *) 0)
*eptr++ = '\0';
while (eptr) {
/* Isolate the next token */
sptr = eptr;
- if ((eptr = index(sptr, '-')) != (char *) 0)
+ if ((eptr = strchr(sptr, '-')) != (char *) 0)
*eptr++ = '\0';
/* Try to match it to something */
/* distinct female name [caveman/cavewoman, priest/priestess] */
if (gend == 1)
/* female specified; replace male role name with female one */
- Sprintf(index(buf, ':'), ": %s", roles[r].name.f);
+ Sprintf(strchr(buf, ':'), ": %s", roles[r].name.f);
else if (gend < 0)
/* gender unspecified; append slash and female role name */
Sprintf(eos(buf), "/%s", roles[r].name.f);
(void) dlb_fseek(rumors, (long) g.true_rumor_start, SEEK_SET);
ftell_rumor_start = dlb_ftell(rumors);
(void) dlb_fgets(line, sizeof line, rumors);
- if ((endp = index(line, '\n')) != 0)
+ if ((endp = strchr(line, '\n')) != 0)
*endp = 0;
Sprintf(rumor_buf, "T %06ld %s", ftell_rumor_start,
xcrypt(line, xbuf));
while (dlb_fgets(line, sizeof line, rumors)
&& dlb_ftell(rumors) < g.true_rumor_end)
continue;
- if ((endp = index(line, '\n')) != 0)
+ if ((endp = strchr(line, '\n')) != 0)
*endp = 0;
Sprintf(rumor_buf, " %6s %s", "", xcrypt(line, xbuf));
putstr(tmpwin, 0, rumor_buf);
(void) dlb_fseek(rumors, (long) g.false_rumor_start, SEEK_SET);
ftell_rumor_start = dlb_ftell(rumors);
(void) dlb_fgets(line, sizeof line, rumors);
- if ((endp = index(line, '\n')) != 0)
+ if ((endp = strchr(line, '\n')) != 0)
*endp = 0;
Sprintf(rumor_buf, "F %06ld %s", ftell_rumor_start,
xcrypt(line, xbuf));
while (dlb_fgets(line, sizeof line, rumors)
&& dlb_ftell(rumors) < g.false_rumor_end)
continue;
- if ((endp = index(line, '\n')) != 0)
+ if ((endp = strchr(line, '\n')) != 0)
*endp = 0;
Sprintf(rumor_buf, " %6s %s", "", xcrypt(line, xbuf));
putstr(tmpwin, 0, rumor_buf);
putstr(tmpwin, 0, xbuf);
/* show the bad line; we don't know whether it has been
encrypted via xcrypt() so show it both ways */
- if ((endp = index(line, '\n')) != 0)
+ if ((endp = strchr(line, '\n')) != 0)
*endp = 0;
putstr(tmpwin, 0, "- first line, as is");
putstr(tmpwin, 0, line);
goto closeit;
}
++entrycount;
- if ((endp = index(line, '\n')) != 0)
+ if ((endp = strchr(line, '\n')) != 0)
*endp = 0;
putstr(tmpwin, 0, xcrypt(line, xbuf));
if (!dlb_fgets(line, sizeof line, fh)) {
putstr(tmpwin, 0, "(no second entry)");
} else {
++entrycount;
- if ((endp = index(line, '\n')) != 0)
+ if ((endp = strchr(line, '\n')) != 0)
*endp = 0;
putstr(tmpwin, 0, xcrypt(line, xbuf));
while (dlb_fgets(line, sizeof line, fh)) {
++entrycount;
- if ((endp = index(line, '\n')) != 0)
+ if ((endp = strchr(line, '\n')) != 0)
*endp = 0;
(void) xcrypt(line, xbuf);
}
(void) dlb_fseek(fh, startpos, SEEK_SET);
(void) dlb_fgets(buf, bufsiz, fh);
}
- if ((newl = index(buf, '\n')) != 0)
+ if ((newl = strchr(buf, '\n')) != 0)
*newl = '\0';
/* decrypt line; make sure that our intermediate buffer is big enough */
xbufp = (strlen(buf) <= sizeof xbuf - 1) ? &xbuf[0]
putstr(tmpwin, 0, "");
while (dlb_fgets(line, COLNO, oracles) && strcmp(line, "---\n")) {
- if ((endp = index(line, '\n')) != 0)
+ if ((endp = strchr(line, '\n')) != 0)
*endp = 0;
putstr(tmpwin, 0, xcrypt(line, xbuf));
}
gender and/or to distinguish an individual from a type
(code is a single punctuation character when present) */
while (dlb_fgets(hline, sizeof hline, bogonfile)) {
- if ((endp = index(hline, '\n')) != 0)
+ if ((endp = strchr(hline, '\n')) != 0)
*endp = '\0'; /* strip newline */
(void) xcrypt(hline, xbuf);
unpadline(xbuf);
- if (!xbuf[0] || !index(bogon_codes, xbuf[0]))
+ if (!xbuf[0] || !strchr(bogon_codes, xbuf[0]))
code = '\0', startp = &xbuf[0]; /* ordinary */
else
code = xbuf[0], startp = &xbuf[1]; /* special */
/* Make sure bill is set only when the
dead shk is the resident shk. */
- if ((p = index(u.ushops, eshk->shoproom)) != 0) {
+ if ((p = strchr(u.ushops, eshk->shoproom)) != 0) {
setpaid(mtmp);
eshk->bill_p = (struct bill_x *) 0;
/* remove eshk->shoproom from u.ushops */
return;
if (!(shkp = shop_keeper(*enterstring))) {
- if (!index(empty_shops, *enterstring)
+ if (!strchr(empty_shops, *enterstring)
&& in_rooms(u.ux, u.uy, SHOPBASE)
!= in_rooms(u.ux0, u.uy0, SHOPBASE))
deserted_shop(enterstring);
if (!inhishop(shkp)) {
/* dump core when referenced */
eshkp->bill_p = (struct bill_x *) -1000;
- if (!index(empty_shops, *enterstring))
+ if (!strchr(empty_shops, *enterstring))
deserted_shop(enterstring);
Strcpy(empty_shops, u.ushops);
u.ushops[0] = '\0';
{
struct eshk *eshkp = ESHK(mtmp);
- return (index(in_rooms(mtmp->mx, mtmp->my, SHOPBASE), eshkp->shoproom)
+ return (strchr(in_rooms(mtmp->mx, mtmp->my, SHOPBASE), eshkp->shoproom)
&& on_level(&eshkp->shoplevel, &u.uz));
}
mtmp2 = mtmp->nmon;
eshkp = ESHK(mtmp);
local = on_level(&eshkp->shoplevel, &u.uz);
- if (local && index(u.ushops, eshkp->shoproom)) {
+ if (local && strchr(u.ushops, eshkp->shoproom)) {
/* inside this shk's shop [there might be more than one
resident shk if hero is standing in a breech of a shared
wall, so give priority to one who's also owed money] */
return FALSE;
}
/* does it belong to shkp? */
- if (!index(in_rooms(x, y, SHOPBASE), ESHK(shkp)->shoproom))
+ if (!strchr(in_rooms(x, y, SHOPBASE), ESHK(shkp)->shoproom))
return FALSE;
return TRUE;
while (dam) {
coordxy x = dam->place.x, y = dam->place.y;
- if (index(in_rooms(x, y, SHOPBASE), ESHK(shkp)->shoproom)) {
+ if (strchr(in_rooms(x, y, SHOPBASE), ESHK(shkp)->shoproom)) {
dam2 = dam->next;
if (prevdam)
prevdam->next = dam2;
do {
msg = temple_msg[rn2(SIZE(temple_msg) - 1 + hallu)];
- if (index(msg, '*') && speechless)
+ if (strchr(msg, '*') && speechless)
continue;
- if (index(msg, '#') && in_sight)
+ if (strchr(msg, '#') && in_sight)
continue;
break; /* msg is acceptable */
} while (++trycount < 50);
while (!letter(*msg))
++msg; /* skip control flags */
- if (index(msg, '%')) {
+ if (strchr(msg, '%')) {
DISABLE_WARNING_FORMAT_NONLITERAL
You_hear(msg, halu_gname(EPRI(mtmp)->shralign));
RESTORE_WARNING_FORMAT_NONLITERAL
return;
}
if (tended_shop(sroom)
- && !index(u.ushops, (int) (ROOM_INDEX(sroom) + ROOMOFFSET))) {
+ && !strchr(u.ushops, (int) (ROOM_INDEX(sroom) + ROOMOFFSET))) {
static const char *const shop_msg[3] = {
"someone cursing shoplifters.",
"the chime of a cash register.", "Neiman and Marcus arguing!",
mf->hei = 0;
tmps = mf->data;
while (tmps && *tmps) {
- char *s1 = index(tmps, '\n');
+ char *s1 = strchr(tmps, '\n');
if (mf->hei > MAP_Y_LIM) {
free(mf->data);
ilet = yn_function(qbuf, (char *) 0, '\0', TRUE);
if (ilet == '*' || ilet == '?')
break; /* use menu mode */
- if (index(quitchars, ilet))
+ if (strchr(quitchars, ilet))
return FALSE;
idx = spell_let_to_idx(ilet);
if (unwornmask && mon->mtame && (unwornmask & W_SADDLE) != 0L
&& !obj->unpaid && costly_spot(omx, omy)
/* being at costly_spot guarantees lev->roomno is not 0 */
- && index(in_rooms(u.ux, u.uy, SHOPBASE), levl[omx][omy].roomno)) {
+ && strchr(in_rooms(u.ux, u.uy, SHOPBASE), levl[omx][omy].roomno)) {
obj->no_charge = 1;
}
/* obj_no_longer_held(obj); -- done by place_object */
{
struct permonst *ptr = mtmp->data;
- return (index(steeds, ptr->mlet) && (ptr->msize >= MZ_MEDIUM)
+ return (strchr(steeds, ptr->mlet) && (ptr->msize >= MZ_MEDIUM)
&& (!humanoid(ptr) || ptr->mlet == S_CENTAUR) && !amorphous(ptr)
&& !noncorporeal(ptr) && !is_whirly(ptr) && !unsolid(ptr));
}
separating space slips through; for handling or set description,
symbol set creator is responsible for preceding '#' with a space
and that comment itself doesn't contain " #") */
- if ((commentp = rindex(buf, '#')) != 0 && commentp[-1] == ' ')
+ if ((commentp = strrchr(buf, '#')) != 0 && commentp[-1] == ' ')
commentp[-1] = '\0';
/* find the '=' or ':' */
- bufp = index(buf, '=');
- altp = index(buf, ':');
+ bufp = strchr(buf, '=');
+ altp = strchr(buf, ':');
if (!bufp || (altp && altp < bufp))
bufp = altp;
if (!bufp) {
* "S_sample=','" or "S_sample=':'".
*/
- if ((op = index(opts, ',')) != 0) {
+ if ((op = strchr(opts, ',')) != 0) {
*op++ = '\0';
if (!parsesymbols(op, which_set))
return FALSE;
/* S_sample:string */
symname = opts;
- strval = index(opts, ':');
+ strval = strchr(opts, ':');
if (!strval)
- strval = index(opts, '=');
+ strval = strchr(opts, '=');
if (!strval)
return FALSE;
*strval++ = '\0';
{ "S_explode8", "S_expl_bc" }, { "S_explode9", "S_expl_br" },
};
size_t len = strlen(buf);
- const char *p = index(buf, ':'), *q = index(buf, '=');
+ const char *p = strchr(buf, ':'), *q = strchr(buf, '=');
const struct symparse *sp = loadsyms;
if (!p || (q && q < p))
} else {
if (costly_spot(otx, oty)
&& (!costly_spot(tx, ty)
- || !index(in_rooms(tx, ty, 0), *in_rooms(otx, oty, 0)))) {
+ || !strchr(in_rooms(tx, ty, 0), *in_rooms(otx, oty, 0)))) {
if (costly_spot(u.ux, u.uy)
- && index(u.urooms, *in_rooms(otx, oty, 0)))
+ && strchr(u.urooms, *in_rooms(otx, oty, 0)))
addtobill(obj, FALSE, FALSE, FALSE);
else
(void) stolen_value(obj, otx, oty, FALSE, FALSE);
} else {
const char *str = choke_texts[SIZE(choke_texts) - i];
- if (index(str, '%'))
+ if (strchr(str, '%'))
urgent_pline(str, hcolor(NH_BLUE));
else
urgent_pline("%s", str);
if (((HLevitation & TIMEOUT) % 2L) && i > 0L && i <= SIZE(levi_texts)) {
const char *s = levi_texts[SIZE(levi_texts) - i];
- if (index(s, '%')) {
+ if (strchr(s, '%')) {
boolean danger = (is_pool_or_lava(u.ux, u.uy)
&& !Is_waterlevel(&u.uz));
if (nolimbs(g.youmonst.data) && strstri(buf, "limbs"))
(void) strsubst(buf, "limbs", "extremities");
- if (index(buf, '%')) {
+ if (strchr(buf, '%')) {
if (i == 4L) { /* "you are turning green" */
if (!Blind) /* [what if you're already green?] */
urgent_pline(buf, hcolor(NH_GREEN));
if (!fgets(inbuf, sizeof inbuf, rfile)) {
/* sscanf will fail and tt->points will be set to 0 */
*inbuf = '\0';
- } else if (!index(inbuf, '\n')) {
+ } else if (!strchr(inbuf, '\n')) {
Strcpy(&inbuf[sizeof inbuf - 2], "\n");
discardexcess(rfile);
}
!strncmp(" (", t1->death + 7, 2) ? t1->death + 7 + 2 : "",
t1->maxlvl);
/* fixup for closing paren in "escaped... with...Amulet)[max..." */
- if ((bp = index(linebuf, ')')) != 0)
+ if ((bp = strchr(linebuf, ')')) != 0)
*bp = (t1->deathdnum == astral_level.dnum) ? '\0' : ' ';
second_line = FALSE;
} else if (!strncmp("ascended", t1->death, 8)) {
return 1;
for (i = 0; i < playerct; i++) {
- if (players[i][0] == '-' && index("pr", players[i][1])
+ if (players[i][0] == '-' && strchr("pr", players[i][1])
&& players[i][2] == 0 && i + 1 < playerct) {
const char *arg = players[i + 1];
if ((players[i][1] == 'p'
}
Strcat(pbuf, players[i]);
if (i < playerct - 1) {
- if (players[i][0] == '-' && index("pr", players[i][1])
+ if (players[i][0] == '-' && strchr("pr", players[i][1])
&& players[i][2] == 0)
Strcat(pbuf, " ");
else
nsb_mung_line(p)
char *p;
{
- while ((p = index(p, ' ')) != 0)
+ while ((p = strchr(p, ' ')) != 0)
*p = '|';
}
nsb_unmung_line(p)
char *p;
{
- while ((p = index(p, '|')) != 0)
+ while ((p = strchr(p, '|')) != 0)
*p = ' ';
}
#endif /* NO_SCAN_BRACK */
trapdescr = trapname(t->ttyp, FALSE);
if (!which)
which = t->tseen ? the_your[t->madeby_u]
- : index(vowels, *trapdescr) ? "an" : "a";
+ : strchr(vowels, *trapdescr) ? "an" : "a";
if (*which)
which = strcat(strcpy(whichbuf, which), " ");
if (cp && *cp) {
cval = dcount = 0;
if ((unicode = ((*cp == 'U' || *cp == 'u') && cp[1] == '+')) && cp[2]
- && (dp = index(hex, cp[2])) != 0) {
+ && (dp = strchr(hex, cp[2])) != 0) {
cp += 2; /* move past the 'U' and '+' */
do {
cval = (cval * 16) + ((int) (dp - hex) / 2);
- } while (*++cp && (dp = index(hex, *cp)) != 0 && ++dcount < 7);
+ } while (*++cp && (dp = strchr(hex, *cp)) != 0 && ++dcount < 7);
}
}
return cval;
/* if extra text (git info) is present, put it on separate line
but don't wrap on (x86) */
if (strlen(buf) >= COLNO)
- p = rindex(buf, '(');
+ p = strrchr(buf, '(');
if (p && p > buf && p[-1] == ' ' && p[1] != 'x')
p[-1] = '\0';
else
break;
}
(void) strip_newline(buf);
- if (index(buf, '\t') != 0)
+ if (strchr(buf, '\t') != 0)
(void) tabexpand(buf);
if (*buf && *buf != ' ') {
if (prolog || !*buf)
continue;
- if (index(buf, ':'))
+ if (strchr(buf, ':'))
insert_rtoption(buf);
if (*buf)
istr[j] = str;
if (j == 2)
break;
- } else if (index("0123456789", *str) != 0) {
+ } else if (strchr("0123456789", *str) != 0) {
str++;
} else
return 0L;
if (Is_weapon && otmp->blessed && mon_hates_blessings(mon))
tmp += 2;
- if (is_spear(otmp) && index(kebabable, ptr->mlet))
+ if (is_spear(otmp) && strchr(kebabable, ptr->mlet))
tmp += 2;
/* trident is highly effective against swimmers */
const char *dp;
for (; *str && ++dcount <= 4; ++str) {
- if ((dp = index(hex, *str)) != 0) {
+ if ((dp = strchr(hex, *str)) != 0) {
retval++;
rndchk = (rndchk * 16) + ((int) (dp - hex) / 2);
} else
if (rndchk == g.context.rndencode) {
*glyph_ptr = dcount = 0;
for (; *str && ++dcount <= 4; ++str) {
- if ((dp = index(hex, *str)) != 0) {
+ if ((dp = strchr(hex, *str)) != 0) {
retval++;
*glyph_ptr = (*glyph_ptr * 16) + ((int) (dp - hex) / 2);
} else
alt = big_to_little(res);
if (alt != res && (g.mvitals[alt].mvflags & G_GENOD) == 0) {
const char *mnam = mons[alt].pmnames[NEUTRAL],
- *lastspace = rindex(mnam, ' ');
+ *lastspace = strrchr(mnam, ' ');
/* only non-juveniles can become alternate choice */
if (strncmp(mnam, "baby ", 5)
}
/* keep special fields (including charges on wands) */
- if (index(charged_objs, otmp->oclass))
+ if (strchr(charged_objs, otmp->oclass))
otmp->spe = obj->spe;
otmp->recharged = obj->recharged;
if (s && *s) {
(void) strncpy(g.plname, s, sizeof g.plname - 1);
- if (index(g.plname, '-'))
+ if (strchr(g.plname, '-'))
return TRUE;
}
}
if (sysopt.wizards && sysopt.wizards[0]) {
char *tmp = build_english_list(sysopt.wizards);
pline("Only user%s %s may access debug (wizard) mode.",
- index(sysopt.wizards, ' ') ? "s" : "", tmp);
+ strchr(sysopt.wizards, ' ') ? "s" : "", tmp);
free(tmp);
} else
pline("Entering explore/discovery mode instead.");
union REGS inregs;
char drive;
- if ((ptr = index(str, ':')) != (char *) 0) {
+ if ((ptr = strchr(str, ':')) != (char *) 0) {
drive = toupper(*(ptr - 1));
inregs.h.ah = SELECTDISK;
inregs.h.dl = drive - 'A';
cvalue[0] = choices;
/* find the next ' ' or tab */
- cptr = index(cvalue[0], '-');
+ cptr = strchr(cvalue[0], '-');
if (!cptr)
- cptr = index(cvalue[0], ' ');
+ cptr = strchr(cvalue[0], ' ');
if (!cptr)
- cptr = index(cvalue[0], '\t');
+ cptr = strchr(cvalue[0], '\t');
if (!cptr)
return 0;
*cptr = '\0';
} while (isspace(*cptr) || (*cptr == '-'));
cvalue[1] = cptr;
- cptr = index(cvalue[1], '-');
+ cptr = strchr(cvalue[1], '-');
if (!cptr)
- cptr = index(cvalue[0], ' ');
+ cptr = strchr(cvalue[0], ' ');
if (!cptr)
- cptr = index(cvalue[0], '\t');
+ cptr = strchr(cvalue[0], '\t');
if (!cptr)
return 0;
*cptr = '\0';
/* sysconf should be searched for in this location */
envp = nh_getenv("COMMONPROGRAMFILES");
if (envp) {
- if ((sptr = index(envp, ';')) != 0)
+ if ((sptr = strchr(envp, ';')) != 0)
*sptr = '\0';
if (strlen(envp) > 0) {
g.fqn_prefix[SYSCONFPREFIX] =
* overridden */
envp = nh_getenv("USERPROFILE");
if (envp) {
- if ((sptr = index(envp, ';')) != 0)
+ if ((sptr = strchr(envp, ';')) != 0)
*sptr = '\0';
if (strlen(envp) > 0) {
g.fqn_prefix[CONFIGPREFIX] =
size_t n;
int k;
- if (!ent || !*ent || !trm || !*trm || (col = index(ent, ':')) == 0)
+ if (!ent || !*ent || !trm || !*trm || (col = strchr(ent, ':')) == 0)
return 0;
(void) strcpy(tc_entry, trm);
- if (((bar = index(ent, '|')) != 0 && bar < col)
+ if (((bar = strchr(ent, '|')) != 0 && bar < col)
|| ((long) (n = strlen(trm)) == (long) (col - ent)
&& strncmp(ent, trm, n) == 0))
(void) strcat(tc_entry, col);
*op++ = *ip, bufsiz -= 1;
if (ip[0] == ':' && ip[1] == 't' && ip[2] == 'c' && ip[3] == '=') {
tc_fetch = &ip[4];
- if ((ip = index(tc_fetch, ':')) != 0)
+ if ((ip = strchr(tc_fetch, ':')) != 0)
*ip = '\0';
break;
}
char *nxt, *lst, *p = ent;
size_t n = strlen(nam);
- if ((lst = index(p, ':')) == 0)
+ if ((lst = strchr(p, ':')) == 0)
lst = p + strlen(p);
while (p < lst) {
- if ((nxt = index(p, '|')) == 0 || nxt > lst)
+ if ((nxt = strchr(p, '|')) == 0 || nxt > lst)
nxt = lst;
if ((long) (nxt - p) == (long) n && strncmp(p, nam, n) == 0)
return lst;
if (!p || p[2] != '=')
return (char *) 0;
p += 3;
- if ((q = index(p, ':')) == 0)
+ if ((q = strchr(p, ':')) == 0)
q = p + strlen(p);
r = result = *outptr;
while (p < q) {
end = p + strlen(p);
while (p < end) {
- if ((p = index(p, ':')) == 0)
+ if ((p = strchr(p, ':')) == 0)
break;
++p;
if (p[0] == field[0] && p[1] == field[1]
}
if (tc_end) {
if (p) {
- if ((q = index(p + 2, ':')) == 0)
+ if ((q = strchr(p + 2, ':')) == 0)
q = end;
} else
q = 0;
LF from becoming CR+LF, for instance; only
makes sense if this is a cursor positioning
sequence, but we have no way to check that */
- while (index("\004\t\n\013\f\r", *r)) {
+ while (strchr("\004\t\n\013\f\r", *r)) {
if (ac & 1) { /* row */
if (!UP || !*UP)
break; /* can't fix */
struct passwd *user;
char dnbuf[100], *index(), *strcat(), *strcpy();
- sl = index(dest, '/');
+ sl = strchr(dest, '/');
if (sl == NULL) {
fprintf(stderr, "Illegal ~user\n");
exit(3);
return (char *) 0;
}
- if ((p = index(arg, '=')) == 0)
- p = index(arg, ':');
+ if ((p = strchr(arg, '=')) == 0)
+ p = strchr(arg, ':');
if (p && opttype == ArgValDisallowed)
goto loptnotallowed;
if (s && *s) {
(void) strncpy(g.plname, s, sizeof g.plname - 1);
- if (index(g.plname, '-'))
+ if (strchr(g.plname, '-'))
return TRUE;
}
}
if (sysopt.wizards && sysopt.wizards[0]) {
char *tmp = build_english_list(sysopt.wizards);
pline("Only user%s %s may access debug (wizard) mode.",
- index(sysopt.wizards, ' ') ? "s" : "", tmp);
+ strchr(sysopt.wizards, ' ') ? "s" : "", tmp);
free(tmp);
} else
pline("Entering explore/discovery mode instead.");
/* This file collects some Unix dependencies */
-#include "hack.h" /* mainly for index() which depends on BSD */
+#include "hack.h" /* mainly for strchr() which depends on BSD */
#include <errno.h>
#include <sys/stat.h>
{
register char *lp;
- while ((lp = index(s, '.')) != 0 || (lp = index(s, '/')) != 0
- || (lp = index(s, ' ')) != 0)
+ while ((lp = strchr(s, '.')) != 0 || (lp = strchr(s, '/')) != 0
+ || (lp = strchr(s, ' ')) != 0)
*lp = '_';
#if defined(SYSV) && !defined(AIX_31) && !defined(SVR4) && !defined(LINUX) \
&& !defined(__APPLE__)
{
char filnambuf[BUFSIZ]; /*(not BUFSZ)*/
- if (index(file, ';')) {
+ if (strchr(file, ';')) {
/* assumes remove or delete, not vms_unlink */
if (!unlink(file)) {
(void) sleep(1);
(void) unlink(file);
}
- } else if (!index(file, '.')) {
+ } else if (!strchr(file, '.')) {
/* force some punctuation to be present */
file = strcat(strcpy(filnambuf, file), ".");
}
char filnambuf[BUFSIZ]; /*(not BUFSZ)*/
int fd;
- if (!index(file, '.') && !index(file, ';')) {
+ if (!strchr(file, '.') && !strchr(file, ';')) {
/* force some punctuation to be present to make sure that
the file name can't accidentally match a logical name */
file = strcat(strcpy(filnambuf, file), ";0");
char filnambuf[BUFSIZ]; /*(not BUFSZ)*/
FILE *fp;
- if (!index(file, '.') && !index(file, ';')) {
+ if (!strchr(file, '.') && !strchr(file, ';')) {
/* force some punctuation to be present to make sure that
the file name can't accidentally match a logical name */
file = strcat(strcpy(filnambuf, file), ";0");
return TRUE;
/* doesn't match full word, but maybe we got a false hit when
looking for "jane" in the list "janedoe jane" so keep going */
- p = index(sptr + 1, ' ');
- q = index(sptr + 1, ',');
+ p = strchr(sptr + 1, ' ');
+ q = strchr(sptr + 1, ',');
if (!p || (q && q < p))
p = q;
if (!p)
idx = -1;
val = -1;
- kp = index(op, '/');
+ kp = strchr(op, '/');
if (kp) {
*kp = '\0';
kp++;
if (length < 1 || length > 3)
return;
for (i = 0; i < length; i++)
- if (!index(digits, kp[i]))
+ if (!strchr(digits, kp[i]))
return;
val = atoi(kp);
length = strlen(op);
if (length < 1 || length > 3)
return;
for (i = 0; i < length; i++)
- if (!index(digits, op[i]))
+ if (!strchr(digits, op[i]))
return;
idx = atoi(op);
}
strcpy_s(path, path_size, root_path);
- char * colon = index(path, ';');
+ char * colon = strchr(path, ';');
if (colon != NULL) path[0] = '\0';
if (strlen(path) == 0) return;
{
char *ptr;
char drive;
- if ((ptr = index(str, ':')) != (char *) 0) {
+ if ((ptr = strchr(str, ':')) != (char *) 0) {
drive = toupper((uchar) *(ptr - 1));
_chdrive((drive - 'A') + 1);
}
unsigned len = (unsigned) strlen(line); /* includes newline */
if (len <= padlength) {
- endp = index(line, '\n'); /* fgetline() guarantees a newline even if
+ endp = strchr(line, '\n'); /* fgetline() guarantees a newline even if
* the input file's last line lacks one */
/* this is safe provided that padlength+1 is less than the allocation
matches a regular entry (bogusmon "grue"), that entry will become
more likely to be picked than normal but it's nothing to worry about */
Strcpy(buf, deflt_content);
- if (!index(buf, '\n')) /* lines from the file include trailing newline +*/
+ if (!strchr(buf, '\n')) /* lines from the file include trailing newline +*/
Strcat(buf, "\n"); /* so make sure that the default one does too */
(void) fputs(xcrypt(padline(buf, padlength)), ofp);
Strcpy(cbuf, ctime(&clocktim));
#endif /* REPRODUCIBLE_BUILD */
- if ((c = index(cbuf, '\n')) != 0)
+ if ((c = strchr(cbuf, '\n')) != 0)
*c = '\0'; /* strip off the '\n' */
#ifdef NHSTDC
ul_sfx = "UL";
/* read the gitinfo file */
while ((line = fgetline(gifp)) != 0) {
- strval = index(line, '=');
+ strval = strchr(line, '=');
if (strval && strlen(strval) < (BUFSZ-1)) {
opt = line;
*strval++ = '\0';
/* strip off the '\n' */
- if ((c = index(strval, '\n')) != 0)
+ if ((c = strchr(strval, '\n')) != 0)
*c = '\0';
- if ((c = index(opt, '\n')) != 0)
+ if ((c = strchr(opt, '\n')) != 0)
*c = '\0';
/* strip leading and trailing white space */
while (*strval == ' ' || *strval == '\t')
free((genericptr_t) c), c = NULL;
}
break; /* either with or without added newline, we're done */
- } else if (index(c, '\n')) {
+ } else if (strchr(c, '\n')) {
/* normal case: we have a full line */
break;
}
{
char *tf;
- tf = rindex(lock, '.');
+ tf = strrchr(lock, '.');
if (!tf)
tf = lock + strlen(lock);
(void) sprintf(tf, ".%d", lev);
++numdefs;
}
linelen += strlen(inbuf);
- if (!index(inbuf, '\n'))
+ if (!strchr(inbuf, '\n'))
continue;
if (linelen > longlen)
longlen = linelen;
}
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)
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();
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 */
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 */
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');
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) {
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;
}
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);
#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
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;
}
/* 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 */
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;
}
/* 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 */
/* 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 */
/* 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 */
} 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)
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;
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 */
}
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 = ' ';
}
[Note: wgetnstr() treats <escape> as an ordinary character
so user has to type <escape><return> for it to behave the
way we want it to.] */
- if (input[0] != '\033' && index(input, '\033') != 0)
+ if (input[0] != '\033' && strchr(input, '\033') != 0)
input[0] = '\0';
} while (--trylim > 0 && !input[0]);
curs_set(0);
break;
}
- if (choices != NULL && answer != '\0' && index(choices, answer))
+ if (choices != NULL && answer != '\0' && strchr(choices, answer))
break;
}
curs_set(0);
ret = '\n';
/* msgtype=stop should require space/enter rather than any key,
as we want to prevent YASD from direction keys. */
- } while (!index(resp, (char) ret));
+ } while (!strchr(resp, (char) ret));
if (oldcrsr >= 0)
(void) curs_set(oldcrsr);
case BL_SCORE:
#ifdef SCORE_ON_BOTL
if ((sho_score & 2) != 0) { /* strip "S:" prefix */
- if ((colon = index(text, ':')) != 0)
+ if ((colon = strchr(text, ':')) != 0)
text = strcat(strcpy(sbuf, " "), colon + 1);
else
sho_score = 0;
/* most status_vals_long[] are "long-text : value" and
unlike horizontal status's abbreviated "ab:value",
we highlight just the value portion */
- p = (fld != BL_TITLE) ? index(text, ':') : 0;
+ p = (fld != BL_TITLE) ? strchr(text, ':') : 0;
p = !p ? text : p + 1;
while (*p == ' ')
++p;
*p = savedch;
text = p; /* rest of field */
if ((fld == BL_HPMAX || fld == BL_ENEMAX)
- && (p = index(text, ')')) != 0) {
+ && (p = strchr(text, ')')) != 0) {
savedch = *p;
*p = '\0';
} else
} else {
text = status_vals[fldidx];
if (fldidx != BL_TITLE && fldidx != BL_LEVELDESC) {
- if ((colon = index(text, ':')) != 0)
+ if ((colon = strchr(text, ':')) != 0)
text = colon + 1;
}
lbl = status_fieldnm[fldidx];
fprintf(stdout, "--More--");
(void) fflush(stdout);
- while (!index(valid, nhgetch()))
+ while (!strchr(valid, nhgetch()))
;
}
return FALSE;
}
- p = rindex(filename, '/');
+ p = strrchr(filename, '/');
if (p)
p++;
else
morc = '\033';
break;
}
- if ((s && index(s, c)) || c == x || (x == '\n' && c == '\r')) {
+ if ((s && strchr(s, c)) || c == x || (x == '\n' && c == '\r')) {
morc = (char) c;
break;
}
break;
if (tl == otl) {
/* Eek! A huge token. Try splitting after it. */
- tl = index(otl, ' ');
+ tl = strchr(otl, ' ');
if (!tl)
break; /* No choice but to spit it out whole. */
}
if (resp) {
char *rb, respbuf[QBUFSZ];
- allow_num = (index(resp, '#') != 0);
+ allow_num = (strchr(resp, '#') != 0);
Strcpy(respbuf, resp);
/* normally we force lowercase, but if any uppercase letters
are present in the allowed response, preserve case;
break;
}
/* 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';
}
digit_ok = allow_num && digit(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) {
tty_nhbell();
q = (char) 0;
} else if (q == '#' || digit_ok) {
break; /* overflow: try again */
digit_string[0] = z;
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 */
tty_putstr(BASE_WINDOW, 0, prompt);
do {
pick4u = lowc(readchar());
- if (index(quitchars, pick4u))
+ if (strchr(quitchars, pick4u))
pick4u = 'y';
- } while (!index(ynaqchars, pick4u));
+ } while (!strchr(ynaqchars, pick4u));
if ((int) strlen(prompt) + 1 < CO) {
/* Echo choice and move back down line */
tty_putsym(BASE_WINDOW, (int) strlen(prompt) + 1, echoline,
accelerator; including it in gacc allows gold to
be selected via group when not on current page */
|| curr->gselector == GOLD_SYM)
- && !index(gacc, curr->gselector)
+ && !strchr(gacc, curr->gselector)
&& (cw->how == PICK_ANY
|| gcnt[GSELIDX(curr->gselector)] == 1)) {
*rp++ = curr->gselector;
- *rp = '\0'; /* re-terminate for index() */
+ *rp = '\0'; /* re-terminate for strchr() */
}
}
resp_len = 0; /* lint suppression */
entries, so we don't rely on curr->identifier here) */
attr_n = 0; /* whole line */
if (curr->str[0] && curr->str[1] == ' '
- && curr->str[2] && index("-+#", curr->str[2])
+ && curr->str[2] && strchr("-+#", curr->str[2])
&& curr->str[3] == ' ')
/* [0]=letter, [1]==space, [2]=[-+#], [3]=space */
attr_n = 4; /* [4:N]=entry description */
}
really_morc = morc; /* (only used with MENU_EXPLICIT_CHOICE) */
- if ((rp = index(resp, morc)) != 0 && rp < resp + resp_len)
+ if ((rp = strchr(resp, morc)) != 0 && rp < resp + resp_len)
/* explicit menu selection; don't override it if it also
happens to match a mapped menu command (such as ':' to
look inside a container vs ':' to search) */
/* special case: '0' is also the default ball class;
some menus use digits as potential group accelerators
but their entries don't rely on counts */
- if (!counting && index(gacc, morc))
+ if (!counting && strchr(gacc, morc))
goto group_accel;
count = (count * 10L) + (long) (morc - '0');
morc = really_morc;
/*FALLTHRU*/
default:
- if (cw->how == PICK_NONE || !index(resp, morc)) {
+ if (cw->how == PICK_NONE || !strchr(resp, morc)) {
/* unacceptable input received */
tty_nhbell();
break;
- } else if (index(gacc, morc)) {
+ } else if (strchr(gacc, morc)) {
group_accel:
/* group accelerator; for the PICK_ONE case, we know that
it matches exactly one item in order to be in gacc[] */
/* compress out consecutive spaces if line is too long;
topline wrapping converts space at wrap point into newline,
we reverse that here */
- if ((int) strlen(str) >= CO || index(str, '\n')) {
+ if ((int) strlen(str) >= CO || strchr(str, '\n')) {
const char *in_str = str;
char c, *outstr = cbuf, *outend = &cbuf[sizeof cbuf - 1];
boolean was_space = TRUE; /* True discards all leading spaces;
*ob = '\0';
if (!cw->cury && (int) strlen(str) >= CO) {
/* the characters before "St:" are unnecessary */
- nb = index(str, ':');
+ nb = strchr(str, ':');
if (nb && nb > str + 2)
str = nb - 2;
}
wins[datawin]->offy = 0;
}
while (dlb_fgets(buf, BUFSZ, f)) {
- if ((cr = index(buf, '\n')) != 0)
+ if ((cr = strchr(buf, '\n')) != 0)
*cr = 0;
#ifdef MSDOS
- if ((cr = index(buf, '\r')) != 0)
+ if ((cr = strchr(buf, '\r')) != 0)
*cr = 0;
#endif
- if (index(buf, '\t') != 0)
+ if (strchr(buf, '\t') != 0)
(void) tabexpand(buf);
empty = FALSE;
tty_putstr(datawin, 0, buf);
break;
case BL_GOLD:
/* \GXXXXNNNN counts as 1 [moot since we use decode_mixed() above] */
- if ((p = index(status_vals[fldidx], '\\')) != 0 && p[1] == 'G')
+ if ((p = strchr(status_vals[fldidx], '\\')) != 0 && p[1] == 'G')
tty_status[NOW][fldidx].lth -= (10 - 1);
break;
case BL_CAP:
{
/* try changing Dlvl: to Dl: */
char buf[BUFSZ];
- char *levval = index(status_vals[BL_LEVELDESC], ':');
+ char *levval = strchr(status_vals[BL_LEVELDESC], ':');
if (levval) {
dlvl_shrinklvl = lvl;
if (GetNHApp()->regNetHackMode && ((lParam & 1 << 29) != 0)) {
unsigned char c = (unsigned char) (wParam & 0xFF);
unsigned char scancode = (lParam >> 16) & 0xFF;
- if (index(extendedlist, tolower(c)) != 0) {
+ if (strchr(extendedlist, tolower(c)) != 0) {
NHEVENT_KBD(M(tolower(c)));
} else if (scancode == (SCANLO + SIZE(scanmap)) - 1) {
NHEVENT_KBD(M('?'));
/* 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,
if (choices) {
char *cb, choicebuf[QBUFSZ];
- allow_num = (index(choices, '#') != 0);
+ allow_num = (strchr(choices, '#') != 0);
Strcpy(choicebuf, choices);
- if ((cb = index(choicebuf, '\033')) != 0) {
+ if ((cb = strchr(choicebuf, '\033')) != 0) {
/* anything beyond <esc> is hidden */
*cb = '\0';
}
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);
Strcat(message, " ");
digit_ok = allow_num && digit(ch);
if (ch == '\033') {
- if (index(choices, 'q'))
+ if (strchr(choices, 'q'))
ch = 'q';
- else if (index(choices, 'n'))
+ else if (strchr(choices, 'n'))
ch = 'n';
else
ch = def;
break;
- } else if (index(quitchars, ch)) {
+ } else if (strchr(quitchars, ch)) {
ch = def;
break;
- } else if (!index(choices, ch) && !digit_ok) {
+ } else if (!strchr(choices, ch) && !digit_ok) {
mswin_nhbell();
ch = (char) 0;
/* and try again... */
digit_string[0] = z;
mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, digit_string, 1);
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 */
if (strlen(++colorstring) != 6)
return;
- red_value = (int) (index(hexadecimals, tolower((uchar) *colorstring))
+ red_value = (int) (strchr(hexadecimals, tolower((uchar) *colorstring))
- hexadecimals);
++colorstring;
red_value *= 16;
- red_value += (int) (index(hexadecimals, tolower((uchar) *colorstring))
+ red_value += (int) (strchr(hexadecimals, tolower((uchar) *colorstring))
- hexadecimals);
++colorstring;
- green_value = (int) (index(hexadecimals,
+ green_value = (int) (strchr(hexadecimals,
tolower((uchar) *colorstring))
- hexadecimals);
++colorstring;
green_value *= 16;
- green_value += (int) (index(hexadecimals,
+ green_value += (int) (strchr(hexadecimals,
tolower((uchar) *colorstring))
- hexadecimals);
++colorstring;
- blue_value = (int) (index(hexadecimals, tolower((uchar) *colorstring))
+ blue_value = (int) (strchr(hexadecimals, tolower((uchar) *colorstring))
- hexadecimals);
++colorstring;
blue_value *= 16;
- blue_value += (int) (index(hexadecimals,
+ blue_value += (int) (strchr(hexadecimals,
tolower((uchar) *colorstring))
- hexadecimals);
++colorstring;