1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-07-04 02:35:29 +00:00
elinks/doc/tools/help2doc
Kalle Olavi Niemitalo 5fcf175963 help2doc: rewrite in Perl
This version takes about 1/300 of the time of the shell version
and fixes several errors in the output, most importantly that
option descriptions were being truncated at the first empty line.

Because help2doc is run only from make update-man, and the distributed
tarballs include prebuilt man pages, people building ELinks need not
have Perl installed.
2008-03-08 14:51:25 +02:00

84 lines
2.5 KiB
Perl
Executable File

#! /usr/bin/perl
use strict;
use warnings;
my ($elinks, $option) = @ARGV;
if ($option =~ /command/) {
open my $pipe, "-|", $elinks, "--long-help" or die;
my $version = <$pipe>;
chomp $version;
$version =~ s/^ELinks ([-.\w]+).*$/$1/ or die "unusual version: $version";
my $blank = 1;
while (<$pipe>) {
if (/^ {4}(-.*?) *$/) {
# ' -anonymous [0|1] (default: 0)'
# ' -config-dir <str> (default: "")'
$_ = $1;
s/ {2,}/ /g;
print "${_}::\n";
} elsif (/^ {12}\t(-eval .*)$/) {
print "\n\t$1\n";
} elsif (/^ {12}\t(\w+\(.*\)) +: (.*)$/) {
# ' openURL(URL, new-tab) : open URL in new tab'
print "\t- `$1`: $2\n";
} elsif (/^ {12}\t(\d+) (means .+)$/) {
# ' 0 means only show serious errors'
print "\t- $1:\t$2\n";
} elsif (s/^ {12}//) {
s/'([^']+)'/\\'$1\\'/g;
s((~/\.elinks|-dump|-default-mime-type|text/html|-touch-files|-no-connect|-session-ring))(`$1`)g;
s/(ELinks|HOME)/'$1'/g;
print "\t$_";
} else {
print "\n" unless $blank;
$blank = 2;
}
$blank = ($blank == 2);
}
print "Generated using output from ELinks version $version.\n";
} elsif ($option =~ /config/) {
open my $pipe, "-|", $elinks, "--config-help" or die;
my $version = <$pipe>;
chomp $version;
$version =~ s/^ELinks ([-.\w]+).*$/$1/ or die "unusual version: $version";
my $blank = 1;
my $continued = 0;
while (<$pipe>) {
if (/^ {2}[^ ].*: \(([-.\w]+)\)$/) {
# ' Active link: (document.browse.links.active_link)'
print "$1::\n";
} elsif (/^ {4}([^ ].*?)$/) {
# ' bookmarks.file_format <num> (default: 0)'
print "$1::\n";
} elsif (/^ {12,}$/) {
print "+\n";
$continued = 1;
} elsif (s/^ {12,}//) {
# escape things that might look like AsciiDoc markup
s/'(.*?)'/\\'$1\\'/g;
s/\{(.*?)\}/\\{$1\\}/g;
# add the actual AsciiDoc markup
s/(ELinks|WWW_HOME)/'$1'/g;
s((~/\.elinks))(`$1`)g;
if (/^(-?\d[-+\d]*?) +(.*)$/) {
# ' 1+ is use cookie's expiration date, but limit age to the given'
print "\t- $1:\t$2\n";
} elsif ($continued) {
print "$_";
} else {
print "\t$_";
}
} else {
print "\n" unless $blank;
$blank = 2;
$continued = 0;
}
$blank = ($blank == 2);
}
print "Generated using output from ELinks version $version.\n";
} else {
die "usage: $0 ELINKS-EXECUTABLE option-command.txt\n"
. " or: $0 ELINKS-EXECUTABLE option-config.txt\n";
}