17c478bd9Sstevel@tonic-gate#!/usr/bin/sh 27c478bd9Sstevel@tonic-gate# 37c478bd9Sstevel@tonic-gate# CDDL HEADER START 47c478bd9Sstevel@tonic-gate# 57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 67c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only 77c478bd9Sstevel@tonic-gate# (the "License"). You may not use this file except in compliance 87c478bd9Sstevel@tonic-gate# with the License. 97c478bd9Sstevel@tonic-gate# 107c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 117c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 127c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 137c478bd9Sstevel@tonic-gate# and limitations under the License. 147c478bd9Sstevel@tonic-gate# 157c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 167c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 177c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 187c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 197c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 207c478bd9Sstevel@tonic-gate# 217c478bd9Sstevel@tonic-gate# CDDL HEADER END 227c478bd9Sstevel@tonic-gate# 237c478bd9Sstevel@tonic-gate# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T 247c478bd9Sstevel@tonic-gate# All Rights Reserved 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate# Copyright (c) 1999, 2001 by Sun Microsystems, Inc. 287c478bd9Sstevel@tonic-gate# All rights reserved. 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gateusage="usage: diff3 file1 file2 file3" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate# mktmpdir - Create a private (mode 0700) temporary directory inside of /tmp 337c478bd9Sstevel@tonic-gate# for this process's temporary files. We set up a trap to remove the 347c478bd9Sstevel@tonic-gate# directory on exit (trap 0), and also on SIGHUP, SIGINT, SIGQUIT, SIGPIPE, 357c478bd9Sstevel@tonic-gate# and SIGTERM. 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gatemktmpdir() { 387c478bd9Sstevel@tonic-gate tmpdir=/tmp/diff3.$$ 397c478bd9Sstevel@tonic-gate trap '/usr/bin/rm -rf $tmpdir' 0 1 2 3 13 15 407c478bd9Sstevel@tonic-gate /usr/bin/mkdir -m 700 $tmpdir || exit 1 417c478bd9Sstevel@tonic-gate} 427c478bd9Sstevel@tonic-gatemktmpdir 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gatee= 457c478bd9Sstevel@tonic-gatecase $1 in 467c478bd9Sstevel@tonic-gate-*) 477c478bd9Sstevel@tonic-gate e=$1 487c478bd9Sstevel@tonic-gate shift;; 497c478bd9Sstevel@tonic-gateesac 507c478bd9Sstevel@tonic-gateif [ $# != 3 ]; then 517c478bd9Sstevel@tonic-gate echo ${usage} 1>&2 527c478bd9Sstevel@tonic-gate exit 1 537c478bd9Sstevel@tonic-gatefi 547c478bd9Sstevel@tonic-gateif [ \( -f $1 -o -c $1 \) -a \( -f $2 -o -c $2 \) -a \( -f $3 -o -c $3 \) ]; then 557c478bd9Sstevel@tonic-gate : 567c478bd9Sstevel@tonic-gateelse 577c478bd9Sstevel@tonic-gate echo ${usage} 1>&2 587c478bd9Sstevel@tonic-gate exit 1 597c478bd9Sstevel@tonic-gatefi 607c478bd9Sstevel@tonic-gatef1=$1 f2=$2 f3=$3 617c478bd9Sstevel@tonic-gateif [ -c $f1 ] 627c478bd9Sstevel@tonic-gatethen 637c478bd9Sstevel@tonic-gate /usr/bin/cat $f1 > $tmpdir/d3c$$ 647c478bd9Sstevel@tonic-gate f1=$tmpdir/d3c$$ 657c478bd9Sstevel@tonic-gatefi 667c478bd9Sstevel@tonic-gateif [ -c $f2 ] 677c478bd9Sstevel@tonic-gatethen 687c478bd9Sstevel@tonic-gate /usr/bin/cat $f2 > $tmpdir/d3d$$ 697c478bd9Sstevel@tonic-gate f2=$tmpdir/d3d$$ 707c478bd9Sstevel@tonic-gatefi 717c478bd9Sstevel@tonic-gateif [ -c $f3 ] 727c478bd9Sstevel@tonic-gatethen 737c478bd9Sstevel@tonic-gate /usr/bin/cat $f3 > $tmpdir/d3e$$ 747c478bd9Sstevel@tonic-gate f3=$tmpdir/d3e$$ 757c478bd9Sstevel@tonic-gatefi 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate/usr/bin/diff $f1 $f3 > $tmpdir/d3a$$ 2> $tmpdir/d3a$$.err 787c478bd9Sstevel@tonic-gateSTATUS=$? 797c478bd9Sstevel@tonic-gateif [ $STATUS -eq 1 ] 807c478bd9Sstevel@tonic-gatethen 81*d2d52addSAlexander Pyhalov /usr/bin/grep -q "^[<>]" $tmpdir/d3a$$ 827c478bd9Sstevel@tonic-gate RET=$? 837c478bd9Sstevel@tonic-gate if [ $RET -eq 1 ] 847c478bd9Sstevel@tonic-gate then 857c478bd9Sstevel@tonic-gate /usr/bin/cat $tmpdir/d3a$$ 867c478bd9Sstevel@tonic-gate exit $STATUS 877c478bd9Sstevel@tonic-gate fi 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate if [ $RET -gt 1 ] 907c478bd9Sstevel@tonic-gate then 917c478bd9Sstevel@tonic-gate echo "diff3 failed" 1>&2 927c478bd9Sstevel@tonic-gate exit $STATUS 937c478bd9Sstevel@tonic-gate fi 947c478bd9Sstevel@tonic-gatefi 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gateif [ $STATUS -gt 1 ] 977c478bd9Sstevel@tonic-gatethen 987c478bd9Sstevel@tonic-gate /usr/bin/cat $tmpdir/d3a$$.err 997c478bd9Sstevel@tonic-gate exit $STATUS 1007c478bd9Sstevel@tonic-gatefi 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate/usr/bin/diff $f2 $f3 > $tmpdir/d3b$$ 2> $tmpdir/d3b$$.err 1037c478bd9Sstevel@tonic-gateSTATUS=$? 1047c478bd9Sstevel@tonic-gateif [ $STATUS -eq 1 ] 1057c478bd9Sstevel@tonic-gatethen 106*d2d52addSAlexander Pyhalov /usr/bin/grep -q "^[<>]" $tmpdir/d3b$$ 1077c478bd9Sstevel@tonic-gate RET=$? 1087c478bd9Sstevel@tonic-gate if [ $RET -eq 1 ] 1097c478bd9Sstevel@tonic-gate then 1107c478bd9Sstevel@tonic-gate /usr/bin/cat $tmpdir/d3b$$ 1117c478bd9Sstevel@tonic-gate exit $STATUS 1127c478bd9Sstevel@tonic-gate fi 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate if [ $RET -gt 1 ] 1157c478bd9Sstevel@tonic-gate then 1167c478bd9Sstevel@tonic-gate echo "diff3 failed" 1>&2 1177c478bd9Sstevel@tonic-gate exit $STATUS 1187c478bd9Sstevel@tonic-gate fi 1197c478bd9Sstevel@tonic-gatefi 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gateif [ $STATUS -gt 1 ] 1227c478bd9Sstevel@tonic-gatethen 1237c478bd9Sstevel@tonic-gate /usr/bin/cat $tmpdir/d3b$$.err 1247c478bd9Sstevel@tonic-gate exit $STATUS 1257c478bd9Sstevel@tonic-gatefi 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate/usr/lib/diff3prog $e $tmpdir/d3[ab]$$ $f1 $f2 $f3 128