package TTPP;
use strict;
use Template;
use HTML::Parser;
sub error($)
{
my $errorMessage = shift;
print "Content-type: text/html\n\n";
print << "EOF";
Error
Error
$errorMessage
EOF
}
sub preprocess($$)
{
my $source = shift;
my $dest = shift;
{
package MyParser;
use base 'HTML::Parser';
sub start {
my($self, $tagname, $attr, $attrseq, $origtext) = @_;
$self->{textstring} .= $origtext;
}
sub end {
my($self, $tagname, $origtext) = @_;
$self->{textstring} .= $origtext;
}
sub comment {
my($self, $commenttext) = @_;
if(substr($commenttext, 0, 1) eq '%' &&
substr($commenttext, -1) eq '%' ) {
$self->{textstring} .= "[$commenttext]";
}
}
sub text {
my($self, $origtext, $is_cdata) = @_;
$self->{textstring} .= $origtext;
}
}
my $p = MyParser->new;
unless(-e $source) {
return 0;
}
$p->parse_file($source);
open FH, "> $dest" or return 0;
binmode FH;
print FH $p->{textstring};
close FH;
return 1;
}
1;