xref: /titanic_52/usr/src/cmd/diff/diffh.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #include <stdio.h>
34*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
35*7c478bd9Sstevel@tonic-gate #include <unistd.h>
36*7c478bd9Sstevel@tonic-gate #include <ctype.h>
37*7c478bd9Sstevel@tonic-gate #include <locale.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
40*7c478bd9Sstevel@tonic-gate #include <limits.h>
41*7c478bd9Sstevel@tonic-gate #include <stdarg.h>
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #define	C		3
44*7c478bd9Sstevel@tonic-gate #define	RANGE		30
45*7c478bd9Sstevel@tonic-gate #define	LEN		255
46*7c478bd9Sstevel@tonic-gate #define	INF		16384
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate char *text[2][RANGE];
49*7c478bd9Sstevel@tonic-gate long lineno[2] = {1, 1};	/* no. of 1st stored line in each file */
50*7c478bd9Sstevel@tonic-gate int ntext[2];		/* number of stored lines in each */
51*7c478bd9Sstevel@tonic-gate long n0, n1;		/* scan pointer in each */
52*7c478bd9Sstevel@tonic-gate int bflag;
53*7c478bd9Sstevel@tonic-gate int debug = 0;
54*7c478bd9Sstevel@tonic-gate FILE *file[2];
55*7c478bd9Sstevel@tonic-gate static int diffFound = 0;
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate static char *getl(int f, long n);
58*7c478bd9Sstevel@tonic-gate static void clrl(int f, long n);
59*7c478bd9Sstevel@tonic-gate static void movstr(char *s, char *t);
60*7c478bd9Sstevel@tonic-gate static int easysynch(void);
61*7c478bd9Sstevel@tonic-gate static int output(int a, int b);
62*7c478bd9Sstevel@tonic-gate static void change(long a, int b, long c, int d, char *s);
63*7c478bd9Sstevel@tonic-gate static void range(long a, int b);
64*7c478bd9Sstevel@tonic-gate static int cmp(char *s, char *t);
65*7c478bd9Sstevel@tonic-gate static FILE *dopen(char *f1, char *f2);
66*7c478bd9Sstevel@tonic-gate static void progerr(char *s);
67*7c478bd9Sstevel@tonic-gate static void error(char *err, ...);
68*7c478bd9Sstevel@tonic-gate static int hardsynch(void);
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate 	/* return pointer to line n of file f */
71*7c478bd9Sstevel@tonic-gate static char *
72*7c478bd9Sstevel@tonic-gate getl(int f, long n)
73*7c478bd9Sstevel@tonic-gate {
74*7c478bd9Sstevel@tonic-gate 	char *t;
75*7c478bd9Sstevel@tonic-gate 	int delta, nt;
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate again:
78*7c478bd9Sstevel@tonic-gate 	delta = n - lineno[f];
79*7c478bd9Sstevel@tonic-gate 	nt = ntext[f];
80*7c478bd9Sstevel@tonic-gate 	if (delta < 0)
81*7c478bd9Sstevel@tonic-gate 		progerr("1");
82*7c478bd9Sstevel@tonic-gate 	if (delta < nt)
83*7c478bd9Sstevel@tonic-gate 		return (text[f][delta]);
84*7c478bd9Sstevel@tonic-gate 	if (delta > nt)
85*7c478bd9Sstevel@tonic-gate 		progerr("2");
86*7c478bd9Sstevel@tonic-gate 	if (nt >= RANGE)
87*7c478bd9Sstevel@tonic-gate 		progerr("3");
88*7c478bd9Sstevel@tonic-gate 	if (feof(file[f]))
89*7c478bd9Sstevel@tonic-gate 		return (NULL);
90*7c478bd9Sstevel@tonic-gate 	t = text[f][nt];
91*7c478bd9Sstevel@tonic-gate 	if (t == 0) {
92*7c478bd9Sstevel@tonic-gate 		t = text[f][nt] = (char *)malloc(LEN+1);
93*7c478bd9Sstevel@tonic-gate 		if (t == NULL)
94*7c478bd9Sstevel@tonic-gate 			if (hardsynch())
95*7c478bd9Sstevel@tonic-gate 				goto again;
96*7c478bd9Sstevel@tonic-gate 			else
97*7c478bd9Sstevel@tonic-gate 				progerr("5");
98*7c478bd9Sstevel@tonic-gate 	}
99*7c478bd9Sstevel@tonic-gate 	t = fgets(t, LEN, file[f]);
100*7c478bd9Sstevel@tonic-gate 	if (t != NULL)
101*7c478bd9Sstevel@tonic-gate 		ntext[f]++;
102*7c478bd9Sstevel@tonic-gate 	return (t);
103*7c478bd9Sstevel@tonic-gate }
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate 	/* remove thru line n of file f from storage */
106*7c478bd9Sstevel@tonic-gate static void
107*7c478bd9Sstevel@tonic-gate clrl(int f, long n)
108*7c478bd9Sstevel@tonic-gate {
109*7c478bd9Sstevel@tonic-gate 	int i, j;
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate 	j = n-lineno[f]+1;
112*7c478bd9Sstevel@tonic-gate 	for (i = 0; i+j < ntext[f]; i++)
113*7c478bd9Sstevel@tonic-gate 		movstr(text[f][i+j], text[f][i]);
114*7c478bd9Sstevel@tonic-gate 	lineno[f] = n+1;
115*7c478bd9Sstevel@tonic-gate 	ntext[f] -= j;
116*7c478bd9Sstevel@tonic-gate }
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate static void
119*7c478bd9Sstevel@tonic-gate movstr(char *s, char *t)
120*7c478bd9Sstevel@tonic-gate {
121*7c478bd9Sstevel@tonic-gate 	while (*t++ = *s++)
122*7c478bd9Sstevel@tonic-gate 		continue;
123*7c478bd9Sstevel@tonic-gate }
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate int
126*7c478bd9Sstevel@tonic-gate main(int argc, char **argv)
127*7c478bd9Sstevel@tonic-gate {
128*7c478bd9Sstevel@tonic-gate 	char *s0, *s1;
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate 	if ((argc > 1) && (*argv[1] == '-')) {
131*7c478bd9Sstevel@tonic-gate 		argc--;
132*7c478bd9Sstevel@tonic-gate 		argv++;
133*7c478bd9Sstevel@tonic-gate 		while (*++argv[0])
134*7c478bd9Sstevel@tonic-gate 			if (*argv[0] == 'b')
135*7c478bd9Sstevel@tonic-gate 				bflag++;
136*7c478bd9Sstevel@tonic-gate 	}
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
139*7c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)		/* Should be defined by cc -D */
140*7c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN	"SYS_TEST"	/* Use this only if it weren't */
141*7c478bd9Sstevel@tonic-gate #endif
142*7c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate 	if (argc != 3)
145*7c478bd9Sstevel@tonic-gate 		error(gettext("must have 2 file arguments"));
146*7c478bd9Sstevel@tonic-gate 	file[0] = dopen(argv[1], argv[2]);
147*7c478bd9Sstevel@tonic-gate 	file[1] = dopen(argv[2], argv[1]);
148*7c478bd9Sstevel@tonic-gate 	for (;;) {
149*7c478bd9Sstevel@tonic-gate 		s0 = getl(0, ++n0);
150*7c478bd9Sstevel@tonic-gate 		s1 = getl(1, ++n1);
151*7c478bd9Sstevel@tonic-gate 		if (s0 == NULL || s1 == NULL)
152*7c478bd9Sstevel@tonic-gate 			break;
153*7c478bd9Sstevel@tonic-gate 		if (cmp(s0, s1) != 0) {
154*7c478bd9Sstevel@tonic-gate 			if (!easysynch() && !hardsynch())
155*7c478bd9Sstevel@tonic-gate 				progerr("5");
156*7c478bd9Sstevel@tonic-gate 		} else {
157*7c478bd9Sstevel@tonic-gate 			clrl(0, n0);
158*7c478bd9Sstevel@tonic-gate 			clrl(1, n1);
159*7c478bd9Sstevel@tonic-gate 		}
160*7c478bd9Sstevel@tonic-gate 	}
161*7c478bd9Sstevel@tonic-gate 	/* diff is expected to return 1 if the files differ */
162*7c478bd9Sstevel@tonic-gate 	if (s0 == NULL && s1 == NULL)
163*7c478bd9Sstevel@tonic-gate 		return (diffFound);
164*7c478bd9Sstevel@tonic-gate 	if (s0 == NULL) {
165*7c478bd9Sstevel@tonic-gate 		(void) output(-1, INF);
166*7c478bd9Sstevel@tonic-gate 		return (1);
167*7c478bd9Sstevel@tonic-gate 	}
168*7c478bd9Sstevel@tonic-gate 	if (s1 == NULL) {
169*7c478bd9Sstevel@tonic-gate 		(void) output(INF, -1);
170*7c478bd9Sstevel@tonic-gate 		return (1);
171*7c478bd9Sstevel@tonic-gate 	}
172*7c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
173*7c478bd9Sstevel@tonic-gate }
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate 	/* synch on C successive matches */
176*7c478bd9Sstevel@tonic-gate static int
177*7c478bd9Sstevel@tonic-gate easysynch()
178*7c478bd9Sstevel@tonic-gate {
179*7c478bd9Sstevel@tonic-gate 	int i, j;
180*7c478bd9Sstevel@tonic-gate 	int k, m;
181*7c478bd9Sstevel@tonic-gate 	char *s0, *s1;
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate 	for (i = j = 1; i < RANGE && j < RANGE; i++, j++) {
184*7c478bd9Sstevel@tonic-gate 		s0 = getl(0, n0+i);
185*7c478bd9Sstevel@tonic-gate 		if (s0 == NULL)
186*7c478bd9Sstevel@tonic-gate 			return (output(INF, INF));
187*7c478bd9Sstevel@tonic-gate 		for (k = C-1; k < j; k++) {
188*7c478bd9Sstevel@tonic-gate 			for (m = 0; m < C; m++)
189*7c478bd9Sstevel@tonic-gate 				if (cmp(getl(0, n0+i-m),
190*7c478bd9Sstevel@tonic-gate 					getl(1, n1+k-m)) != 0)
191*7c478bd9Sstevel@tonic-gate 					goto cont1;
192*7c478bd9Sstevel@tonic-gate 			return (output(i-C, k-C));
193*7c478bd9Sstevel@tonic-gate cont1:
194*7c478bd9Sstevel@tonic-gate 			;
195*7c478bd9Sstevel@tonic-gate 		}
196*7c478bd9Sstevel@tonic-gate 		s1 = getl(1, n1+j);
197*7c478bd9Sstevel@tonic-gate 		if (s1 == NULL)
198*7c478bd9Sstevel@tonic-gate 			return (output(INF, INF));
199*7c478bd9Sstevel@tonic-gate 		for (k = C-1; k <= i; k++) {
200*7c478bd9Sstevel@tonic-gate 			for (m = 0; m < C; m++)
201*7c478bd9Sstevel@tonic-gate 				if (cmp(getl(0, n0+k-m),
202*7c478bd9Sstevel@tonic-gate 					getl(1, n1+j-m)) != 0)
203*7c478bd9Sstevel@tonic-gate 					goto cont2;
204*7c478bd9Sstevel@tonic-gate 			return (output(k-C, j-C));
205*7c478bd9Sstevel@tonic-gate cont2:
206*7c478bd9Sstevel@tonic-gate 			;
207*7c478bd9Sstevel@tonic-gate 		}
208*7c478bd9Sstevel@tonic-gate 	}
209*7c478bd9Sstevel@tonic-gate 	return (0);
210*7c478bd9Sstevel@tonic-gate }
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate static int
213*7c478bd9Sstevel@tonic-gate output(int a, int b)
214*7c478bd9Sstevel@tonic-gate {
215*7c478bd9Sstevel@tonic-gate 	int i;
216*7c478bd9Sstevel@tonic-gate 	char *s;
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate 	if (a < 0)
219*7c478bd9Sstevel@tonic-gate 		change(n0-1, 0, n1, b, "a");
220*7c478bd9Sstevel@tonic-gate 	else if (b < 0)
221*7c478bd9Sstevel@tonic-gate 		change(n0, a, n1-1, 0, "d");
222*7c478bd9Sstevel@tonic-gate 	else
223*7c478bd9Sstevel@tonic-gate 		change(n0, a, n1, b, "c");
224*7c478bd9Sstevel@tonic-gate 	for (i = 0; i <= a; i++) {
225*7c478bd9Sstevel@tonic-gate 		s = getl(0, n0+i);
226*7c478bd9Sstevel@tonic-gate 		if (s == NULL)
227*7c478bd9Sstevel@tonic-gate 			break;
228*7c478bd9Sstevel@tonic-gate 		(void) printf("< %s", s);
229*7c478bd9Sstevel@tonic-gate 		clrl(0, n0+i);
230*7c478bd9Sstevel@tonic-gate 	}
231*7c478bd9Sstevel@tonic-gate 	n0 += i-1;
232*7c478bd9Sstevel@tonic-gate 	if (a >= 0 && b >= 0)
233*7c478bd9Sstevel@tonic-gate 		(void) printf("---\n");
234*7c478bd9Sstevel@tonic-gate 	for (i = 0; i <= b; i++) {
235*7c478bd9Sstevel@tonic-gate 		s = getl(1, n1+i);
236*7c478bd9Sstevel@tonic-gate 		if (s == NULL)
237*7c478bd9Sstevel@tonic-gate 			break;
238*7c478bd9Sstevel@tonic-gate 		(void) printf("> %s", s);
239*7c478bd9Sstevel@tonic-gate 		clrl(1, n1+i);
240*7c478bd9Sstevel@tonic-gate 	}
241*7c478bd9Sstevel@tonic-gate 	diffFound = 1;
242*7c478bd9Sstevel@tonic-gate 	n1 += i-1;
243*7c478bd9Sstevel@tonic-gate 	return (1);
244*7c478bd9Sstevel@tonic-gate }
245*7c478bd9Sstevel@tonic-gate 
246*7c478bd9Sstevel@tonic-gate static void
247*7c478bd9Sstevel@tonic-gate change(long a, int b, long c, int d, char *s)
248*7c478bd9Sstevel@tonic-gate {
249*7c478bd9Sstevel@tonic-gate 	range(a, b);
250*7c478bd9Sstevel@tonic-gate 	(void) printf("%s", s);
251*7c478bd9Sstevel@tonic-gate 	range(c, d);
252*7c478bd9Sstevel@tonic-gate 	(void) printf("\n");
253*7c478bd9Sstevel@tonic-gate }
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate static void
256*7c478bd9Sstevel@tonic-gate range(long a, int b)
257*7c478bd9Sstevel@tonic-gate {
258*7c478bd9Sstevel@tonic-gate 	if (b == INF)
259*7c478bd9Sstevel@tonic-gate 		(void) printf("%ld,$", a);
260*7c478bd9Sstevel@tonic-gate 	else if (b == 0)
261*7c478bd9Sstevel@tonic-gate 		(void) printf("%ld", a);
262*7c478bd9Sstevel@tonic-gate 	else
263*7c478bd9Sstevel@tonic-gate 		(void) printf("%ld,%ld", a, a+b);
264*7c478bd9Sstevel@tonic-gate }
265*7c478bd9Sstevel@tonic-gate 
266*7c478bd9Sstevel@tonic-gate static int
267*7c478bd9Sstevel@tonic-gate cmp(char *s, char *t)
268*7c478bd9Sstevel@tonic-gate {
269*7c478bd9Sstevel@tonic-gate 	if (debug)
270*7c478bd9Sstevel@tonic-gate 		(void) printf("%s:%s\n", s, t);
271*7c478bd9Sstevel@tonic-gate 	for (;;) {
272*7c478bd9Sstevel@tonic-gate 		if (bflag && isspace(*s) && isspace(*t)) {
273*7c478bd9Sstevel@tonic-gate 			while (isspace(*++s))
274*7c478bd9Sstevel@tonic-gate 				;
275*7c478bd9Sstevel@tonic-gate 			while (isspace(*++t))
276*7c478bd9Sstevel@tonic-gate 				;
277*7c478bd9Sstevel@tonic-gate 		}
278*7c478bd9Sstevel@tonic-gate 		if (*s != *t || *s == 0)
279*7c478bd9Sstevel@tonic-gate 			break;
280*7c478bd9Sstevel@tonic-gate 		s++;
281*7c478bd9Sstevel@tonic-gate 		t++;
282*7c478bd9Sstevel@tonic-gate 	}
283*7c478bd9Sstevel@tonic-gate 	return (*s-*t);
284*7c478bd9Sstevel@tonic-gate }
285*7c478bd9Sstevel@tonic-gate 
286*7c478bd9Sstevel@tonic-gate static FILE *
287*7c478bd9Sstevel@tonic-gate dopen(char *f1, char *f2)
288*7c478bd9Sstevel@tonic-gate {
289*7c478bd9Sstevel@tonic-gate 	FILE *f;
290*7c478bd9Sstevel@tonic-gate 	char b[PATH_MAX], *bptr, *eptr;
291*7c478bd9Sstevel@tonic-gate 	struct stat statbuf;
292*7c478bd9Sstevel@tonic-gate 
293*7c478bd9Sstevel@tonic-gate 	if (cmp(f1, "-") == 0) {
294*7c478bd9Sstevel@tonic-gate 		if (cmp(f2, "-") == 0)
295*7c478bd9Sstevel@tonic-gate 			error(gettext("can't do - -"));
296*7c478bd9Sstevel@tonic-gate 		else {
297*7c478bd9Sstevel@tonic-gate 			if (fstat(fileno(stdin), &statbuf) == -1)
298*7c478bd9Sstevel@tonic-gate 				error(gettext("can't access stdin"));
299*7c478bd9Sstevel@tonic-gate 			else
300*7c478bd9Sstevel@tonic-gate 				return (stdin);
301*7c478bd9Sstevel@tonic-gate 		}
302*7c478bd9Sstevel@tonic-gate 	}
303*7c478bd9Sstevel@tonic-gate 	if (stat(f1, &statbuf) == -1)
304*7c478bd9Sstevel@tonic-gate 		error(gettext("can't access %s"), f1);
305*7c478bd9Sstevel@tonic-gate 	if ((statbuf.st_mode & S_IFMT) == S_IFDIR) {
306*7c478bd9Sstevel@tonic-gate 		for (bptr = b; *bptr = *f1++; bptr++)
307*7c478bd9Sstevel@tonic-gate 			;
308*7c478bd9Sstevel@tonic-gate 		*bptr++ = '/';
309*7c478bd9Sstevel@tonic-gate 		for (eptr = f2; *eptr; eptr++)
310*7c478bd9Sstevel@tonic-gate 			if (*eptr == '/' && eptr[1] != 0 && eptr[1] != '/')
311*7c478bd9Sstevel@tonic-gate 				f2 = eptr+1;
312*7c478bd9Sstevel@tonic-gate 		while (*bptr++ = *f2++)
313*7c478bd9Sstevel@tonic-gate 			;
314*7c478bd9Sstevel@tonic-gate 		f1 = b;
315*7c478bd9Sstevel@tonic-gate 	}
316*7c478bd9Sstevel@tonic-gate 	f = fopen(f1, "r");
317*7c478bd9Sstevel@tonic-gate 	if (f == NULL)
318*7c478bd9Sstevel@tonic-gate 		error(gettext("can't open %s"), f1);
319*7c478bd9Sstevel@tonic-gate 	return (f);
320*7c478bd9Sstevel@tonic-gate }
321*7c478bd9Sstevel@tonic-gate 
322*7c478bd9Sstevel@tonic-gate 
323*7c478bd9Sstevel@tonic-gate static void
324*7c478bd9Sstevel@tonic-gate progerr(char *s)
325*7c478bd9Sstevel@tonic-gate {
326*7c478bd9Sstevel@tonic-gate 	error(gettext("program error %s"), s);
327*7c478bd9Sstevel@tonic-gate }
328*7c478bd9Sstevel@tonic-gate 
329*7c478bd9Sstevel@tonic-gate static void
330*7c478bd9Sstevel@tonic-gate error(char *err, ...)
331*7c478bd9Sstevel@tonic-gate {
332*7c478bd9Sstevel@tonic-gate 	va_list	ap;
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate 	va_start(ap, err);
335*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "diffh: ");
336*7c478bd9Sstevel@tonic-gate 	(void) vfprintf(stderr, err, ap);
337*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "\n");
338*7c478bd9Sstevel@tonic-gate 	va_end(ap);
339*7c478bd9Sstevel@tonic-gate 	exit(2);
340*7c478bd9Sstevel@tonic-gate }
341*7c478bd9Sstevel@tonic-gate 
342*7c478bd9Sstevel@tonic-gate 	/* stub for resychronization beyond limits of text buf */
343*7c478bd9Sstevel@tonic-gate static int
344*7c478bd9Sstevel@tonic-gate hardsynch()
345*7c478bd9Sstevel@tonic-gate {
346*7c478bd9Sstevel@tonic-gate 	change(n0, INF, n1, INF, "c");
347*7c478bd9Sstevel@tonic-gate 	(void) printf(gettext("---change record omitted\n"));
348*7c478bd9Sstevel@tonic-gate 	error(gettext("can't resynchronize"));
349*7c478bd9Sstevel@tonic-gate 	return (0);
350*7c478bd9Sstevel@tonic-gate }
351