#!/bin/csh -f
set file = ~/anand/personal/birthdays
set months = (jan feb mar apr may jun jul aug sep oct nov dec)
set year = 2000
set cal = ~/Calendar/xy$year/xc
set monthnum = 0
if ($#argv == 0) then
	grep ^`date +"%d.%m."` $file
	exit
else if ("$argv[1]" == "-help") then
	echo "Usage: `basename $0`:: (birthdays falling today)"
	echo "       `basename $0`:: month (month = 1...12 or Jan...Dec)"
	echo "       `basename $0`:: -month month (month = 1...12 or Jan...Dec)"
	echo "       `basename $0`:: -name name (name = string pattern in name)"
	echo "       `basename $0`:: -help"
else if ("$argv[1]" == "-name") then
	grep -i $argv[2] $file
else if ("$argv[1]" == "-update") then
	set monthname = `echo $months | fmt -1 | grep $argv[2]`
	if ("$monthname" == "") then
		set monthname = $months[$argv[2]]
	endif
	set monthnum = `echo $months | fmt -1 | grep -n $monthname | cut -d: -f1`
	set monthname = "`echo $monthname | cut -c1 | tr \[a-z\] \{A-Z\]``echo $monthname | cut -c2-`"
	if ($monthnum < 10) set monthnum = "0$monthnum"
	foreach event ("`grep \.$monthnum\. $file`")
		set day = `echo $event | cut -d. -f1`
		@ d = $day
		set day = $d
		echo "Adding: "`echo $event`
		echo $event | sed "s/^..........[ 	]*//" >> $cal$day$monthname$year
	end
else
	if ("$argv[1]" == "-month") shift
	set month = `echo $argv[1] | tr "[A-Z]" "[a-z]"`
	set monthnum = `echo $months | fmt -1 | grep -n $month | cut -d: -f1`
	if ("$monthnum" == "") set monthnum = $argv[1]
	if ($monthnum < 10) set monthnum = 0$monthnum
	grep "\.$monthnum\." $file
endif
