#!/sw/bin/perl -w
#########################
# By: Ventz Petko       #
# Date: 8-03-05         #
# Parse Pork Buddy Logs #
#########################
use strict;
use Getopt::Std;

sub usage() {
    print "\t\tUsage: /porklog.pl -t amount_of_date_info
                -m month -d date -b buddy_sn.log\n";
    print "\t\tEx: ./porklog.pl -t md -m Jan -d 1 -b ventz.log\n"; exit();
}

our($opt_t, $opt_m, $opt_d, $opt_b);
getopt("tmdb");

if (!(defined $opt_t)) { usage(); exit; }
if ($opt_t eq "md" && (!(defined $opt_m) && !(defined $opt_d))) {
    usage(); exit; 
}

my ($flag); $flag = 0;
open(FP, $opt_b);
while (<FP>) {
    $_ =~ s/^---------- Log started on (.?.?.?) (.?.?.?) (.?.?) (.*):(.*):(.*)/---------- Log started on $1 $2 $3 ---------- /g; 
    if ($_ =~ /$opt_m/) { if ($_ =~ /$opt_d/) { $flag = 1; } }
    if($_ =~ s/^---------- Log ended on (.?.?.?) (.?.?.?) (.?.?) (.*):(.*):(.*)/---------- Log ended on $1 $2 $3 ----------/g) { 
        print $_; $flag = 0;
    }
    
    if ($flag eq 1) { print $_; }


 
}
close(FP);
