#!/bin/sh
#
# This file should only be run automatically by make, not directly by
# the user.
#
# This script is part of the SUIF version control system.  It is used
# by the makefiles to check out RCS files.  It takes two arguments:
# the name of the RCS file and the name of the file to be checked out.

# make sure that the version number, if set, is reasonable
ver_assert_ver_exists ${VERSION}
if test ${?} != 0 ; then
	exit 1
fi

rcs_ver_opt=`ver_file_rcs_opt ${2} ${VERSION}`

# check if the target file already exists
if test -f ${2} ; then

	# check if it is writable
	if (test `find ${2} "(" -perm 444 -print ")" -o \
			    "(" -perm 555 -print ")"`"" != ${2}"") ; then

		# make sure that the version was not specified
		if test ${VERSION}"" = "" ; then
			exit 0
		fi

		echo "version was specified but writable "${2}" exists"
		exit 1
	fi
fi

if test -f RCS/${2},nosub ; then
    extra_co_flag=-ko
else
    extra_co_flag=
fi

if rcsdiff -q ${rcs_ver_opt} ${extra_co_flag} ${2} > /dev/null 2>&1; then
    exit 0
fi

${CO} ${COFLAGS} ${extra_co_flag} -x,v/,link ${rcs_ver_opt} ${1} ${2}
exit ${?}
