[elinks-dev] doc/tools/help2doc rewrite in Perl

Kalle Olavi Niemitalo kon at iki.fi
Fri Mar 7 16:44:11 MST 2008


Here is a Perl version of doc/tools/help2doc.
The shell version takes 1 min 33 s but this takes only 0.30 s.
It generates an identical option-command.txt but fixes several bugs
in option-config.txt, as you can see from the included diff.
document.dump.separator is still not entirely right though.

OK to apply?  If not, please fix the shell version.

======================================================================

#! /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}(-.*?) *$/) {
	    $_ = $1;
	    s/ {2,}/ /g;
	    print "${_}::\n";
	} elsif (/^ {12}\t(-eval .*)$/) {
	    print "\n\t$1\n";
	} elsif (/^ {12}\t(\w+\(.*\)) +: (.*)$/) {
	    print "\t- `$1`: $2\n";
	} elsif (/^ {12}\t(\d+) (means .+)$/) {
	    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;
    while (<$pipe>) {
	if (/^ {2}[^ ].*: \(([-.\w]+)\)$/) {
	    print "$1::\n";
	} elsif (/^ {4}([^ ].*?)$/) {
	    print "$1::\n";
	} 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]*?) +(.*)$/) {
		print "\t- $1:\t$2\n";
	    } else {
		print "\t$_";
	    }
	} else {
	    print "\n" unless $blank;
	    $blank = 2;
	}
	$blank = ($blank == 2);
    }
    print "Generated using output from ELinks version $version.\n";
} else {
    die "you rang?";
}

======================================================================

--- option-config-old.txt	2008-03-08 01:28:40.000000000 +0200
+++ option-config-new.txt	2008-03-08 01:29:05.000000000 +0200
@@ -124,7 +124,7 @@
 	- -1:	is use cookie's expiration date if any
 	- 0:	is force expiration at the end of session, ignoring cookie's
 	expiration date
-	- 1:	+ is use cookie's expiration date, but limit age to the given
+	- 1+:	is use cookie's expiration date, but limit age to the given
 	number of days
 
 cookies.paranoid_security [0|1] (default: 0)::
@@ -360,10 +360,11 @@
 	Start typeahead searching when an unbound key is pressed without
 	any modifiers. Note that most keys have default bindings, so this
 	feature will not be useful unless you unbind them.
-
-when you (when you press a key bound to search-typeahead or similar)::
-	1 automatically starts typeahead searching thru link text
-	2 automatically starts typeahead searching thru all document text
+	
+	- 0:	disables this feature; typeahead searching will only be used
+	when you press a key bound to search-typeahead or similar
+	- 1:	automatically starts typeahead searching thru link text
+	- 2:	automatically starts typeahead searching thru all document text
 
 document.browse.margin_width <num> (default: 3)::
 	Horizontal text margin.
@@ -441,6 +442,8 @@
 	since the document was initially loaded or most recently
 	revalidated with the server, the server will be checked in case
 	there is a more up-to-date version of the document.
+	
+	A value of -1 disables automatic revalidation.
 
 document.codepage::
 	Charset options.
@@ -514,8 +517,8 @@
 
 document.css.media <str> (default: "tty")::
 	CSS media types that 'ELinks' claims to support, separated with
-	commas. The "all" type is implied. Currently, only ASCII
-	characters work reliably here. See CSS2 section 7:
+	commas.  The "all" type is implied.  Currently, only ASCII
+	characters work reliably here.  See CSS2 section 7:
 	http://www.w3.org/TR/1998/REC-CSS2-19980512/media.html
 
 document.css.stylesheet <str> (default: "")::
@@ -578,7 +581,9 @@
 	Whether to print references (URIs) of document links
 	in dump output.
 
-document.dump.separator <str> (document.dump.separator <str> (default: ")::
+document.dump.separator <str> (default: "::
+
+	String which separates two dumps.
 
 document.dump.width <num> (default: 80)::
 	Width of screen in characters when dumping documents.
@@ -926,7 +931,7 @@
 	hidden in local directory listings.
 
 protocol.file.try_encoding_extensions [0|1] (default: 1)::
-	When set, if we can\'t open a file named \'filename', we'll try
+	When set, if we can\'t open a file named \'filename\', we\'ll try
 	to open \'filename\' with some encoding extension appended
 	(ie. \'filename.gz\'); it depends on the supported encodings.
 
@@ -1028,11 +1033,13 @@
 	If enabled, the capability to receive compressed content (gzip and/or
 	bzip2) is announced to the server, which usually sends the reply
 	compressed, thus saving some bandwidth at slight CPU expense.
-
-option. If (option. If that helps, there may be a bug in the decompression part)::
+	
+	If 'ELinks' displays a incomplete page or garbage, try disabling this
+	option. If that helps, there may be a bug in the decompression part
 	of 'ELinks'. Please report such bugs.
-
-has no (has no effect. To check the supported features, see Help -> About.)::
+	
+	If 'ELinks' has been compiled without compression support, this option
+	has no effect. To check the supported features, see Help -> About.
 
 protocol.http.trace [0|1] (default: 0)::
 	If active, all HTTP requests are sent with TRACE as their method
@@ -1073,7 +1080,7 @@
 
 protocol.nntp.header_entries <str> (default: "Subject,From,Date,Message-ID,Newsgroups")::
 	Comma separated list of which entries in the article header
-	to show. E.g. \'Subject\' and 'From'.
+	to show. E.g. \'Subject\' and \'From\'.
 	All header entries can be read in the header info dialog.
 
 protocol.rewrite::
@@ -1105,7 +1112,7 @@
 protocol.rewrite.default_template <str> (default: "")::
 	Default URI template used when the string entered in
 	the goto dialog does not appear to be a URI or a filename
-	(i.e. contains no \'.\', ':' or '/' characters), and does
+	(i.e. contains no \'.\', \':\' or \'/\' characters), and does
 	not match any defined prefixes. Set the value to "" to
 	disable use of the default template rewrite rule.
 	%c in the template means the current URL,
@@ -1123,7 +1130,7 @@
 	Enable smart prefixes - URI templates triggered by writing
 	given abbreviation to the Goto URL dialog followed by a list
 	of arguments from which the actual URI is composed - i.e.
-	\'gg:search keywords\' or 'gn search keywords for news'.
+	\'gg:search keywords\' or \'gn search keywords for news\'.
 
 protocol.user::
 	User protocols. Options in this tree specify external
@@ -1996,7 +2003,7 @@
 ui.sessions.homepage <str> (default: "")::
 	The URI to load either at startup time when no URI was given
 	on the command line or when requested by the goto-url-home action.
-	Set to "" if the environment variable WWW_'HOME' should be used
+	Set to "" if the environment variable 'WWW_HOME' should be used
 	as homepage URI instead.
 
 ui.sessions.keep_session_active [0|1] (default: 0)::
@@ -2006,6 +2013,8 @@
 	Automatically save a snapshot of all tabs periodically.
 	This will periodically bookmark the tabs of each terminal in a separate folder
 	for recovery after a crash.
+	
+	This feature requires bookmark support.
 
 ui.tabs::
 	Window tabs settings.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
Url : http://linuxfromscratch.org/pipermail/elinks-dev/attachments/20080308/023d64a1/attachment.bin 


More information about the elinks-dev mailing list