| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: var.c,v 1.314 2020/07/26 15:26:27 rillig Exp $ */ | | 1 | /* $NetBSD: var.c,v 1.315 2020/07/26 15:37:44 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.314 2020/07/26 15:26:27 rillig Exp $"; | | 72 | static char rcsid[] = "$NetBSD: var.c,v 1.315 2020/07/26 15:37:44 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.314 2020/07/26 15:26:27 rillig Exp $"); | | 79 | __RCSID("$NetBSD: var.c,v 1.315 2020/07/26 15:37:44 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 | * |
| @@ -1315,44 +1315,45 @@ ModifyWord_Subst(const char *word, SepBu | | | @@ -1315,44 +1315,45 @@ ModifyWord_Subst(const char *word, SepBu |
1315 | SepBuf_AddBytes(buf, args->rhs, args->rhsLen); | | 1315 | SepBuf_AddBytes(buf, args->rhs, args->rhsLen); |
1316 | args->pflags |= VARP_SUB_MATCHED; | | 1316 | args->pflags |= VARP_SUB_MATCHED; |
1317 | } else { | | 1317 | } else { |
1318 | SepBuf_AddBytes(buf, args->rhs, args->rhsLen); | | 1318 | SepBuf_AddBytes(buf, args->rhs, args->rhsLen); |
1319 | SepBuf_AddBytes(buf, word + args->lhsLen, wordLen - args->lhsLen); | | 1319 | SepBuf_AddBytes(buf, word + args->lhsLen, wordLen - args->lhsLen); |
1320 | args->pflags |= VARP_SUB_MATCHED; | | 1320 | args->pflags |= VARP_SUB_MATCHED; |
1321 | } | | 1321 | } |
1322 | return; | | 1322 | return; |
1323 | } | | 1323 | } |
1324 | | | 1324 | |
1325 | if (args->pflags & VARP_ANCHOR_END) { | | 1325 | if (args->pflags & VARP_ANCHOR_END) { |
1326 | if (wordLen < args->lhsLen) | | 1326 | if (wordLen < args->lhsLen) |
1327 | goto nosub; | | 1327 | goto nosub; |
| | | 1328 | |
1328 | const char *start = word + (wordLen - args->lhsLen); | | 1329 | const char *start = word + (wordLen - args->lhsLen); |
1329 | if (memcmp(start, args->lhs, args->lhsLen) != 0) | | 1330 | if (memcmp(start, args->lhs, args->lhsLen) != 0) |
1330 | goto nosub; | | 1331 | goto nosub; |
1331 | | | 1332 | |
1332 | SepBuf_AddBytesBetween(buf, word, start); | | 1333 | SepBuf_AddBytesBetween(buf, word, start); |
1333 | SepBuf_AddBytes(buf, args->rhs, args->rhsLen); | | 1334 | SepBuf_AddBytes(buf, args->rhs, args->rhsLen); |
1334 | args->pflags |= VARP_SUB_MATCHED; | | 1335 | args->pflags |= VARP_SUB_MATCHED; |
1335 | return; | | 1336 | return; |
1336 | } | | 1337 | } |
1337 | | | 1338 | |
1338 | /* unanchored */ | | 1339 | /* unanchored */ |
1339 | const char *cp; | | 1340 | const char *match; |
1340 | while ((cp = Str_FindSubstring(word, args->lhs)) != NULL) { | | 1341 | while ((match = Str_FindSubstring(word, args->lhs)) != NULL) { |
1341 | SepBuf_AddBytesBetween(buf, word, cp); | | 1342 | SepBuf_AddBytesBetween(buf, word, match); |
1342 | SepBuf_AddBytes(buf, args->rhs, args->rhsLen); | | 1343 | SepBuf_AddBytes(buf, args->rhs, args->rhsLen); |
1343 | args->pflags |= VARP_SUB_MATCHED; | | 1344 | args->pflags |= VARP_SUB_MATCHED; |
1344 | wordLen -= (cp - word) + args->lhsLen; | | 1345 | wordLen -= (match - word) + args->lhsLen; |
1345 | word = cp + args->lhsLen; | | 1346 | word += (match - word) + args->lhsLen; |
1346 | if (wordLen == 0 || !(args->pflags & VARP_SUB_GLOBAL)) | | 1347 | if (wordLen == 0 || !(args->pflags & VARP_SUB_GLOBAL)) |
1347 | break; | | 1348 | break; |
1348 | } | | 1349 | } |
1349 | nosub: | | 1350 | nosub: |
1350 | SepBuf_AddBytes(buf, word, wordLen); | | 1351 | SepBuf_AddBytes(buf, word, wordLen); |
1351 | } | | 1352 | } |
1352 | | | 1353 | |
1353 | #ifndef NO_REGEX | | 1354 | #ifndef NO_REGEX |
1354 | /*- | | 1355 | /*- |
1355 | *----------------------------------------------------------------------- | | 1356 | *----------------------------------------------------------------------- |
1356 | * VarREError -- | | 1357 | * VarREError -- |
1357 | * Print the error caused by a regcomp or regexec call. | | 1358 | * Print the error caused by a regcomp or regexec call. |
1358 | * | | 1359 | * |