#! /bin/sh
NOW=`date`
HR=`expr "$NOW" : "^... ... .. \([0-2][0-9]\):[0-5][0-9]:.."`
MN=`expr "$NOW" : "^... ... .. [0-2][0-9]:\([0-5][0-9]\):.."`
echo "It's now $HR:$MN"
FILE=$HR$MN.snd
if [ ! -s $FILE ]; then
	ERR=1
	while [ $ERR -lt 10 ]; do
		# Try ERR minutes in the future...
		M=`expr $MN + $ERR`
		H=$HR
		if [ $M -ge 60 ]; then
			M=`expr $MN + $ERR - 60`
			H=`expr $HR + 1`
			if [ $H -ge 24 ]; then
				H=`expr $HR - 23`
			fi
			if [ $H -lt 10 ]; then H=0$H; fi
		fi
		if [ $M -lt 10 ]; then M=0$M; fi
		FILE=$H$M.snd
		if [ -s $FILE ]; then break; fi
		# Try ERR minutes in the past...
		M=`expr $MN - $ERR`
		H=$HR
		if [ $M -lt 0 ]; then
			M=`expr $MN + 60`
			M=`expr $M - $ERR`
			H=`expr $HR - 1`
			if [ $H -lt 0 ]; then
				H=`expr $HR + 23`
			fi
			if [ $H -lt 10 ]; then H=0$H; fi
		fi
		if [ $M -lt 10 ]; then M=0$M; fi
		FILE=$H$M.snd
		if [ -s $FILE ]; then break; fi
		ERR=`expr $ERR + 1`
	done
fi
d=Sounds
sndplay $d/dddd0.snd $d/pause.snd $d/$FILE $d/pause.snd $d/ddddd0.snd
