#! /bin/csh/ -f
################################################################################
# Author: Kun Luo
#This command script is used to help the user to maintain the file system, first
#the user need to have the access right to RCS files, then can he (or she) 
#will be able to use this command script properly. The name of this command 
#script is called :
#
################################################################################
if( $#argv != 1) then
     echo 'Error: You must specify which file you want to check out '
     echo '       and you only need to specify the filename here. '
     exit(1)
endif

#########################################################################
# You need to set up file directory and file name for output list here
#########################################################################
set history_path = ($CVIPHOME)
set CVIP = $CVIPHOME
set history_file = ($history_path/CVIPtools_history)
set trackfile = ($CVIPHOME/docs/.rcstrack)
umask 007

#protect the old path
set oldpath=($path)

#set up new path so that user can have the access to the rcs functions calls
set path=(/opt/apps3/gnu/bin $path)

#first check if revision outside is different from revision inside
rcsdiff $argv[1] >& /dev/null
if( $status == 1) then
   echo "The file outside is different from revision in RCS..."
   echo -n "Do you still want to continue?(y/n)"
   switch("$<")
	case "Y":
	case "y":
	    cp $argv[1]  $argv[1].bak
	    breaksw
	default:
	    exit(1)
   endsw
endif

co -l $argv[1] |& tee /tmp/history_file.$$ 
set status1 = ($status)

if( $status1 == 0 ) then
   rm -f $history_file.backup
   cp $history_file $history_file.backup
   chmod 660 $history_file.backup
   echo "***($CVIP:t)$argv[1] checked out by $user at `date '+ %Y/%m/%d %T'` from `hostname` ">>$history_file
   echo "***($CVIP:t)$argv[1] checked out by $user at `date '+ %Y/%m/%d %T'` from `hostname` ">>$trackfile
   grep revision /tmp/history_file.$$ >> $history_file
endif
set path = ($oldpath)
rm -f  /tmp/history_file.$$
