]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
gen.pl: make the "manpageification" faster
authorDaniel Stenberg <daniel@haxx.se>
Mon, 4 Mar 2024 14:16:11 +0000 (15:16 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 5 Mar 2024 09:54:23 +0000 (10:54 +0100)
The function that replaces occurances of "--longoption" with "-Z,
--longoption" etc with the proper highlight applied, no longer loops
over the options.

Closes #13041

docs/cmdline-opts/_OPTIONS.md
docs/cmdline-opts/gen.pl

index 8f388130aaa09e70cf21b7819c550d76ce9ab06e..106298e7457ab18d172e4ffe48def829ed446e3a 100644 (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
index 9105529998f251b708dec6b7ecaf7ed0f774a9d8..e7b621b2dc26b3780fd28b2415458a86afe1ef5c 100755 (executable)
@@ -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