1#!/bin/ksh - 2# 3# $OpenBSD: diff3.ksh,v 1.1 2003/07/10 16:06:07 millert Exp $ 4# 5# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com> 6# 7# Permission to use, copy, modify, and distribute this software for any 8# purpose with or without fee is hereby granted, provided that the above 9# copyright notice and this permission notice appear in all copies. 10# 11# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18# 19# Sponsored in part by the Defense Advanced Research Projects 20# Agency (DARPA) and Air Force Research Laboratory, Air Force 21# Materiel Command, USAF, under agreement number F39502-99-1-0512. 22# 23 24set -o posix # set POSIX mode to prevent +foo in getopts 25OPTIND=1 # force getopts to reset itself 26 27export PATH=/bin:/usr/bin 28diff3prog=/usr/libexec/diff3prog 29USAGE="usage: diff3 [-aexEX3] file1 file2 file3" 30 31# Pull out any command line flags (some for diff, some for diff3) 32dflags= 33d3flags= 34while getopts "aeExX3" c; do 35 case "$c" in 36 a) 37 dflags="$dflags $1" 38 shift 39 ;; 40 e|E|x|X|3) 41 d3flags="-$c" 42 shift 43 ;; 44 *) 45 echo "$USAGE" 1>&2 46 exit 1 47 ;; 48 esac 49done 50shift $(( $OPTIND - 1 )) 51 52TMP1=`mktemp -t d3a.XXXXXXXXXX` || exit 1 53TMP2=`mktemp -t d3b.XXXXXXXXXX` 54if [ $? -ne 0 ]; then 55 rm -f $TMP1 56 exit 1 57fi 58trap "/bin/rm -f $TMP1 $TMP2" 0 1 2 13 15 59diff $dflags $1 $3 > $TMP1 60diff $dflags $2 $3 > $TMP2 61$DIFF3PROG $d3flags $TMP1 $TMP2 $1 $2 $3 62exit $? 63