#!/usr/bin/perl

open(SECT,$ARGV[0]);
$max = 0;
while(<SECT>)
{
	($name,$target) = split(/\|/);
	$SECTIONS{$name} = $target;
	if (length($name) > $max)
	{
		$max = length($name);
	}
}

open (IN, $ARGV[1]);

while (<IN>)
{
if ((/^<sec/) && (/no_header|unknown/))
	{
	$check = 1;
	next;	
	}
if (/\/sec/)
{
	$check = 0;
	next;
}
next if (/^<sec/);

if ($check == 1)
{
	#check first line for header
	s/^\*// if (/^\*|/);
	if (/^(lab|data)/i)
	{
		print STDERR $_;
		s/([\W ])/:. $1/;
		print STDERR $_;
	}	
	else
	{
		if (/:\./)
		{
			$name = $_;
			chomp($name);
	        	$name =~ s/:\.*$//;	
			if (!exists($SECTIONS{lc($name)}))
			{
			print STDERR "section:"  ,$name, "\n" if (!/<ign>/);
			}
		}
		elsif (/<ign>/)
		{

		}
		else
		{
                	$name = $_;
                	chomp($name);
                	$name =~ s/\.*$//;
			if (length($name) < $max)
			{
				if (!exists($SECTIONS{lc($name)}))
                		{
                       		print STDERR "section:  ", $name, "\n";
				#print STDERR $_;
				#s/\.$/:\./ if (!/^\d/);
				#print STDERR $_;
                		}
				else
				{
				print STDERR $_;
                        	s/\.$/:\./;
                        	print STDERR $_;
				}
			}
			else
			{
				print STDERR "==========", $_ ;
			}
		}

	}



$check = 0;
}

print;

}
