#!/usr/local/bin/perl
# LaTeX2HTML Version 96.3 : install_test
# This perl script substitutes the variable $LATEX2HTMLDIR in the main
# latex2html script with the actual path to the latex2html distribution
# files. It then tests for the availability of the external support programs.
# To do the installation manually:
# (1) Edit the file latex2html.config to set the correct pathnames where
# necessary
# (2) Put the path to the latex2html source files in the variable
# $LATEX2HTMLDIR in the main latex2html script
# OR
# set an environment variable LATEX2HTMLDIR to point to the latex2html
# source files.
#
# Read latex2html.config to get the value of $LATEX2HTML
&read_config_file;
# Substitute the variable $LATEX2HTMLDIR
print "\nMain script installation was " . (&substitute_dir_variable ? "" : "not ") .
"successful.\n";
print "Testing availability of external programs...\n";
&test_external_programs;
sub read_config_file {
&deal_with_forward_references;
require("latex2html.config") if
((-f "latex2html.config") ||
die "Could not find file latex2html.config\n");
}
# Changes lines of the form:
# $LATEX2HTMLDIR =
# to
# $LATEX2HTMLDIR =
sub substitute_dir_variable {
local($SUCCESS) = 0;
local($verbatim) = 0;
local($doc) = 0;
if ( (-f "$LATEX2HTMLDIR/latex2html.src") ||
die "\nCannot find $LATEX2HTMLDIR/latex2html.src\nPlease check the value of \$LATEX2HTMLDIR in latex2html.config\n") {
open(IN, "<$LATEX2HTMLDIR/latex2html.src")
|| die "Cannot open $LATEX2HTMLDIR/latex2html.src";
# rename("$LATEX2HTMLDIR/latex2html","$LATEX2HTMLDIR/latex2html.bak");
open(OUT, ">$LATEX2HTMLDIR/latex2html")
|| die "Cannot open $LATEX2HTMLDIR/latex2html";
chmod 0755, "$LATEX2HTMLDIR/latex2html";
open(DOC, ">$LATEX2HTMLDIR/latex2html.tex")
|| die "Cannot open $LATEX2HTMLDIR/latex2html.tex";
print DOC "\\documentclass{article}\n";
print DOC "\\begin{document}\n";
print DOC "\\title{\\LaTeX\\ To HTML Translation}\n";
print DOC "\\author{Nikos Drakos, rewritten by Marcus E. Hennecke and Michael Downes}\n";
print DOC "\\maketitle\n";
while () {
if (s/^#\s+//) {
$doc = 1;
if ($verbatim) {
print DOC "\\end{verbatim}\n";
$verbatim = 0;
}
s/\\([a-zA-Z\@]+|[^a-zA-Z@])/\\verb|$&|/g;
s/[\$&%_{}]/\\$&/g;
s/\^/\\^{}/g;
s/#####+\s*([^#]+)\s*#####+/\\section{$1}/;
s/#/\\$&/g;
s/=====+\s*([^=]+)\s*=====+/\\subsection{$1}/;
s/\+\+\+\+\++\s*([^+]+)\s*\+\+\+\+\++/\\subsubsection{$1}/;
s/-----+\s*([^-]+)\s*-----+/\\paragraph{$1}/;
print DOC;
} elsif (!/^#-/) {
s/\$LATEX2HTMLDIR\s*=.*$/
do {$SUCCESS = 1;
"\$LATEX2HTMLDIR='$LATEX2HTMLDIR';" .
"# Inserted by installation script"}/eo unless $SUCESS;
print OUT;
next if (!$doc || /^##/ || (/^\s*$/ && !$verbatim));
unless ($verbatim) {
print DOC "\\begin{verbatim}\n";
$verbatim = 1;
}
print DOC;
}
last if /\_\_END\_\_/;
}
print DOC "\\end{verbatim}\n" if ($verbatim);
print DOC "\\end{document}\n";
close IN;
close OUT;
close DOC;
}
$SUCCESS && (! &look_for("$LATEX2HTMLDIR/latex2html","exec",
"LaTeX2HTML program in $LATEX2HTMLDIR"));
}
sub deal_with_forward_references {
foreach ("ignore_commands", "process_commands_in_tex", "get_image_size") {
eval "sub $_ {}"}
}
sub test_external_programs {
local ($nolatex2html, $version, $revision, $nopic, $nojust, $tmp) = (0,0);
# Perl
$ver = $] * 1.0;
$vers = sprintf("%4.3f", $ver);
if ($ver < 5.001) {
print "\n*** ERROR: You are using Perl version $vers\n".
"\nThis may cause problems." .
"Please upgrade to version 5 at patch level 1\n";}
else {print "Perl version $vers is OK. \n"}
$version=undef;
$_ = &get_first_line_of_stderr("$DVIPS -f DUMMY");
s/dvipsk?\s*([\d\.]+)/$version = $1;/eo;
$patch = $version;
if ($patch && ($patch < 5.516)) {
$nopic = 1;
print "\n*** Warning: You are using DVIPS $version.".
"\nThis may cause problems when generating inlined images" .
"\nif your DVIPS does not support the command line options".
"\n-S, -i and -o".
"\nSee the manual for more details.\n";}
elsif (! $patch) {
print "Warning: I was not able to find DVIPS. ".
"\nPlease make sure that your version of DVIPS".
"\nsupports the command line options -S, -i and -o.".
"\nVersion 5.516 or higher is OK.".
"\nI was unable to verify your version.\n";}
else {
print "DVIPS version $version is OK.\n"}
$nopic = &look_for($PSTOGIF,"util", "pstogif");
foreach ($LATEX, $ENV{'GS'},
$ENV{'PNMCROP'}, $ENV{'PPMTOGIF'}) {
$tmp = &look_for($_, "util", $_);
$nopic = $tmp unless $nopic;
}
print "Warning: May not be able to convert equations, figures, tables ".
"\nand unknown environments to inlined images.\n" if $nopic;
$gs = $ENV{'GS'};
$_ = `$gs -h`;
$version = 0;
s/(version|Ghostscript)\s+([\d\.]+)/$version = $1;/eio;
unless (/ppmraw/) {
print "*** ERROR:\n",
"Your version of GS may not support DEVICE=ppmraw.\n",
"You may need to obtain a new binary, or rebuild GS.\n";
}
# if ($version ge 3.0) {
# print "You are using GS version $version\n".
# "Updating pstoppm.ps in latex2html.config...\n";
# print `perl -pi.bak -e "s/pstoppm.ps/pstoppm3.ps/;" latex2html.config`;
# print "Done.\n";
# }
foreach ($GIFTOPPM, $PNMFILE, $PNMTILE, $PNMCAT, $PNMFLIP) {
$tmp = &look_for($_, "util", $_);
$nojust = $tmp unless $nojust;
}
print "Warning: Will not be able to right justify equations.\n" if $nojust;
print "Warning: Please check the relevant pathnames in latex2html.config.\n"
if ($nojust || $nopic || $nolatex2html);
print "Warning: Will not be able to deal with some style files.\n"
if &look_for($LATEX2HTMLSTYLES, "dir", "Styles directory");
}
sub look_for {
local($what,$type, $name) = @_;
local($fail,$_);
if (($type eq "exec") && (! -x $what)) {
print "Making $what executable...\n";
chmod 0755, $what;
if (! -x $what) {
$fail = "Error: Could not make $what executable.\n";
}
}
elsif (($type eq "util") && (! -f $what)) {
print "Looking for $name...\n";
$_ = `sh -c "type $what"`;
chop;
if ((/no /) || (/not found/) || (/^\s*$/)) {
$fail = "Warning: $name was * NOT * found.\n";}
else {
$what = $_;}
}
elsif (($type eq "dir") && (! -d $what)) {
$fail = "Error: directory $name was * NOT * found.\n";
}
($fail ? print $fail : print "$name was found.\n");
$fail;
}
# Page 164 of the Camel book.
sub get_first_line_of_stderr {
local($prog) = @_[0];
open(SO, ">&STDOUT");
open(SE, ">&STDERR");
open(STDOUT, ">/tmp/foo$$");
open(STDERR,">&STDOUT");
select(STDERR); $| = 1;
select(STDOUT); $| = 1;
`$prog`;
close(STDOUT);
close(STDERR);
open(STDOUT, ">&SO");
open(STDERR, ">&SE");
open(FOO," ;
close(FOO);
$_;
}