Sun Jul 26 12:19:37 2020 UTC ()
make(1): fix bug in :S modifier from 2020-07-19


(rillig)
diff -r1.309 -r1.310 src/usr.bin/make/var.c
diff -r1.24 -r1.25 src/usr.bin/make/unit-tests/modmisc.mk

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

--- src/usr.bin/make/var.c 2020/07/26 10:11:04 1.309
+++ src/usr.bin/make/var.c 2020/07/26 12:19:37 1.310
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: var.c,v 1.309 2020/07/26 10:11:04 rillig Exp $ */ 1/* $NetBSD: var.c,v 1.310 2020/07/26 12:19:37 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.309 2020/07/26 10:11:04 rillig Exp $"; 72static char rcsid[] = "$NetBSD: var.c,v 1.310 2020/07/26 12:19:37 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.309 2020/07/26 10:11:04 rillig Exp $"); 79__RCSID("$NetBSD: var.c,v 1.310 2020/07/26 12:19:37 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 *
@@ -1329,31 +1329,31 @@ ModifyWord_Subst(const char *word, SepBu @@ -1329,31 +1329,31 @@ ModifyWord_Subst(const char *word, SepBu
1329 goto nosub; 1329 goto nosub;
1330 1330
1331 SepBuf_AddBytes(buf, word, start - word); 1331 SepBuf_AddBytes(buf, word, start - word);
1332 SepBuf_AddBytes(buf, args->rhs, args->rhsLen); 1332 SepBuf_AddBytes(buf, args->rhs, args->rhsLen);
1333 args->pflags |= VARP_SUB_MATCHED; 1333 args->pflags |= VARP_SUB_MATCHED;
1334 return; 1334 return;
1335 } 1335 }
1336 1336
1337 /* unanchored */ 1337 /* unanchored */
1338 const char *cp; 1338 const char *cp;
1339 while ((cp = Str_FindSubstring(word, args->lhs)) != NULL) { 1339 while ((cp = Str_FindSubstring(word, args->lhs)) != NULL) {
1340 SepBuf_AddBytes(buf, word, cp - word); 1340 SepBuf_AddBytes(buf, word, cp - word);
1341 SepBuf_AddBytes(buf, args->rhs, args->rhsLen); 1341 SepBuf_AddBytes(buf, args->rhs, args->rhsLen);
 1342 args->pflags |= VARP_SUB_MATCHED;
1342 wordLen -= (cp - word) + args->lhsLen; 1343 wordLen -= (cp - word) + args->lhsLen;
1343 word = cp + args->lhsLen; 1344 word = cp + args->lhsLen;
1344 if (wordLen == 0 || !(args->pflags & VARP_SUB_GLOBAL)) 1345 if (wordLen == 0 || !(args->pflags & VARP_SUB_GLOBAL))
1345 break; 1346 break;
1346 args->pflags |= VARP_SUB_MATCHED; 
1347 } 1347 }
1348nosub: 1348nosub:
1349 SepBuf_AddBytes(buf, word, wordLen); 1349 SepBuf_AddBytes(buf, word, wordLen);
1350} 1350}
1351 1351
1352#ifndef NO_REGEX 1352#ifndef NO_REGEX
1353/*- 1353/*-
1354 *----------------------------------------------------------------------- 1354 *-----------------------------------------------------------------------
1355 * VarREError -- 1355 * VarREError --
1356 * Print the error caused by a regcomp or regexec call. 1356 * Print the error caused by a regcomp or regexec call.
1357 * 1357 *
1358 * Side Effects: 1358 * Side Effects:
1359 * An error gets printed. 1359 * An error gets printed.

cvs diff -r1.24 -r1.25 src/usr.bin/make/unit-tests/modmisc.mk (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/modmisc.mk 2020/07/26 12:18:11 1.24
+++ src/usr.bin/make/unit-tests/modmisc.mk 2020/07/26 12:19:37 1.25
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $Id: modmisc.mk,v 1.24 2020/07/26 12:18:11 rillig Exp $ 1# $Id: modmisc.mk,v 1.25 2020/07/26 12:19:37 rillig Exp $
2# 2#
3# miscellaneous modifier tests 3# miscellaneous modifier tests
4 4
5# do not put any dirs in this list which exist on some 5# do not put any dirs in this list which exist on some
6# but not all target systems - an exists() check is below. 6# but not all target systems - an exists() check is below.
7path=:/bin:/tmp::/:.:/no/such/dir:. 7path=:/bin:/tmp::/:.:/no/such/dir:.
8# strip cwd from path. 8# strip cwd from path.
9MOD_NODOT=S/:/ /g:N.:ts: 9MOD_NODOT=S/:/ /g:N.:ts:
10# and decorate, note that $'s need to be doubled. Also note that  10# and decorate, note that $'s need to be doubled. Also note that
11# the modifier_variable can be used with other modifiers. 11# the modifier_variable can be used with other modifiers.
12MOD_NODOTX=S/:/ /g:N.:@d@'$$d'@ 12MOD_NODOTX=S/:/ /g:N.:@d@'$$d'@
13# another mod - pretend it is more interesting 13# another mod - pretend it is more interesting
14MOD_HOMES=S,/home/,/homes/, 14MOD_HOMES=S,/home/,/homes/,
@@ -63,28 +63,27 @@ emptyvar: @@ -63,28 +63,27 @@ emptyvar:
63 @echo C:${:C,^$,empty,} 63 @echo C:${:C,^$,empty,}
64 @echo @:${:@var@${var}@} 64 @echo @:${:@var@${var}@}
65 65
66# The :U modifier turns even the "" variable into something that has a value. 66# The :U modifier turns even the "" variable into something that has a value.
67# The resulting variable is empty, but is still considered to contain a 67# The resulting variable is empty, but is still considered to contain a
68# single empty word. This word can be accessed by the :S and :C modifiers, 68# single empty word. This word can be accessed by the :S and :C modifiers,
69# but not by the :@ modifier since it explicitly skips empty words. 69# but not by the :@ modifier since it explicitly skips empty words.
70undefvar: 70undefvar:
71 @echo S:${:U:S,^$,empty,} 71 @echo S:${:U:S,^$,empty,}
72 @echo C:${:U:C,^$,empty,} 72 @echo C:${:U:C,^$,empty,}
73 @echo @:${:U:@var@empty@} 73 @echo @:${:U:@var@empty@}
74 74
75WORDS= sequences of letters 75WORDS= sequences of letters
76# FIXME: The "*" in "letters" must not be substituted because of the 1. 76.if ${WORDS:S,e,*,1} != "s*quences of letters"
77.if ${WORDS:S,e,*,1} != "s*quences of l*tters" 
78.warning ${WORDS:S,e,*,1} 77.warning ${WORDS:S,e,*,1}
79.endif 78.endif
80.if ${WORDS:S,e,*,} != "s*quences of l*tters" 79.if ${WORDS:S,e,*,} != "s*quences of l*tters"
81.error oops 80.error oops
82.endif 81.endif
83.if ${WORDS:S,e,*,g} != "s*qu*nc*s of l*tt*rs" 82.if ${WORDS:S,e,*,g} != "s*qu*nc*s of l*tt*rs"
84.error oops 83.error oops
85.endif 84.endif
86.if ${WORDS:S,^sequ,occurr,} != "occurrences of letters" 85.if ${WORDS:S,^sequ,occurr,} != "occurrences of letters"
87.error oops 86.error oops
88.endif 87.endif
89.if ${WORDS:S,^of,with,} != "sequences with letters" 88.if ${WORDS:S,^of,with,} != "sequences with letters"
90.error oops 89.error oops