5 This script generates the manpage.
7 Example: gen.pl mainpage > curl.1
11 We open *input* files in :crlf translation (a no-op on many platforms) in
12 case we have CRLF line endings in Windows but a perl that defaults to LF.
13 Unfortunately it seems some perls like msysgit can't handle a global input-only
14 :crlf so it has to be specified on each file open for text input.
19 my $some_dir=$ARGV[1] || ".";
21 opendir(my $dh, $some_dir) || die "Can't opendir $some_dir: $!";
22 my @s = grep { /\.d$/ && -f "$some_dir/$_" } readdir($dh);
32 # get the long name version, return the man page string
36 if($optlong{$k} ne "") {
38 $l = "\\fI-".$optlong{$k}.", --$k\\fP";
50 # skip lines starting with space (examples)
52 for my $k (keys %optlong) {
53 my $l = manpageify($k);
54 $d =~ s/--$k([^a-z0-9_-])/$l$1/;
62 my($standalone, $data)=@_;
65 ".SH \"SEE ALSO\"\n$data\n";
68 return "See also $data. ";
73 my ($standalone, $data)=@_;
75 return ".SH \"OVERRIDES\"\n$data\n";
83 my ($standalone, $data)=@_;
85 return ".SH \"PROTOCOLS\"\n$data\n";
93 my ($standalone, $data)=@_;
95 return ".SH \"ADDED\"\nAdded in curl version $data\n";
98 return "Added in $data. ";
103 my ($f, $standalone)=@_;
104 open(F, "<:crlf", "$some_dir/$f") ||
115 my $magic; # cmdline special option
117 if(/^Short: *(.)/i) {
120 elsif(/^Long: *(.*)/i) {
123 elsif(/^Added: *(.*)/i) {
126 elsif(/^Tags: *(.*)/i) {
129 elsif(/^Arg: *(.*)/i) {
132 elsif(/^Magic: *(.*)/i) {
135 elsif(/^Mutexed: *(.*)/i) {
138 elsif(/^Protocols: *(.*)/i) {
141 elsif(/^See-also: *(.*)/i) {
144 elsif(/^Requires: *(.*)/i) {
147 elsif(/^Help: *(.*)/i) {
152 print STDERR "WARN: no 'Long:' in $f\n";
158 print STDERR "WARN: unrecognized line in $f, ignoring:\n:'$_';"
167 if(defined($short) && $long) {
168 $opt = "-$short, --$long";
170 elsif($short && !$long) {
173 elsif($long && !$short) {
182 print ".TH curl 1 \"30 Nov 2016\" \"curl 7.52.0\" \"curl manual\"\n";
183 print ".SH OPTION\n";
187 print ".IP \"$opt\"\n";
190 print protocols($standalone, $protocols);
194 print ".SH DESCRIPTION\n";
202 my @m=split(/ /, $seealso);
205 my $l = manpageify($k);
206 $mstr .= sprintf "%s$l", $mstr?" and ":"";
208 push @foot, seealso($standalone, $mstr);
211 my $l = manpageify($long);
212 push @foot, "$l requires that the underlying libcurl".
213 " was built to support $requires. ";
216 my @m=split(/ /, $mutexed);
219 my $l = manpageify($k);
220 $mstr .= sprintf "%s$l", $mstr?" and ":"";
222 push @foot, overrides($standalone, "This option overrides $mstr. ");
225 push @foot, added($standalone, $added);
229 my $f = join("", @foot);
230 $f =~ s/ +\z//; # remove trailing space
238 open(F, "<:crlf", "$some_dir/$f");
248 elsif(/^Long: (.*)/i) {
251 elsif(/^Help: (.*)/i) {
254 elsif(/^Arg: (.*)/i) {
257 elsif(/^Protocols: (.*)/i) {
266 $optshort{$short}=$long;
269 $optlong{$long}=$short;
270 $helplong{$long}=$help;
271 $arglong{$long}=$arg;
272 $protolong{$long}=$protocols;
284 open(F, "<:crlf", "$some_dir/$f");
294 foreach my $f (sort keys %helplong) {
296 my $short = $optlong{$long};
299 if(defined($short) && $long) {
300 $opt = "-$short, --$long";
302 elsif($long && !$short) {
306 my $arg = $arglong{$long};
311 my $line = sprintf " %-19s %s\n", $opt, $helplong{$f};
313 if(length($line) > 79) {
314 print STDERR "WARN: the --$long line is too long\n";
321 # show the page header
322 header("page-header");
324 # output docs for all options
325 foreach my $f (sort @s) {
329 header("page-footer");
335 print STDERR "$f: failed\n";
341 foreach my $f (keys %optlong) {
342 my @p = split(/ /, $protolong{$f});
347 for(sort keys %prots) {
348 printf "$_ (%d options)\n", $prots{$_};
356 if($f eq "mainpage") {
360 elsif($f eq "listhelp") {
364 elsif($f eq "single") {
365 showonly(shift @ARGV);
368 elsif($f eq "protos") {
374 print "Usage: gen.pl <mainpage/listhelp/single FILE/protos> [srcdir]\n";
377 #------------------------------------------------------------------------
379 # learn all existing options