 # *-*-perl-*-*
    eval 'exec perl -S $0 "$@"'
    if $running_under_some_shell;
# --------------------------------------------------------------------
# List the pec records which has queries greater than specified value.
#					erhyuant@catarina.usc.edu
# --------------------------------------------------------------------

$QUERY_COUNT = 10;		#default queries count

require 'getopts.pl';
$USAGE = "USAGE: $0 options
        (ex $0 -f /usr/checker/checker-pec.result -c 10)
        -h      this message
        -f      input file  (default: standard input)
        -c      queries count (default: 10)
";

&Getopts ('hf:c:');
if ($opt_h) { print $USAGE; exit; }
if ($opt_c) { $QUERY_COUNT = scalar($opt_c); }

# setup file handler (RPT_IN) for input
#if ($opt_f) {
#  open (h_in,"$opt_f") || die "Error: Open $opt_f for reading!";
#  $RPT_IN = h_in;
#}
#else { $RPT_IN = STDIN; }
open (h_in,"/usr/checker/checker-pec.result") || die "Error: Open $opt_f for reading!";
$RPT_IN = h_in;

$cgi_para = $ENV{'QUERY_STRING'};
$cgi_para =~ /^QueryCount=([\d]*)/;
if ($1 ne "") {
  $QUERY_COUNT = scalar ($1);
}

#print outcurrent time
$the_time = `date`;
print "Current time: $the_time\n";

# locate the header then print 5 lines after that location
while (<$RPT_IN>) {
  if (/PEC Investigated Resolver/) {
    print $_;
    for ($i = 0; $i < 4; ++$i) {
      $_ = <$RPT_IN>;
      print $_;
    }
    last;
  }
}

# print out qualified records
while (<$RPT_IN>) {
  $line = $_;
  if (/^([\d]+\.[\d]+\.[\d]+\.[\d]+)[\s]+([\S]+)[\s]+([\S]+)[\s]+([\d]+)[\s]+([\d]+)/) 
  {
    if ($5 >= $QUERY_COUNT) {
      print $line;
      $line = <$RPT_IN>;
      print $line;
      print "\n";
    }
  }
}
close ($RPT_IN);
exit;
