Skip to content

Commit

Permalink
Make help-extract.pl work with Perl 5.10.x.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zackw committed Jul 10, 2022
1 parent f580247 commit db7205a
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions build-aux/help-extract.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ($)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit db7205a

Please sign in to comment.