#!/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 takes
# exactly two arguments.  The first is the source revision number and
# the second is the source file name.

if test ! "(" -d RCS ")" ; then
    echo "missing RCS directory" 1>&2
    exit 1
fi

if test -d RCS/${2} ; then
    mkdir ${2}
    if test ${?} != 0 ; then
        exit 1
    fi

    cd ${2}
    if test ${?} != 0 ; then
        exit 1
    fi

    ln -s ../RCS/${2} RCS
    if test ${?} != 0 ; then
        exit 1
    fi

    ver_get_sources_for_version ${1}
    if test ${?} != 0 ; then
        exit 1
    fi

    exit 0
fi

if test ! "(" "(" -r RCS/${2},v ")" -o "(" -r RCS/${2},link ")" ")" ; then
    echo "cannot find either RCS files RCS/"${2}",v or RCS/"${2}",link" 1>&2
    exit 1
fi

if test -d ${2} ; then
    echo "cannot make source file; "${2}" is a directory" 1>&2
    exit 1;
fi

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

co -q -r${1} ${extra_co_flag} -x,v/,link ${2}
exit ${?}
