#! /bin/bsh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/bin/sccs/sccsdiff.sh 1.11 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1985,1993 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)92 1.11 4/9/07 06:41:45
#
#  COMPONENT_NAME: CMDSCCS      Source Code Control System (sccs)
#
#  FUNCTIONS: N/A
#
#  ORIGINS: 3, 10, 27
#
#  (C) COPYRIGHT International Business Machines Corp. 1985, 1993
#  All Rights Reserved
# Licensed Materials - Property of IBM
#
#  US Government Users Restricted Rights - Use, duplication or
#  disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#

DSPMSG=/usr/bin/dspmsg

umask 077

sid1= sid2= num= pipe= files=

for i in $@
do
	case $i in

	-*)
		case $i in

		-r*)
			if [ ! "$sid1" ]
			then
				sid1=$i
			elif [ ! "$sid2" ]
			then
				sid2=$i
			else
				$DSPMSG sccs.cat 2 'Usage:  %s -rSID1 -rSID2 \[-p\] \[-sNumber\] SCCSFile...\n\tCompares two versions of a Source Code Control System (SCCS) file.\n' $0 1>&2
				exit 1
			fi
			;;
		-s*)
			num=`/usr/bin/expr "$i" : '-s\(.*\)'`
			;;
		-p*)
			pipe=yes
			;;
		*)
			files=
			break
			;;
		esac
		;;
	*s.*)
		files="$files $i"
		;;
	*)
		$DSPMSG sccs.cat 1 '  %1$s: %2$s is not an SCCS file.\n\tSpecify an SCCS file.\n' $0 $i 1>&2
		;;
	esac
done

if [ -z "$files" ] || [ ! "$sid1" ] || [ ! "$sid2" ]
then
	$DSPMSG sccs.cat 2 'Usage:  %s -rSID1 -rSID2 \[-p\] \[-sNumber\] SCCSFile...\n\tCompares two versions of a Source Code Control System (SCCS) file.\n' $0 1>&2
	exit 1
fi

TMPDIR=${TMPDIR:-$HOME/tmp}
if [ ! -d $TMPDIR ] 
then  
     TMPDIR=/tmp
fi

TMPDIR=$TMPDIR/sccsdiff.$$

trap "/usr/bin/rm -rf $TMPDIR ; exit 1" 0 1 2 3 15

/usr/bin/mkdir $TMPDIR 2>/dev/null 1>/dev/null
if  [ $? -ne 0 ] 
then

        $DSPMSG sccs.cat 5 'Could not create temporary directory %s\n' $TMPDIR 1>&2
        exit 1
fi

for i in $files
do
	if /usr/bin/get -s -p -k $sid1 $i > $TMPDIR/geta$$
	then
		if /usr/bin/get -s -p -k $sid2 $i > $TMPDIR/getb$$
		then
			/usr/bin/bdiff $TMPDIR/geta$$ $TMPDIR/getb$$ $num > $TMPDIR/getc$$
		fi
	fi
	if [ ! -s $TMPDIR/getc$$ ]
	then
		if [ -f $TMPDIR/getc$$ ]
		then
			$DSPMSG sccs.cat 3 '%s: There are no differences between the specified\n\tversions of these files.\n' $i >$TMPDIR/getc$$
		else
			exit 1
		fi
	fi
	if [ "$pipe" ]
	then
		msg=`$DSPMSG sccs.cat 4 '%1$s: %2$s versus %3$s\n' $i $sid1 $sid2`
		/usr/bin/pr -h "$msg" $TMPDIR/getc$$
	else
		/usr/bin/cat $TMPDIR/getc$$
	fi
done

trap 0
/usr/bin/rm -rf $TMPDIR