#!/Perl

print "Hello, World... Convert FONT to span class\n";

#my $in_file = "c:\\HOMEPAGE\\P26\\perl\\perl_ref.htm";
#my $out_file = "tempfont.htm";
#my $log_file = "tempfont.txt";

my $in_file = "tempfont.htm";
my $out_file = "tempfont2.htm";
my $log_file = "tempfont2.txt";


my ($IF, $OF, $OL);

open $OL, ">$log_file" or die "ERROR: Unable to open LOG file $log_file ...\n";

open $IF, "<$in_file" or die "ERROR: Unable to open $in_file ... aborting ...\n";
my @lines = <$IF>; # slurp in while file ...
close( $IF);

print "Got ".scalar @lines." of input ...\n";
my $line = '';
my @newlines = ();
foreach $line (@lines) {
	if ($line =~ /(<font color=\"\#)(.+?)(\">)(\w+?)(<\/font>)/ ) { # (\#[A-F0-9]+?)(>)/ ) {
		prt( "Got 1[$1] 2[$2] 3[$3] 4[$4] 5[$5] 6[$6]...\n" );
		if ($2 eq '0000FF') {
			$line =~ s/<font color=\"\#0000FF\">/<span class=\"blue\">/;
			$line =~ s/<\/font>/<\/span>/;
		} elsif ($2 eq 'FF0000') {
			$line =~ s/<font color=\"\#FF0000\">/<span class=\"red\">/;
			$line =~ s/<\/font>/<\/span>/;
		} elsif ($2 eq '006600') {
			$line =~ s/<font color=\"\#006600\">/<span class=\"green\">/;
			$line =~ s/<\/font>/<\/span>/;
		} elsif ($2 eq '800000') {
			$line =~ s/<font color=\"\#800000\">/<span class=\"brown\">/;
			$line =~ s/<\/font>/<\/span>/;
		}
	}
	push(@newlines, $line);
}

open $OF, ">$out_file" or die "ERROR: Unable to create $out_file ...\n";
foreach $line (@newlines) {
	print $OF $line;
}
close $OF;
sub prt {
	my $m = shift;
	print $m;
	print $OL $m;
}
