#!/afs/athena/contrib/perl5/perl

open(F1, $ARGV[0]);
open(F2, $ARGV[1]);

while($wct1 < 25){
	$w = (<F1>);
	$w =~ s/[^\w ]//g;
	$line++;
	print("Reading line $line ($wct1 words so far) $w\n");
	@words = split(" ", $w);
	if(($wct1+$#words) <25){
		$wct1+=$#words;
	}
	else {
		@remwords = @words[(25-$wct1)..$#words];
		last;
	}
}

print("Seeking for $remwords[0]\n");

while($cword ne lc($remwords[0])){
	if($#newwords == -1){
		$w = (<F2>);
		$w =~ s/[^\w ]//g;
		@newwords = split(" ", $w);
	}
	$cword = lc(shift(@newwords));
}

@w1 = @remwords;
unshift(@newwords, $cword);
@w2 = @newwords;
$fuzz = 15;
MAIN: while(1) {
	if($#w1 < $fuzz){
		$w = (<F1>);
		$w =~ s/[^\w ]//g;
		@w1 = (@w1, split(" ", $w));
		$line++;
	}
	if($#w2 < $fuzz){
		$w = (<F2>);
		$w =~ s/[^\w ]//g;
		@w2 = (@w2, split(" ", $w));
	}
	while(($w1 = lc(shift(@w1))) eq "") { next MAIN if $#w1 == -1;}
	while(($w2 = lc(shift(@w2))) eq "") { next MAIN if $#w2 == -1;}
#	$w1 =~s/\W//g;
#	$w2 =~s/\W//g;
	if($w1 ne $w2){
#		print("Mismatch at line $line on words $w1/$w2\n");
		$fmatch = 0;
		for $f (0..$fuzz){
			if($w1 eq lc($w2[$f])){
				print &space("", $w2)."\n";
				$w2 = shift(@w2);
				print &space($w1, $w2)."\n";
				$fmatch = 1;
				last;
			}
			if($w2 eq lc($w1[$f])){
				print &space($w1, "")."\n";
				$w1 = shift(@w1);
				print &space($w1, $w2)."\n";
				$fmatch = 1;
				last
			}
		}
		if(!$fmatch){
			print(&space($w1, $w2)."**********($line)\n");
		}
	}
	else{
			print(&space($w1, $w2)."\n");
	}
}
exit;

while(1){
	$w = (<F2>);
	@words2 = split(//, $w);
}

sub space {
	my($a, $b) = @_;

	$ap = $a.(" " x (30-length($a)));
	$blob = $ap.$b;
	$ret = $blob.(" " x (50-length($blob)));
	$ret;
}