#!/usr/bin/perl -w

use strict;

my $total = 0;
my $success = 0;

FILE: for my $file ( @ARGV ) {
    open DECISION, $file or die;

    $total++;
    
    my $prior_history;
    my $disposition;

    while ( <DECISION>) {
      if ( m{<b>PRIOR HISTORY:</b>(.*?)<b>} ) {
	$prior_history = $1;
      }

      if ( m{<b>DISPOSITION:</b>(.*?)<br} ) {
	$disposition = $1;
      }
    }

    if ( not defined $prior_history ) {
      print STDERR "No prior history in $file.\n";
      next FILE;
    }

    if ( not defined $disposition ) {
      print STDERR "No disposition in $file.\n";
      next FILE;
    }

    my ($prior) = $prior_history =~ m{(?:CERTIORARI TO THE|APPEAL FROM THE) (.*?)[<\.]};
    my ($disp) = $disposition =~ m{.*, (.*)$};

    if ( not defined $prior ) {
      print STDERR "bad prior in $file\n";
      next FILE;
    }

    if ( not defined $disp ) {
      $disp = $disposition;
    }
    if ( (defined $prior) and (defined $disp) ) {
      print "$file $prior ||| $disp\n";
      $success++;
    }
}

print STDERR "$success / $total\n";
