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): use consistent pattern for parsing whi...



details:   https://anonhg.NetBSD.org/src/rev/5760d140c5fa
branches:  trunk
changeset: 955557:5760d140c5fa
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 03 21:19:54 2020 +0000

description:
make(1): use consistent pattern for parsing whitespace

The pp and cpp in the function names stand for "parsing position" and
"const parsing position".

diffstat:

 usr.bin/make/arch.c  |  16 ++++---------
 usr.bin/make/cond.c  |  17 ++++++--------
 usr.bin/make/for.c   |  19 ++++++---------
 usr.bin/make/job.c   |  10 +++-----
 usr.bin/make/make.h  |  16 +++++++++++++-
 usr.bin/make/parse.c |  60 ++++++++++++++++-----------------------------------
 usr.bin/make/var.c   |   7 ++---
 7 files changed, 61 insertions(+), 84 deletions(-)

diffs (truncated from 424 to 300 lines):

diff -r 92313a4c1daa -r 5760d140c5fa usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Sat Oct 03 20:34:06 2020 +0000
+++ b/usr.bin/make/arch.c       Sat Oct 03 21:19:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.128 2020/10/03 10:04:34 rillig Exp $        */
+/*     $NetBSD: arch.c,v 1.129 2020/10/03 21:19:54 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -134,7 +134,7 @@
 #include    "config.h"
 
 /*     "@(#)arch.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: arch.c,v 1.128 2020/10/03 10:04:34 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.129 2020/10/03 21:19:54 rillig Exp $");
 
 #ifdef TARGET_MACHINE
 #undef MAKE_MACHINE
@@ -413,15 +413,9 @@
        free(libName);
     }
 
-    /*
-     * We promised the pointer would be set up at the next non-space, so
-     * we must advance cp there before setting *linePtr... (note that on
-     * entrance to the loop, cp is guaranteed to point at a ')')
-     */
-    do {
-       cp++;
-    } while (*cp != '\0' && ch_isspace(*cp));
-
+    cp++;                      /* skip the ')' */
+    /* We promised that linePtr would be set up at the next non-space. */
+    pp_skip_whitespace(&cp);
     *linePtr = cp;
     return TRUE;
 }
diff -r 92313a4c1daa -r 5760d140c5fa usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sat Oct 03 20:34:06 2020 +0000
+++ b/usr.bin/make/cond.c       Sat Oct 03 21:19:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.156 2020/10/01 22:42:00 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.157 2020/10/03 21:19:54 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -93,7 +93,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.156 2020/10/01 22:42:00 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.157 2020/10/03 21:19:54 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -186,8 +186,7 @@
 static void
 CondParser_SkipWhitespace(CondParser *par)
 {
-    while (ch_isspace(par->p[0]))
-       par->p++;
+    cpp_skip_whitespace(&par->p);
 }
 
 /* Parse the argument of a built-in function.
@@ -697,8 +696,7 @@
     }
 
     /* A variable is empty when it just contains spaces... 4/15/92, christos */
-    while (ch_isspace(val[0]))
-       val++;
+    cpp_skip_whitespace(&val);
 
     /*
      * For consistency with the other functions we can't generate the
@@ -745,8 +743,7 @@
            continue;
        cp += fn_def->fn_name_len;
        /* There can only be whitespace before the '(' */
-       while (ch_isspace(*cp))
-           cp++;
+       cpp_skip_whitespace(&cp);
        if (*cp != '(')
            break;
 
@@ -776,8 +773,8 @@
      * expression.
      */
     arglen = ParseFuncArg(&cp, doEval, NULL, &arg);
-    for (cp1 = cp; ch_isspace(*cp1); cp1++)
-       continue;
+    cp1 = cp;
+    cpp_skip_whitespace(&cp1);
     if (*cp1 == '=' || *cp1 == '!')
        return CondParser_Comparison(par, doEval);
     par->p = cp;
diff -r 92313a4c1daa -r 5760d140c5fa usr.bin/make/for.c
--- a/usr.bin/make/for.c        Sat Oct 03 20:34:06 2020 +0000
+++ b/usr.bin/make/for.c        Sat Oct 03 21:19:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: for.c,v 1.89 2020/09/28 20:46:11 rillig Exp $  */
+/*     $NetBSD: for.c,v 1.90 2020/10/03 21:19:54 rillig Exp $  */
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -61,7 +61,7 @@
 #include    "strlist.h"
 
 /*     "@(#)for.c      8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: for.c,v 1.89 2020/09/28 20:46:11 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.90 2020/10/03 21:19:54 rillig Exp $");
 
 typedef enum {
     FOR_SUB_ESCAPE_CHAR = 0x0001,
@@ -119,8 +119,8 @@
     Words words;
 
     /* Skip the '.' and any following whitespace */
-    for (ptr = line + 1; ch_isspace(*ptr); ptr++)
-       continue;
+    ptr = line + 1;
+    cpp_skip_whitespace(&ptr);
 
     /*
      * If we are not in a for loop quickly determine if the statement is
@@ -152,8 +152,7 @@
     while (TRUE) {
        size_t len;
 
-       while (ch_isspace(*ptr))
-           ptr++;
+       cpp_skip_whitespace(&ptr);
        if (*ptr == '\0') {
            Parse_Error(PARSE_FATAL, "missing `in' in for");
            For_Free(new_for);
@@ -179,8 +178,7 @@
        return -1;
     }
 
-    while (ch_isspace(*ptr))
-       ptr++;
+    cpp_skip_whitespace(&ptr);
 
     /*
      * Make a list with the remaining words.
@@ -267,9 +265,8 @@
     const char *ptr = line;
 
     if (*ptr == '.') {
-
-       for (ptr++; *ptr && ch_isspace(*ptr); ptr++)
-           continue;
+       ptr++;
+       cpp_skip_whitespace(&ptr);
 
        if (strncmp(ptr, "endfor", 6) == 0 && (ch_isspace(ptr[6]) || !ptr[6])) {
            DEBUG1(FOR, "For: end for %d\n", forLevel);
diff -r 92313a4c1daa -r 5760d140c5fa usr.bin/make/job.c
--- a/usr.bin/make/job.c        Sat Oct 03 20:34:06 2020 +0000
+++ b/usr.bin/make/job.c        Sat Oct 03 21:19:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.256 2020/10/03 15:28:37 rillig Exp $ */
+/*     $NetBSD: job.c,v 1.257 2020/10/03 21:19:54 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -143,7 +143,7 @@
 #include "trace.h"
 
 /*     "@(#)job.c      8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.256 2020/10/03 15:28:37 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.257 2020/10/03 21:19:54 rillig Exp $");
 
 # define STATIC static
 
@@ -655,8 +655,7 @@
        cmd++;
     }
 
-    while (ch_isspace(*cmd))
-       cmd++;
+    pp_skip_whitespace(&cmd);
 
     /*
      * If the shell doesn't have error control the alternate echo'ing will
@@ -2211,8 +2210,7 @@
     Boolean    fullSpec = FALSE;
     Shell      *sh;
 
-    while (ch_isspace(*line))
-       line++;
+    pp_skip_whitespace(&line);
 
     free(shellArgv);
 
diff -r 92313a4c1daa -r 5760d140c5fa usr.bin/make/make.h
--- a/usr.bin/make/make.h       Sat Oct 03 20:34:06 2020 +0000
+++ b/usr.bin/make/make.h       Sat Oct 03 21:19:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.151 2020/09/28 22:38:32 rillig Exp $        */
+/*     $NetBSD: make.h,v 1.152 2020/10/03 21:19:54 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -616,6 +616,20 @@
 static inline MAKE_ATTR_UNUSED char ch_toupper(char ch)
 { return (char)toupper((unsigned char)ch); }
 
+static inline MAKE_ATTR_UNUSED void
+cpp_skip_whitespace(const char **pp)
+{
+    while (ch_isspace(**pp))
+       (*pp)++;
+}
+
+static inline MAKE_ATTR_UNUSED void
+pp_skip_whitespace(char **pp)
+{
+    while (ch_isspace(**pp))
+       (*pp)++;
+}
+
 #ifndef MAKE_NATIVE
 #define MAKE_RCSID(id) static volatile char rcsid[] = id
 #else
diff -r 92313a4c1daa -r 5760d140c5fa usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Oct 03 20:34:06 2020 +0000
+++ b/usr.bin/make/parse.c      Sat Oct 03 21:19:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.344 2020/10/01 23:44:36 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.345 2020/10/03 21:19:54 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -132,7 +132,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.344 2020/10/01 23:44:36 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.345 2020/10/03 21:19:54 rillig Exp $");
 
 /* types and constants */
 
@@ -768,8 +768,7 @@
        line++;
     if (!ch_isspace(*line))
        return FALSE;                   /* not for us */
-    while (ch_isspace(*line))
-       line++;
+    pp_skip_whitespace(&line);
 
     (void)Var_Subst(line, VAR_CMD, VARE_WANTRES, &line);
     /* TODO: handle errors */
@@ -1071,8 +1070,7 @@
     else if (lstart[0] == '.') {
        const char *dirstart = lstart + 1;
        const char *dirend;
-       while (ch_isspace(*dirstart))
-           dirstart++;
+       cpp_skip_whitespace(&dirstart);
        dirend = dirstart;
        while (ch_isalnum(*dirend) || *dirend == '-')
            dirend++;
@@ -1404,9 +1402,7 @@
                Parse_Error(PARSE_WARNING, "Extra target ignored");
            }
        } else {
-           while (*cp && ch_isspace(*cp)) {
-               cp++;
-           }
+           pp_skip_whitespace(&cp);
        }
        line = cp;
        if (*line == '\0')
@@ -1479,9 +1475,7 @@
      * LINE will now point to the first source word, if any, or the
      * end of the string if not.
      */
-    while (*cp && ch_isspace(*cp)) {
-       cp++;
-    }
+    pp_skip_whitespace(&cp);
     line = cp;
 
     /*
@@ -1606,9 +1600,7 @@
            if (savec != '\0') {
                cp++;
            }
-           while (*cp && ch_isspace(*cp)) {
-               cp++;
-           }
+           pp_skip_whitespace(&cp);
            line = cp;
        }
        if (paths) {
@@ -1659,9 +1651,7 @@
 
                ParseDoSrc(tOp, line, specType);
            }



Home | Main Index | Thread Index | Old Index