#!/usr/bin/perl

#
# Read input parameters
#
(open INPUT, "$ARGV[0]") || die "ERROR: cannot open file $ARGV[0]";
@lines = <INPUT>;
close(INPUT);
#
# Find command-line parameter
#
foreach $line (@lines) {
  chomp($line);
  @words=split(/\s+/,$line);
  if ($words[0] eq "_factor_1_value") {
     $tmp=$words[1];
     print "TMP $tmp\n";
     `python ../src/exact/exact -f $tmp | grep -v "WARNING" > $ARGV[2] 2>&1`;
     @items=split(/\./,$tmp);
     foreach $val (@items) {
       print "ITEM $val\n";
       }
     $command=$items[0];
     print "CMD $command\n";
     last;
     }
  }
#
# Generate measurements
#
print "DIFFING " . $ARGV[2] . " and ${command}.qa\n";
if (! -e $ARGV[2]) {
   $diffs = "Missing file " . $ARGV[2]
} elsif (! -e "${command}.qa") {
   $diffs = "Missing file ${command}.qa"
} else {
  $diffs = `diff $ARGV[2] ${command}.qa 2>&1`;
}
open OUTPUT, ">$ARGV[1]";
print OUTPUT "exit_status numeric/integer 0\n";
if ($diffs eq "") {
   print OUTPUT "diffs numeric/boolean 0\n";
}
else {
   print OUTPUT "diffs numeric/boolean 1\n";
}
print OUTPUT "diff_output text/string \"\"\"\n";
print OUTPUT "$diffs\n";
print OUTPUT "\"\"\"\n";
close(OUTPUT);
