#! /bin/sh
#
# 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.

CWD=`pwd`

#
# After doing diffs on any checked out file, make sure it has the proper
# SCCS keywords so sccs-what will be happy
#
SCCS_WHAT_KEYWORDS="@(#)workspace_checkin	1.3 96/10/10 SMI"

echo "Looking for checked out files..."
ECHO_ONLY=
FILES=`find . -name p.\* -print`

if [ "$1" = "-l" ]; then
        echo "These files are checked out:"
        ECHO_ONLY=1  
fi
 
WD=`pwd` 

for i in ${FILES} ; do
        FILENAME=`basename $i | sed -e "s#p.##" `
        SCCS_DIRNAME=`dirname $i`
        DIRNAME=`dirname ${SCCS_DIRNAME}`
        FULLNAME=${DIRNAME}/${FILENAME}

        cd $CWD/${DIRNAME}

        if [ ${ECHO_ONLY} ]; then
                echo ${FULLNAME}
        else
                sccs diffs $FILENAME
                if [ `grep -c "${SCCS_WHAT_KEYWORDS}" ${FILENAME}` -eq 0 ]; then
                  echo "(hey, this file has no what keywords)"
                fi   
                echo "Checkin ${FULLNAME}? [y|n|u]: "
                read checkin
                if [ "$checkin" = "" -o "$checkin" = "y" ]; then
                        sccs delget $FILENAME
                elif [ $checkin = "u" ]; then
                        sccs unedit $FILENAME
                fi
        fi
done
 
echo "Scanning for files not under SCCS control... (^C to bail out)"

#
# For each file ending with the given list of SUFFIXES, make sure
# it is under SCCS control
#
 
#
# This find command will find all files
#
cd ${WD}
 
echo "Filtering Codemgr_ws_data, .a, .mo,  *~, .make.state, *.o  and ccr_export files"
ALL_FILES=`find . -type f -print  | grep -v Codemgr_wsdata/ | grep -v SCCS | grep -v .a$ |
grep -v .mo$ | grep -v ~$ | grep -v ccr_export | grep -v .make.state | grep -v .o$`
 
for f in ${ALL_FILES}; do
        DIRNAME=`dirname $f`
        BASENAME=`basename $f`
        if [ "`basename $DIRNAME`" = SCCS ]; then
                # Skip files in SCCS directory
                continue;
        fi
        if [ ! -f ${DIRNAME}/SCCS/s.$BASENAME ]; then
            # Not under sccs, ask if they want it under sccs
            echo "Do you want $f under SCCS control? [y] "
            read sccs_create
            if [ "$sccs_create" = "" -o "$sccs_create" = "y" ]; then
                (cd $DIRNAME; sccs create $BASENAME; rm ,$BASENAME)
            fi
            continue
        fi   
done
                 
