Fri Aug 28 17:15:04 2020 UTC ()
make(1): fix manual page about the modifiers of the :C modifier


(rillig)
diff -r1.288 -r1.289 src/usr.bin/make/make.1
diff -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-subst-regex.exp
diff -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-subst-regex.mk

cvs diff -r1.288 -r1.289 src/usr.bin/make/make.1 (expand / switch to unified diff)

--- src/usr.bin/make/make.1 2020/08/22 19:30:58 1.288
+++ src/usr.bin/make/make.1 2020/08/28 17:15:04 1.289
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: make.1,v 1.288 2020/08/22 19:30:58 sjg Exp $ 1.\" $NetBSD: make.1,v 1.289 2020/08/28 17:15:04 rillig Exp $
2.\" 2.\"
3.\" Copyright (c) 1990, 1993 3.\" Copyright (c) 1990, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
5.\" 5.\"
6.\" Redistribution and use in source and binary forms, with or without 6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions 7.\" modification, are permitted provided that the following conditions
8.\" are met: 8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright 9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer. 10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the 12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution. 13.\" documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors 14.\" 3. Neither the name of the University nor the names of its contributors
@@ -19,27 +19,27 @@ @@ -19,27 +19,27 @@
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE. 28.\" SUCH DAMAGE.
29.\" 29.\"
30.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 30.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
31.\" 31.\"
32.Dd August 22, 2020 32.Dd August 28, 2020
33.Dt MAKE 1 33.Dt MAKE 1
34.Os 34.Os
35.Sh NAME 35.Sh NAME
36.Nm make 36.Nm make
37.Nd maintain program dependencies 37.Nd maintain program dependencies
38.Sh SYNOPSIS 38.Sh SYNOPSIS
39.Nm 39.Nm
40.Op Fl BeikNnqrstWwX 40.Op Fl BeikNnqrstWwX
41.Op Fl C Ar directory 41.Op Fl C Ar directory
42.Op Fl D Ar variable 42.Op Fl D Ar variable
43.Op Fl d Ar flags 43.Op Fl d Ar flags
44.Op Fl f Ar makefile 44.Op Fl f Ar makefile
45.Op Fl I Ar directory 45.Op Fl I Ar directory
@@ -1300,35 +1300,35 @@ See also @@ -1300,35 +1300,35 @@ See also
1300Causes the value to be treated as a sequence of 1300Causes the value to be treated as a sequence of
1301words delimited by white space. 1301words delimited by white space.
1302See also 1302See also
1303.Ql Cm \&:[@] . 1303.Ql Cm \&:[@] .
1304.Sm off 1304.Sm off
1305.It Cm \&:S No \&/ Ar old_string No \&/ Ar new_string No \&/ Op Cm 1gW 1305.It Cm \&:S No \&/ Ar old_string No \&/ Ar new_string No \&/ Op Cm 1gW
1306.Sm on 1306.Sm on
1307Modifies the first occurrence of 1307Modifies the first occurrence of
1308.Ar old_string 1308.Ar old_string
1309in each word of the variable's value, replacing it with 1309in each word of the variable's value, replacing it with
1310.Ar new_string . 1310.Ar new_string .
1311If a 1311If a
1312.Ql g 1312.Ql g
1313is appended to the last slash of the pattern, all occurrences 1313is appended to the last delimiter of the pattern, all occurrences
1314in each word are replaced. 1314in each word are replaced.
1315If a 1315If a
1316.Ql 1 1316.Ql 1
1317is appended to the last slash of the pattern, only the first occurrence 1317is appended to the last delimiter of the pattern, only the first occurrence
1318is affected. 1318is affected.
1319If a 1319If a
1320.Ql W 1320.Ql W
1321is appended to the last slash of the pattern, 1321is appended to the last delimiter of the pattern,
1322then the value is treated as a single word 1322then the value is treated as a single word
1323(possibly containing embedded white space). 1323(possibly containing embedded white space).
1324If 1324If
1325.Ar old_string 1325.Ar old_string
1326begins with a caret 1326begins with a caret
1327.Pq Ql ^ , 1327.Pq Ql ^ ,
1328.Ar old_string 1328.Ar old_string
1329is anchored at the beginning of each word. 1329is anchored at the beginning of each word.
1330If 1330If
1331.Ar old_string 1331.Ar old_string
1332ends with a dollar sign 1332ends with a dollar sign
1333.Pq Ql \&$ , 1333.Pq Ql \&$ ,
1334it is anchored at the end of each word. 1334it is anchored at the end of each word.
@@ -1377,33 +1377,26 @@ Normally, the first occurrence of the pa @@ -1377,33 +1377,26 @@ Normally, the first occurrence of the pa
1377in each word of the value is substituted with 1377in each word of the value is substituted with
1378.Ar replacement . 1378.Ar replacement .
1379The 1379The
1380.Ql 1 1380.Ql 1
1381modifier causes the substitution to apply to at most one word; the 1381modifier causes the substitution to apply to at most one word; the
1382.Ql g 1382.Ql g
1383modifier causes the substitution to apply to as many instances of the 1383modifier causes the substitution to apply to as many instances of the
1384search pattern 1384search pattern
1385.Ar pattern 1385.Ar pattern
1386as occur in the word or words it is found in; the 1386as occur in the word or words it is found in; the
1387.Ql W 1387.Ql W
1388modifier causes the value to be treated as a single word 1388modifier causes the value to be treated as a single word
1389(possibly containing embedded white space). 1389(possibly containing embedded white space).
1390Note that 
1391.Ql 1 
1392and 
1393.Ql g 
1394are orthogonal; the former specifies whether multiple words are 
1395potentially affected, the latter whether multiple substitutions can 
1396potentially occur within each affected word. 
1397.Pp 1390.Pp
1398As for the 1391As for the
1399.Cm \&:S 1392.Cm \&:S
1400modifier, the 1393modifier, the
1401.Ar pattern 1394.Ar pattern
1402and 1395and
1403.Ar replacement 1396.Ar replacement
1404are subjected to variable expansion before being parsed as 1397are subjected to variable expansion before being parsed as
1405regular expressions. 1398regular expressions.
1406.It Cm \&:T 1399.It Cm \&:T
1407Replaces each word in the variable with its last path component. 1400Replaces each word in the variable with its last path component.
1408.It Cm \&:u 1401.It Cm \&:u
1409Removes adjacent duplicate words (like 1402Removes adjacent duplicate words (like

cvs diff -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-subst-regex.exp (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/varmod-subst-regex.exp 2020/08/16 12:30:45 1.2
+++ src/usr.bin/make/unit-tests/varmod-subst-regex.exp 2020/08/28 17:15:04 1.3
@@ -1,22 +1,15 @@ @@ -1,22 +1,15 @@
1mod-regex: 
2:a b b c: 
3:a b b c: 
4: b c: 
5make: Regex compilation error: (details omitted) 1make: Regex compilation error: (details omitted)
6:C,word,____,:Q}: 2mod-regex-compile-error: C,word,____,:Q}.
7:a c: 
8:x__ 3 x__ 3: 
9mod-regex-limits:00-ok:1 2323 45456 
10make: No subexpression \1 3make: No subexpression \1
11make: No subexpression \1 4make: No subexpression \1
12make: No subexpression \1 5make: No subexpression \1
13make: No subexpression \1 6make: No subexpression \1
14mod-regex-limits:11-missing:1 6 7mod-regex-limits:11-missing:1 6
15mod-regex-limits:11-ok:1 22 446 8mod-regex-limits:11-ok:1 22 446
16make: No subexpression \2 9make: No subexpression \2
17make: No subexpression \2 10make: No subexpression \2
18make: No subexpression \2 11make: No subexpression \2
19make: No subexpression \2 12make: No subexpression \2
20mod-regex-limits:22-missing:1 6 13mod-regex-limits:22-missing:1 6
21make: No subexpression \2 14make: No subexpression \2
22make: No subexpression \2 15make: No subexpression \2

cvs diff -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-subst-regex.mk (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/varmod-subst-regex.mk 2020/08/16 12:30:45 1.2
+++ src/usr.bin/make/unit-tests/varmod-subst-regex.mk 2020/08/28 17:15:04 1.3
@@ -1,30 +1,87 @@ @@ -1,30 +1,87 @@
1# $NetBSD: varmod-subst-regex.mk,v 1.2 2020/08/16 12:30:45 rillig Exp $ 1# $NetBSD: varmod-subst-regex.mk,v 1.3 2020/08/28 17:15:04 rillig Exp $
2# 2#
3# Tests for the :C,from,to, variable modifier. 3# Tests for the :C,from,to, variable modifier.
4 4
5all: mod-regex 5all: mod-regex-compile-error
6all: mod-regex-limits 6all: mod-regex-limits
7all: mod-regex-errors 7all: mod-regex-errors
8 8
9mod-regex: 9# The variable expression expands to 4 words. Of these words, none matches
10 @echo $@: 10# the regular expression "a b" since these words don't contain any
11 @echo :${:Ua b b c:C,a b,,:Q}: 11# whitespace.
12 @echo :${:Ua b b c:C,a b,,1:Q}: 12.if ${:Ua b b c:C,a b,,} != "a b b c"
13 @echo :${:Ua b b c:C,a b,,W:Q}: 13.error
14 @echo :${:Uword1 word2:C,****,____,g:C,word,____,:Q}: 14.endif
15 @echo :${:Ua b b c:C,b,,g:Q}: 
16 @echo :${:U1 2 3 1 2 3:C,1 2,___,Wg:C,_,x,:Q}: 
17 15
 16# Using the '1' modifier does not change anything. The '1' modifier just
 17# means to apply at most 1 replacement in the whole variable expression.
 18.if ${:Ua b b c:C,a b,,1} != "a b b c"
 19.error
 20.endif
 21
 22# The 'W' modifier treats the whole variable value as a single big word,
 23# containing whitespace. This big word matches the regular expression,
 24# therefore it gets replaced. Whitespace is preserved after replacing.
 25.if ${:Ua b b c:C,a b,,W} != " b c"
 26.error
 27.endif
 28
 29# The 'g' modifier does not have any effect here since each of the words
 30# contains the character 'b' a single time.
 31.if ${:Ua b b c:C,b,,g} != "a c"
 32.error
 33.endif
 34
 35# The first :C modifier has the 'W' modifier, which makes the whole
 36# expression a single word. The 'g' modifier then replaces all occurrences
 37# of "1 2" with "___". The 'W' modifier only applies to this single :C
 38# modifier. This is demonstrated by the :C modifier that follows. If the
 39# 'W' modifier would be preserved, only a single underscore would have been
 40# replaced with an 'x'.
 41.if ${:U1 2 3 1 2 3:C,1 2,___,Wg:C,_,x,} != "x__ 3 x__ 3"
 42.error
 43.endif
 44
 45# The regular expression does not match in the first word.
 46# It matches once in the second word, and the \0\0 doubles that word.
 47# In the third word, the regular expression matches as early as possible,
 48# and since the matches must not overlap, the next possible match would
 49# start at the 6, but at that point, there is only one character left,
 50# and that cannot match the regular expression "..". Therefore only the
 51# "45" is doubled in the result.
 52.if ${:U1 23 456:C,..,\0\0,} != "1 2323 45456"
 53.error
 54.endif
 55
 56# The modifier '1' applies the replacement at most once, across the whole
 57# variable value, no matter whether it is a single big word or many small
 58# words.
 59#
 60# Up to 2020-08-28, the manual page said that the modifiers '1' and 'g'
 61# were orthogonal, which was wrong.
 62.if ${:U12345 12345:C,.,\0\0,1} != "112345 12345"
 63.error
 64.endif
 65
 66# Multiple asterisks form an invalid regular expression. This produces an
 67# error message and (as of 2020-08-28) stops parsing in the middle of the
 68# variable expression. The unparsed part of the expression is then copied
 69# verbatim to the output, which is unexpected and can lead to strange shell
 70# commands being run.
 71mod-regex-compile-error:
 72 @echo $@: ${:Uword1 word2:C,****,____,g:C,word,____,:Q}.
 73
 74# These tests generate error messages but as of 2020-08-28 just continue
 75# parsing and execution as if nothing bad had happened.
18mod-regex-limits: 76mod-regex-limits:
19 @echo $@:00-ok:${:U1 23 456:C,..,\0\0,:Q} 
20 @echo $@:11-missing:${:U1 23 456:C,..,\1\1,:Q} 77 @echo $@:11-missing:${:U1 23 456:C,..,\1\1,:Q}
21 @echo $@:11-ok:${:U1 23 456:C,(.).,\1\1,:Q} 78 @echo $@:11-ok:${:U1 23 456:C,(.).,\1\1,:Q}
22 @echo $@:22-missing:${:U1 23 456:C,..,\2\2,:Q} 79 @echo $@:22-missing:${:U1 23 456:C,..,\2\2,:Q}
23 @echo $@:22-missing:${:U1 23 456:C,(.).,\2\2,:Q} 80 @echo $@:22-missing:${:U1 23 456:C,(.).,\2\2,:Q}
24 @echo $@:22-ok:${:U1 23 456:C,(.)(.),\2\2,:Q} 81 @echo $@:22-ok:${:U1 23 456:C,(.)(.),\2\2,:Q}
25 # The :C modifier only handles single-digit capturing groups, 82 # The :C modifier only handles single-digit capturing groups,
26 # which is more than enough for daily use. 83 # which is more than enough for daily use.
27 @echo $@:capture:${:UabcdefghijABCDEFGHIJrest:C,(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.),\9\8\7\6\5\4\3\2\1\0\10\11\12,} 84 @echo $@:capture:${:UabcdefghijABCDEFGHIJrest:C,(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.),\9\8\7\6\5\4\3\2\1\0\10\11\12,}
28 85
29mod-regex-errors: 86mod-regex-errors:
30 @echo $@: ${UNDEF:Uvalue:C,[,,} 87 @echo $@: ${UNDEF:Uvalue:C,[,,}