summaryrefslogtreecommitdiff
path: root/mk
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2020-05-11 19:52:13 +0000
committerrillig <rillig@pkgsrc.org>2020-05-11 19:52:13 +0000
commit410abb43017d6e300eb42c21a76cca0086d87a0a (patch)
tree80e074fec3d33e9b4ea342c3f49a5e391a9b10f9 /mk
parentf4d514e69bbf4d4bf68144cd124029bfed3e26b7 (diff)
downloadpkgsrc-410abb43017d6e300eb42c21a76cca0086d87a0a.tar.gz
mk/subst.mk: fix edge case in detection of identity substitutions
In a basic regular expression, a dollar-sign only means end-of-string if it appears at the end of the pattern, or (at the choice of the implementation) at the end of a \(...\) subexpression. This affects the package converters/help2man that uses a regular expression containing a dollar in a non-final position. This regular expression had not been detected as an identity substitution even though it is one.
Diffstat (limited to 'mk')
-rw-r--r--mk/scripts/subst-identity.awk10
1 files changed, 7 insertions, 3 deletions
diff --git a/mk/scripts/subst-identity.awk b/mk/scripts/subst-identity.awk
index f9e9f3c4e33..28fa6a5773b 100644
--- a/mk/scripts/subst-identity.awk
+++ b/mk/scripts/subst-identity.awk
@@ -1,5 +1,5 @@
#! /usr/bin/awk -f
-# $NetBSD: subst-identity.awk,v 1.2 2020/05/06 06:14:56 rillig Exp $
+# $NetBSD: subst-identity.awk,v 1.3 2020/05/11 19:52:14 rillig Exp $
#
# Tests whether a sed(1) command line consists of only identity substitutions
# like s,id,id,.
@@ -9,13 +9,17 @@
# Returns the first character of the given regular expression,
# if it is a single-character regular expression.
-function identity_char(s) {
+function identity_char(s, sep, i) {
if (s ~ /^[\t -~]/ && s !~ /^[$&*.\[\\\]^]/)
return substr(s, 1, 1);
if (s ~ /^\\[$*.\[\]^]/)
return substr(s, 2, 1) "x";
if (s ~ /^\[[$*.]\]/)
return substr(s, 2, 1) "xx";
+ if (substr(s, 1, 1) == "$" && substr(s, 2, 1) != sep)
+ return substr(s, 1, 1);
+ if (substr(s, 1, 1) == "^" && i > 3)
+ return substr(s, 1, 1);
return "";
}
@@ -29,7 +33,7 @@ function is_identity_subst(s, len, i, sep, pat_from, pat_to, ch, subst) {
i = 3;
pat_to = "";
while (i < len && substr(s, i, 1) != sep) {
- ch = identity_char(substr(s, i));
+ ch = identity_char(substr(s, i), sep, i);
if (ch == "")
break;
pat_to = pat_to substr(ch, 1, 1);