| @@ -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 |
72 | static char rcsid[] = "$NetBSD: var.c,v 1.322 2020/07/26 17:44:54 rillig Exp $"; | | 72 | static 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 |
77 | static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; | | 77 | static 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}...@ */ |
2070 | static Boolean | | 2070 | static Boolean |
2071 | ApplyModifier_Loop(const char *mod, ApplyModifiersState *st) { | | 2071 | ApplyModifier_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) { |