diffh.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <locale.h>
#include <limits.h>
#include <stdarg.h>
#define C 3
#define RANGE 30
#define LEN 255
#define INF 16384
int bflag;
int debug = 0;
static int diffFound = 0;
static char *getl(int f, long n);
static void clrl(int f, long n);
static void movstr(char *s, char *t);
static int easysynch(void);
static int output(int a, int b);
static void change(long a, int b, long c, int d, char *s);
static void range(long a, int b);
static int cmp(char *s, char *t);
static void progerr(char *s);
static int hardsynch(void);
/* return pointer to line n of file f */
static char *
getl(int f, long n)
{
char *t;
if (delta < 0)
progerr("1");
progerr("2");
progerr("3");
return (NULL);
if (t == 0) {
if (t == NULL)
if (hardsynch())
goto again;
else
progerr("5");
}
if (t != NULL)
ntext[f]++;
return (t);
}
/* remove thru line n of file f from storage */
static void
clrl(int f, long n)
{
int i, j;
j = n-lineno[f]+1;
for (i = 0; i+j < ntext[f]; i++)
lineno[f] = n+1;
ntext[f] -= j;
}
static void
movstr(char *s, char *t)
{
while (*t++ = *s++)
continue;
}
int
{
argc--;
argv++;
while (*++argv[0])
if (*argv[0] == 'b')
bflag++;
}
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
if (argc != 3)
for (;;) {
break;
progerr("5");
} else {
}
}
/* diff is expected to return 1 if the files differ */
return (diffFound);
return (1);
}
return (1);
}
/* NOTREACHED */
}
/* synch on C successive matches */
static int
{
int i, j;
int k, m;
for (k = C-1; k < j; k++) {
for (m = 0; m < C; m++)
goto cont1;
return (output(i-C, k-C));
;
}
for (k = C-1; k <= i; k++) {
for (m = 0; m < C; m++)
goto cont2;
return (output(k-C, j-C));
;
}
}
return (0);
}
static int
output(int a, int b)
{
int i;
char *s;
if (a < 0)
else if (b < 0)
else
for (i = 0; i <= a; i++) {
if (s == NULL)
break;
(void) printf("< %s", s);
}
n0 += i-1;
if (a >= 0 && b >= 0)
(void) printf("---\n");
for (i = 0; i <= b; i++) {
if (s == NULL)
break;
(void) printf("> %s", s);
}
diffFound = 1;
n1 += i-1;
return (1);
}
static void
change(long a, int b, long c, int d, char *s)
{
range(a, b);
(void) printf("%s", s);
range(c, d);
(void) printf("\n");
}
static void
range(long a, int b)
{
if (b == INF)
(void) printf("%ld,$", a);
else if (b == 0)
(void) printf("%ld", a);
else
(void) printf("%ld,%ld", a, a+b);
}
static int
cmp(char *s, char *t)
{
if (debug)
(void) printf("%s:%s\n", s, t);
for (;;) {
while (isspace(*++s))
;
while (isspace(*++t))
;
}
if (*s != *t || *s == 0)
break;
s++;
t++;
}
return (*s-*t);
}
static FILE *
{
FILE *f;
else {
else
return (stdin);
}
}
;
*bptr++ = '/';
;
f1 = b;
}
if (f == NULL)
return (f);
}
static void
progerr(char *s)
{
}
static void
{
exit(2);
}
/* stub for resychronization beyond limits of text buf */
static int
{
return (0);
}