gen.pl: make the "manpageification" faster

The function that replaces occurances of "--longoption" with "-Z,
--longoption" etc with the proper highlight applied, no longer loops
over the options.

Closes #13041
This commit is contained in:
Daniel Stenberg 2024-03-04 15:16:11 +01:00
parent 6f685f04fd
commit eb9166dc66
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
2 changed files with 12 additions and 14 deletions

View File

@ -17,7 +17,7 @@ options *-O*, *-L* and *-v* at once as *-OLv*.
In general, all boolean options are enabled with --**option** and yet again
disabled with --**no-**option. That is, you use the same option name but
prefix it with `no-`. However, in this list we mostly only list and show the
*--option* version of them.
--**option** version of them.
When --next is used, it resets the parser state and you start again with a
clean option state, except for the options that are global. Global options

View File

@ -72,16 +72,23 @@ close(INC);
sub manpageify {
my ($k)=@_;
my $l;
my $trail;
# the matching pattern might include a trailing dot that cannot be part of
# the option name
if($k =~ s/\.$//) {
# cut off trailing dot
$trail = ".";
}
my $klong = $k;
# quote "bare" minuses in the long name
$klong =~ s/-/\\-/g;
if($optlong{$k} ne "") {
if($optlong{$k}) {
# both short + long
$l = "\\fI-".$optlong{$k}.", \\-\\-$klong\\fP";
$l = "\\fI-".$optlong{$k}.", \\-\\-$klong\\fP$trail";
}
else {
# only long
$l = "\\fI\\-\\-$klong\\fP";
$l = "\\fI\\-\\-$klong\\fP$trail";
}
return $l;
}
@ -289,16 +296,7 @@ sub render {
$d =~ s/\\/\\\\/g;
if(!$quote && $d =~ /--/) {
# scan for options in longest-names first order
for my $k (sort {length($b) <=> length($a)} keys %optlong) {
# --tlsv1 is complicated since --tlsv1.2 etc are also
# acceptable options!
if(($k eq "tlsv1") && ($d =~ /--tlsv1\.[0-9]\\f/)) {
next;
}
my $l = manpageify($k);
$d =~ s/--$k([^a-z0-9-])/$l$1/g;
}
$d =~ s/--([a-z0-9.-]+)/manpageify($1)/ge;
}
# quote minuses in the output