#!/usr/bin/perl -w
##
# $Id: gphtml,v 1.7 2002/12/25 16:12:02 fenrir Exp $
# gphelp originally written by Niels Skoruppa; maintained by
# Karim Belabas (since v 1.8)
#
# This script generates html documentation of the gp/pari functions
# on using the tex documentation as given in chapter 3 of the users manual.
# Currently this is a workaround since there seems to exist no reasonable
# plain TeX to html converter. Here we just take the outputs of
# gphelp -raw (or alternatively -detex) and translate them into html form.
# It will be easy to replace, in the following code, the use of this
# function by a more powerful tex2html translator
# (if there were one in sight).
#
# Usage: gphtml [--dist|--4gui|--subsections|--no_entries|--use_detex]
#
# Without any option this will create, in the directory where you
# called, a subdirectory named html, and therein the html documentation.
# With --dist this will add this file and a tar archive of html to html.
# With --4gui this creates a directory called ref containing the reference
# docs for pariguide.
# The other options are for debugging purposes or consistency checks only.
#
# Adjust the three pathes below (look for AdJuSt).
#########################################################################
#use strict 'vars';
my (
$USERSCH3_TEX, $HTML, $REF, $REF_HEADER,
# $DATE,
$distFlag, $guiFlag, $subsectionsFlag, $no_entriesFlag, $checkFlag, $option,
%pics, %basicFrames,
# $version,
@shortcuts, %subsections, %sections, %fill,
@ou, %tr, %trans0, %trans1, %trans, %html,
$gl_key, $gl_item, $gl_letter, $gl_contents,
);
$DATE = localtime();
##############
# AdJuSt these
##############
$HTML = './html/'; # or where ever you like the html pages
$REF = './ref/'; # or wherever you like the pariguide ref pages
$base = "/usr/local/src/pari"; # the toplevel PARI/GP sources
#########################
# Parse the argument line
#########################
$option = '-raw';
$distFlag = $guiFlag = $subsectionsFlag = $no_entriesFlag = $checkFlag = 0;
for (@ARGV) {
/--dist/ and do { $distFlag = 1; next;};
/--4gui/ and do { $guiFlag = 1; $HTML = $REF; next;};
/--subsections/ and do { $subsectionsFlag = 1; next;};
/--no_entries/ and do { $no_entriesFlag = 1; next;};
/--use_detex/ and do { $option = '-detex'; next;};
/--base=(.*)/ and do { $base = $1; next;};
/--HTML=(.*)/ and do { $HTML = $1; next;};
&usage;
}
$USERSCH3_TEX = "$base/doc/usersch3.tex";
$gp = "$base/gp";
$gphelp = "$base/doc/gphelp";
sub usage {
print STDERR "Usage: $0 [--dist|--4gui|--subsections|--no_entries|--use_detex]\n";
exit( 0);
}
############################################################
# We see first what information the system has about pari/gp
# and collect it
############################################################
initVersionAndShortcuts();
initSubsections();
cleanSubsections();
#########################################
# If we only want to list the subsections
# of usersch3.tex, then this
#########################################
1 == $subsectionsFlag and do {
foreach $gl_key ( sort keys %sections) {
print "$gl_key $sections{$gl_key}\n";
}
foreach $gl_key ( sort keys %subsections) {
print "\n\n $gl_key \n\n";
foreach $gl_item ( @{ $subsections{ $gl_key}}) {
print "\t$gl_item\n";
}
}
exit( 0);
};
######################################################################
# Here we start writing all *.html files of the pariguide doc
# to a directory named ref.
######################################################################
1 == $guiFlag and do {
system( "mkdir -p $REF");
$REF_HEADER = "
) {
if (s/\\section\{(.*?)\}//) {
$key = $1;
$subsections{$key} = []; #["\[loeffel\]\_\_\(\)\_\_"];
$sections{$j} = $key;
$tmp = $key; $tmp =~ s/\ /\_/g;
#KB print "$key ==> $tmp\n";
$fill{$key} = $tmp;
$j++;
}
if( s/\\subseckbd\{(.*?)\}//) {
push @{ $subsections{ $key}}, "\[$1\]\_\_\(kbd\)\_\_";
}
if( s/\\subsecidx\{(.*?)\}//) {
push @{ $subsections{ $key}}, "\[$1\]\_\_\(idx\)\_\_";
}
if( s/\\subsec\{(.*?)\}//) {
push @{ $subsections{ $key}}, "\[$1\]\_\_\(nix\)\_\_";
}
if( s/\\subsubsecidx\{(.*?)\}//) {
push @{ $subsections{ $key}}, "\[$1\]\_\_\(sidx\)\_\_";
}
if( s/\\subsubsecidxunix\{(.*?)\}//) {
push @{ $subsections{ $key}}, "\[$1\]\_\_\(sidxu\)\_\_";
}
}
close IN;
}
sub cleanSubsections {
##########################
# Some subsection titles
# are not found by gphelp.
# Here we help "by hand".
##########################
my( $pair, $item, $a, $j);
my(%table) = (
"Conversions and similar elementary functions or commands"
=> [["components of a PARI object", "component"]],
"Programming in GP"
=> [['Control statements', '?'],
['Specific functions used in GP programming', '?']],
"Standard monadic or dyadic operators"
=> [['\%', '?'],
['+$/$-', '+/-'],
['\bs','\\'],
['\bs/','\/'],
['\pow','^'],
['Comparison and boolean operators','<,<,>=,>,==,!=,||,&&,!,|,&,<>']],
"Transcendental functions"
=> [['\pow','^']]
);
while (my ($key, $val) = each %table) {
next if (!defined($subsections{$key}));
foreach $pair ( @{ $val}) {
$j=0;
foreach $item ( @{ $subsections{ $key}}) {
$a = quotemeta(@{ $pair}[0]);
if( $item =~ /^\[$a\]/) {
if( @{ $pair}[1] eq '?') {
splice @{ $subsections{ $key}}, $j, 1;
}
else {
splice @{ $subsections{ $key}}, $j, 1, "[@{ $pair}[1]]__()__";
}
}
$j++;
}
}
}
}
sub writeToC4Ref {
###################################
# Writes index.html, the entry page
# for the reference documentation.
# Relies on the hash %subsection.
###################################
my( $key, $contents, $toc1, $toc2, $letter);
$toc1 = $toc2 ='';
$z = 0;
foreach $key ( sort keys %subsections) {
0 == $z and $toc1 = $toc1."\n";
$toc1 = $toc1
.'| '
.$key
.' | '."\n";
1 == $z and $toc1 = $toc1."
\n";
$z++; 2 == $z and $z = 0;
}
1 == $z and $toc1 = $toc1." | \n";
foreach $letter ( (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z)) {
$toc2 = $toc2
.''
.$letter.''."\n";
}
$contents = <<"__UP_TO_HERE__";
Functions by Category
Functions in Alphabetical Order
$toc2
Catalogue of Functions for the $version.
(generated by gphtml on $DATE.)
__UP_TO_HERE__
$contents = $REF_HEADER.$contents;
printHTML( "index.html", "Table of Contents",
'bgcolor="#FFFFFF"', $contents);
}
sub writeToC {
#################################
# Writes toc.html.
# Relies on the hash %subsection.
#################################
my( $key, $contents, $toc1, $toc2, $letter);
$toc1 = $toc2 ='';
foreach $key ( sort keys %subsections) {
die "Unknown subsection: $key" if ( !defined($fill{$key}) );
$toc1 = $toc1
.''
.$key
.''."\n".'
'."\n";
}
foreach $letter ( (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z)) {
$toc2 = $toc2
.' '
.$letter.''."\n";
}
$contents = <<"__UP_TO_HERE__";
Functions by Category
$toc1
Functions in Alphabetical Order
$toc2
__UP_TO_HERE__
printHTML( "toc.html", "Table of Contents",
'background="./toc.jpg"', $contents);
}
sub writeFunctionsByCategorie {
############################################
# Writes, for each list of subsection titles
# pointed to by $key, an html file called
# cont_$key.html. This a a collection of
# links to the respective entries in
# $key.html.
# Uses the hash %subsection.
# Call in the form
# writeFunctionsByCategorie( $key)
############################################
my( $key, $item, $contents);
$key = $_[0];
$contents ="\nIndex: $key
\n";
foreach $item (sort @{ $subsections{$key}}) {
$item =~ /^\[(.*?)\]\_\_\((.*?)\)\_\_$/;
$contents = $contents
.' '.$1.''."\n";
}
printHTML( "cont_$fill{$key}.html", "$key", 'bgcolor = "#FFFFFF"', $contents);
}
sub writeIndex {
############################################
# Writes an html file called
# function_index.html. This a a collection of
# links to the respective entries in
# the entry pages.
# Uses the hash %subsection.
# Call in the form
# writeIndex( number_of_columns)
############################################
my( $numOfCols, $letter, @tmp, $key, $item, $contents, $z, %subsectionsByAl);
$numOfCols = $_[0];
$contents = $REF_HEADER;
$contents = $contents
."Index of Functions
\n";
$contents = $contents
.''."\n";
foreach $letter ( (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z)) {
$subsectionsByAl{ $letter} = []; @tmp = ();
foreach $key ( keys %subsections) {
foreach $item ( @{ $subsections{ $key}}) {
if( $item =~ /^\[$letter/ || $item =~ /^\[\l$letter/) {
$item =~ /^\[(.*?)\]\_\_\((.*?)\)\_\_$/;
push @{ $subsectionsByAl{ $letter}}, "\[$1\]\_\_\($key\)\_\_\n";
push @tmp, "\[$1\]\_\_\($key\)\_\_\n";
}
}
}
$contents = $contents."\n| $letter | \n";
$z = 1;
foreach $item (sort @tmp) {
$item =~ /^\[(.*?)\]\_\_\((.*?)\)\_\_$/;
if( $z == $numOfCols) {
$contents = $contents."
\n\n| | \n";
$z = 1;
}
$contents = $contents
.''.$1.''." | \n";
$z++;
}
for(; $z < $numOfCols; $z++) {
$contents = $contents." | \n";
}
$contents = $contents.'
'."\n";
}
$contents = $contents."
";
printHTML("function_index.html", "Index of Functions", 'bgcolor = "#FFFFFF"', $contents);
}
sub writeFunctionsByAlphabet {
############################################
# Writes, for each letter $letter
# an html file called
# cont_$letter.html. This a a collection of
# links to the respective entries in
# the entry pages.
# Uses the hash %subsection.
# Call in the form
# writeFunctionsByAlphabet( $letter)
############################################
my( $letter, @tmp, $key, $item, $contents, %subsectionsByAl);
$letter = $_[0];
$subsectionsByAl{ $letter} = []; @tmp = ();
foreach $key ( keys %subsections) {
foreach $item ( @{ $subsections{ $key}}) {
if( $item =~ /^\[$letter/ || $item =~ /^\[\l$letter/) {
$item =~ /^\[(.*?)\]\_\_\((.*?)\)\_\_$/;
push @{ $subsectionsByAl{ $letter}}, "\[$1\]\_\_\($key\)\_\_\n";
push @tmp, "\[$1\]\_\_\($key\)\_\_\n";
}
}
}
$contents = "\nIndex: $letter
\n";;
foreach $item (sort @tmp) {
$item =~ /^\[(.*?)\]\_\_\((.*?)\)\_\_$/;
$contents = $contents
.' '
.$1.''."\n";
}
printHTML( "cont_$letter.html", "$letter", 'bgcolor = "#FFFFFF"', $contents);
}
sub writeEntries4Ref() {
###############################################
# Writes, for each list pointed to by $key,
# a file $key.html which will contain the
# subsections of the corresponding section
# in usersch3.tex.
# Needs correcly initializes hash %subsectiones
# and uses for the moment "gphelp -detex" or
# "gphelp -detex" (accordingly to what option
# is set)
# to convert subsections of usersch3.tex
# into html.
# Use in the form writeEntries( $key)
###############################################
my( $contents, $item, $entry, $l, $r, $d, $key, @text, $link, $function);
$key = $_[0];
print STDERR "\twriting: $key ...\n";
initFixedData();
$contents = "\n".$REF_HEADER;
$contents = $contents."$key
\n\n";
$contents = $contents
."\n"
."| \n";
foreach $item (sort @{ $subsections{$key}}) {
$item =~ /^\[(.*?)\]\_\_\((.*?)\)\_\_$/;
$contents = $contents
.''.$1.' '."\n";
}
$contents = $contents
." |
\n| |
\n";
foreach $item (@{ $subsections{$key}}) {
$item =~ s/^\[(.*?)\]\_\_\((.*?)\)\_\_$/$1/;
$entry = `$gphelp '$option' '$item'`;
$entry =~ /not\ found/ and unhappy("\t$item");
if( $option eq '-raw') {
# first kill TeX leftovers
for $key ( keys %trans0) {
$l = quotemeta( $key); $r = $trans0{$key};
$entry =~ s/$l/$r/gs;
}
for $key ( keys %trans1) {
$l = quotemeta( $key); $r = $trans1{$key};
$entry =~ s/$l/$r/gs;
}
# TO_DO: Fix the dirty hack from here
$l = '\@1\@\[startcode\]'; $r = '';
$entry =~ s/$l(.*?)/$r$1/gs;
$l = '\@2\@\[endcode\]'; $r = '
';
$entry =~ s/$l(.*?)/$r$1/gs;
# to here.
for $key ( keys %trans) {
$l = quotemeta( $key); $r = $trans{$key};
$entry =~ s/$l/$r/gs;
}
# then make a nice header
$entry =~ s/^(.*?)\:/\$1\<\/h4\>\n\
/gs;
# now care for the @[] markers
for $key ( @ou) {
$l = quotemeta( $tr{$key}); $r = $html{$key};
$entry =~ s/$l(.*?)/$r$1/gs;
}
# where @[dollar] is more difficult (or should we just throw it ?)
$d = '\@\[dollar\]';
# while( $entry =~ s/$d(.*?)$d/\
';
printHTML( "$fill{$key}.html", "$key", 'bgcolor=\"#FFFFFF\"', $contents);
print STDERR "\t ... \e[0;32m\e[1m DONE\e[m\n";
}
sub writeEntries() {
###############################################
# Writes, for each list pointed to by $key,
# a file $key.html which will contain the
# subsections of the corresponding section
# in usersch3.tex.
# Needs correcly initializes hash %subsectiones
# and uses for the moment "gphelp -detex" or
# "gphelp -detex" (accordingly to what option
# is set)
# to convert subsections of usersch3.tex
# into html.
# Use in the form writeEntries( $key)
###############################################
my( $contents, $item, $entry, $l, $r, $d, $key);
$key = $_[0];
print STDERR "\twriting: $key ...\n";
initFixedData();
$contents = "\n$key
\n\n";
foreach $item (@{ $subsections{$key}}) {
$item =~ s/^\[(.*?)\]\_\_\((.*?)\)\_\_$/$1/;
$entry = `$gphelp '$option' '$item'`;
($entry =~ /^'.*' not\ found !$/) and unhappy("\t$item");
if( $option eq '-raw') {
# first kill TeX leftovers
for $key ( keys %trans0) {
$l = quotemeta( $key); $r = $trans0{$key};
$entry =~ s/$l/$r/gs;
}
for $key ( keys %trans1) {
$l = quotemeta( $key); $r = $trans1{$key};
$entry =~ s/$l/$r/gs;
}
# TO_DO: Fix the dirty hack from here
$l = '\@1\@\[startcode\]'; $r = '';
$entry =~ s/$l(.*?)/$r$1/gs;
$l = '\@2\@\[endcode\]'; $r = '
';
$entry =~ s/$l(.*?)/$r$1/gs;
# to here.
for $key ( keys %trans) {
$l = quotemeta( $key); $r = $trans{$key};
$entry =~ s/$l/$r/gs;
}
# then make a nice header
$entry =~ s/^(.*?)\:/\$1\<\/h4\>\n\
/gs;
# now care for the @[] markers
for $key ( @ou) {
$l = quotemeta( $tr{$key}); $r = $html{$key};
$entry =~ s/$l(.*?)/$r$1/gs;
}
# where @[dollar] is more difficult (or should we just throw it ?)
$d = '\@\[dollar\]';
# while( $entry =~ s/$d(.*?)$d/\