#!/bin/ksh
#
# THIS SAMPLE PROGRAM IS BEING PROVIDED "AS IS" AND ONLY AS A COURTESY TO
# THE RECIPIENT.  SUN MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS 
# OR IMPLIED WITH RESPECT TO THIS SAMPLE PROGRAM INCLUDING QUALITY, PERF- 
# FORMANCE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON- 
# INFRINGEMENT.  IN NO EVENT WILL SUN BE LIABLE FOR ANY DIRECT, INDIRECT,  
# SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR  
# INABILITY TO USE THIS SAMPLE PROGRAM.
 
syntax() {
    echo 'Syntax is : sccsmk [-b] [-d] file ... '
    echo "    where -d => make a directory"
    echo "          -b => make a binary file"
    exit 10
}
 
SCCS_BIN=/usr/ccs/bin

 
# Parse the arguments for flags.
# the two flags "-b" and "-d" are mutually incompatible, which simplifies things.
dflag=""
bflag=""
if [ "$1" = "-d" ]
then
    shift
    dflag=1
fi
if [ "$1" = "-b" ]
then
    shift
    bflag="-b"
fi
# Check there aren't any more flags.
case $1 in
    -*)
        syntax
        ;;
esac
 
while [ "$1" != "" ]
do
    file_name=$1
    shift
    if [ "$dflag" = 1 ]
    then
 
        # We're making a directory
        if [ -r "$file_name" ]
        then
            print -u2 $0: ERROR $file_name already exists
            exit 5
        fi
        mkdir -p ${file_name}/SCCS
    else

        # We're making a file.
        if [ -r SCCS/?.${file_name} ]
        then
            print -u2 File ${file_name} already exists under SCCS
            exit 10
        fi
 
        if [ -r ${file_name} ]
        then
            ${SCCS_BIN}/admin -n $bflag -y"First verion" -i${file_name} SCCS/s.${file_name}            chmod ugu-w ${file_name}
        else
            ${SCCS_BIN}/admin -n $bflag -y"First verion" SCCS/s.${file_name}
        fi
        ${SCCS_BIN}/get -e SCCS/s.${file_name}
    fi
done
 
exit 0
