#!/bin/sh
# \
exec tclsh "$0" "$@"

if { $argc > 2 } {
	puts stderr {Usage: HTML2text [infile [outfile]]}
	exit 1
}

if { $argc == 0 } {
	set infile  stdin
	set outfile stdout
} elseif { $argc == 1 } {
	set infile  [open [lindex $argv 0] r]
	set outfile stdout
} else {
	set infile  [open [lindex $argv 0] r]
	set outfile [open [lindex $argv 1] w]
}

set basedir /home/joe/lib/HTML2text
# Read in the HTML parsing routines from Sun's HTML library
source $basedir/html_library-0.3/html_library.tcl

# Read in the text rendering routines
source $basedir/html_text.tcl

# Add any changes to the default renderings here
#   A couple of examples:
#     To make <STRONG> text be surrounded by -> and <-
#       set HTtext_map(strong) "-> <-"
#
#     To make <EM> text be surrounded by equal signs
#       set HTtext_map(em) =


# read the entire input file into the variable html
set html [read $infile]
close $infile

# do the HTML->text conversion
set text [HTconvert $html]

# write it to the output file
puts $outfile $text
close $outfile
