#!/usr/bin/perl -w
# $Id: setext2html.txt,v 1.9 2007/09/08 $
# setext -> HTML converter
#
# (C) 2002 Erik Oliver
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.
use strict;
use Carp;
# Global variables
my $numargs = @ARGV;
my $infile;
my $outfile;
my %href;
my @toc;
my $tocindex = -1;
sub style_encode($) {
use HTML::Entities;
my $string = shift;
my $flag = 0;
sub encode_only($) {
use HTML::Entities;
my $string = shift;
$string = encode_entities($string,"<>&");
return($string);
}
if ($numargs == 1) {
if($ARGV[0] =~ s/\.etx$// ) {
print STDERR "warning: one argument form used but called with $ARGV[0].etx, argument shortened to $ARGV[0].\n";
}
if (! -e $infile) {
print STDERR "error: Input, $infile, does not exist\n";
exit -1;
}
if (! -r $infile) {
print STDERR "error: Input, $infile, not readable\n";
exit -1;
}
open INFILE, "<$infile" ||
die "Could not open $infile for reading, $!";
my @data = <INFILE>; # slurp input
chomp @data; # strip newlines
close INFILE;
open OUTFILE,">$outfile" ||
die "Could not open $outfile for writing, $!";
## Loop 1: Find any href-tt tags and hash the URL against a key
## [Also escape a literal "`" with +++.
for(my $loop=0; $loop <= @data; $loop++)
{
if(!$data[$loop]) { next; } # skip blank lines
# header information
print OUTFILE "<h1>$htmltitle</h1>\n" if ($htmltitle);
print OUTFILE "<p>By ",encode_only($htmlauthor),"</p>\n" if ($htmlauthor);
print OUTFILE "<p>$htmldate</p>\n" if ($htmldate);
# table of contents?
print OUTFILE "<h1>Table of Contents</h1>\n";
print OUTFILE "<ul>\n";
my $lastlevel = 0;
for(my $loop = 0; $loop <= $tocindex; $loop++)
{
$_ = $toc[$loop];
m#([^:]*):(.*)#;
my $level = $1;
my $content = $2;