#!perl -nlw
# tail -c +0 -f noprof | perl ../random/cabal-description.pl| perl ../random/classify-ghc-errors-with-description.pl | tee /tmp/errorsnpackages
use FileHandle;
BEGIN{
    STDOUT->autoflush(1);
}
print if / ERROR /;
unless($j){
    $j="$1      INLINE $4" if /^(\S+:).*hsc?:\d+(-\d+)?:\d+(-\d+)?: error: (.*)/;
    $j="$1      INLINE $2" if /^(\S+:).*:\d+:\d+: fatal error: (.*)/;
    $j="$1    $2" if /^(\S+:)(.*No executables and no library found\. Nothing to do\..*)/;
    $j="$1    $2" if /^(\S+:)(.*cabal: can\x27t find source.*)/;
    $j="$1    $2" if /^(\S+:).*(ghc:\s*panic.*)/;
    $j="$1    $2" if /^(\S+:).*(error: undefined reference to .*)/;
    $j="$1    $2" if /^(\S+:).*depends on.*which failed/;
    $j=$_ if /could not execute/ or /: The program .* is required but / or /exec: permission denied/ or /runInteractiveProcess: exec: / or /Simplifier ticks exhausted/ or /:  : copyFile: does not exist \(No such file or directory\)/ or /configure: error:/ or /No libraries, executables, tests, or benchmarks are enabled for package/ or /Failing due to -Werror/ or /<no location info>: error: / or /:  ghc: unrecognised flag/ or /No executables and no library found\. Nothing to do\./ or /The package has an impossible version range for a dependency/ or /File in tar archive is not in the expected directory/ or /ghc: on the commandline: malformed integer argument in -Odph/ or /installed package info from too old version of Cabal \(key field does not match id field\)/ or /on the commandline: error: \[-Werror\]/ ;
    if($n) {
	  unless(/^\S+:\s+warning:/ or /^\S+:\s*$/) {
	      $j=$_;
	  }  # weird C warnings in HsSyck
	  $n=0;
    }
    if(/((hsc?)|(\.c)):\d+(-\d+)?:\d+(-\d+)?: error:$/ or /:\d+: \(column \d+\) \[ERROR\]  >>>/){
        # get next line
	$n=1
    }
    # this one trumps
    $j="$1    $2" if /^(\S+:)(.*Missing \(or bad\).*(librar|header file).*)/;
}else {
    if (/\(Use .* to permit this/ or /Enable .* to allow it/ or /Use .* if you want to/ or /Use .* to accept this/){
	s/^[0-9.]+:\s*//;
	$j.="  $_";
    }
}
if(/^[0-9.]+:  description\s*:/i){
      $d=$_;
}
if(/^[0-9.]+:  synopsis\s*:/i){
      $s=$_;
  }
if(/ ROOT FAILURE /){
    #print"";
    print $s if$s;
    print $d if $d;
    print $j if$j;
    print;
    undef $j;
    undef $s;
    undef $d;
}
if(/:  Completed\s+\S+-[0-9.]+$/){  #was "Installed" in an older version of cabal
    undef $j;
    undef $s;
    undef $d;
}
