Module Name:    src
Committed By:   rillig
Date:           Sat Oct  3 21:19:54 UTC 2020

Modified Files:
        src/usr.bin/make: arch.c cond.c for.c job.c make.h parse.c var.c

Log Message:
make(1): use consistent pattern for parsing whitespace

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


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 src/usr.bin/make/arch.c
cvs rdiff -u -r1.156 -r1.157 src/usr.bin/make/cond.c
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/make/for.c
cvs rdiff -u -r1.256 -r1.257 src/usr.bin/make/job.c
cvs rdiff -u -r1.151 -r1.152 src/usr.bin/make/make.h
cvs rdiff -u -r1.344 -r1.345 src/usr.bin/make/parse.c
cvs rdiff -u -r1.563 -r1.564 src/usr.bin/make/var.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/arch.c
diff -u src/usr.bin/make/arch.c:1.128 src/usr.bin/make/arch.c:1.129
--- src/usr.bin/make/arch.c:1.128	Sat Oct  3 10:04:34 2020
+++ src/usr.bin/make/arch.c	Sat Oct  3 21:19:54 2020
@@ -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 @@ Arch_ParseArchive(char **linePtr, GNodeL
 	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;
 }

Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.156 src/usr.bin/make/cond.c:1.157
--- src/usr.bin/make/cond.c:1.156	Thu Oct  1 22:42:00 2020
+++ src/usr.bin/make/cond.c	Sat Oct  3 21:19:54 2020
@@ -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 @@ CondParser_PushBack(CondParser *par, Tok
 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 @@ ParseEmptyArg(const char **linePtr, Bool
     }
 
     /* 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 @@ CondParser_Func(CondParser *par, Boolean
 	    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 @@ CondParser_Func(CondParser *par, Boolean
      * 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;

Index: src/usr.bin/make/for.c
diff -u src/usr.bin/make/for.c:1.89 src/usr.bin/make/for.c:1.90
--- src/usr.bin/make/for.c:1.89	Mon Sep 28 20:46:11 2020
+++ src/usr.bin/make/for.c	Sat Oct  3 21:19:54 2020
@@ -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 @@ For_Eval(const char *line)
     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 @@ For_Eval(const char *line)
     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 @@ For_Eval(const char *line)
 	return -1;
     }
 
-    while (ch_isspace(*ptr))
-	ptr++;
+    cpp_skip_whitespace(&ptr);
 
     /*
      * Make a list with the remaining words.
@@ -267,9 +265,8 @@ For_Accum(const char *line)
     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);

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.256 src/usr.bin/make/job.c:1.257
--- src/usr.bin/make/job.c:1.256	Sat Oct  3 15:28:37 2020
+++ src/usr.bin/make/job.c	Sat Oct  3 21:19:54 2020
@@ -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 @@ JobPrintCommand(void *cmdp, void *jobp)
 	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 @@ Job_ParseShell(char *line)
     Boolean	fullSpec = FALSE;
     Shell	*sh;
 
-    while (ch_isspace(*line))
-	line++;
+    pp_skip_whitespace(&line);
 
     free(shellArgv);
 

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.151 src/usr.bin/make/make.h:1.152
--- src/usr.bin/make/make.h:1.151	Mon Sep 28 22:38:32 2020
+++ src/usr.bin/make/make.h	Sat Oct  3 21:19:54 2020
@@ -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_t
 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

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.344 src/usr.bin/make/parse.c:1.345
--- src/usr.bin/make/parse.c:1.344	Thu Oct  1 23:44:36 2020
+++ src/usr.bin/make/parse.c	Sat Oct  3 21:19:54 2020
@@ -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 @@ ParseMessage(char *line)
 	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 @@ ParseErrorNoDependency(const char *lstar
     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 @@ ParseDoDependency(char *line)
 		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 @@ ParseDoDependency(char *line)
      * 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 @@ ParseDoDependency(char *line)
 	    if (savec != '\0') {
 		cp++;
 	    }
-	    while (*cp && ch_isspace(*cp)) {
-		cp++;
-	    }
+	    pp_skip_whitespace(&cp);
 	    line = cp;
 	}
 	if (paths) {
@@ -1659,9 +1651,7 @@ ParseDoDependency(char *line)
 
 		ParseDoSrc(tOp, line, specType);
 	    }
-	    while (*cp && ch_isspace(*cp)) {
-		cp++;
-	    }
+	    pp_skip_whitespace(&cp);
 	    line = cp;
 	}
     }
@@ -1854,8 +1844,7 @@ Parse_DoVar(char *line, GNode *ctxt)
 	    break;
     }
 
-    while (ch_isspace(*cp))
-	cp++;
+    pp_skip_whitespace(&cp);
 
     if (DEBUG(LINT)) {
 	if (type != VAR_SUBST && strchr(cp, '$') != NULL) {
@@ -2408,11 +2397,7 @@ ParseTraditionalInclude(char *line)
 
     DEBUG2(PARSE, "%s: %s\n", __func__, file);
 
-    /*
-     * Skip over whitespace
-     */
-    while (ch_isspace(*file))
-	file++;
+    pp_skip_whitespace(&file);
 
     /*
      * Substitute for any variables in the file name before trying to
@@ -2454,11 +2439,7 @@ ParseGmakeExport(char *line)
 
     DEBUG2(PARSE, "%s: %s\n", __func__, variable);
 
-    /*
-     * Skip over whitespace
-     */
-    while (ch_isspace(*variable))
-	variable++;
+    pp_skip_whitespace(&variable);
 
     for (value = variable; *value && *value != '='; value++)
 	continue;
@@ -2793,9 +2774,7 @@ FinishDependencyGroup(void)
 static void
 ParseLine_ShellCommand(char *cp)
 {
-    for (; ch_isspace(*cp); cp++)
-	continue;
-
+    pp_skip_whitespace(&cp);
     if (*cp == '\0')
 	return;			/* skip empty commands */
 
@@ -2853,16 +2832,16 @@ Parse_File(const char *name, int fd)
 		 * On the other hand they can be suffix rules (.c.o: ...)
 		 * or just dependencies for filenames that start '.'.
 		 */
-		for (cp = line + 1; ch_isspace(*cp); cp++)
-		    continue;
+		cp = line + 1;
+		pp_skip_whitespace(&cp);
 		if (IsInclude(cp, FALSE)) {
 		    ParseDoInclude(cp);
 		    continue;
 		}
 		if (strncmp(cp, "undef", 5) == 0) {
 		    const char *varname;
-		    for (cp += 5; ch_isspace(*cp); cp++)
-			continue;
+		    cp += 5;
+		    pp_skip_whitespace(&cp);
 		    varname = cp;
 		    for (; !ch_isspace(*cp) && *cp != '\0'; cp++)
 			continue;
@@ -2872,8 +2851,8 @@ Parse_File(const char *name, int fd)
 		    /* TODO: use Str_Words, like everywhere else */
 		    continue;
 		} else if (strncmp(cp, "export", 6) == 0) {
-		    for (cp += 6; ch_isspace(*cp); cp++)
-			continue;
+		    cp += 6;
+		    pp_skip_whitespace(&cp);
 		    Var_Export(cp, TRUE);
 		    continue;
 		} else if (strncmp(cp, "unexport", 8) == 0) {
@@ -2933,8 +2912,7 @@ Parse_File(const char *name, int fd)
 	     */
 	    cp = line;
 	    if (ch_isspace(line[0])) {
-		while (ch_isspace(*cp))
-		    cp++;
+		pp_skip_whitespace(&cp);
 		while (*cp && (ParseIsEscaped(line, cp) ||
 			*cp != ':' && *cp != '!')) {
 		    cp++;

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.563 src/usr.bin/make/var.c:1.564
--- src/usr.bin/make/var.c:1.563	Sat Oct  3 14:41:20 2020
+++ src/usr.bin/make/var.c	Sat Oct  3 21:19:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.563 2020/10/03 14:41:20 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.564 2020/10/03 21:19:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -121,7 +121,7 @@
 #include    "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.563 2020/10/03 14:41:20 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.564 2020/10/03 21:19:54 rillig Exp $");
 
 #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
 #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
@@ -677,8 +677,7 @@ Var_UnExport(const char *str)
 	if (cp && *cp)
 	    setenv(MAKE_LEVEL_ENV, cp, 1);
     } else {
-	for (; ch_isspace(*str); str++)
-	    continue;
+	cpp_skip_whitespace(&str);
 	if (str[0] != '\0')
 	    varnames = str;
     }

Reply via email to