2016-11-14 06:40:12 +08:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
2017-01-17 07:26:08 +08:00
|
|
|
=begin comment
|
|
|
|
|
|
|
|
This script generates the manpage.
|
|
|
|
|
|
|
|
Example: gen.pl mainpage > curl.1
|
|
|
|
|
|
|
|
Dev notes:
|
|
|
|
|
|
|
|
We open *input* files in :crlf translation (a no-op on many platforms) in
|
|
|
|
case we have CRLF line endings in Windows but a perl that defaults to LF.
|
|
|
|
Unfortunately it seems some perls like msysgit can't handle a global input-only
|
|
|
|
:crlf so it has to be specified on each file open for text input.
|
|
|
|
|
|
|
|
=end comment
|
|
|
|
=cut
|
|
|
|
|
2017-02-07 05:47:41 +08:00
|
|
|
my $some_dir=$ARGV[1] || ".";
|
2016-11-14 06:40:12 +08:00
|
|
|
|
|
|
|
opendir(my $dh, $some_dir) || die "Can't opendir $some_dir: $!";
|
|
|
|
my @s = grep { /\.d$/ && -f "$some_dir/$_" } readdir($dh);
|
|
|
|
closedir $dh;
|
|
|
|
|
|
|
|
my %optshort;
|
|
|
|
my %optlong;
|
2016-11-15 16:08:50 +08:00
|
|
|
my %helplong;
|
|
|
|
my %arglong;
|
2016-11-16 17:42:02 +08:00
|
|
|
my %redirlong;
|
2016-11-16 21:20:13 +08:00
|
|
|
my %protolong;
|
2016-11-14 06:40:12 +08:00
|
|
|
|
|
|
|
# get the long name version, return the man page string
|
|
|
|
sub manpageify {
|
|
|
|
my ($k)=@_;
|
|
|
|
my $l;
|
|
|
|
if($optlong{$k} ne "") {
|
|
|
|
# both short + long
|
|
|
|
$l = "\\fI-".$optlong{$k}.", --$k\\fP";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
# only long
|
|
|
|
$l = "\\fI--$k\\fP";
|
|
|
|
}
|
|
|
|
return $l;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub printdesc {
|
|
|
|
my @desc = @_;
|
|
|
|
for my $d (@desc) {
|
|
|
|
# skip lines starting with space (examples)
|
|
|
|
if($d =~ /^[^ ]/) {
|
|
|
|
for my $k (keys %optlong) {
|
|
|
|
my $l = manpageify($k);
|
2016-11-16 06:44:36 +08:00
|
|
|
$d =~ s/--$k([^a-z0-9_-])/$l$1/;
|
2016-11-14 06:40:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
print $d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 18:41:02 +08:00
|
|
|
sub seealso {
|
|
|
|
my($standalone, $data)=@_;
|
|
|
|
if($standalone) {
|
|
|
|
return sprintf
|
|
|
|
".SH \"SEE ALSO\"\n$data\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return "See also $data. ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub overrides {
|
|
|
|
my ($standalone, $data)=@_;
|
|
|
|
if($standalone) {
|
|
|
|
return ".SH \"OVERRIDES\"\n$data\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub protocols {
|
|
|
|
my ($standalone, $data)=@_;
|
|
|
|
if($standalone) {
|
|
|
|
return ".SH \"PROTOCOLS\"\n$data\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return "($data) ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub added {
|
|
|
|
my ($standalone, $data)=@_;
|
|
|
|
if($standalone) {
|
|
|
|
return ".SH \"ADDED\"\nAdded in curl version $data\n";
|
|
|
|
}
|
|
|
|
else {
|
2016-11-28 07:54:16 +08:00
|
|
|
return "Added in $data. ";
|
2016-11-16 18:41:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-14 06:40:12 +08:00
|
|
|
sub single {
|
2016-11-16 18:41:02 +08:00
|
|
|
my ($f, $standalone)=@_;
|
2017-02-07 05:47:41 +08:00
|
|
|
open(F, "<:crlf", "$some_dir/$f") ||
|
2016-11-16 18:41:02 +08:00
|
|
|
return 1;
|
2016-11-14 06:40:12 +08:00
|
|
|
my $short;
|
|
|
|
my $long;
|
|
|
|
my $tags;
|
|
|
|
my $added;
|
|
|
|
my $protocols;
|
|
|
|
my $arg;
|
|
|
|
my $mutexed;
|
|
|
|
my $requires;
|
|
|
|
my $seealso;
|
|
|
|
my $magic; # cmdline special option
|
|
|
|
while(<F>) {
|
2016-11-16 21:20:13 +08:00
|
|
|
if(/^Short: *(.)/i) {
|
2016-11-14 06:40:12 +08:00
|
|
|
$short=$1;
|
|
|
|
}
|
2016-11-16 21:20:13 +08:00
|
|
|
elsif(/^Long: *(.*)/i) {
|
2016-11-14 06:40:12 +08:00
|
|
|
$long=$1;
|
|
|
|
}
|
2016-11-16 21:20:13 +08:00
|
|
|
elsif(/^Added: *(.*)/i) {
|
2016-11-14 06:40:12 +08:00
|
|
|
$added=$1;
|
|
|
|
}
|
2016-11-16 21:20:13 +08:00
|
|
|
elsif(/^Tags: *(.*)/i) {
|
2016-11-14 06:40:12 +08:00
|
|
|
$tags=$1;
|
|
|
|
}
|
2016-11-16 21:20:13 +08:00
|
|
|
elsif(/^Arg: *(.*)/i) {
|
2016-11-14 06:40:12 +08:00
|
|
|
$arg=$1;
|
|
|
|
}
|
2016-11-16 21:20:13 +08:00
|
|
|
elsif(/^Magic: *(.*)/i) {
|
2016-11-14 06:40:12 +08:00
|
|
|
$magic=$1;
|
|
|
|
}
|
2016-11-16 21:20:13 +08:00
|
|
|
elsif(/^Mutexed: *(.*)/i) {
|
2016-11-14 06:40:12 +08:00
|
|
|
$mutexed=$1;
|
|
|
|
}
|
2016-11-16 21:20:13 +08:00
|
|
|
elsif(/^Protocols: *(.*)/i) {
|
2016-11-14 06:40:12 +08:00
|
|
|
$protocols=$1;
|
|
|
|
}
|
2016-11-16 21:20:13 +08:00
|
|
|
elsif(/^See-also: *(.*)/i) {
|
2016-11-14 06:40:12 +08:00
|
|
|
$seealso=$1;
|
|
|
|
}
|
2016-11-16 21:20:13 +08:00
|
|
|
elsif(/^Requires: *(.*)/i) {
|
2016-11-14 06:40:12 +08:00
|
|
|
$requires=$1;
|
|
|
|
}
|
2016-11-16 21:20:13 +08:00
|
|
|
elsif(/^Help: *(.*)/i) {
|
|
|
|
;
|
|
|
|
}
|
2016-11-14 06:40:12 +08:00
|
|
|
elsif(/^---/) {
|
2016-11-16 21:20:13 +08:00
|
|
|
if(!$long) {
|
|
|
|
print STDERR "WARN: no 'Long:' in $f\n";
|
|
|
|
}
|
2016-11-14 06:40:12 +08:00
|
|
|
last;
|
|
|
|
}
|
2016-11-16 21:20:13 +08:00
|
|
|
else {
|
|
|
|
chomp;
|
|
|
|
print STDERR "WARN: unrecognized line in $f, ignoring:\n:'$_';"
|
|
|
|
}
|
2016-11-14 06:40:12 +08:00
|
|
|
}
|
|
|
|
my @dest;
|
|
|
|
while(<F>) {
|
|
|
|
push @desc, $_;
|
|
|
|
}
|
|
|
|
close(F);
|
|
|
|
my $opt;
|
|
|
|
if(defined($short) && $long) {
|
|
|
|
$opt = "-$short, --$long";
|
|
|
|
}
|
|
|
|
elsif($short && !$long) {
|
|
|
|
$opt = "-$short";
|
|
|
|
}
|
|
|
|
elsif($long && !$short) {
|
|
|
|
$opt = "--$long";
|
|
|
|
}
|
|
|
|
|
|
|
|
if($arg) {
|
|
|
|
$opt .= " $arg";
|
|
|
|
}
|
|
|
|
|
2016-11-16 18:41:02 +08:00
|
|
|
if($standalone) {
|
|
|
|
print ".TH curl 1 \"30 Nov 2016\" \"curl 7.52.0\" \"curl manual\"\n";
|
|
|
|
print ".SH OPTION\n";
|
|
|
|
print "curl $opt\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print ".IP \"$opt\"\n";
|
|
|
|
}
|
2016-11-28 08:01:13 +08:00
|
|
|
if($protocols) {
|
|
|
|
print protocols($standalone, $protocols);
|
2016-11-16 18:41:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if($standalone) {
|
|
|
|
print ".SH DESCRIPTION\n";
|
2016-11-14 06:40:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
printdesc(@desc);
|
|
|
|
undef @desc;
|
|
|
|
|
|
|
|
my @foot;
|
|
|
|
if($seealso) {
|
|
|
|
my @m=split(/ /, $seealso);
|
|
|
|
my $mstr;
|
|
|
|
for my $k (@m) {
|
|
|
|
my $l = manpageify($k);
|
|
|
|
$mstr .= sprintf "%s$l", $mstr?" and ":"";
|
|
|
|
}
|
2016-11-16 18:41:02 +08:00
|
|
|
push @foot, seealso($standalone, $mstr);
|
2016-11-14 06:40:12 +08:00
|
|
|
}
|
|
|
|
if($requires) {
|
|
|
|
my $l = manpageify($long);
|
|
|
|
push @foot, "$l requires that the underlying libcurl".
|
|
|
|
" was built to support $requires. ";
|
|
|
|
}
|
|
|
|
if($mutexed) {
|
|
|
|
my @m=split(/ /, $mutexed);
|
|
|
|
my $mstr;
|
|
|
|
for my $k (@m) {
|
|
|
|
my $l = manpageify($k);
|
|
|
|
$mstr .= sprintf "%s$l", $mstr?" and ":"";
|
|
|
|
}
|
2016-11-16 18:41:02 +08:00
|
|
|
push @foot, overrides($standalone, "This option overrides $mstr. ");
|
2016-11-14 06:40:12 +08:00
|
|
|
}
|
|
|
|
if($added) {
|
2016-11-16 18:41:02 +08:00
|
|
|
push @foot, added($standalone, $added);
|
2016-11-14 06:40:12 +08:00
|
|
|
}
|
|
|
|
if($foot[0]) {
|
|
|
|
print "\n";
|
2016-12-18 01:14:01 +08:00
|
|
|
my $f = join("", @foot);
|
|
|
|
$f =~ s/ +\z//; # remove trailing space
|
|
|
|
print "$f\n";
|
2016-11-14 06:40:12 +08:00
|
|
|
}
|
2016-11-16 18:41:02 +08:00
|
|
|
return 0;
|
2016-11-14 06:40:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sub getshortlong {
|
|
|
|
my ($f)=@_;
|
2017-02-07 05:47:41 +08:00
|
|
|
open(F, "<:crlf", "$some_dir/$f");
|
2016-11-14 06:40:12 +08:00
|
|
|
my $short;
|
|
|
|
my $long;
|
2016-11-15 16:08:50 +08:00
|
|
|
my $help;
|
|
|
|
my $arg;
|
2016-11-16 21:20:13 +08:00
|
|
|
my $protocols;
|
2016-11-14 06:40:12 +08:00
|
|
|
while(<F>) {
|
|
|
|
if(/^Short: (.)/i) {
|
|
|
|
$short=$1;
|
|
|
|
}
|
|
|
|
elsif(/^Long: (.*)/i) {
|
|
|
|
$long=$1;
|
|
|
|
}
|
2016-11-15 16:08:50 +08:00
|
|
|
elsif(/^Help: (.*)/i) {
|
|
|
|
$help=$1;
|
|
|
|
}
|
|
|
|
elsif(/^Arg: (.*)/i) {
|
|
|
|
$arg=$1;
|
|
|
|
}
|
2016-11-16 21:20:13 +08:00
|
|
|
elsif(/^Protocols: (.*)/i) {
|
|
|
|
$protocols=$1;
|
|
|
|
}
|
2016-11-14 06:40:12 +08:00
|
|
|
elsif(/^---/) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(F);
|
|
|
|
if($short) {
|
|
|
|
$optshort{$short}=$long;
|
|
|
|
}
|
|
|
|
if($long) {
|
|
|
|
$optlong{$long}=$short;
|
2016-11-15 16:08:50 +08:00
|
|
|
$helplong{$long}=$help;
|
|
|
|
$arglong{$long}=$arg;
|
2016-11-16 21:20:13 +08:00
|
|
|
$protolong{$long}=$protocols;
|
2016-11-14 06:40:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub indexoptions {
|
|
|
|
foreach my $f (@s) {
|
|
|
|
getshortlong($f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub header {
|
2016-11-16 18:41:02 +08:00
|
|
|
my ($f)=@_;
|
2017-02-07 05:47:41 +08:00
|
|
|
open(F, "<:crlf", "$some_dir/$f");
|
2016-11-14 06:40:12 +08:00
|
|
|
my @d;
|
|
|
|
while(<F>) {
|
|
|
|
push @d, $_;
|
|
|
|
}
|
|
|
|
close(F);
|
|
|
|
printdesc(@d);
|
|
|
|
}
|
|
|
|
|
2016-11-15 16:08:50 +08:00
|
|
|
sub listhelp {
|
|
|
|
foreach my $f (sort keys %helplong) {
|
|
|
|
my $long = $f;
|
|
|
|
my $short = $optlong{$long};
|
|
|
|
my $opt;
|
|
|
|
|
|
|
|
if(defined($short) && $long) {
|
|
|
|
$opt = "-$short, --$long";
|
|
|
|
}
|
|
|
|
elsif($long && !$short) {
|
|
|
|
$opt = " --$long";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $arg = $arglong{$long};
|
|
|
|
if($arg) {
|
|
|
|
$opt .= " $arg";
|
|
|
|
}
|
2017-05-09 05:30:29 +08:00
|
|
|
my $desc = $helplong{$f};
|
|
|
|
$desc =~ s/\"/\\\"/g; # escape double quotes
|
2016-11-15 16:08:50 +08:00
|
|
|
|
2017-05-09 05:30:29 +08:00
|
|
|
my $line = sprintf " {\"%s\",\n \"%s\"},\n", $opt, $desc;
|
2016-11-16 17:42:02 +08:00
|
|
|
|
2017-05-09 05:30:29 +08:00
|
|
|
if(length($opt) + length($desc) > 78) {
|
2016-11-16 17:42:02 +08:00
|
|
|
print STDERR "WARN: the --$long line is too long\n";
|
|
|
|
}
|
|
|
|
print $line;
|
2016-11-15 16:08:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub mainpage {
|
|
|
|
# show the page header
|
2016-11-16 18:41:02 +08:00
|
|
|
header("page-header");
|
2016-11-15 16:08:50 +08:00
|
|
|
|
|
|
|
# output docs for all options
|
|
|
|
foreach my $f (sort @s) {
|
2016-11-16 18:41:02 +08:00
|
|
|
single($f, 0);
|
|
|
|
}
|
2016-11-28 07:54:16 +08:00
|
|
|
|
|
|
|
header("page-footer");
|
2016-11-16 18:41:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sub showonly {
|
|
|
|
my ($f) = @_;
|
|
|
|
if(single($f, 1)) {
|
|
|
|
print STDERR "$f: failed\n";
|
2016-11-15 16:08:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 21:20:13 +08:00
|
|
|
sub showprotocols {
|
|
|
|
my %prots;
|
|
|
|
foreach my $f (keys %optlong) {
|
|
|
|
my @p = split(/ /, $protolong{$f});
|
|
|
|
for my $p (@p) {
|
|
|
|
$prots{$p}++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(sort keys %prots) {
|
|
|
|
printf "$_ (%d options)\n", $prots{$_};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-15 16:08:50 +08:00
|
|
|
sub getargs {
|
|
|
|
my $f;
|
|
|
|
do {
|
|
|
|
$f = shift @ARGV;
|
|
|
|
if($f eq "mainpage") {
|
|
|
|
mainpage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
elsif($f eq "listhelp") {
|
|
|
|
listhelp();
|
|
|
|
return;
|
|
|
|
}
|
2016-11-16 18:41:02 +08:00
|
|
|
elsif($f eq "single") {
|
|
|
|
showonly(shift @ARGV);
|
|
|
|
return;
|
|
|
|
}
|
2016-11-16 21:20:13 +08:00
|
|
|
elsif($f eq "protos") {
|
|
|
|
showprotocols();
|
|
|
|
return;
|
|
|
|
}
|
2016-11-15 16:08:50 +08:00
|
|
|
} while($f);
|
|
|
|
|
2017-02-07 05:47:41 +08:00
|
|
|
print "Usage: gen.pl <mainpage/listhelp/single FILE/protos> [srcdir]\n";
|
2016-11-15 16:08:50 +08:00
|
|
|
}
|
|
|
|
|
2016-11-14 06:40:12 +08:00
|
|
|
#------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# learn all existing options
|
|
|
|
indexoptions();
|
|
|
|
|
2016-11-15 16:08:50 +08:00
|
|
|
getargs();
|
2016-11-14 06:40:12 +08:00
|
|
|
|