makepath()
{
        if [[ ${#1} -eq 0 || -d $1 ]]
        then
                return 0
        fi
        if [[ "${1%/j}" = "$1" ]]
        then
                mkdir $1
                return $?
        fi
        makepath ${1%/j} || return 1
        mkdir $1
        return $?
}
sccsname()
{
        _dir=$(dirname $1)
        _base=$(basename $1)
        echo $_dir/s.$_base
}
checkargs()
{
        if [[ $# != 2 ]]
        then
                print -u2 "usage: checkin <source> <dest>"
                exit 1
        fi
        if [[ ! -d $1 ]]
        then
                print -u2 "$1: Not a directory"
                exit 1
        fi
        # Check second argument
        if [[ -a $2 && ! -d $2 ]]
        then
                print -u2 "$2: Not a directory"
                exit 1
        fi
        # Check that neither argument is a prefix of the other
        if [[ $1 = $2j || $2 = $1j ]]
        then
                print -u2 "Cannot create one hierarchy below or above the other"
                exit 1
        fi
        return 0
}
ERRS=./err_file
REPORT=./report
checkargs "$@"
# Open error and report files
exec 3>$ERRS
exec 4>$REPORT
source=$1
dest=$2
find $source -print |
while read pathname
do
        target=$dest${pathname#$source}
        if [[ -d $pathname ]]
        then
                makepath $target || print -u3 "Cannot create $target"
        elif [[ -f $pathname ]]
        then
                target=$(sccsname $target)
                admin -i$pathname $target >&4 2>&3 || \
                        print -u3 "Cannot create $target"
        else
                print -u4 "$pathname not directory or regular file: skipped"
        fi
done
exec 3<&-
exec 4<&-
exit 0
