#!/bin/bash # addagenda--Prompts the user to add a new event for the agenda script. setglobal agendafile = ""$HOME/.agenda"" proc isDayName { # return = 0 if all is well, 1 on error match $[echo $1 | tr '[[:upper:]]' '[[:lower:]]] { with sun*|mon*|tue*|wed*|thu*|fri*|sat* setglobal retval = '0' with * setglobal retval = '1' } return $retval } proc isMonthName { match $[echo $1 | tr '[[:upper:]]' '[[:lower:]]] { with jan*|feb*|mar*|apr*|may*|jun* return 0 with jul*|aug*|sep*|oct*|nov*|dec* return 0 with * return 1 } } proc normalize { # Return string with first char uppercase, next two lowercase. /bin/echo -n $1 | cut -c1 | tr '[[:lower:]]' '[[:upper:]]' echo $1 | cut -c2-3| tr '[[:upper:]]' '[[:lower:]]' } if test ! -w $HOME { echo "$0: cannot write in your home directory ($HOME)" > !2 exit 1 } echo "Agenda: The Unix Reminder Service" /bin/echo -n "Date of event (day mon, day month year, or dayname): " read word1 word2 word3 junk if isDayName $word1 { if test ! -z $word2 { echo "Bad dayname format: just specify the day name by itself." > !2 exit 1 } setglobal date = $[normalize $word1] } else { if test -z $word2 { echo "Bad dayname format: unknown day name specified" > !2 exit 1 } if test ! -z $[echo $word1|sed 's/[[:digit:]]//g] { echo "Bad date format: please specify day first, by day number" > !2 exit 1 } if test $word1 -lt 1 -o $word1 -gt 31 { echo "Bad date format: day number can only be in range 1-31" > !2 exit 1 } if ! isMonthName $word2 { echo "Bad date format: unknown month name specified." > !2 exit 1 } setglobal word2 = $[normalize $word2] if test -z $word3 { setglobal date = ""$word1$word2"" } else { if test ! -z $[echo $word3|sed 's/[[:digit:]]//g] { echo "Bad date format: third field should be year." > !2 exit 1 } elif test $word3 -lt 2000 -o $word3 -gt 2500 { echo "Bad date format: year value should be 2000-2500" > !2 exit 1 } setglobal date = ""$word1$word2$word3"" } } /bin/echo -n "One-line description: " read description # Ready to write to data file echo "$[echo $date|sed 's/ //g]|$description" >> $agendafile exit 0