#!/usr/local/bin/perl5.000

#  This script works with perl4 too, but perl5.000 is several times quicker


while (<>) {

  if (/^ *.+\(# *[0-9]+\) .+ #[0-9]+ @ .+,.+/ ||
   /^[A-Za-z].+ \(#[0-9]+\) .+ [0-9]+% efficient .* @ .+,.+/ ||
   /^Kawhomp! Mine detected by .+ \(#[0-9]+\) in .+,.+!/ ||
   /^\[fert:[0-9]+\]/ ||
   /^\[oil:[0-9]+\]/ || 
   /^Shells hit/ || /sunk!$/) {
    print $lastcommand if ($lastcommand ne $lastprint);
    $lastprint = $lastcommand;
    print;
    next;
  }

  elsif (/^> BULLETIN/) {
    print $lastcommand if ($lastcommand ne $lastprint);
    $lastprint = $lastcommand;
    do {
      print;
      $_ = <>;
    } until (/^([a-zA-Z0-9]+ \[)|(\[[0-9]+:[0-9]+\] Command :)|(> Product)|(> Telegram)/);
  }

  elsif (/^SPY report/) {
    print $lastcommand if ($lastcommand ne $lastprint);
    $lastprint = $lastcommand;
    do {
      print;
      $_ = <>;
    } until (/^$/ || /^([a-zA-Z0-9]+ \[)|(\[[0-9]+:[0-9]+\] Command :)/);
  }

  elsif (/^SPY Plane report/) {
    print $lastcommand if ($lastcommand ne $lastprint);
    $lastprint = $lastcommand;
    do {
      print;
      $_ = <>;
    } until (/^([a-zA-Z0-9]+ \[)|(\[[0-9]+:[0-9]+\] Command :)/);
  }

  if (/^([a-zA-Z0-9]+ \[)|(\[[0-9]+:[0-9]+\] Command :)/) {
    $lastcommand=$_;
  }
}
