#!/bin/ksh
#	
#	CALEDIT
#	Last Modification:  February 2000
##################################################################
#
#	Check that the proper calling sequence was supplied
#
case $1 in
   "vi"   ) echo " "
	    echo "Valid option supplied..."
	    echo " ";;
   "text" ) echo " "
	    echo "Valid option supplied..." 
	    echo " " ;;
   "emacs" ) echo " "
	    echo "Valid option supplied..."
	    echo " " ;;
   "emacsnw" ) echo " "
	    echo "Valid option supplied..."
	    echo " " ;;
    *     ) echo " "
	    echo "WARNING:"
	    echo "           Calling sequence is:  caledit vi (vi editor)"
	    echo "                           OR :  caledit text (text editor)"
	    echo "                           OR :  caledit emacs (emacs editor)"
            echo "  " 
	    exit ;;
esac
#
#       CHECK IF a calendar.lock file exists, if it does, throw out 
#	the user immediately.  OTHERWISE, create a calendar.lock file
#	to prevent other people from editing.
#
   if [[ -a calendar.lock ]]; then
       echo " "
       echo "WARNING:   File is being edited by another user !!!! "
       echo "           CALENDAR.LOCK file exists... "
       echo "           Try again later...!! "
       echo " "
       exit
   else
       touch calendar.lock
       cp calendar.html ~/old_calendars/`date "+%y%m%d_%H%M"`
       case $1 in
          "vi"   ) (vi calendar.html)  ;;
          "text" ) xedit calendar.html ;;
          "emacs" ) emacs calendar.html  ;;
          "emacsnw" ) emacs -nw calendar.html  ;;
       esac
   fi
#
#	REMOVE CALENDAR.LOCK FILE
#
   echo "Removing calendar.lock file..."
   rm calendar.lock

