Module Name:    src
Committed By:   rillig
Date:           Sun Oct  4 10:35:25 UTC 2020

Modified Files:
        src/usr.bin/make: nonints.h parse.c var.c

Log Message:
make(1): only use the VARE_ASSIGN flag if necessary

When checking the right-hand side of a variable assignment for syntax
errors, it does not matter  whether a '$$' is expanded to '$' or kept as
'$$'.


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.349 -r1.350 src/usr.bin/make/parse.c
cvs rdiff -u -r1.564 -r1.565 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/nonints.h
diff -u src/usr.bin/make/nonints.h:1.134 src/usr.bin/make/nonints.h:1.135
--- src/usr.bin/make/nonints.h:1.134	Sat Oct  3 15:00:57 2020
+++ src/usr.bin/make/nonints.h	Sun Oct  4 10:35:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.134 2020/10/03 15:00:57 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.135 2020/10/04 10:35:25 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -192,10 +192,13 @@ void Targ_Propagate(void);
 /* var.c */
 
 typedef enum {
+    VARE_NONE		= 0,
     /* Treat undefined variables as errors. */
     VARE_UNDEFERR	= 0x01,
     /* Expand and evaluate variables during parsing. */
     VARE_WANTRES	= 0x02,
+    /* In an assignment using the ':=' operator, keep '$$' as '$$' instead
+     * of reducing it to a single '$'. */
     VARE_ASSIGN		= 0x04
 } VarEvalFlags;
 

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.349 src/usr.bin/make/parse.c:1.350
--- src/usr.bin/make/parse.c:1.349	Sun Oct  4 07:49:45 2020
+++ src/usr.bin/make/parse.c	Sun Oct  4 10:35:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.349 2020/10/04 07:49:45 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.350 2020/10/04 10:35:25 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.349 2020/10/04 07:49:45 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.350 2020/10/04 10:35:25 rillig Exp $");
 
 /* types and constants */
 
@@ -1845,10 +1845,11 @@ Parse_DoVar(char *line, GNode *ctxt)
 
     if (DEBUG(LINT)) {
 	if (type != VAR_SUBST && strchr(cp, '$') != NULL) {
-	    /* sanity check now */
+	    /* Check for syntax errors such as unclosed expressions or
+	     * unknown modifiers. */
 	    char *expandedValue;
 
-	    (void)Var_Subst(cp, ctxt, VARE_ASSIGN, &expandedValue);
+	    (void)Var_Subst(cp, ctxt, VARE_NONE, &expandedValue);
 	    /* TODO: handle errors */
 	    free(expandedValue);
 	}

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.564 src/usr.bin/make/var.c:1.565
--- src/usr.bin/make/var.c:1.564	Sat Oct  3 21:19:54 2020
+++ src/usr.bin/make/var.c	Sun Oct  4 10:35:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.564 2020/10/03 21:19:54 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.565 2020/10/04 10:35:25 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.564 2020/10/03 21:19:54 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.565 2020/10/04 10:35:25 rillig Exp $");
 
 #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
 #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
@@ -3768,11 +3768,7 @@ Var_Subst(const char *str, GNode *ctxt, 
 
     while (*p != '\0') {
 	if (p[0] == '$' && p[1] == '$') {
-	    /*
-	     * A dollar sign may be escaped with another dollar sign.
-	     * In such a case, we skip over the escape character and store the
-	     * dollar sign into the buffer directly.
-	     */
+	    /* A dollar sign may be escaped with another dollar sign. */
 	    if (save_dollars && (eflags & VARE_ASSIGN))
 		Buf_AddByte(&buf, '$');
 	    Buf_AddByte(&buf, '$');

Reply via email to