From db7205a8647f5c197953a60d1e86a9993e1a9dca Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Sun, 10 Jul 2022 11:47:45 -0400 Subject: [PATCH] Make help-extract.pl work with Perl 5.10.x. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The main issue was use of s///r; the /r modifier was added in 5.14. Since the baseline is now 5.10.0 instead of 5.6.0, a couple places can be tidied up using slightly newer constructs. * help-extract.pl: Use File::Spec::Functions instead of File::Spec for reduced clunkiness. (eval_qq_no_interpolation): Don’t use s///r. Do use \K and (?=...) to match the empty string (but only in just the right locations), so we don’t need to use $& in the replacement. (main): Don’t use s///r. --- build-aux/help-extract.pl | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/build-aux/help-extract.pl b/build-aux/help-extract.pl index 931331e3..2fc25379 100644 --- a/build-aux/help-extract.pl +++ b/build-aux/help-extract.pl @@ -19,10 +19,7 @@ use 5.010; use strict; use warnings; - -# File::Spec itself was added in 5.005. -# File::Spec::Functions was added in 5.6.1 which is just barely too new. -use File::Spec; +use File::Spec::Functions qw(catfile); # This script is not intended to be used directly. It's run by # help2man via wrappers in man/, e.g. man/autoconf.w, as if it were @@ -51,11 +48,17 @@ ($) # The argument is expected to be a "double quoted string" including the # leading and trailing delimiters. Returns the text of this string after # processing backslash escapes but NOT interpolation. - # / (?\\\\)* blah /x means match blah preceded by an - # *even* number of backslashes. It would be nice if we could use \K - # to exclude the backslashes from the matched text, but that was only - # added in Perl 5.10 and we still support back to 5.006. - return eval $_[0] =~ s/ (?\\\\)* [\$\@] /\\$&/xrg; + my $s = $_[0]; + + # Escape $ and @ inside the string, if they are not already escaped. + # The regex matches the empty string, but only if it is preceded by an + # even number of backslashes (including zero) and followed by either a + # literal $ or a literal @. Then we insert a backslash at the position + # of the match. + $s =~ s/ (?:\A|[^\\]) (?:\\\\)* \K (?=[\$\@]) /\\/xg; + + # It is now safe to feed the string to 'eval'. + return eval $s; } sub extract_channeldefs_usage ($) @@ -198,9 +201,10 @@ () die $usage; } - my $cmd_name = $source =~ s{^.*/([^./]+)\.in$}{$1}r; - $source = File::Spec->catfile($top_srcdir, $source); - $channeldefs_pm = File::Spec->catfile($top_srcdir, $channeldefs_pm); + my $cmd_name = $source; + $cmd_name =~ s{^.*/([^./]+)\.in$}{$1}; + $source = catfile($top_srcdir, $source); + $channeldefs_pm = catfile($top_srcdir, $channeldefs_pm); my $text = extract_assignment ($source, $channeldefs_pm, $what); $text =~ s/\$0\b/$cmd_name/g;