#!/usr/bin/perl

$file = (-r "$ENV{'HOME'}/calendar")	 ? "$ENV{'HOME'}/calendar"     :
	(-r "$ENV{'HOME'}/etc/calendar") ? "$ENV{'HOME'}/etc/calendar" :
					   './calendar';

# calend - simple replacement for a subset of the calendar reminder service
# Steve Kinzler, steve@kinzler.com, Sep 08
# https://kinzler.com/me/home.html#unix

# I don't find calendar(1) in modern RedHat Linuxes, nor a good source
# for it, nor any simple replacement.  FreeBSD's calendar(1) doesn't just
# compile, and remind(1) is quite overkill.

# Format like:
#Jan  1	it is the first of January
#*/1	it is the first of the month

$usage = "usage: $0\n";
die $usage if @ARGV;

%mon  = (0, 'Jan', 1, 'Feb',  2, 'Mar',  3, 'Apr',
	 4, 'May', 5, 'Jun',  6, 'Jul',  7, 'Aug',
	 8, 'Sep', 9, 'Oct', 10, 'Nov', 11, 'Dec');
($day, $mon) = (localtime(time))[3, 4];
$Mon  = $mon{$mon};
$patt = join('|', values %mon);

open(FILE, $file) || die "$0: cannot open $file ($!)\n";
foreach (<FILE>) {
	next unless /^(\*|$patt)[\s\/]+(\d+)\s/;
	print if ($1 eq '*' || $1 eq $Mon) && ($2 == $day);
}
close FILE;
