#!/usr/local/bin/perl # # Turns a tree of text files into another tree of html files. # For files with special formatting i.e. a table made of tabs or # spaces, HTML would collapse this formatting into unreadable output. # This program has been modified to look for the HTML tags
# to preserve formatting. Simply insert those tags around your formatted text. # # Assumes use of frames (netscape,i.e.), with a default right frame named # defright.html as an introduction. Assumes you have the following files # available to attach or link to: # header.html, footer.html, disclaimer.html, default.html that puts # docleft.html into the left frame and docright.html into the right frame. # # mcorcoran 7/5/1998 $mydate=`date`; # name to put on top page title: $person="Mike Corcoran"; # debugging on/off 1/0 $debug=0; #find your home directory: $HOME=(getpwuid($<))[7]; # tree of text files to convert to html: $indir="$HOME/docs"; # where to find default header and footer files: $defaultsdir="$HOME/webdocs"; # where to create the HTML tree: $outdir="$HOME/www/htmldocs"; #------------------------------------------------------------------------------ # main() # initialize a counter to see how many files are in this tree: $totalfiles="0"; if (! -d $outdir ) { print "$outdir does not exist, creating it. \n"; mkdir ($outdir,"0"); chmod 0755, $outdir; } system ("cp $defaultsdir/defright.html $outdir"); system ("cp $defaultsdir/default.html $outdir"); system ("cp $defaultsdir/disclaimer.html $outdir"); #system ("touch $outdir/dirindex.html"); chdir $indir; @dirlist=`find . -type d -print`; # add a space since it will get chopped(): $dirlist[$#dirlist+1]=". "; #skip $dirlist[0] since it's ".", do last so counter will count all files: for $i (1 .. $#dirlist) { chop($dirlist[$i]); next if ($dirlist[$i] eq ".."); if (! -d "$outdir/$dirlist[$i]") { print "$outdir/$dirlist[$i] does not exist, creating it\n"; mkdir ("$outdir/$dirlist[$i]","0"); chmod 0755, "$outdir/$dirlist[$i]"; } chdir "$indir/$dirlist[$i]"; if ($debug){print "opening index.html for writing \n";} open (indexfh,">$outdir/$dirlist[$i]/index.html") || die "can't open index.html for writing\n"; print indexfh " \n
\n";
open (infh,"$infile") || die "can't open $infile for reading \n";
$no_br=0;
while ( \n \nTotal of $totalfiles documents in this tree\n";
print indexfh " \n Tree last built on See The Code to build this tree\n";
}
print indexfh " \n \n";
close (indexfh);
}
system ("mv $outdir/index.html $outdir/docleft.html");
# copy this code to where people can see it:
system ("cp $HOME/webdocs/makewebdocs $HOME/www/makewebdocs");
system ("cp $HOME/webdocs/*html $HOME/www/makewebdocs");
/)
{
$no_br=1;
}
if (/<\/pre>/)
{
$no_br=0;
}
if ($no_br)
{
print outfh "$_";
}
else
{
print outfh "$_
";
}
}
close(infh);
close(outfh);
system ("cat $defaultsdir/footer.html >> $outfile");
}
}
if ($dirlist[$i] eq ".")
{
$date=`date`;
print indexfh "
$date \n";
print indexfh "