#! /bin/sh
#
# Copyright 14 Dec 1995 Sun Microsystems, Inc. All Rights Reserved
#
# @(#)rsccs	1.1	95/12/14 SMI
#
# 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.

looks_like_source()
{
  if [ -x $1 ]; then
    return 1
  else
    case $1 in
      *.o | *.so | *.a | core | a.out )	# binaries
	return 1 ;;

      *~ | *% | *.backup | *.recover | *.BAK )	# editor backups
	return 1 ;;

      *.clg )				# compilation logs
	return 1 ;;

      *.sdu | *.csdu | *.lsdu )		# ObjectStore schema update files
	return 1 ;;

      *.new | *._h )			# new derived sources
	return 1 ;;

      *.E | *.F )			# cpp/cfront output
	return 1 ;;

      ,* )				# stuff newly checked in to SCCS
	return 1 ;;

      *.elc )				# compiled elisp code
	return 1 ;;

      *.ok )				# result of tests
	return 1 ;;

      *.tmp | *.log )			# random temporary file
	return 1 ;;

      *.out )				# typically yacc logs
	return 1 ;;

      *.ps )				# postscript (no-one writes it directly
	return 1 ;;			# any more, do they?)

      *.mo )				# mcode output files?
	return 1 ;;

      uid0:* )				# files imported into a starlight environment
	return 1 ;;

      * )
	if head -7 $1 | fgrep -si "generated by" ; then
	  return 1
	fi ;;
    esac
  fi
  return 0
}

check_SCCS_keywords()
{
  for i in * ; do
    diri=${dir:+$dir/}$i
    if [ -d $i ]; then
      case $i in
	SCCS )
	  for f in SCCS/s.* ; do
	    if sccs get -p  $f 2>&1 1>/dev/null | fgrep -s "No id keywords" ; then
	      file=${dir:+$dir/}`echo $f | sed -e 's|SCCS/s.||'`
	      checked_in_by=`sccs prt -y $f | awk '/^SCCS/{print $6;}'`
	      echo "($checked_in_by)" $file does not contain SCCS keywords
            fi
	  done
	  ;;
	Codemgr_wsdata | PT | Templates.DB | ptrepository )
	  ;;
	* )
	  ( dir=$diri; cd $i ; check_SCCS_keywords $* )
      esac
    fi
  done

}


clean()
{
  for i in * ; do
    diri=${dir:+$dir/}$i
    if [ -d $i ]; then
      case $i in
	SCCS )
	  sccs clean # clean current directory
	  ;;
	Codemgr_wsdata | PT | Templates.DB |ptrepository )
	  ;;
	* )
	  ( dir=$diri; cd $i ; clean )
      esac
    fi
  done

}


get()
{
  for i in * ; do
    diri=${dir:+$dir/}$i
    if [ -d $i ]; then
      case $i in
	SCCS )
	  sccs get SCCS # get files in current directory
	  ;;
	Codemgr_wsdata | PT | Templates.DB | ptrepository )
	  ;;
	* )
	  ( dir=$diri; cd $i ; get )
      esac
    fi
  done

}


delget()
{
  for i in * ; do
    diri=${dir:+$dir/}$i
    if [ -d $i ]; then
      case $i in
	SCCS )
	  for f in `sccs tell -u` ; do
	    echo checking in ${dir:+$dir/}$f
	    sccs delget "$*" $f
	  done
	  ;;
	Codemgr_wsdata | PT | Templates.DB | ptrepository )
	  ;;
	* )
	  ( dir=$diri; cd $i ; delget $* )
      esac
    fi
  done

}


diffs()
{
  for i in * ; do
    diri=${dir:+$dir/}$i
    if [ -d $i ]; then
      case $i in
	SCCS )
	  for f in `sccs tell -u` ; do
	    echo
	    echo
	    echo checking ${dir:+$dir/}$f
	    sccs diffs $* $f
	  done
	  ;;
	Codemgr_wsdata | PT | Templates.DB | ptrepository )
	  ;;
	* )
	  ( dir=$diri; cd $i ; diffs $* )
      esac
    fi
  done

}


tell()
{
  for i in * ; do
    diri=${dir:+$dir/}$i
    if [ -d $i ]; then
      case $i in
	Codemgr_wsdata | PT | SCCS | Templates.DB | ptrepository )
	  ;;
	* )
	  ( dir=$diri; cd $i ; tell )
      esac
    else
      if [ -r SCCS/p.$i ]; then
	echo $diri is checked out
      elif [ ! -r SCCS/s.$i ]; then
	if looks_like_source $i ; then
	  echo $diri appears to be source but is not under SCCS control
	fi
      fi
    fi
  done

}



usage()
{
  echo "$prog [-w] clean"
  echo "		recursively look for directories containing SCCS"
  echo "		directories, and run 'sccs clean' in them"
  echo "$prog [-w] get"
  echo "		recursively look for directories containing SCCS"
  echo "		directories, and run 'sccs get SCCS' in them"
  echo "$prog [-w] delget <args>"
  echo "		recursively look for directories containing SCCS"
  echo "		directories, and run 'sccs delget <args> <file>'"
  echo "		there for each <file> that is checked out by the user"
  echo "		e.g. $prog -w delget \"-yupdate message\""
  echo "$prog [-w] tell"
  echo "		recursively scan for files that are checked out or"
  echo "		which appear to be source and are not checked in"
  echo "$prog [-w] check_SCCS_keywords"
  echo "		recursively scan for SCCS files and verify that they"
  echo "		contain SCCS keywords.  Those that don't are reported"
  echo "		together with the userid of the person who checked in"
  echo "		the last version."
  echo
  echo "In any subdirectory of a TeamWare workspace, -w can be used to cause"
  echo "the script to run on the whole workspace, and not just the current"
  echo "directory and its subdirectories."
}


prog=`basename $0`

if test $# -eq 0 ; then
    usage
    exit 1
fi


# first, pick up special options before SCCS subcommand

while test $# -gt 0 ; do
    case $1 in
        -w )    workspace=`/home/bristor/tw/bin/wsroot` ;
		if [ -z "$workspace" ]; then
		  echo -w specified, but not in a workspace
		  exit 1
		fi
		shift ;;
	-* )	echo bad option: $1 ; usage ; exit 1 ;;
        * )	break ;;
    esac
done

cd ${workspace:-.}

# now execute subcommand, passing it any remaining options

case $1 in
    check_SCCS_keywords | clean | diffs | get | delget | tell )
	$* ;;

    * )
	echo unrecognized SCCS subcommand
	;;
esac


