#!/usr/bin/perl
#
# Stewart Stremler
#
# Progression:
#  description:
#  date: <date to key off of> ... author: <author to key from>
#  <data>
#  ----------------------------
#  (repeat)
#  
#=============================================================================

$srch = 0;

if ( $#ARGV != 1 ) {
   die "Usage: $0 date-string user-string\n";
}

$date_str = "invalid!";
$user_str = "invalid!";

if ( $ARGV[0] =~ /[0-9]+\/[0-9]+/ ) { $date_str = $ARGV[0]; }
if ( $ARGV[1] =~ /[a-z]+/ )         { $user_str = $ARGV[1]; }

if ( $date_str eq "invalid!" || $user_str eq "invalid!" ) {
   print "Usage: $0 date-string user-string\n";
   print "\tdate-string is of the form YYYY/MM ($date_str)\n";
   print "\tuser-string is an alpha-character only username ($user_str)\n";
   die "Correct your input and try again.";
}

$got_entry = 0;
$skip = 1;
while (<STDIN>) {
   if ( $skip ) { # skip the header stuff
      if ( /description:/ ) {
         $skip = 0;
      }
   } else { # found the logs
      if ( /^date: $date_str.* author: $user_str/ ) {
          $got_entry = 1;
      }

      if ( /^===========================*/ ) {
          $got_entry = 0;
          $skip = 1;
      }

      if ( $got_entry ) {
         print $_;
      }

      if ( /^----------------------------/ ) {
          $got_entry = 0;
      }
   }
}

print "done.\n";

#EOF#
