#!/usr/bin/perl -w
##########################################################################
# $Id: applydate,v 1.8 2002/10/14 16:21:57 kirk Exp $
##########################################################################

########################################################
# This was written and is maintained by:
#    Kirk Bauer <kirk@kaybee.org>
#
# Please send all comments, suggestions, bug reports,
#    etc, to kirk@kaybee.org.
########################################################

use POSIX qw(strftime);

# I plan to add a *lot* more date flexibility at a later time...

my $time = time;

if ( $ENV{'LOGWATCH_DATE_RANGE'} eq 'yesterday') {
   $SearchDate = strftime("%b %d", localtime($time-86400));
   $SearchYear = strftime("%Y", localtime($time-86400));
}
elsif ( $ENV{'LOGWATCH_DATE_RANGE'} eq 'today') {
   $SearchDate = strftime("%b %d", localtime($time));
   $SearchYear = strftime("%Y", localtime($time));
}
elsif ( $ENV{'LOGWATCH_DATE_RANGE'} eq 'all') {
   $SearchDate = "... ..";
   $SearchYear = "....";
}

# The date might be "Dec 09", but it needs to be "Dec  9"...
$SearchDate =~ s/ 0/  /;

if ( $ENV{'LOGWATCH_DEBUG'} > 5 ) {
   print STDERR "DEBUG: Inside ApplyDate (xferlog)...\n";
   print STDERR "DEBUG: Range: " . $ENV{'LOGWATCH_DATE_RANGE'} . "\n";
   print STDERR "DEBUG: Looking For: " . $SearchDate . "\n";
}

while (defined($ThisLine = <STDIN>)) {
    if ($ThisLine =~ m/^... $SearchDate ..:..:.. $SearchYear/o) {
      print $ThisLine;
    }
}

