#!/usr/local/bin/perl

require 'sgmllex.pl';

%html_ents = split(/\s+/, <<EOF);
amp &
lt <
gt >
quot "
EOF
 
# "

$| = 1; # no buffering

undef($/);
$_ = <>;

$mode = $sgml'Element; #'

while($_){
    @stuff = &sgml'lex($mode); #' perl-mode fixup
    &sgml'dump(*html_ents, @stuff); #'

    if($stuff[0] eq 'DATA' || $stuff[0] eq 'SPACE'){
	shift(@stuff); shift(@stuff);
    }

    if($stuff[0] eq 'START'
       && ($stuff[1] eq '<XMP'
	   || $stuff[1] eq '<LISTING')){
	$mode = $sgml'CDATA; #'
    }else{
	$mode = $sgml'Mixed; #'
    }
}
