#!/usr/bin/perl -w

%skipped_scores = ();
open (IN, "<freqs");
while (<IN>) {
  next if /^\s+OVERALL\s/;
  @s = split;
  if ($s[0] < 0) { $skipped_scores{$s[3]} = 1; }
}
close IN;

my $gascores = '';
while (<>) {
  /^score\s+(\S+)\s/ or next;
  next if (defined $skipped_scores{$1});
  next if ($1 eq '(null)');	# er, oops ;)

  $gascores .= $_;
}

open (IN, "<../spamassassin.cf");
my $out = '';
my $pre = '';
while (<IN>) {
  if (/^\s*score\s+(\S+)\s/) {
    $gascores =~ s/^score\s+$1\s.*?\n//gm;
  }
  $pre .= $_;
  /^# Start of GA-evolved scores/ and last;
}

while (<IN>) {
  /^# End of GA-evolved scores/ and last;
}
$out .= $_;

while (<IN>) {
  if (/^\s*score\s+(\S+)\s/) {
    $gascores =~ s/^score\s+$1\s.*?\n//gm;
  }
  $out .= $_;
}
close IN;

print $pre, "\n", $gascores, "\n", $out;
