some C99 changes
Instead of using index() macro defined to strchr, use C99 strchr.
Instead of using rindex() macro defined to strrchr, use C99 strrchr.
If you want to try building on a platform that doesn't offer those
two functions, these are available:
define NOT_C99 /* to make some non-C99 code available */
define NEED_INDEX /* to define a macro for index() */
define NEED_RINDX /* to define a macro for rindex() */
This commit is contained in:
@@ -541,7 +541,7 @@ whoami(void)
|
||||
|
||||
if (s && *s) {
|
||||
(void) strncpy(g.plname, s, sizeof g.plname - 1);
|
||||
if (index(g.plname, '-'))
|
||||
if (strchr(g.plname, '-'))
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
@@ -609,7 +609,7 @@ wd_message(void)
|
||||
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.");
|
||||
|
||||
@@ -457,7 +457,7 @@ chdrive(char *str)
|
||||
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';
|
||||
|
||||
@@ -766,11 +766,11 @@ assign_videoshades(char *choiceptr)
|
||||
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';
|
||||
@@ -780,11 +780,11 @@ assign_videoshades(char *choiceptr)
|
||||
} 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';
|
||||
|
||||
@@ -198,7 +198,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
/* 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] =
|
||||
@@ -241,7 +241,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
* 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] =
|
||||
|
||||
@@ -102,10 +102,10 @@ tc_store(const char *trm, const char *ent)
|
||||
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);
|
||||
@@ -171,7 +171,7 @@ tc_find(FILE *fp, const char *term, char *buffer, int bufsiz)
|
||||
*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;
|
||||
}
|
||||
@@ -197,11 +197,11 @@ tc_name(const char *nam, char *ent)
|
||||
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;
|
||||
@@ -248,7 +248,7 @@ tgetstr(const char *which, char **outptr)
|
||||
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) {
|
||||
@@ -320,7 +320,7 @@ tc_field(const char *field, const char **tc_end)
|
||||
|
||||
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]
|
||||
@@ -329,7 +329,7 @@ tc_field(const char *field, const char **tc_end)
|
||||
}
|
||||
if (tc_end) {
|
||||
if (p) {
|
||||
if ((q = index(p + 2, ':')) == 0)
|
||||
if ((q = strchr(p + 2, ':')) == 0)
|
||||
q = end;
|
||||
} else
|
||||
q = 0;
|
||||
@@ -395,7 +395,7 @@ tparam(const char *ctl, /* parameter control string */
|
||||
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 */
|
||||
|
||||
@@ -134,7 +134,7 @@ main(int argc, char **argv)
|
||||
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);
|
||||
|
||||
@@ -336,8 +336,8 @@ lopt(
|
||||
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;
|
||||
|
||||
@@ -831,7 +831,7 @@ whoami(void)
|
||||
|
||||
if (s && *s) {
|
||||
(void) strncpy(g.plname, s, sizeof g.plname - 1);
|
||||
if (index(g.plname, '-'))
|
||||
if (strchr(g.plname, '-'))
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
@@ -897,7 +897,7 @@ wd_message(void)
|
||||
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.");
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
/* 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>
|
||||
@@ -218,8 +218,8 @@ regularize(char *s)
|
||||
{
|
||||
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__)
|
||||
|
||||
@@ -117,13 +117,13 @@ vms_creat(const char *file, unsigned int mode)
|
||||
{
|
||||
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), ".");
|
||||
}
|
||||
@@ -142,7 +142,7 @@ vms_open(const char *file, int flags, unsigned int mode)
|
||||
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");
|
||||
@@ -163,7 +163,7 @@ vms_fopen(const char *file, const char *mode)
|
||||
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");
|
||||
|
||||
@@ -392,8 +392,8 @@ check_user_string(const char *userlist)
|
||||
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)
|
||||
|
||||
@@ -1962,7 +1962,7 @@ map_subkeyvalue(char* op)
|
||||
|
||||
idx = -1;
|
||||
val = -1;
|
||||
kp = index(op, '/');
|
||||
kp = strchr(op, '/');
|
||||
if (kp) {
|
||||
*kp = '\0';
|
||||
kp++;
|
||||
@@ -1970,14 +1970,14 @@ map_subkeyvalue(char* op)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ build_environment_path(
|
||||
|
||||
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;
|
||||
|
||||
@@ -135,7 +135,7 @@ chdrive(char* str)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user