| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: var.c,v 1.247 2020/07/04 03:08:20 lukem Exp $ */ | | 1 | /* $NetBSD: var.c,v 1.248 2020/07/04 10:19:39 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.247 2020/07/04 03:08:20 lukem Exp $"; | | 72 | static char rcsid[] = "$NetBSD: var.c,v 1.248 2020/07/04 10:19:39 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.247 2020/07/04 03:08:20 lukem Exp $"); | | 79 | __RCSID("$NetBSD: var.c,v 1.248 2020/07/04 10:19:39 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. The value and variable name need not | | 91 | * yet exist. The value and variable name need not |
92 | * be preserved. | | 92 | * be preserved. |
| @@ -289,53 +289,26 @@ typedef struct { | | | @@ -289,53 +289,26 @@ typedef struct { |
289 | int nsub; | | 289 | int nsub; |
290 | regmatch_t *matches; | | 290 | regmatch_t *matches; |
291 | char *replace; | | 291 | char *replace; |
292 | int flags; | | 292 | int flags; |
293 | } VarREPattern; | | 293 | } VarREPattern; |
294 | #endif | | 294 | #endif |
295 | | | 295 | |
296 | /* struct passed to VarSelectWords() for ":[start..end]" */ | | 296 | /* struct passed to VarSelectWords() for ":[start..end]" */ |
297 | typedef struct { | | 297 | typedef struct { |
298 | int start; /* first word to select */ | | 298 | int start; /* first word to select */ |
299 | int end; /* last word to select */ | | 299 | int end; /* last word to select */ |
300 | } VarSelectWords_t; | | 300 | } VarSelectWords_t; |
301 | | | 301 | |
302 | static Var *VarFind(const char *, GNode *, int); | | | |
303 | static void VarAdd(const char *, const char *, GNode *); | | | |
304 | static Boolean VarHead(GNode *, Var_Parse_State *, | | | |
305 | char *, Boolean, Buffer *, void *); | | | |
306 | static Boolean VarTail(GNode *, Var_Parse_State *, | | | |
307 | char *, Boolean, Buffer *, void *); | | | |
308 | static Boolean VarSuffix(GNode *, Var_Parse_State *, | | | |
309 | char *, Boolean, Buffer *, void *); | | | |
310 | static Boolean VarRoot(GNode *, Var_Parse_State *, | | | |
311 | char *, Boolean, Buffer *, void *); | | | |
312 | static Boolean VarMatch(GNode *, Var_Parse_State *, | | | |
313 | char *, Boolean, Buffer *, void *); | | | |
314 | #ifdef SYSVVARSUB | | | |
315 | static Boolean VarSYSVMatch(GNode *, Var_Parse_State *, | | | |
316 | char *, Boolean, Buffer *, void *); | | | |
317 | #endif | | | |
318 | static Boolean VarNoMatch(GNode *, Var_Parse_State *, | | | |
319 | char *, Boolean, Buffer *, void *); | | | |
320 | #ifndef NO_REGEX | | | |
321 | static void VarREError(int, regex_t *, const char *); | | | |
322 | static Boolean VarRESubstitute(GNode *, Var_Parse_State *, | | | |
323 | char *, Boolean, Buffer *, void *); | | | |
324 | #endif | | | |
325 | static Boolean VarSubstitute(GNode *, Var_Parse_State *, | | | |
326 | char *, Boolean, Buffer *, void *); | | | |
327 | static Boolean VarLoopExpand(GNode *, Var_Parse_State *, | | | |
328 | char *, Boolean, Buffer *, void *); | | | |
329 | static char *VarGetPattern(GNode *, Var_Parse_State *, | | 302 | static char *VarGetPattern(GNode *, Var_Parse_State *, |
330 | VarPattern_Flags, const char **, int, | | 303 | VarPattern_Flags, const char **, int, |
331 | VarPattern_Flags *, int *, VarPattern *); | | 304 | VarPattern_Flags *, int *, VarPattern *); |
332 | static char *VarQuote(char *, Boolean); | | 305 | static char *VarQuote(char *, Boolean); |
333 | static char *VarHash(char *); | | 306 | static char *VarHash(char *); |
334 | static char *VarModify(GNode *, Var_Parse_State *, | | 307 | static char *VarModify(GNode *, Var_Parse_State *, |
335 | const char *, | | 308 | const char *, |
336 | Boolean (*)(GNode *, Var_Parse_State *, char *, Boolean, Buffer *, void *), | | 309 | Boolean (*)(GNode *, Var_Parse_State *, char *, Boolean, Buffer *, void *), |
337 | void *); | | 310 | void *); |
338 | static char *VarOrder(const char *, const char); | | 311 | static char *VarOrder(const char *, const char); |
339 | static char *VarUniq(const char *); | | 312 | static char *VarUniq(const char *); |
340 | static int VarWordCompare(const void *, const void *); | | 313 | static int VarWordCompare(const void *, const void *); |
341 | | | 314 | |