#!/usr/bin/perl

#Delete strings which are not current in Catalan version

open (COMP, $ARGV[0]);

my $FILEBASE = "/toni/mozillatrans/cvs-aviary";
my $filein;
my $filein2;
my $det = 0;
my $detca = 0;
my $catsobre;
my %array;

while (<COMP>){

	if ($_=~/^Entities\s*in\s*\.\/(\S+)\s*don't\s*match\:/) {

		$filein = $1;
		$det++;

	
	}

	if ($_=~/^Properties\s*in\s*\.\/(\S+)\s*don't\s*match\:/) {

		$filein = $1;
		$det++;

	
	}


	if ($_=~/^\s*$/) {$det=0; $detca=0;}
	
	if ($_=~/^\s*In\s*(l10n\S+)\:/) {$filein2 = $1; $detca++; }
	
	else {

		if ($det>0 and $detca>0) {
		
			if ($_=~/^\s*(\S+)/) {
			
				push (@{$array{"/$filein2/$filein"}}, $1);
			}	
		}
	}

		
				
}

close (COMP);

foreach my $path (keys %array) {


	my $fileout = $path;
	$fileout =~ s/\//*/g;

	print "; $fileout\n";
	
	my $i =0;

	print "$FILEBASE/$path\n";

	open (FILEOUT, ">clean/$fileout");
	open (FILE, "$FILEBASE/$path") || die "Cannot open!";

	while (<FILE>) {

       		 $i=0;
       	 	foreach my $o (@{$array{$path}}) {

               		if ($_=~/$o/g) {
        
              		  $i++;
                	}
        
       		 }

       	 if ($i==0) {print FILEOUT;}
	}

	close (FILE);
	close (FILEOUT);
}


