Sun Jul 26 18:11:12 2020 UTC ()
make(1): merge VARE_NOSUBST into VARE_WANTRES

The flag VARE_NOSUBST is only a few days old. It had grown out of the
VARP_NOSUBST and VAR_NOSUBST flags, not knowing at that time that it
meant the exact opposite of VARE_WANTRES.


(rillig)
diff -r1.82 -r1.83 src/usr.bin/make/nonints.h
diff -r1.322 -r1.323 src/usr.bin/make/var.c

cvs diff -r1.82 -r1.83 src/usr.bin/make/Attic/nonints.h (expand / switch to unified diff)

--- src/usr.bin/make/Attic/nonints.h 2020/07/20 19:53:40 1.82
+++ src/usr.bin/make/Attic/nonints.h 2020/07/26 18:11:12 1.83
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: nonints.h,v 1.82 2020/07/20 19:53:40 rillig Exp $ */ 1/* $NetBSD: nonints.h,v 1.83 2020/07/26 18:11:12 rillig Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -171,32 +171,29 @@ void Targ_SetMain(GNode *); @@ -171,32 +171,29 @@ void Targ_SetMain(GNode *);
171int Targ_PrintCmd(void *, void *); 171int Targ_PrintCmd(void *, void *);
172int Targ_PrintNode(void *, void *); 172int Targ_PrintNode(void *, void *);
173char *Targ_FmtTime(time_t); 173char *Targ_FmtTime(time_t);
174void Targ_PrintType(int); 174void Targ_PrintType(int);
175void Targ_PrintGraph(int); 175void Targ_PrintGraph(int);
176void Targ_Propagate(void); 176void Targ_Propagate(void);
177void Targ_Propagate_Wait(void); 177void Targ_Propagate_Wait(void);
178 178
179/* var.c */ 179/* var.c */
180 180
181typedef enum { 181typedef enum {
182 /* Treat undefined variables as errors. */ 182 /* Treat undefined variables as errors. */
183 VARE_UNDEFERR = 0x01, 183 VARE_UNDEFERR = 0x01,
184 /* Actually evaluate the text, fully expanding variables. 184 /* Expand and evaluate variables during parsing. */
185 * Without this flag, the text is only parsed but not evaluated. */ 
186 VARE_WANTRES = 0x02, 185 VARE_WANTRES = 0x02,
187 VARE_ASSIGN = 0x04, 186 VARE_ASSIGN = 0x04
188 /* Return the literal text, without expanding variables. */ 
189 VARE_NOSUBST = 0x08 
190} VarEvalFlags; 187} VarEvalFlags;
191 188
192void Var_Delete(const char *, GNode *); 189void Var_Delete(const char *, GNode *);
193void Var_Set(const char *, const char *, GNode *); 190void Var_Set(const char *, const char *, GNode *);
194void Var_Append(const char *, const char *, GNode *); 191void Var_Append(const char *, const char *, GNode *);
195Boolean Var_Exists(const char *, GNode *); 192Boolean Var_Exists(const char *, GNode *);
196char *Var_Value(const char *, GNode *, char **); 193char *Var_Value(const char *, GNode *, char **);
197char *Var_Parse(const char *, GNode *, VarEvalFlags, int *, void **); 194char *Var_Parse(const char *, GNode *, VarEvalFlags, int *, void **);
198char *Var_Subst(const char *, const char *, GNode *, VarEvalFlags); 195char *Var_Subst(const char *, const char *, GNode *, VarEvalFlags);
199char *Var_GetTail(const char *); 196char *Var_GetTail(const char *);
200char *Var_GetHead(const char *); 197char *Var_GetHead(const char *);
201void Var_Init(void); 198void Var_Init(void);
202void Var_End(void); 199void Var_End(void);

cvs diff -r1.322 -r1.323 src/usr.bin/make/var.c (expand / switch to unified diff)

--- src/usr.bin/make/var.c 2020/07/26 17:44:54 1.322
+++ src/usr.bin/make/var.c 2020/07/26 18:11:12 1.323
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: var.c,v 1.322 2020/07/26 17:44:54 rillig Exp $ */ 1/* $NetBSD: var.c,v 1.323 2020/07/26 18:11:12 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -59,34 +59,34 @@ @@ -59,34 +59,34 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: var.c,v 1.322 2020/07/26 17:44:54 rillig Exp $"; 72static char rcsid[] = "$NetBSD: var.c,v 1.323 2020/07/26 18:11:12 rillig Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76#if 0 76#if 0
77static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; 77static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
78#else 78#else
79__RCSID("$NetBSD: var.c,v 1.322 2020/07/26 17:44:54 rillig Exp $"); 79__RCSID("$NetBSD: var.c,v 1.323 2020/07/26 18:11:12 rillig Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * var.c -- 85 * var.c --
86 * Variable-handling functions 86 * Variable-handling functions
87 * 87 *
88 * Interface: 88 * Interface:
89 * Var_Set Set the value of a variable in the given 89 * Var_Set Set the value of a variable in the given
90 * context. The variable is created if it doesn't 90 * context. The variable is created if it doesn't
91 * yet exist. 91 * yet exist.
92 * 92 *
@@ -1824,27 +1824,27 @@ ParseModifierPart(GNode *ctxt, const cha @@ -1824,27 +1824,27 @@ ParseModifierPart(GNode *ctxt, const cha
1824 for (cp = *tstr; *cp != '\0' && *cp != delim; cp++) { 1824 for (cp = *tstr; *cp != '\0' && *cp != delim; cp++) {
1825 Boolean is_escaped = cp[0] == '\\' && (cp[1] == delim || 1825 Boolean is_escaped = cp[0] == '\\' && (cp[1] == delim ||
1826 cp[1] == '\\' || cp[1] == '$' || (subst != NULL && cp[1] == '&')); 1826 cp[1] == '\\' || cp[1] == '$' || (subst != NULL && cp[1] == '&'));
1827 if (is_escaped) { 1827 if (is_escaped) {
1828 Buf_AddByte(&buf, cp[1]); 1828 Buf_AddByte(&buf, cp[1]);
1829 cp++; 1829 cp++;
1830 } else if (*cp == '$') { 1830 } else if (*cp == '$') {
1831 if (cp[1] == delim) { /* Unescaped $ at end of pattern */ 1831 if (cp[1] == delim) { /* Unescaped $ at end of pattern */
1832 if (out_pflags != NULL) 1832 if (out_pflags != NULL)
1833 *out_pflags |= VARP_ANCHOR_END; 1833 *out_pflags |= VARP_ANCHOR_END;
1834 else 1834 else
1835 Buf_AddByte(&buf, *cp); 1835 Buf_AddByte(&buf, *cp);
1836 } else { 1836 } else {
1837 if (!(eflags & VARE_NOSUBST)) { 1837 if (eflags & VARE_WANTRES) {
1838 char *cp2; 1838 char *cp2;
1839 int len; 1839 int len;
1840 void *freeIt; 1840 void *freeIt;
1841 1841
1842 /* 1842 /*
1843 * If unescaped dollar sign not before the 1843 * If unescaped dollar sign not before the
1844 * delimiter, assume it's a variable 1844 * delimiter, assume it's a variable
1845 * substitution and recurse. 1845 * substitution and recurse.
1846 */ 1846 */
1847 cp2 = Var_Parse(cp, ctxt, errnum | (eflags & VARE_WANTRES), 1847 cp2 = Var_Parse(cp, ctxt, errnum | (eflags & VARE_WANTRES),
1848 &len, &freeIt); 1848 &len, &freeIt);
1849 Buf_AddStr(&buf, cp2); 1849 Buf_AddStr(&buf, cp2);
1850 free(freeIt); 1850 free(freeIt);
@@ -2065,35 +2065,35 @@ typedef struct { @@ -2065,35 +2065,35 @@ typedef struct {
2065 (strncmp(s, want, n) == 0 && \ 2065 (strncmp(s, want, n) == 0 && \
2066 (s[n] == st->endc || s[n] == ':' || s[n] == '=')) 2066 (s[n] == st->endc || s[n] == ':' || s[n] == '='))
2067#define CHARMOD_MATCH(c) (c == st->endc || c == ':') 2067#define CHARMOD_MATCH(c) (c == st->endc || c == ':')
2068 2068
2069/* :@var@...${var}...@ */ 2069/* :@var@...${var}...@ */
2070static Boolean 2070static Boolean
2071ApplyModifier_Loop(const char *mod, ApplyModifiersState *st) { 2071ApplyModifier_Loop(const char *mod, ApplyModifiersState *st) {
2072 ModifyWord_LoopArgs args; 2072 ModifyWord_LoopArgs args;
2073 2073
2074 args.ctx = st->ctxt; 2074 args.ctx = st->ctxt;
2075 st->cp = mod + 1; 2075 st->cp = mod + 1;
2076 char delim = '@'; 2076 char delim = '@';
2077 args.tvar = ParseModifierPart(st->ctxt, &st->cp, delim, 2077 args.tvar = ParseModifierPart(st->ctxt, &st->cp, delim,
2078 st->eflags | VARE_NOSUBST, 2078 st->eflags & ~VARE_WANTRES,
2079 NULL, NULL, NULL); 2079 NULL, NULL, NULL);
2080 if (args.tvar == NULL) { 2080 if (args.tvar == NULL) {
2081 st->missing_delim = delim; 2081 st->missing_delim = delim;
2082 return FALSE; 2082 return FALSE;
2083 } 2083 }
2084 2084
2085 args.str = ParseModifierPart(st->ctxt, &st->cp, delim, 2085 args.str = ParseModifierPart(st->ctxt, &st->cp, delim,
2086 st->eflags | VARE_NOSUBST, 2086 st->eflags & ~VARE_WANTRES,
2087 NULL, NULL, NULL); 2087 NULL, NULL, NULL);
2088 if (args.str == NULL) { 2088 if (args.str == NULL) {
2089 st->missing_delim = delim; 2089 st->missing_delim = delim;
2090 return FALSE; 2090 return FALSE;
2091 } 2091 }
2092 2092
2093 st->termc = *st->cp; 2093 st->termc = *st->cp;
2094 2094
2095 args.eflags = st->eflags & (VARE_UNDEFERR | VARE_WANTRES); 2095 args.eflags = st->eflags & (VARE_UNDEFERR | VARE_WANTRES);
2096 int prev_sep = st->sep; 2096 int prev_sep = st->sep;
2097 st->sep = ' '; /* XXX: this is inconsistent */ 2097 st->sep = ' '; /* XXX: this is inconsistent */
2098 st->newStr = ModifyWords(st->ctxt, st->sep, st->oneBigWord, st->nstr, 2098 st->newStr = ModifyWords(st->ctxt, st->sep, st->oneBigWord, st->nstr,
2099 ModifyWord_Loop, &args); 2099 ModifyWord_Loop, &args);
@@ -2847,29 +2847,28 @@ ApplyModifier_Assign(const char *mod, Ap @@ -2847,29 +2847,28 @@ ApplyModifier_Assign(const char *mod, Ap
2847 2847
2848 switch (op[0]) { 2848 switch (op[0]) {
2849 case '+': 2849 case '+':
2850 case '?': 2850 case '?':
2851 case '!': 2851 case '!':
2852 st->cp = mod + 3; 2852 st->cp = mod + 3;
2853 break; 2853 break;
2854 default: 2854 default:
2855 st->cp = mod + 2; 2855 st->cp = mod + 2;
2856 break; 2856 break;
2857 } 2857 }
2858 2858
2859 char delim = st->startc == PROPEN ? PRCLOSE : BRCLOSE; 2859 char delim = st->startc == PROPEN ? PRCLOSE : BRCLOSE;
2860 VarEvalFlags eflags = (st->eflags & VARE_WANTRES) ? 0 : VARE_NOSUBST; 
2861 char *val = ParseModifierPart(st->ctxt, &st->cp, delim, 2860 char *val = ParseModifierPart(st->ctxt, &st->cp, delim,
2862 st->eflags | eflags, NULL, NULL, NULL); 2861 st->eflags, NULL, NULL, NULL);
2863 if (st->v->flags & VAR_JUNK) { 2862 if (st->v->flags & VAR_JUNK) {
2864 /* restore original name */ 2863 /* restore original name */
2865 free(st->v->name); 2864 free(st->v->name);
2866 st->v->name = sv_name; 2865 st->v->name = sv_name;
2867 } 2866 }
2868 if (val == NULL) { 2867 if (val == NULL) {
2869 st->missing_delim = delim; 2868 st->missing_delim = delim;
2870 return 'c'; 2869 return 'c';
2871 } 2870 }
2872 2871
2873 st->termc = *--st->cp; 2872 st->termc = *--st->cp;
2874 2873
2875 if (st->eflags & VARE_WANTRES) { 2874 if (st->eflags & VARE_WANTRES) {