#!/usr/bin/perl 

use FileHandle;
use constant FONT => "symbol";

foreach (@ARGV) {
	no_font($_);
}

sub no_font {
    my ($file) = @_;
    my $text = slurp_copy($file);

    my @tokens = split(m{(</*font[^>]*>)}si, $text);

    my @faces;
    foreach my $token (@tokens) {
	if ($token =~ m{<font[^>]+face="([^"]*)"}i) {
	    push (@faces, lc($1));
	    $token = "" if @faces[-1] eq FONT;

	} elsif ($token =~ m{</font}i) {
	    $token = "" if $faces[-1] eq FONT;
	    pop(@faces);
	}
    }

    $text = join("", @tokens);

    my $fd = FileHandle->new(">$file") 
      or die "Can't replace $file: $!\n";
    print $fd $text;
    $fd->close();

}

sub slurp_copy {
    my ($file) = @_;

    my $fd = FileHandle->new($file) 
      or die "Can't open $file: $!\n";
    my $text = do {local $/; <$fd>};
    $fd->close();

    my $backup = $file . "~";

    my $fd = FileHandle->new(">$backup") 
      or die "Can't backup $file: $!\n";
    print $fd $text;
    $fd->close();

    return $text;
}