#!/usr/bin/bsh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/bin/diff3/diff3.sh 1.17 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1985,1992 
# 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 
# @(#)87      1.17  src/bos/usr/bin/diff3/diff3.sh, cmdfiles, bos720 4/23/08 08:00:48
#
# COMPONENT_NAME: (CMDFILES) commands that manipulate files
#
# FUNCTIONS: diff3
#
# ORIGINS: 3, 18, 26, 27
#
# (C) COPYRIGHT International Business Machines Corp. 1985, 1992
# 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.
#
# (c) Copyright 1990, OPEN SOFTWARE FOUNDATION, INC.
# ALL RIGHTS RESERVED
#
#                                                                   
#  diff3  [-ex3EX] file1 file2 file3 
#  compares three files
#  this shell script calls /usr/lbin/diff3prog to do the work.

usage() {
  if [ -x /usr/bin/dspmsg ]; then
  /usr/bin/dspmsg -s 2 diff3.cat 1 'Usage: diff3 [-e|-x|-E|-X|-3] File1 File2 File3\n' 1>&2 
  else
    msg='usage: diff3 [-e|-x|-E|-X|-3] file1 file2 file3';
    eval echo $msg 1>&2; 
  fi
  exit 1
}

e=
set -- `/usr/bin/getopt 3exEX $*`
if [ $? != 0 ]
then usage
fi
while [ $# -gt 0 ]
do
  case $1 in    
  -- )	shift
	break
	;;
  -*)	if [ .$e = . ]
	then
	  e=$1
	  shift
	else
	  usage
	fi
	;;
  * )	break
	;;
  esac
done

if [ $# -ne 3 ]
then
  usage
fi
umask 077
TMP=/tmp
TMP=$TMP/bsh.$$
/usr/bin/mkdir $TMP || {
        echo " bsh: Could not create temporary files" 1>&2
	exit 1
}
trap "/usr/bin/rm -fr $TMP; trap '' 0; exit" 1 2 13 15
/usr/bin/diff $1 $3 >$TMP/d3a$$ 2>$TMP/diff3err$$
diffRC=$?
if [ $diffRC -le 1 ]
then
  /usr/bin/diff $2 $3 >$TMP/d3b$$ 2>$TMP/diff3err$$
  diffRC=$?
fi
if [ $diffRC -gt 1 ]
then
  if [ -x /usr/bin/dspmsg ]; then
  /usr/bin/dspmsg -s 2 diff3.cat 2 "diff3: A diff command failed in diff3.\n" 1>&2
  else
    msg='diff3: A diff command failed in diff3.\n';
    eval echo $msg 1>&2; 
  fi

  echo "`/usr/bin/cat $TMP/diff3err$$`" 1>&2
  /usr/bin/rm -rf $TMP

  exit $diffRC
fi

/usr/lbin/diff3prog $e $TMP/d3[ab]$$ $1 $2 $3
if [ $? != 0 ]

then /usr/bin/rm -rf $TMP 
     exit 1
else /usr/bin/rm -rf $TMP
fi
exit 0