#!/usr/local/bin/perl
# provide author feedback for ISCA #20 

# modified by Andrew Erlichson 1/4/93
# usage:  scantext.pl <filename> 1stpaper# <2ndpaper#> ...
# if no paper numbers are specified, the whole file is processed, 
# as before.

# stash current paper into master list
sub OUTPUT {
    $apno = sprintf("%03d",$pno);
    $#text = $nln-1;
    $master[$npaps] = join(":%:",$#text, @text);
    $index[$npaps] = join(":%:", $apno, $npaps);
#    print STDERR "review $npaps stored.\n";
    $npaps++;
    $dirty = 0;
}

# dump out the master list
sub DUMP {
    print STDERR "Total of $npaps processed.\n";
    $lpno = -1;
NEXTPAPER:
    while($npaps--) {
	($pno,$offset) = split(/:%:/,$sindex[$npaps],2);
        if (!$printall) {
            $printIt = 0;
            foreach $reqPaper (@ARGV) {
                if ($reqPaper == $pno) {
	          $printIt = 1;
                }
            }
            if (!$printIt) {
                next NEXTPAPER;
            }
        }
	($nln,$text) = split(/:%:/,$master[$offset],2);
	@text = split(/:%:/,$text);
	$#text = $nln;
	if ($lpno != $pno) {
	    $lpno = $pno;
	    printf("\f\n");
	}
	print(@text);
	print("\f\n");
#	print STDERR "review $offset retrieved.\n";
    }
}


$ignore = 1;
$blank1 = 0;
$blank2 = 0;
$dirty = 0;
$filename = shift(@ARGV);       # first line is input file
if (!open(INPUTFILE, $filename)) {
   print STDERR "Can't open $filename---exiting\n";
   print "Usage: scantext.pl <inputfile> <reqpaper1> [<reqpaper2>] ..etc\n";
   exit (1);
}
$printall = 0;
if ($#ARGV==-1) { 
  $printall = 1;
} 
while(<INPUTFILE>) {

    s/\f//;
    if (/^\s*$/) {
	$blank2 = $blank1;
	$blank1 = 1;
    }
    else {
	$blank2 = 0;
	$blank1 = 0;
    }

    $new = 0;
    $new = 1 if (/^\s*1993 ISCA #20--Electronic Referee\'s Report\s*$/i);
    $ignore = 1 if (/={10,}/);

    
#    if ($new && $dirty && !$ignore) {
#	print STDERR "Didn't find private comments at $. in $ARGV\n";
#
#    }

    if (/Paper Number:/i) {
	/:\s*(\d+)/;
	$pno = $1;
    }

    if ($new) {
	&OUTPUT if ($dirty);
	$ignore = 0;
	$nln = 0;
    }

    if (!$ignore && !$blank2) {
	$text[$nln++] = $_;
	$dirty = 1;
    }

}
&OUTPUT if ($dirty);
@sindex = reverse sort @index;
&DUMP;









