Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): add wrappers around ctype.h functions



details:   https://anonhg.NetBSD.org/src/rev/525d3465d551
branches:  trunk
changeset: 943839:525d3465d551
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Sep 11 17:32:36 2020 +0000

description:
make(1): add wrappers around ctype.h functions

This avoids casting the argument to unsigned char, and to cast the
result of toupper/tolower back to char.

diffstat:

 usr.bin/make/arch.c     |  16 +++++-----
 usr.bin/make/compat.c   |  12 +++---
 usr.bin/make/cond.c     |  23 +++++++-------
 usr.bin/make/for.c      |  24 +++++++--------
 usr.bin/make/job.c      |  11 +++---
 usr.bin/make/main.c     |   8 ++--
 usr.bin/make/make.h     |  17 ++++++++++-
 usr.bin/make/metachar.h |   4 +-
 usr.bin/make/parse.c    |  74 +++++++++++++++++++++++-------------------------
 usr.bin/make/var.c      |  23 +++++++-------
 10 files changed, 110 insertions(+), 102 deletions(-)

diffs (truncated from 819 to 300 lines):

diff -r ac39d7ff2f8d -r 525d3465d551 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Fri Sep 11 16:37:48 2020 +0000
+++ b/usr.bin/make/arch.c       Fri Sep 11 17:32:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.110 2020/09/07 06:51:05 rillig Exp $        */
+/*     $NetBSD: arch.c,v 1.111 2020/09/11 17:32:36 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.110 2020/09/07 06:51:05 rillig Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.111 2020/09/11 17:32:36 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)arch.c     8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: arch.c,v 1.110 2020/09/07 06:51:05 rillig Exp $");
+__RCSID("$NetBSD: arch.c,v 1.111 2020/09/11 17:32:36 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -265,11 +265,11 @@
         */
        Boolean doSubst = FALSE; /* TRUE if need to substitute in memName */
 
-       while (*cp != '\0' && *cp != ')' && isspace ((unsigned char)*cp)) {
+       while (*cp != '\0' && *cp != ')' && ch_isspace(*cp)) {
            cp++;
        }
        memName = cp;
-       while (*cp != '\0' && *cp != ')' && !isspace ((unsigned char)*cp)) {
+       while (*cp != '\0' && *cp != ')' && !ch_isspace(*cp)) {
            if (*cp == '$') {
                /*
                 * Variable spec, so call the Var module to parse the puppy
@@ -448,7 +448,7 @@
      */
     do {
        cp++;
-    } while (*cp != '\0' && isspace ((unsigned char)*cp));
+    } while (*cp != '\0' && ch_isspace(*cp));
 
     *linePtr = cp;
     return TRUE;
@@ -631,7 +631,7 @@
             * first <namelen> bytes of the file
             */
            if (strncmp(memName, AR_EFMT1, sizeof(AR_EFMT1) - 1) == 0 &&
-               isdigit((unsigned char)memName[sizeof(AR_EFMT1) - 1])) {
+               ch_isdigit(memName[sizeof(AR_EFMT1) - 1])) {
 
                int elen = atoi(&memName[sizeof(AR_EFMT1)-1]);
 
@@ -879,7 +879,7 @@
                 */
            if (strncmp(arhPtr->ar_name, AR_EFMT1,
                                        sizeof(AR_EFMT1) - 1) == 0 &&
-               isdigit((unsigned char)arhPtr->ar_name[sizeof(AR_EFMT1) - 1])) {
+               ch_isdigit(arhPtr->ar_name[sizeof(AR_EFMT1) - 1])) {
 
                int elen = atoi(&arhPtr->ar_name[sizeof(AR_EFMT1)-1]);
                char ename[MAXPATHLEN + 1];
diff -r ac39d7ff2f8d -r 525d3465d551 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Fri Sep 11 16:37:48 2020 +0000
+++ b/usr.bin/make/compat.c     Fri Sep 11 17:32:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat.c,v 1.139 2020/08/30 20:08:47 rillig Exp $      */
+/*     $NetBSD: compat.c,v 1.140 2020/09/11 17:32:36 rillig Exp $      */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: compat.c,v 1.139 2020/08/30 20:08:47 rillig Exp $";
+static char rcsid[] = "$NetBSD: compat.c,v 1.140 2020/09/11 17:32:36 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)compat.c   8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: compat.c,v 1.139 2020/08/30 20:08:47 rillig Exp $");
+__RCSID("$NetBSD: compat.c,v 1.140 2020/09/11 17:32:36 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -264,7 +264,7 @@
        cmd++;
     }
 
-    while (isspace((unsigned char)*cmd))
+    while (ch_isspace(*cmd))
        cmd++;
 
     /*
@@ -416,9 +416,9 @@
                        fprintf(debug_file, "\n*** Failed target:  %s\n*** Failed command: ",
                            gn->name);
                        for (cp = cmd; *cp; ) {
-                           if (isspace((unsigned char)*cp)) {
+                           if (ch_isspace(*cp)) {
                                fprintf(debug_file, " ");
-                               while (isspace((unsigned char)*cp))
+                               while (ch_isspace(*cp))
                                    cp++;
                            } else {
                                fprintf(debug_file, "%c", *cp);
diff -r ac39d7ff2f8d -r 525d3465d551 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Fri Sep 11 16:37:48 2020 +0000
+++ b/usr.bin/make/cond.c       Fri Sep 11 17:32:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.133 2020/09/11 16:37:48 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.134 2020/09/11 17:32:36 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: cond.c,v 1.133 2020/09/11 16:37:48 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.134 2020/09/11 17:32:36 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)cond.c     8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: cond.c,v 1.133 2020/09/11 16:37:48 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.134 2020/09/11 17:32:36 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -175,7 +175,7 @@
 static int
 is_token(const char *str, const char *tok, size_t len)
 {
-    return strncmp(str, tok, len) == 0 && !isalpha((unsigned char)str[len]);
+    return strncmp(str, tok, len) == 0 && !ch_isalpha(str[len]);
 }
 
 /* Push back the most recent token read. We only need one level of this. */
@@ -191,7 +191,7 @@
 static void
 CondParser_SkipWhitespace(CondParser *par)
 {
-    while (isspace((unsigned char)par->p[0]))
+    while (ch_isspace(par->p[0]))
        par->p++;
 }
 
@@ -472,7 +472,7 @@
             */
            if ((par->p == start + len) &&
                (par->p[0] == '\0' ||
-                isspace((unsigned char)par->p[0]) ||
+                ch_isspace(par->p[0]) ||
                 strchr("!=><)", par->p[0]))) {
                goto cleanup;
            }
@@ -485,8 +485,7 @@
            str = NULL;         /* not finished yet */
            continue;
        default:
-           if (strictLHS && !qt && *start != '$' &&
-               !isdigit((unsigned char)*start)) {
+           if (strictLHS && !qt && *start != '$' && !ch_isdigit(*start)) {
                /* lhs must be quoted, a variable reference or number */
                if (*freeIt) {
                    free(*freeIt);
@@ -700,7 +699,7 @@
     }
 
     /* A variable is empty when it just contains spaces... 4/15/92, christos */
-    while (isspace((unsigned char)val[0]))
+    while (ch_isspace(val[0]))
        val++;
 
     /*
@@ -748,7 +747,7 @@
            continue;
        cp += fn_def->fn_name_len;
        /* There can only be whitespace before the '(' */
-       while (isspace((unsigned char)*cp))
+       while (ch_isspace(*cp))
            cp++;
        if (*cp != '(')
            break;
@@ -767,7 +766,7 @@
 
     /* Push anything numeric through the compare expression */
     cp = par->p;
-    if (isdigit((unsigned char)cp[0]) || strchr("+-", cp[0]))
+    if (ch_isdigit(cp[0]) || strchr("+-", cp[0]))
        return CondParser_Comparison(par, doEval);
 
     /*
@@ -779,7 +778,7 @@
      * expression.
      */
     arglen = ParseFuncArg(&cp, doEval, NULL, &arg);
-    for (cp1 = cp; isspace((unsigned char)*cp1); cp1++)
+    for (cp1 = cp; ch_isspace(*cp1); cp1++)
        continue;
     if (*cp1 == '=' || *cp1 == '!')
        return CondParser_Comparison(par, doEval);
diff -r ac39d7ff2f8d -r 525d3465d551 usr.bin/make/for.c
--- a/usr.bin/make/for.c        Fri Sep 11 16:37:48 2020 +0000
+++ b/usr.bin/make/for.c        Fri Sep 11 17:32:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: for.c,v 1.78 2020/09/07 06:28:22 rillig Exp $  */
+/*     $NetBSD: for.c,v 1.79 2020/09/11 17:32:36 rillig Exp $  */
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -30,14 +30,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: for.c,v 1.78 2020/09/07 06:28:22 rillig Exp $";
+static char rcsid[] = "$NetBSD: for.c,v 1.79 2020/09/11 17:32:36 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)for.c      8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: for.c,v 1.78 2020/09/07 06:28:22 rillig Exp $");
+__RCSID("$NetBSD: for.c,v 1.79 2020/09/11 17:32:36 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -129,7 +129,7 @@
     Words words;
 
     /* Skip the '.' and any following whitespace */
-    for (ptr = line + 1; isspace((unsigned char)*ptr); ptr++)
+    for (ptr = line + 1; ch_isspace(*ptr); ptr++)
        continue;
 
     /*
@@ -137,7 +137,7 @@
      * a for.
      */
     if (ptr[0] != 'f' || ptr[1] != 'o' || ptr[2] != 'r' ||
-       !isspace((unsigned char)ptr[3])) {
+       !ch_isspace(ptr[3])) {
        if (ptr[0] == 'e' && strncmp(ptr + 1, "ndfor", 5) == 0) {
            Parse_Error(PARSE_FATAL, "for-less endfor");
            return -1;
@@ -162,7 +162,7 @@
     while (TRUE) {
        size_t len;
 
-       while (isspace((unsigned char)*ptr))
+       while (ch_isspace(*ptr))
            ptr++;
        if (*ptr == '\0') {
            Parse_Error(PARSE_FATAL, "missing `in' in for");
@@ -170,7 +170,7 @@
            return -1;
        }
 
-       for (len = 1; ptr[len] && !isspace((unsigned char)ptr[len]); len++)
+       for (len = 1; ptr[len] && !ch_isspace(ptr[len]); len++)
            continue;
        if (len == 2 && ptr[0] == 'i' && ptr[1] == 'n') {
            ptr += 2;
@@ -189,7 +189,7 @@
        return -1;
     }
 
-    while (isspace((unsigned char)*ptr))
+    while (ch_isspace(*ptr))
        ptr++;
 
     /*
@@ -277,17 +277,15 @@
 
     if (*ptr == '.') {
 
-       for (ptr++; *ptr && isspace((unsigned char)*ptr); ptr++)
+       for (ptr++; *ptr && ch_isspace(*ptr); ptr++)
            continue;
 
-       if (strncmp(ptr, "endfor", 6) == 0 &&
-           (isspace((unsigned char)ptr[6]) || !ptr[6])) {
+       if (strncmp(ptr, "endfor", 6) == 0 && (ch_isspace(ptr[6]) || !ptr[6])) {
            if (DEBUG(FOR))
                (void)fprintf(debug_file, "For: end for %d\n", forLevel);
            if (--forLevel <= 0)
                return 0;
-       } else if (strncmp(ptr, "for", 3) == 0 &&



Home | Main Index | Thread Index | Old Index