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

# 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;
    while($npaps--) {
	($pno,$offset) = split(/:%:/,$sindex[$npaps],2);
	($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 = 0;
$blank1 = 0;
$blank2 = 0;
$dirty = 0;

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

    $new = 0;
    $new = 1 if (/^Paper Number:.*/i);    
    $ignore = 1 if (/={10,}/);

    
    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;









