#!/usr/bin/perl -w
use strict;
# This script parses a text file with lines of format:
#   <YEAR> <MONTH> <DAY> <DAYOFWEEK> <MESSAGE>
# and outputs <MESSAGE> for each line where all four other fields match
# today.  The first four fields can be *, a number, or (for month and
# dayofweek) a 3-letter lowercase label.  Ranges are not (yet) supported.
# Lines starting with # are treated as comments.
#
# For instance, you might do the following:
#   * * 1 mon First business day of the month
#   * * 1 tue First business day of the month
#   * * 1 wed First business day of the month
#   * * 1 thu First business day of the month
#   * * 1 fri First business day of the month
#   * * 2 mon First business day of the month
#   * * 3 mon First business day of the month

my @now=localtime(time);
my %curyear=map {($_,1)} ("*",1900+$now[5]);
my %curmonth=map {($_,1)} ("*",1+$now[4]);
   $curmonth{(qw(jan feb mar apr may jun jul aug sep oct nov dec))[$now[4]]}=1;
my %curday=map {($_,1)} ("*",$now[3]);
my %curdow=map {($_,1)} ("*",$now[6]);
   $curdow{7}=1 if(0==$now[6]);
   $curdow{(qw(sun mon tue wed thu fri sat))[$now[6]]}=1;

while(defined(my $line=<>)) {
	chomp $line;
	$line =~ s/^\s+//s;
	next if(0==length $line);
	next if("#" eq substr($line,0,1));
	my ($year,$month,$day,$dow,$message)=split /\s+/s,$line,5;
	next unless($curyear{lc $year});
	next unless($curmonth{lc $month});
	next unless($curday{lc $day});
	next unless($curdow{lc $dow});
	print "$message\n";
}
0;
