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