:
#! /bin/sh
#	events [N]|-[vhe]|[-em]|[-rm]
#	List today's events or events for the next N days.
#	With the -v, -h, -e or -em flags, vi, hed, ed or emacs
#	are invoked on the database.
#	The -rm flag removes the lock file.
#	Make sure that $e is writeable by all.
#	$B is the location of the `dates' program.
#	Author : Oscar Nierstrasz @ ..!utcsrgv!oscar
e=/usr/pub/events
B=/usr/local/bin
l=/tmp/lock_events
u="Usage: events [#days] | [-vi] | [-ed] | [-hed] | [-emacs]"
case $# in
0 )	arg=0 ;;
1 )	arg=$1 ;;
* )	echo "$u" 1>&2
	exit ;;
esac
case $arg in
-v )	ed=vi ;;
-vi )	ed=vi ;;
-h )	ed=hed ;;
-hed )	ed=hed ;;
-e )	ed=ed ;;
-ed )	ed=ed ;;
-em )	ed=emacs ;;
-emacs ) ed=emacs ;;
-rm )	rm -f $l
	exit ;;
-* )	echo "events : unknown flag" 1>&2
	exit ;;
[0-9]* ) $B/dates -t $arg $e
	exit ;;
* )	echo "$u" 1>&2
	exit ;;
esac

umask 0777
if (echo > $l) 2> /dev/null
then
	umask 022
	$ed $e
	rm -f $l
else
	echo "Sorry, someone is already editing the events file!" 1>&2
fi
