autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/5] Make help-extract.pl work with Perl 5.10.x.


From: Zack Weinberg
Subject: [PATCH 4/5] Make help-extract.pl work with Perl 5.10.x.
Date: Sun, 10 Jul 2022 15:09:00 -0400

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 | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/build-aux/help-extract.pl b/build-aux/help-extract.pl
index 931331e3..a53a7db7 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 @@ sub eval_qq_no_interpolation ($)
   # 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 @@ The script-source argument should also be relative to 
top_srcdir.
       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;
-- 
2.36.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]