1#!/bin/ksh - 2# 3# $OpenBSD: diff3.ksh,v 1.6 2019/09/28 17:30:07 ajacoutot Exp $ 4# 5# Copyright (c) 2003 Todd C. Miller <millert@openbsd.org> 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=/usr/bin:/bin:/usr/sbin:/sbin 28diff3prog=/usr/libexec/diff3prog 29USAGE="usage: diff3 [-3aEeXx] 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 -$c" 38 ;; 39 e|E|x|X|3) 40 d3flags="-$c" 41 ;; 42 *) 43 echo "$USAGE" 1>&2 44 exit 1 45 ;; 46 esac 47done 48shift $(( $OPTIND - 1 )) 49 50if [ $# -lt 3 ]; then 51 echo "$USAGE" 1>&2 52 exit 1 53fi 54 55TMP1=`mktemp -t d3a.XXXXXXXXXX` || exit 1 56TMP2=`mktemp -t d3b.XXXXXXXXXX` 57if [ $? -ne 0 ]; then 58 rm -f $TMP1 59 exit 1 60fi 61trap "/bin/rm -f $TMP1 $TMP2" 0 1 2 13 15 62diff $dflags -- $1 $3 > $TMP1 63diff $dflags -- $2 $3 > $TMP2 64$diff3prog $d3flags -- $TMP1 $TMP2 $1 $2 $3 65exit $? 66