Annotation of src/usr.bin/diff3/diff3.ksh, Revision 1.4
1.1 millert 1: #!/bin/ksh -
2: #
1.4 ! jmc 3: # $OpenBSD: diff3.ksh,v 1.3 2006/01/28 07:27:38 tedu Exp $
1.1 millert 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:
24: set -o posix # set POSIX mode to prevent +foo in getopts
25: OPTIND=1 # force getopts to reset itself
26:
27: export PATH=/bin:/usr/bin
28: diff3prog=/usr/libexec/diff3prog
1.4 ! jmc 29: USAGE="usage: diff3 [-3aEeXx] file1 file2 file3"
1.1 millert 30:
31: # Pull out any command line flags (some for diff, some for diff3)
32: dflags=
33: d3flags=
34: while getopts "aeExX3" c; do
35: case "$c" in
36: a)
1.2 millert 37: dflags="$dflags -$c"
1.1 millert 38: ;;
39: e|E|x|X|3)
40: d3flags="-$c"
41: ;;
42: *)
43: echo "$USAGE" 1>&2
44: exit 1
45: ;;
46: esac
47: done
48: shift $(( $OPTIND - 1 ))
49:
1.2 millert 50: if [ $# -lt 3 ]; then
51: echo "$USAGE" 1>&2
52: exit 1
53: fi
54:
1.1 millert 55: TMP1=`mktemp -t d3a.XXXXXXXXXX` || exit 1
56: TMP2=`mktemp -t d3b.XXXXXXXXXX`
57: if [ $? -ne 0 ]; then
58: rm -f $TMP1
59: exit 1
60: fi
61: trap "/bin/rm -f $TMP1 $TMP2" 0 1 2 13 15
1.3 tedu 62: diff $dflags -- $1 $3 > $TMP1
63: diff $dflags -- $2 $3 > $TMP2
64: $diff3prog $d3flags -- $TMP1 $TMP2 $1 $2 $3
1.1 millert 65: exit $?