#!/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 $face = "";
    foreach my $token (@tokens) {
	if (m{<font\s+face="([^"]*)"}i) {
	    my $face = lc($1);
	    if ($face eq FONT) {
		$token = "";
	    } else {
		$face = "";
	    }

	} elsif (m{</font/}i) {
	    $token = "" if $face;
	}
    }

    $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;
}
