#!/usr/bin/perl
#Ž´ŽÁŽ»”§Ž³Ž¡Ž¼Ž¥ŽÉŽ¤ŽÏEUC

$in="da";
$out="dt.htm";
$ex="fnc";
@color=('darkred','darkblue','darkgreen','cyan','purple','yellow');
open (FILE, $ex) || die "Can't open $ex\n$!\n";
while (<FILE>) {
	chomp;
	push(@fnc,$_);
}
@fnc=sort @fnc;
close FILE;

#splitter
$spt="\\s|\\c\\n|\\n|\\t|\\^|<[^<>]+>|,|\\.|\\(|\\)|;|:|\\\"|\\?|\\\/|\\\||!";

open (FILE, "$in") || die "Can't open $in\n$!\n";
while (<FILE>)
{
	chomp;
	push (@array, $_);
}
close FILE;

$on=0;
for ($i=0; $i<=$#array; $i++) {
	if ($array[$i] =~ /<text>/) {$on=1; next;}
	if ($array[$i] =~ /<\/text>/) {$on=0; next;}
	if ($on == 0) {next;}
	$do=0;
	$c_count=0;
	@keep = split($spt,$array[$i]);
	@keep=sort @keep;
	for ($j=0; $j<=$#keep; $j++) {
		if ($keep[$j] eq '') {splice(@keep, $j, 1); $j--; next;}
		$keep[$j] =~ tr/A-Z/a-z/;
		$count{$keep[$j]}++;
	}
	while (($key,$value) = each %count) {
		if ($value > 1) {
			@keep=grep(/$key/, @fnc);
			if ($keep[0] eq '') {
				$array[$i] =~ s/\b($key)\b/<FONT COLOR=$color[$c_count] SIZE=+2>$1<\/FONT>/ig;
				$do=1;
				$c_count = ($c_count+1) % 6;
			}
		}
		delete $count{$key};
	}
	if ($do == 1) {push(@lst, $array[$i]);}
}

open (FILE,">$out") || die "Can't open $out\n$!\n";
print FILE "<HTML>\n<HEAD><\/HEAD>\n\n<BODY>\n";
foreach $t (@lst) {
	print FILE $t,"<BR>\n";
}
close FILE;

