File: sccsdiff.sh.in

package info (click to toggle)
cssc 1.4.0-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,580 kB
  • sloc: cpp: 39,778; sh: 16,917; ansic: 13,769; python: 3,923; makefile: 1,701; perl: 342; awk: 15
file content (235 lines) | stat: -rw-r--r-- 6,215 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#! /bin/sh
# sccsdiff.sh.in: Part of GNU CSSC.
#
# Copyright (C) 1997,1998,2001,2004,2007 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# This file is part of CSSC.
# # @configure_input@

# Usage:
# sccsdiff [-p] -rsid -rsid [diff-options] s.filename
#

# $Id: sccsdiff.sh.in,v 1.12 2007/12/17 21:59:50 jay Exp $
# LOG   $Log: sccsdiff.sh.in,v $
# LOG   Revision 1.12  2007/12/17 21:59:50  jay
# LOG   Migrate to GPL version 3
# LOG
# LOG   Revision 1.11  2007/06/19 22:41:15  james_youngman
# LOG   Included copyright notices in some files where these were missing
# LOG
# LOG   Revision 1.10  2004/10/17 11:45:13  james_youngman
# LOG   Fixed SourceForge bug 966010, sccs sccsdiff -r cannot have space
# LOG   before revision number.   We still will have similar problems
# LOG   elsewhere in the suite, I suspect.
# LOG
# LOG   Revision 1.9  2001/11/25 16:01:38  james_youngman
# LOG   Corrected a syntax error.
# LOG
# LOG   Revision 1.8  2001/11/25 14:27:54  james_youngman
# LOG   fixed Debian  Bug#120080: sccs sccsdiff doesn't work (sccsdiff assumes /usr/sccs symlink exists)
# LOG
# LOG   Revision 1.7  1998/03/10 00:22:00  james
# LOG   Support for filenames containing spaces.
# LOG
# LOG   Revision 1.6  1998/03/09 23:25:00  james
# LOG   Bug report from Richard Polton: IRIX's pr(1) requires a space between
# LOG   the "-h" and its argument.
# LOG
# LOG   Revision 1.5  1998/02/09 21:00:19  james
# LOG   Patch from Maurice O'Donnell <mod@tfn.com>: pass "-e" to sed before
# LOG   the sed commands.
# LOG
# LOG   Revision 1.4  1998/01/24 14:15:13  james
# LOG   SCCS compatibility fix -- When "get" fails, exit with value 1, not 2.
# LOG
# LOG   Revision 1.3  1997/12/19 20:40:35  james
# LOG   Modified version of sccsdiff arrived from Richard Polton; took the
# LOG   ideas onboard for a rewrite of sccsdiff.
# LOG
# LOG   Revision 1.2  1997/05/04 14:52:02  james
# LOG   Have to enclose the version string in single rather than double
# LOG   quotes, to protect the dollar signs from shell expansion.
# LOG
# LOG   Revision 1.1  1997/05/04 14:49:22  james
# LOG   Initial revision

# Values substituted by configure:-
pr=@PR@			   # The location of the   pr(1) command
diff=@CONFIG_DIFF_COMMAND@ # The location of the diff(1) command

# Find the "get" command.  The last value tested is "get", and
# that's what we use if we can't find get in any other location.
if test x$get = x
then
    # The CSSC Makefile performs a sed substitution on the next line.
    for get in "__csscutildir__/get" /usr/sccs/get get
    do
	if [ -x "$get" ]
	then
	    break
	fi
    done
fi

version='$Revision: 1.12 $ $State: Exp $'
usage() {
cat <<EOF
$0 [-p] -rsid -rsid [diff-options] s.filename [s.secondfile...]
EOF
}

use_pr=false
first_sid=
second_sid=
diff_options=
sccs_files=

while test $# -gt 0
do
	case "$1" in
	    --help)
		usage
		exit 0
		;;
	    --version)
		echo "$version"
		exit 0
		;;
	    -p) use_pr=true
		shift
		;;
	    -r*)
		# Cope with "-r 1.1" or "-r1.1":
                if test x-r = x"$1"
		then
		    # SID is next argument.
		    arg=-r"$2"
		    shift;
		else
		    # SID imediately follow the "-r", in the same argument.
		    arg="$1"
		fi

		if test x"$first_sid" = x
		then
		    first_sid="$arg"
		else
		    if test x"$second_sid" = x
		    then
			second_sid="$arg"
		    else
			exec >&2
			usage
			echo "Too many -r options."
			exit 1
		    fi
		fi
		shift
		;;
	    -*)
		diff_options="${diff_options} $1"
		shift
		;;
	    *)
		# That is an SCCS file, leave it and everything
		# following it in $*.
		break
		;;
	esac
done

# Show what we got...
## echo "use_pr=" $use_pr
## echo "first SID=" $first_sid
## echo "second SID=" $second_sid
## echo "diff options=" $diff_options
## echo "SCCS files=" $*
## echo \$\# = $#

if test x$second_sid = x
then
    exec >&2
    echo Two SIDs must be specified with the -r option.
    usage
    exit 1
fi


# Remove the leading "-r" from $first_sid and $second_sid
# so that we can echo the correct string as the header line
# introducing the diff.
first_sid=`echo   $first_sid | sed -e 's/^-r//' `
second_sid=`echo $second_sid | sed -e 's/^-r//' `

getprefix=$(mktemp get.XXXXXXX).
g1=$(mktemp get.${first_sid}.XXXXXXX)
g2=$(mktemp get.${second_sid}.XXXXXXX)
dfile=$(mktemp get.d${first_sid}${second_sid}.XXXXXXX)

while test $# -gt 0
do
    rm -f "$g1" "$g2" "$dfile"
    sccsfile="$1"
    shift
    base="`basename $sccsfile | sed -e 's/^s\.//'`"
    pr_header="$sccsfile: $first_sid vs. $second_sid"
    no_pr_header="
------- ${base} -------"

    ${get:-get} -r$first_sid -s -k "-G${g1}" "${sccsfile}" || {
	exec >&2
	echo "Failed to get version $first_sid from $sccsfile"
	exit 1
    }
    ${get:-get} -r$second_sid -s -k "-G${g2}" "${sccsfile}" || {
	rm -f "$g1"
	exec >&2
	echo "Failed to get version $second_sid from $sccsfile"
	exit 1
    }
    # in case noclobber is set...
    rm -f "$dfile"

    # Ignore return value of diff since it just tells us
    # if the two files are different.
    "$diff" $diff_options "$g1" "$g2" > "$dfile"
    if test -f "$dfile"
    then				  # Output file exists.
        if test -s "$dfile"
        then				  # Output file is not empty.
	    if $use_pr
	    then
		$pr -h "$pr_header"        < $dfile
	    else
		echo "$no_pr_header"
		cat "$dfile"
	    fi
        else				  # Output file is empty.
	    echo No differences.
	fi
    else				  # No output file at all!
        echo "$diff produced no output file." >&2
        exit 2
    fi
done					  # Loop over all named SCCS files.
rm -f "$g1" "$g2" "$dfile"
exit 0

# Local Variables:
# Mode: shell
# End: