2018-01-07 14:34:46 +08:00
|
|
|
#!/usr/bin/env perl
|
2020-03-23 21:44:29 +08:00
|
|
|
#***************************************************************************
|
|
|
|
# _ _ ____ _
|
|
|
|
# Project ___| | | | _ \| |
|
|
|
|
# / __| | | | |_) | |
|
|
|
|
# | (__| |_| | _ <| |___
|
|
|
|
# \___|\___/|_| \_\_____|
|
|
|
|
#
|
|
|
|
# Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
|
|
#
|
|
|
|
# This software is licensed as described in the file COPYING, which
|
|
|
|
# you should have received as part of this distribution. The terms
|
|
|
|
# are also available at https://curl.haxx.se/docs/copyright.html.
|
|
|
|
#
|
|
|
|
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
# copies of the Software, and permit persons to whom the Software is
|
|
|
|
# furnished to do so, under the terms of the COPYING file.
|
|
|
|
#
|
|
|
|
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
# KIND, either express or implied.
|
|
|
|
#
|
|
|
|
###########################################################################
|
2016-11-14 06:40:12 +08:00
|
|
|
|
2017-01-17 07:26:08 +08:00
|
|
|
=begin comment
|
|
|
|
|
|
|
|
This script generates the manpage.
|
|
|
|
|
2020-03-26 06:16:28 +08:00
|
|
|
Example: gen.pl <command> [files] > curl.1
|
2017-01-17 07:26:08 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-11-14 06:40:12 +08:00
|
|
|
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;
|
2020-07-13 20:15:04 +08:00
|
|
|
my %catlong;
|
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)=@_;
|
2020-03-26 06:16:28 +08:00
|
|
|
open(F, "<:crlf", "$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;
|
2020-07-13 20:15:04 +08:00
|
|
|
my $category;
|
2016-11-14 06:40:12 +08:00
|
|
|
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;
|
|
|
|
}
|
2020-07-13 20:15:04 +08:00
|
|
|
elsif(/^Category: *(.*)/i) {
|
|
|
|
$category=$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";
|
|
|
|
}
|
2020-07-13 20:15:04 +08:00
|
|
|
if(!$category) {
|
|
|
|
print STDERR "WARN: no 'Category:' 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
|
|
|
}
|
2018-11-26 16:56:49 +08:00
|
|
|
my @desc;
|
2016-11-14 06:40:12 +08:00
|
|
|
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;
|
2020-09-01 16:16:45 +08:00
|
|
|
my $and = 0;
|
|
|
|
my $num = scalar(@m);
|
|
|
|
if($num > 2) {
|
|
|
|
# use commas up to this point
|
|
|
|
$and = $num - 1;
|
|
|
|
}
|
|
|
|
my $i = 0;
|
2016-11-14 06:40:12 +08:00
|
|
|
for my $k (@m) {
|
2018-05-28 20:59:37 +08:00
|
|
|
if(!$helplong{$k}) {
|
|
|
|
print STDERR "WARN: $f see-alsos a non-existing option: $k\n";
|
|
|
|
}
|
2016-11-14 06:40:12 +08:00
|
|
|
my $l = manpageify($k);
|
2020-09-01 16:16:45 +08:00
|
|
|
my $sep = " and";
|
|
|
|
if($and && ($i < $and)) {
|
|
|
|
$sep = ",";
|
|
|
|
}
|
|
|
|
$mstr .= sprintf "%s$l", $mstr?"$sep ":"";
|
|
|
|
$i++;
|
2016-11-14 06:40:12 +08:00
|
|
|
}
|
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) {
|
2018-05-28 20:59:37 +08:00
|
|
|
if(!$helplong{$k}) {
|
|
|
|
print STDERR "WARN: $f mutexes a non-existing option: $k\n";
|
|
|
|
}
|
2016-11-14 06:40:12 +08:00
|
|
|
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)=@_;
|
2020-03-26 06:16:28 +08:00
|
|
|
open(F, "<:crlf", "$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;
|
2020-07-13 20:15:04 +08:00
|
|
|
my $category;
|
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;
|
|
|
|
}
|
2020-07-13 20:15:04 +08:00
|
|
|
elsif(/^Category: (.*)/i) {
|
|
|
|
$category=$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;
|
2020-07-13 20:15:04 +08:00
|
|
|
$catlong{$long}=$category;
|
2016-11-14 06:40:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub indexoptions {
|
2020-03-26 06:16:28 +08:00
|
|
|
my (@files) = @_;
|
|
|
|
foreach my $f (@files) {
|
|
|
|
getshortlong($f);
|
|
|
|
}
|
2016-11-14 06:40:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sub header {
|
2016-11-16 18:41:02 +08:00
|
|
|
my ($f)=@_;
|
2020-03-26 06:16:28 +08:00
|
|
|
open(F, "<:crlf", "$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};
|
2020-07-13 20:15:04 +08:00
|
|
|
my @categories = split ' ', $catlong{$long};
|
|
|
|
my $bitmask;
|
2016-11-15 16:08:50 +08:00
|
|
|
my $opt;
|
|
|
|
|
|
|
|
if(defined($short) && $long) {
|
|
|
|
$opt = "-$short, --$long";
|
|
|
|
}
|
|
|
|
elsif($long && !$short) {
|
|
|
|
$opt = " --$long";
|
|
|
|
}
|
2020-07-13 20:15:04 +08:00
|
|
|
for my $i (0 .. $#categories) {
|
|
|
|
$bitmask .= 'CURLHELP_' . uc $categories[$i];
|
|
|
|
# If not last element, append |
|
|
|
|
if($i < $#categories) {
|
|
|
|
$bitmask .= ' | ';
|
|
|
|
}
|
|
|
|
}
|
2016-11-15 16:08:50 +08:00
|
|
|
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
|
|
|
|
2020-07-13 20:15:04 +08:00
|
|
|
my $line = sprintf " {\"%s\",\n \"%s\",\n %s},\n", $opt, $desc, $bitmask;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-13 20:15:04 +08:00
|
|
|
sub listcats {
|
|
|
|
my %allcats;
|
|
|
|
foreach my $f (sort keys %helplong) {
|
|
|
|
my @categories = split ' ', $catlong{$f};
|
|
|
|
foreach (@categories) {
|
|
|
|
$allcats{$_} = undef;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
my @categories;
|
|
|
|
foreach my $key (keys %allcats) {
|
|
|
|
push @categories, $key;
|
|
|
|
}
|
|
|
|
@categories = sort @categories;
|
|
|
|
unshift @categories, 'hidden';
|
|
|
|
for my $i (0..$#categories) {
|
|
|
|
print '#define ' . 'CURLHELP_' . uc($categories[$i]) . ' ' . "1u << " . $i . "u\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-15 16:08:50 +08:00
|
|
|
sub mainpage {
|
2020-03-26 06:16:28 +08:00
|
|
|
my (@files) = @_;
|
2016-11-15 16:08:50 +08:00
|
|
|
# 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
|
2020-03-26 06:16:28 +08:00
|
|
|
foreach my $f (sort @files) {
|
|
|
|
if(single($f, 0)) {
|
|
|
|
print STDERR "Can't read $f?\n";
|
|
|
|
}
|
2016-11-16 18:41:02 +08:00
|
|
|
}
|
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 {
|
2020-03-26 06:16:28 +08:00
|
|
|
my ($f, @s) = @_;
|
|
|
|
if($f eq "mainpage") {
|
|
|
|
mainpage(@s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
elsif($f eq "listhelp") {
|
|
|
|
listhelp();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
elsif($f eq "single") {
|
|
|
|
showonly($s[0]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
elsif($f eq "protos") {
|
|
|
|
showprotocols();
|
|
|
|
return;
|
|
|
|
}
|
2020-07-13 20:15:04 +08:00
|
|
|
elsif($f eq "listcats") {
|
|
|
|
listcats();
|
|
|
|
return;
|
|
|
|
}
|
2016-11-15 16:08:50 +08:00
|
|
|
|
2020-07-13 20:15:04 +08:00
|
|
|
print "Usage: gen.pl <mainpage/listhelp/single FILE/protos/listcats> [files]\n";
|
2016-11-15 16:08:50 +08:00
|
|
|
}
|
|
|
|
|
2016-11-14 06:40:12 +08:00
|
|
|
#------------------------------------------------------------------------
|
|
|
|
|
2020-03-26 06:16:28 +08:00
|
|
|
my $cmd = shift @ARGV;
|
|
|
|
my @files = @ARGV; # the rest are the files
|
|
|
|
|
2016-11-14 06:40:12 +08:00
|
|
|
# learn all existing options
|
2020-03-26 06:16:28 +08:00
|
|
|
indexoptions(@files);
|
2016-11-14 06:40:12 +08:00
|
|
|
|
2020-03-26 06:16:28 +08:00
|
|
|
getargs($cmd, @files);
|