xref: /illumos-gate/usr/src/cmd/diff3/diff3.sh (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate#!/usr/bin/sh
2*7c478bd9Sstevel@tonic-gate#
3*7c478bd9Sstevel@tonic-gate# CDDL HEADER START
4*7c478bd9Sstevel@tonic-gate#
5*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
7*7c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
8*7c478bd9Sstevel@tonic-gate# with the License.
9*7c478bd9Sstevel@tonic-gate#
10*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
12*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
13*7c478bd9Sstevel@tonic-gate# and limitations under the License.
14*7c478bd9Sstevel@tonic-gate#
15*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
16*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
18*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
19*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
20*7c478bd9Sstevel@tonic-gate#
21*7c478bd9Sstevel@tonic-gate# CDDL HEADER END
22*7c478bd9Sstevel@tonic-gate#
23*7c478bd9Sstevel@tonic-gate#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
24*7c478bd9Sstevel@tonic-gate#	  All Rights Reserved
25*7c478bd9Sstevel@tonic-gate
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate#	Copyright (c) 1999, 2001 by Sun Microsystems, Inc.
28*7c478bd9Sstevel@tonic-gate#	All rights reserved.
29*7c478bd9Sstevel@tonic-gate
30*7c478bd9Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.4	*/
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gateusage="usage: diff3 file1 file2 file3"
33*7c478bd9Sstevel@tonic-gate
34*7c478bd9Sstevel@tonic-gate# mktmpdir - Create a private (mode 0700) temporary directory inside of /tmp
35*7c478bd9Sstevel@tonic-gate# for this process's temporary files.  We set up a trap to remove the
36*7c478bd9Sstevel@tonic-gate# directory on exit (trap 0), and also on SIGHUP, SIGINT, SIGQUIT, SIGPIPE,
37*7c478bd9Sstevel@tonic-gate# and SIGTERM.
38*7c478bd9Sstevel@tonic-gate
39*7c478bd9Sstevel@tonic-gatemktmpdir() {
40*7c478bd9Sstevel@tonic-gate	tmpdir=/tmp/diff3.$$
41*7c478bd9Sstevel@tonic-gate	trap '/usr/bin/rm -rf $tmpdir' 0 1 2 3 13 15
42*7c478bd9Sstevel@tonic-gate	/usr/bin/mkdir -m 700 $tmpdir || exit 1
43*7c478bd9Sstevel@tonic-gate}
44*7c478bd9Sstevel@tonic-gatemktmpdir
45*7c478bd9Sstevel@tonic-gate
46*7c478bd9Sstevel@tonic-gatee=
47*7c478bd9Sstevel@tonic-gatecase $1 in
48*7c478bd9Sstevel@tonic-gate-*)
49*7c478bd9Sstevel@tonic-gate	e=$1
50*7c478bd9Sstevel@tonic-gate	shift;;
51*7c478bd9Sstevel@tonic-gateesac
52*7c478bd9Sstevel@tonic-gateif [ $# != 3 ]; then
53*7c478bd9Sstevel@tonic-gate	echo ${usage} 1>&2
54*7c478bd9Sstevel@tonic-gate	exit 1
55*7c478bd9Sstevel@tonic-gatefi
56*7c478bd9Sstevel@tonic-gateif [ \( -f $1 -o -c $1 \) -a \( -f $2 -o -c $2 \) -a \( -f $3 -o -c $3 \) ]; then
57*7c478bd9Sstevel@tonic-gate	:
58*7c478bd9Sstevel@tonic-gateelse
59*7c478bd9Sstevel@tonic-gate	echo ${usage} 1>&2
60*7c478bd9Sstevel@tonic-gate	exit 1
61*7c478bd9Sstevel@tonic-gatefi
62*7c478bd9Sstevel@tonic-gatef1=$1 f2=$2 f3=$3
63*7c478bd9Sstevel@tonic-gateif [ -c $f1 ]
64*7c478bd9Sstevel@tonic-gatethen
65*7c478bd9Sstevel@tonic-gate	/usr/bin/cat $f1 > $tmpdir/d3c$$
66*7c478bd9Sstevel@tonic-gate	f1=$tmpdir/d3c$$
67*7c478bd9Sstevel@tonic-gatefi
68*7c478bd9Sstevel@tonic-gateif [ -c $f2 ]
69*7c478bd9Sstevel@tonic-gatethen
70*7c478bd9Sstevel@tonic-gate	/usr/bin/cat $f2 > $tmpdir/d3d$$
71*7c478bd9Sstevel@tonic-gate	f2=$tmpdir/d3d$$
72*7c478bd9Sstevel@tonic-gatefi
73*7c478bd9Sstevel@tonic-gateif [ -c $f3 ]
74*7c478bd9Sstevel@tonic-gatethen
75*7c478bd9Sstevel@tonic-gate	/usr/bin/cat $f3 > $tmpdir/d3e$$
76*7c478bd9Sstevel@tonic-gate	f3=$tmpdir/d3e$$
77*7c478bd9Sstevel@tonic-gatefi
78*7c478bd9Sstevel@tonic-gate
79*7c478bd9Sstevel@tonic-gate/usr/bin/diff $f1 $f3 > $tmpdir/d3a$$ 2> $tmpdir/d3a$$.err
80*7c478bd9Sstevel@tonic-gateSTATUS=$?
81*7c478bd9Sstevel@tonic-gateif [ $STATUS -eq 1 ]
82*7c478bd9Sstevel@tonic-gatethen
83*7c478bd9Sstevel@tonic-gate	/usr/xpg4/bin/grep -q "^[<>]" $tmpdir/d3a$$
84*7c478bd9Sstevel@tonic-gate	RET=$?
85*7c478bd9Sstevel@tonic-gate	if [ $RET -eq 1 ]
86*7c478bd9Sstevel@tonic-gate	then
87*7c478bd9Sstevel@tonic-gate		/usr/bin/cat $tmpdir/d3a$$
88*7c478bd9Sstevel@tonic-gate		exit $STATUS
89*7c478bd9Sstevel@tonic-gate	fi
90*7c478bd9Sstevel@tonic-gate
91*7c478bd9Sstevel@tonic-gate	if [ $RET -gt 1 ]
92*7c478bd9Sstevel@tonic-gate	then
93*7c478bd9Sstevel@tonic-gate		echo "diff3 failed" 1>&2
94*7c478bd9Sstevel@tonic-gate		exit $STATUS
95*7c478bd9Sstevel@tonic-gate	fi
96*7c478bd9Sstevel@tonic-gatefi
97*7c478bd9Sstevel@tonic-gate
98*7c478bd9Sstevel@tonic-gateif [ $STATUS -gt 1 ]
99*7c478bd9Sstevel@tonic-gatethen
100*7c478bd9Sstevel@tonic-gate	/usr/bin/cat $tmpdir/d3a$$.err
101*7c478bd9Sstevel@tonic-gate	exit $STATUS
102*7c478bd9Sstevel@tonic-gatefi
103*7c478bd9Sstevel@tonic-gate
104*7c478bd9Sstevel@tonic-gate/usr/bin/diff $f2 $f3 > $tmpdir/d3b$$ 2> $tmpdir/d3b$$.err
105*7c478bd9Sstevel@tonic-gateSTATUS=$?
106*7c478bd9Sstevel@tonic-gateif [ $STATUS -eq 1 ]
107*7c478bd9Sstevel@tonic-gatethen
108*7c478bd9Sstevel@tonic-gate	/usr/xpg4/bin/grep -q "^[<>]" $tmpdir/d3b$$
109*7c478bd9Sstevel@tonic-gate	RET=$?
110*7c478bd9Sstevel@tonic-gate	if [ $RET -eq 1 ]
111*7c478bd9Sstevel@tonic-gate	then
112*7c478bd9Sstevel@tonic-gate		/usr/bin/cat $tmpdir/d3b$$
113*7c478bd9Sstevel@tonic-gate		exit $STATUS
114*7c478bd9Sstevel@tonic-gate	fi
115*7c478bd9Sstevel@tonic-gate
116*7c478bd9Sstevel@tonic-gate	if [ $RET -gt 1 ]
117*7c478bd9Sstevel@tonic-gate	then
118*7c478bd9Sstevel@tonic-gate		echo "diff3 failed" 1>&2
119*7c478bd9Sstevel@tonic-gate		exit $STATUS
120*7c478bd9Sstevel@tonic-gate	fi
121*7c478bd9Sstevel@tonic-gatefi
122*7c478bd9Sstevel@tonic-gate
123*7c478bd9Sstevel@tonic-gateif [ $STATUS -gt 1 ]
124*7c478bd9Sstevel@tonic-gatethen
125*7c478bd9Sstevel@tonic-gate	/usr/bin/cat $tmpdir/d3b$$.err
126*7c478bd9Sstevel@tonic-gate	exit $STATUS
127*7c478bd9Sstevel@tonic-gatefi
128*7c478bd9Sstevel@tonic-gate
129*7c478bd9Sstevel@tonic-gate/usr/lib/diff3prog $e $tmpdir/d3[ab]$$ $f1 $f2 $f3
130