#!/bin/sh
#
# Copyright (c) 1993 InterSoft Co.  All Rights Reserved
# THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF InterSoft Co.
# The copyright notice above does not evidence any
# actual or intended publication of such source code.
#
# MODULE & VERSION : $Id: checkout.sh,v 1.13 1996/08/27 16:35:17 hernan Exp $
# DATE             : $Date: 1996/08/27 16:35:17 $
# TIME             : 
#
#	checkout [-h|-?|-t|-p|-e|-u|-a|-v version] files
#	where:
#
#	h ?		Help
#	t		Test for availability only
#	p		Print to stdout
#	e		Retrieve editable version
#	u		Undo checkout
#	a		Annotate specified version of file
#	v		Retrieve specified version
#
#
# Version for the SCCS Source Code Control System
#
SCCSDIR=SCCS
DELTADIR=""
DELTA=""
KEEP=""
EDIT=""
VERSION=""
STDOUT=""
UNDO=""
TEST=""
ANNOTATE=""
USAGE="Usage: `basename $0` [-?|-h|-t|-p|-e|-u|-a|-v version] files"
SAVEPWD=`pwd`
RET=0

while getopts h?etpuav: OPT
do
	case $OPT in
	e)
		EDIT="-e"
		;;
	u)
		UNDO="1"
		;;
	v)
		VERSION=-r$OPTARG
		;;
	p)
		STDOUT="-p"
		;;
	t)
		TEST="1"
		;;
	a)
		ANNOTATE="1"
		;;
	h|\?)
		echo $USAGE 1>&2
		exit 1;
		;;
	esac
done

shift `expr $OPTIND - 1`

if [ $# -eq 0 ]
then
	echo $USAGE 1>&2
	exit 1
fi

if [ -n "$ANNOTATE" ]
then
	echo 1>&2 "Sorry, annotate option not supported under SCCS."
	exit 3
fi

for i
do
	DIR=`dirname $i`
	FILE=`basename $i`
	cd $SAVEPWD
	cd $DIR
	if [ $? -ne 0 ]
	then
		RET=1
		continue
	fi
	if [ -f "$SCCSDIR/s.$FILE" ]
	then
		DELTADIR=$SCCSDIR
	elif [ -f "s.$FILE" ]
	then
		DELTADIR=.
	else
		if [ -z "$TEST" ]
		then
			echo "Can not find file s.$FILE" 1>&2
		fi
		RET=2
		continue
	fi

	if [ -z "$TEST" ]
	then
		if [ -n "$UNDO" ]
		then
			unget $DELTADIR/s.$FILE
			if [ $? -ne 0 ]
			then
				RET=5
				continue
			fi
		fi
		if [ -n "$STDOUT" ]
		then
			get $EDIT $VERSION $STDOUT $DELTADIR/s.$FILE 2>/dev/null
		else
			get $EDIT $VERSION $STDOUT $DELTADIR/s.$FILE
		fi
		if [ $? -ne 0 ]
		then
			RET=3
			continue
		fi

		if [ "$EDIT" = "-e" ]
		then
			chmod 664 $FILE
			if [ $? -ne 0 ]
			then
				RET=4
				continue
			fi
		fi
	fi
done
exit $RET
