#!/public/bin/perl

# Main module of HTML -> Text Converter
#
# Module input (read from STDIN stream):
#	A text file containing embedded HTML tags.
#
# Output (written to STDOUT stream):
#	the same text but formatted according to the HTML tags

## include the other modules
require "./Input.pl";
require "./Output.pl";
require "./TagRoutines.pl";

$DEBUG = 0;		# set to 1,2, or 3 to trace tag processing

## initialize the other modules
&INInit();
&OUInit();
&TRInit();

## main processing loop
for( ; ; ) {
    ($ma_type, $ma_token) = &INGetToken();

    if ($DEBUG & 1) {
	print "Token type = $ma_type, text = '$ma_token'\n";
    }

    if ($ma_type eq 'EOF') {
	last;
    } elsif ($ma_type eq 'TAG') {
	&TRHandleTag($ma_token);
    } elsif ($ma_type eq 'SPACE') {
	&OUAppendSpace($ma_token);
    } else {
	# $ma_type must be TEXT
	&OUAppendString($ma_token);
    }
}
&TRHandleTag('</HTML>');	# close off any unclosed constructs
&OUFlushOutput();		# output any unfilled last line
