#!/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 ${person}'s system notes \n"; print indexfh " \n"; print indexfh < ENDOFBLURB if ($dirlist[$i] ne ".") { $currdir=$dirlist[$i]; $currdir=~ s/\.\///; print indexfh "

Directory of $currdir

\n"; } else { print indexfh "

Top level Docs Dir

\n"; } print indexfh "
\n"; ($piece1,$piece2,$piece3,$piece4)=split(/\//,$dirlist[$i],3); if ($dirlist[$i] ne ".") { if ($piece3 ne "") { print indexfh "Go to Parent dir ..
\n"; } else { print indexfh "Go to Parent dir ..
\n"; } } if ($debug) { print "chdir $dirlist[$i] ";} $pwd=`pwd`; print "working in $pwd \n"; @filelist=`ls -1`; for $j (0 .. $#filelist) { chop($filelist[$j]); if ($debug) {print "working with $filelist[$j]\n";} $filelist[$j]=~ s/\.\///; if (-d $filelist[$j]) { print indexfh "subdir $filelist[$j]
\n"; } if (-f $filelist[$j]) { # have a file to convert and copy $totalfiles++; $infile="$filelist[$j]"; print indexfh "file $infile
\n"; $outfile="$outdir/$dirlist[$i]/$filelist[$j].html"; if ($debug) {print "infile=$infile\n";} if ($debug) {print "outfile=$outfile\n";} system ("cp $defaultsdir/header.html $outfile"); open (outfh,">>$outfile") || die "Can't open $outfile for writing\n"; print outfh "

$infile

\n"; print outfh "Version date: $mydate

\n"; open (infh,"$infile") || die "can't open $infile for reading \n"; $no_br=0; while () { if (/

/)
					{
					$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 "

\n

\nTotal of $totalfiles documents in this tree\n"; print indexfh "

\n Tree last built on
$date \n"; print indexfh "

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");