make(1): fix manual page about the modifiers of the :C modifierdiff -r1.288 -r1.289 src/usr.bin/make/make.1
(rillig)
--- 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 | |||
1300 | Causes the value to be treated as a sequence of | 1300 | Causes the value to be treated as a sequence of | |
1301 | words delimited by white space. | 1301 | words delimited by white space. | |
1302 | See also | 1302 | See 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 | |
1307 | Modifies the first occurrence of | 1307 | Modifies the first occurrence of | |
1308 | .Ar old_string | 1308 | .Ar old_string | |
1309 | in each word of the variable's value, replacing it with | 1309 | in each word of the variable's value, replacing it with | |
1310 | .Ar new_string . | 1310 | .Ar new_string . | |
1311 | If a | 1311 | If a | |
1312 | .Ql g | 1312 | .Ql g | |
1313 | is appended to the last slash of the pattern, all occurrences | 1313 | is appended to the last delimiter of the pattern, all occurrences | |
1314 | in each word are replaced. | 1314 | in each word are replaced. | |
1315 | If a | 1315 | If a | |
1316 | .Ql 1 | 1316 | .Ql 1 | |
1317 | is appended to the last slash of the pattern, only the first occurrence | 1317 | is appended to the last delimiter of the pattern, only the first occurrence | |
1318 | is affected. | 1318 | is affected. | |
1319 | If a | 1319 | If a | |
1320 | .Ql W | 1320 | .Ql W | |
1321 | is appended to the last slash of the pattern, | 1321 | is appended to the last delimiter of the pattern, | |
1322 | then the value is treated as a single word | 1322 | then the value is treated as a single word | |
1323 | (possibly containing embedded white space). | 1323 | (possibly containing embedded white space). | |
1324 | If | 1324 | If | |
1325 | .Ar old_string | 1325 | .Ar old_string | |
1326 | begins with a caret | 1326 | begins with a caret | |
1327 | .Pq Ql ^ , | 1327 | .Pq Ql ^ , | |
1328 | .Ar old_string | 1328 | .Ar old_string | |
1329 | is anchored at the beginning of each word. | 1329 | is anchored at the beginning of each word. | |
1330 | If | 1330 | If | |
1331 | .Ar old_string | 1331 | .Ar old_string | |
1332 | ends with a dollar sign | 1332 | ends with a dollar sign | |
1333 | .Pq Ql \&$ , | 1333 | .Pq Ql \&$ , | |
1334 | it is anchored at the end of each word. | 1334 | it 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 | |||
1377 | in each word of the value is substituted with | 1377 | in each word of the value is substituted with | |
1378 | .Ar replacement . | 1378 | .Ar replacement . | |
1379 | The | 1379 | The | |
1380 | .Ql 1 | 1380 | .Ql 1 | |
1381 | modifier causes the substitution to apply to at most one word; the | 1381 | modifier causes the substitution to apply to at most one word; the | |
1382 | .Ql g | 1382 | .Ql g | |
1383 | modifier causes the substitution to apply to as many instances of the | 1383 | modifier causes the substitution to apply to as many instances of the | |
1384 | search pattern | 1384 | search pattern | |
1385 | .Ar pattern | 1385 | .Ar pattern | |
1386 | as occur in the word or words it is found in; the | 1386 | as occur in the word or words it is found in; the | |
1387 | .Ql W | 1387 | .Ql W | |
1388 | modifier causes the value to be treated as a single word | 1388 | modifier causes the value to be treated as a single word | |
1389 | (possibly containing embedded white space). | 1389 | (possibly containing embedded white space). | |
1390 | Note that | |||
1391 | .Ql 1 | |||
1392 | and | |||
1393 | .Ql g | |||
1394 | are orthogonal; the former specifies whether multiple words are | |||
1395 | potentially affected, the latter whether multiple substitutions can | |||
1396 | potentially occur within each affected word. | |||
1397 | .Pp | 1390 | .Pp | |
1398 | As for the | 1391 | As for the | |
1399 | .Cm \&:S | 1392 | .Cm \&:S | |
1400 | modifier, the | 1393 | modifier, the | |
1401 | .Ar pattern | 1394 | .Ar pattern | |
1402 | and | 1395 | and | |
1403 | .Ar replacement | 1396 | .Ar replacement | |
1404 | are subjected to variable expansion before being parsed as | 1397 | are subjected to variable expansion before being parsed as | |
1405 | regular expressions. | 1398 | regular expressions. | |
1406 | .It Cm \&:T | 1399 | .It Cm \&:T | |
1407 | Replaces each word in the variable with its last path component. | 1400 | Replaces each word in the variable with its last path component. | |
1408 | .It Cm \&:u | 1401 | .It Cm \&:u | |
1409 | Removes adjacent duplicate words (like | 1402 | Removes adjacent duplicate words (like |
--- 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 @@ | |||
1 | mod-regex: | |||
2 | :a b b c: | |||
3 | :a b b c: | |||
4 | : b c: | |||
5 | make: Regex compilation error: (details omitted) | 1 | make: Regex compilation error: (details omitted) | |
6 | :C,word,____,:Q}: | 2 | mod-regex-compile-error: C,word,____,:Q}. | |
7 | :a c: | |||
8 | :x__ 3 x__ 3: | |||
9 | mod-regex-limits:00-ok:1 2323 45456 | |||
10 | make: No subexpression \1 | 3 | make: No subexpression \1 | |
11 | make: No subexpression \1 | 4 | make: No subexpression \1 | |
12 | make: No subexpression \1 | 5 | make: No subexpression \1 | |
13 | make: No subexpression \1 | 6 | make: No subexpression \1 | |
14 | mod-regex-limits:11-missing:1 6 | 7 | mod-regex-limits:11-missing:1 6 | |
15 | mod-regex-limits:11-ok:1 22 446 | 8 | mod-regex-limits:11-ok:1 22 446 | |
16 | make: No subexpression \2 | 9 | make: No subexpression \2 | |
17 | make: No subexpression \2 | 10 | make: No subexpression \2 | |
18 | make: No subexpression \2 | 11 | make: No subexpression \2 | |
19 | make: No subexpression \2 | 12 | make: No subexpression \2 | |
20 | mod-regex-limits:22-missing:1 6 | 13 | mod-regex-limits:22-missing:1 6 | |
21 | make: No subexpression \2 | 14 | make: No subexpression \2 | |
22 | make: No subexpression \2 | 15 | make: No subexpression \2 |
--- 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 | |||
5 | all: mod-regex | 5 | all: mod-regex-compile-error | |
6 | all: mod-regex-limits | 6 | all: mod-regex-limits | |
7 | all: mod-regex-errors | 7 | all: mod-regex-errors | |
8 | 8 | |||
9 | mod-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. | |||
71 | mod-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. | |||
18 | mod-regex-limits: | 76 | mod-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 | |||
29 | mod-regex-errors: | 86 | mod-regex-errors: | |
30 | @echo $@: ${UNDEF:Uvalue:C,[,,} | 87 | @echo $@: ${UNDEF:Uvalue:C,[,,} |