1#! /bin/sh
2# @(#)sccsdiff.sh	1.14 20/10/31 Copyright 2011-2020 J. Schilling
3#
4# CDDL HEADER START
5#
6# The contents of this file are subject to the terms of the
7# Common Development and Distribution License (the "License").
8# You may not use this file except in compliance with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23# Copyright (c) 1988 AT&T
24# All Rights Reserved
25# Copyright 2003 Sun Microsystems, Inc. All rights reserved.
26# Use is subject to license terms.
27#
28# @(#)sccsdiff.sh 1.15 06/12/12
29#
30#ident	"@(#)sccsdiff.sh"
31#ident	"@(#)sccs:cmd/sccsdiff.sh"
32#	DESCRIPTION:
33#		Execute diff(1) on two versions of a set of
34#		SCCS files and optionally pipe through pr(1).
35#		Optionally specify diff segmentation size.
36# if running under control of the NSE (-q option given), will look for
37# get in the directory from which it was run (if -q, $0 will be full pathname)
38#
39PATH=INS_BASE/SCCS_BIN_PREbin:$PATH:/usr/ccs/bin
40
41trap "rm -f /tmp/get[abc]$$;exit 1" 1 2 3 15
42umask 077
43
44if [ $# -lt 3 ] && [ "$1" != -V ] && [ "$1" != -version ] && [ "$1" != --version ]
45then
46	echo "Usage: sccsdiff -r<sid1> -r<sid2> [-p] [-q] [-N[bulk-spec]] sccsfile ..." 1>&2
47	exit 1
48fi
49
50nseflag=
51rflag=
52addflags=
53Nflag=
54get=get
55for i in "$@"
56do
57	if [ "$addflags" = "yes" ]
58	then
59		flags="$flags $i"
60		addflags=
61		continue
62	fi
63	case "$i" in
64
65	-*)
66		case "$i" in
67
68		-r*)
69			if [ ! "$sid1" ]
70			then
71				sid1=`echo $i | sed -e 's/^-r//'`
72				if [ "$sid1" = "" ]
73				then
74					rflag=yes
75				fi
76			elif [ ! "$sid2" ]
77			then
78				sid2=`echo $i | sed -e 's/^-r//'`
79				if [ "$sid2" = "" ]
80				then
81					rflag=yes
82				fi
83			fi
84			;;
85		-s*)
86			num=`echo $i | sed -e 's/^-s//'`
87			;;
88		-p*)
89			pipe=yes
90			;;
91		-q*)
92			nseflag=-q
93			get=`dirname $0`/get
94			;;
95		-[cefnhbwitu]*)
96			flags="$flags $i"
97			;;
98		-D*)
99			Dopt="-D"
100			Darg=`echo $i | sed -e 's/^-D//'`
101			if [ "$Darg" = "" ]
102			then
103				flags="$flags $i"
104				addflags=yes
105			else
106				flags="$flags $Dopt $Darg"
107			fi
108			;;
109		-C)
110			flags="$flags $i"
111			addflags=yes
112			;;
113		-U*)
114			if [ `echo $i | wc -c` = 3 ]
115			then
116				flags="$flags $i"
117				addflags=yes
118			else
119				opt=`echo $i | sed -e 's/^-U/-U /'`
120				flags="$flags $opt"
121			fi
122			;;
123		-N*)
124			Nflag="$i"
125			;;
126		-V | -version | --version)
127			echo "$0 PROVIDER-SCCS version VERSION VDATE (HOST_SUB)"
128			exit 0
129			;;
130		*)
131			echo "$0: unknown argument: $i" 1>&2
132			exit 1
133			;;
134		esac
135		;;
136	s.*|*/s.*)
137		files="$files $i"
138		;;
139	[1-9]*)
140		if [ "$rflag" != "" ]
141		then
142			if [ ! "$sid1" ]
143			then
144				sid1=$i
145			elif [ ! "$sid2" ]
146			then
147				sid2=$i
148			fi
149		fi
150		rflag=
151		;;
152	*)
153		if [ "$Nflag" ]; then
154			#
155			# In NewMode, get(1) converts g-filenames into
156			# s-filenames if needed, so need to let get(1)
157			# do the checks.
158			#
159			files="$files $i"
160		else
161			echo "$0: $i not an SCCS file" 1>&2
162		fi
163		;;
164	esac
165done
166
167if [ "$files" = "" ]
168then
169	echo "$0: missing file arg (cm3)" 1>&2
170	exit 1
171fi
172
173error=0
174for i in $files
175do
176	rm -f /tmp/get[abc]$$
177	# Good place to check if tmp-files are not deleted
178	# if [ -f /tmp/geta$$ ] ...
179
180	#
181	# $Nflag may contain spaces, so clear IFS for this command
182	#
183	OIFS=$IFS
184	IFS=
185	if $get $nseflag $Nflag -s -o -k -r$sid1 $i -G/tmp/geta$$
186	then
187		if $get $nseflag $Nflag -s -o -k -r$sid2 $i -G/tmp/getb$$
188		then
189			IFS=$OIFS
190			diff $flags /tmp/geta$$ /tmp/getb$$ > /tmp/getc$$
191		else
192			error=1
193			continue	# error: cannot get release $sid2
194		fi
195	else
196		error=1
197		continue	# error: cannot get release $sid1
198	fi
199	IFS=$OIFS
200
201	if [ ! -s /tmp/getc$$ ]
202	then
203		if [ -f /tmp/getc$$ ]
204		then
205			echo "$i: No differences" > /tmp/getc$$
206		else
207			error=1
208			continue	# error: cannot get differences
209		fi
210	fi
211	if [ "$pipe" ]
212	then
213		pr -h "$i: $sid1 vs. $sid2" /tmp/getc$$
214	else
215		file=`basename $i | sed -e 's/^s\.//'`
216		echo
217		echo "------- $file -------"
218		cat /tmp/getc$$
219	fi
220done
221rm -f /tmp/get[abc]$$
222exit $error
223