#!perl -lw
# while read -r file ; do echo $file/$(perl ~/0/r/get-file-name-from-log.pl 'Ambiguous occurrence|LANGUAGEPRAGMA|Use UndecidableInstances to permit|Couldn.* match expected type.*TimeLocale| is gone\. Use |Duplicate instances declarations|use BangPatterns|Unacceptable .* type in foreign declaration|Varible not in scope (catch|unsafePerformIO)|deriving.*clause of a data type declaration' < $file.log ) ; done < ~/0/w/sec/sec
# /^([0-9.]+:  )?(\S+hs):\d+(-\d+)?:\d+(-\d+)?: error:/
die unless defined ($pattern=$ARGV[0]);
#print STDERR "pattern $pattern";
while(<STDIN>){
    #print;
    if (/^([0-9.]+:  )?\[\s*\d+ of\s+\d+\] Compiling \S+\s+\( (\S+),/){
        $fn=$2;
    }
    if (defined $fn and $fn =~ /^dist/) {
        if (/^([0-9.]+:  )?(\S+hsc?):\d+(-\d+)?:\d+(-\d+)?: error:/){
            $fn=$2
        }
    }
    #if(/Ambiguous occurrence.*(traverse|Word|Semigroup)/){
    if(/$pattern/){
        die unless $fn;
        print $fn;
        $found=1;
        last;
    }
}
die $_ unless $found
