#!/usr/bin/perl # # readme2html # Convert raw text to something with a little HTML formatting # # Written by Seth Golub # http://www.cs.wustl.edu/~seth/txt2html/ # # Re-written for use within this library. # $index = "Icons.html"; #$index = "index.html" unless -f $index; die("ERROR: \"README\" not found -- aborting\n") unless -f "README"; die("ERROR: \"Icons.html\" not found to get logo from -- aborting\n") unless -f $index; open(STDIN, "README.html") || die("Unable to read \"README\"\n"); $gifmap_dir = '/home/anthony/icons/support/gifmap'; $prefix = `cat $gifmap_dir/readme.pre`; $append = `cat $gifmap_dir/readme.post`; # find first link on the page # EG: the link to the top level directory # IE: the number of sets of ".." to perform, and this the directory depth open(ICONS, "<$index") || die("Unable to read \"$index\"\n"); while ( ) { next unless /HREF/; s/^[^"]*"//; s/"[^"]*$//; $top_dir = $_; last; } close(ICONS); # ------------------------------ sub htmlise { # convert special characters to HTML equivilents s/\&/\&/g; s/\/\>/g; } sub untabify { # Remove tabs 1 while s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e; } sub do_line { &htmlise; &untabify; s/\s+$//; if( /^$/ ) { print "

\n" unless $blanklines; $blanklines++; } else { $blanklines=0; } if( /^[-=\s]+$/ ) { print "


\n"; $blanklines=0; $_ = ""; } } # Read an Clean the top of README file $_ = ""; while ( /^$/ ) { $_ = ; s/\s+$//; } &htmlise; ($directory, @description) = split; $prefix =~ s/__TOP__/$top_dir/g; $prefix =~ s/__TITLE__/AIcons - "$directory"/g; $prefix =~ s/__DIRECTORY__/$directory/g; $prefix =~ s/__DESCRIPTION__/@description/g; print $prefix; # # Main part of file # $blanklines =1; MAINLOOP: while( ) { &do_line; next if /^Anthony Thyssen/; if ( /^Specific Contribs/ ) { print " Specific Contribs: \n", "

\n", "

\n"; $descdone = 0; CONTRIBS: while ( ) { &do_line; last CONTRIBS if /^See Also/; last CONTRIBS if /^Anthony Thyssen/; last CONTRIBS if $blankline >= 2; # abort on a double blank line next CONTRIBS if /^$/; # no blank lines in ouput block if ( /^ / ) { print $descdone ? ' ' : '
'; $descdone = 1; } elsif ( /^ / ) { print "
"; $descdone = 0; } print $_, "\n"; }; print "

\n"; $blanklines=1; redo MAINLOOP; } if ( /^See Also/ ) { print " See Also: \n", "

\n"; SEEALSO: while ( ) { &do_line; last SEEALSO if /^Specific Contribs/; last SEEALSO if /^Anthony Thyssen/; last SEEALSO if $blankline >= 2; # abort on a double blank line next SEEALSO if /^$/; # no blank lines in ouput block if ( /^ / ) { print "$_
\n"; } elsif ( /^ / ) { s/^\s+//; local($dir,@desc) = split; print "
\n"; printf "%-25s %s
\n", " $dir", "@desc"; } else { print "
\n$_
\n" } } print "

\n"; $blanklines=1; redo MAINLOOP; } print $_, "\n"; # normal line } # # finish up # print $append;