isspace() usage

Replace most uses of isspace() with a simple test for ' ' after
processing the string buffer with mungspaces (which replaces tab
with space, converts instances of consecutive whitespace into a
single space, and removes leading and trailing spaces).  The uses
where this wasn't done now cast their argument to (uchar) so that
platforms with signed chars will never pass negative values to it.

I didn't mess with the menu coloring code (except for casts to the
isspace() argument); it almost certainly could benefit from using
mungspaces.  I did mess with the symset processing quite a bit,
and hope I haven't accidentally broken anything.  Default symbols
and DECgraphics symbols still parse and display ok, so the rest of
dat/symbols should be ok too.  I didn't test symbols in the user's
config file because I don't remember how that's supposed to work.
This commit is contained in:
PatR
2015-04-25 02:11:13 -07:00
parent 672ef5223a
commit 27d8b631cd
5 changed files with 133 additions and 142 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.5 options.c $NHDT-Date: 1428088105 2015/04/03 19:08:25 $ $NHDT-Branch: scshunt-regex $:$NHDT-Revision: 1.182 $ */
/* NetHack 3.5 options.c $NHDT-Date: 1429953065 2015/04/25 09:11:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.186 $ */
/* NetHack 3.5 options.c $Date: 2012/04/09 02:56:30 $ $Revision: 1.153 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -544,7 +544,7 @@ boolean val_allowed;
*q = index(user_string, '=');
if (!p || (q && q < p)) p = q;
while(p && p > user_string && isspace(*(p-1))) p--;
while (p && p > user_string && isspace((uchar)*(p-1))) p--;
if (p) len = (int)(p - user_string);
}
@@ -1176,7 +1176,7 @@ char *str;
tmps = cs;
tmps++;
while (*tmps && isspace(*tmps)) tmps++;
while (*tmps && isspace((uchar)*tmps)) tmps++;
for (i = 0; i < SIZE(colornames); i++)
if (strstri(tmps, colornames[i].name) == tmps) {
@@ -1191,7 +1191,7 @@ char *str;
tmps = strchr(str, '&');
if (tmps) {
tmps++;
while (*tmps && isspace(*tmps)) tmps++;
while (*tmps && isspace((uchar)*tmps)) tmps++;
for (i = 0; i < SIZE(attrnames); i++)
if (strstri(tmps, attrnames[i].name) == tmps) {
a = attrnames[i].attr;
@@ -1205,7 +1205,7 @@ char *str;
tmps = str;
if ((*tmps == '"') || (*tmps == '\'')) {
cs--;
while (isspace(*cs)) cs--;
while (isspace((uchar)*cs)) cs--;
if (*cs == *tmps) {
*cs = '\0';
tmps++;
@@ -1281,9 +1281,9 @@ boolean tinitial, tfrom_file;
}
/* strip leading and trailing white space */
while (isspace(*opts)) opts++;
while (isspace((uchar)*opts)) opts++;
op = eos(opts);
while (--op >= opts && isspace(*op)) *op = '\0';
while (--op >= opts && isspace((uchar)*op)) *op = '\0';
if (!*opts) return;
negated = FALSE;
@@ -4115,8 +4115,7 @@ const char *mapping;
ape->pattern = (char *) alloc(textsize+1);
Strcpy(ape->pattern, text2);
ape->grab = grab;
if (!*apehead) ape->next = (struct autopickup_exception *)0;
else ape->next = *apehead;
ape->next = *apehead;
*apehead = ape;
} else {
raw_print("syntax error in AUTOPICKUP_EXCEPTION");
@@ -4207,7 +4206,7 @@ parsesymbols(opts)
register char *opts;
{
int val;
char *op, *symname, *strval, *p;
char *op, *symname, *strval;
struct symparse *symp;
if ((op = index(opts, ',')) != 0) {
@@ -4218,18 +4217,13 @@ register char *opts;
/* S_sample:string */
symname = opts;
strval = index(opts, ':');
if (!symname || !strval) return;
*strval++ = 0;
if (!strval) strval = index(opts, '=');
if (!strval) return;
*strval++ = '\0';
/* strip leading and trailing white space from symname */
while (isspace(*symname)) symname++;
p = eos(symname);
while (--p >= symname && isspace(*p)) *p = '\0';
/* strip leading and trailing white space from strval */
while (isspace(*strval)) strval++;
p = eos(strval);
while (--p >= strval && isspace(*p)) *p = '\0';
/* strip leading and trailing white space from symname and strval */
mungspaces(symname);
mungspaces(strval);
symp = match_sym(symname);
if (!symp) return;
@@ -4250,8 +4244,12 @@ char *buf;
struct symparse *sp = loadsyms;
if (!p || (q && q < p)) p = q;
while(p && p > buf && isspace(*(p-1))) p--;
if (p) len = (int)(p - buf);
if (p) {
/* note: there will be at most one space before the '='
because caller has condensed buf[] with mungspaces() */
if (p > buf && p[-1] == ' ') p--;
len = (int)(p - buf);
}
while(sp->range) {
if ((len >= strlen(sp->name)) && !strncmpi(buf, sp->name, len))
return sp;
@@ -4424,7 +4422,7 @@ struct fruit *replace_fruit;
for(c = pl_fruit; *c >= '0' && *c <= '9'; c++)
;
if (isspace(*c) || *c == 0) numeric = TRUE;
if (isspace((uchar)*c) || *c == 0) numeric = TRUE;
}
if (found || numeric ||
!strncmp(str, "cursed ", 7) ||
@@ -4847,34 +4845,34 @@ char *op;
wn = tfg = tbg = (char *)0;
/* until first non-space in case there's leading spaces - before colorname*/
while(*newop && isspace(*newop)) newop++;
if (*newop == ' ') newop++;
if (*newop) wn = newop;
else return 0;
/* until first space - colorname*/
while(*newop && !isspace(*newop)) newop++;
while (*newop && *newop != ' ') newop++;
if (*newop) *newop = '\0';
else return 0;
newop++;
/* until first non-space - before foreground*/
while(*newop && isspace(*newop)) newop++;
if (*newop == ' ') newop++;
if (*newop) tfg = newop;
else return 0;
/* until slash - foreground */
while(*newop && *newop != '/') newop++;
while (*newop && *newop != '/') newop++;
if (*newop) *newop = '\0';
else return 0;
newop++;
/* until first non-space (in case there's leading space after slash) - before background */
while(*newop && isspace(*newop)) newop++;
if (*newop == ' ') newop++;
if (*newop) tbg = newop;
else return 0;
/* until first space - background */
while(*newop && !isspace(*newop)) newop++;
while (*newop && *newop != ' ') newop++;
if (*newop) *newop++ = '\0';
for (j = 0; j < 4; ++j) {