Init
This commit is contained in:
44
cmd/diff/Makefile
Executable file
44
cmd/diff/Makefile
Executable file
@@ -0,0 +1,44 @@
|
||||
#
|
||||
#ident "@(#)Makefile 1.10 94/09/06 SMI"
|
||||
#
|
||||
# Copyright (c) 1989 by Sun Microsystems, Inc.
|
||||
#
|
||||
|
||||
PROG= diff diffh
|
||||
SRCS= $(PROG:%=%.c)
|
||||
DIFF= diff
|
||||
DIFFH= diffh
|
||||
|
||||
include ../Makefile.cmd
|
||||
#
|
||||
# for messaging catalog
|
||||
#
|
||||
POFILE= diff.po
|
||||
XGETFLAGS += -a -x diff.xcl
|
||||
|
||||
LDLIBS += -lintl -lw
|
||||
|
||||
ROOTBINDIFF = $(DIFF:%=$(ROOTBIN)/%)
|
||||
ROOTLIBDIFFH = $(DIFFH:%=$(ROOTLIB)/%)
|
||||
|
||||
.KEEP_STATE:
|
||||
|
||||
all: $(PROG)
|
||||
|
||||
#
|
||||
# Use private rule
|
||||
#
|
||||
$(POFILE):
|
||||
$(RM) $@
|
||||
$(COMPILE.cpp) $(SRCS) > diff.po.i
|
||||
$(XGETTEXT) $(XGETFLAGS) diff.po.i
|
||||
sed "/^domain/d" messages.po > $@
|
||||
$(RM) diff.po.i messages.po
|
||||
|
||||
install: all $(ROOTBINDIFF) $(ROOTLIBDIFFH)
|
||||
|
||||
clean:
|
||||
|
||||
lint: lint_SRCS
|
||||
|
||||
include ../Makefile.targ
|
||||
1855
cmd/diff/diff.c
Executable file
1855
cmd/diff/diff.c
Executable file
File diff suppressed because it is too large
Load Diff
165
cmd/diff/diff.h
Executable file
165
cmd/diff/diff.h
Executable file
@@ -0,0 +1,165 @@
|
||||
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
|
||||
/* All Rights Reserved */
|
||||
|
||||
/* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T */
|
||||
/* The copyright notice above does not evidence any */
|
||||
/* actual or intended publication of such source code. */
|
||||
|
||||
#ident "@(#)diff.h 1.6 94/09/06 SMI" /* SVr4.0 1.3 */
|
||||
|
||||
/*
|
||||
* PROPRIETARY NOTICE (Combined)
|
||||
*
|
||||
* This source code is unpublished proprietary information
|
||||
* constituting, or derived under license from AT&T's UNIX(r) System V.
|
||||
* In addition, portions of such source code were derived from Berkeley
|
||||
* 4.3 BSD under license from the Regents of the University of
|
||||
* California.
|
||||
*
|
||||
* Copyright Notice
|
||||
*
|
||||
* Notice of copyright on this source code product does not indicate
|
||||
* publication.
|
||||
*
|
||||
* (c) 1986,1987,1988,1989 Sun Microsystems, Inc
|
||||
* (c) 1983,1984,1985,1986,1987,1988,1989 AT&T.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
* diff - common declarations
|
||||
*/
|
||||
|
||||
|
||||
void done();
|
||||
|
||||
/*
|
||||
* Output format options
|
||||
*/
|
||||
int opt;
|
||||
|
||||
#define D_NORMAL 0 /* Normal output */
|
||||
#define D_EDIT -1 /* Editor script out */
|
||||
#define D_REVERSE 1 /* Reverse editor script */
|
||||
#define D_CONTEXT 2 /* Diff with context */
|
||||
#define D_IFDEF 3 /* Diff with merged #ifdef's */
|
||||
#define D_NREVERSE 4 /* Reverse ed script with numbered */
|
||||
/* lines and no trailing . */
|
||||
|
||||
/*
|
||||
* Constant declarations
|
||||
*/
|
||||
#define HALFMASK 0xf
|
||||
|
||||
#define prints(s) fputs(s, stdout)
|
||||
|
||||
#define MAX_CONTEXT 128
|
||||
|
||||
/*
|
||||
* diff - directory comparison
|
||||
*/
|
||||
#define d_flags d_ino
|
||||
|
||||
#define ONLY 1 /* Only in this directory */
|
||||
#define SAME 2 /* Both places and same */
|
||||
#define DIFFER 4 /* Both places and different */
|
||||
#define DIRECT 8 /* Directory */
|
||||
|
||||
struct dir {
|
||||
u_long d_ino;
|
||||
short d_reclen;
|
||||
short d_namlen;
|
||||
char *d_entry;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* type definitions
|
||||
*/
|
||||
|
||||
struct cand {
|
||||
int x;
|
||||
int y;
|
||||
int pred;
|
||||
} cand;
|
||||
|
||||
struct line {
|
||||
int serial;
|
||||
int value;
|
||||
} *file[2], line;
|
||||
|
||||
/*
|
||||
* The following struct is used to record change information when
|
||||
* doing a "context" diff. (see routine "change" to understand the
|
||||
* highly mneumonic field names)
|
||||
*/
|
||||
struct context_vec {
|
||||
int a; /* start line in old file */
|
||||
int b; /* end line in old file */
|
||||
int c; /* start line in new file */
|
||||
int d; /* end line in new file */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Algorithm related options
|
||||
*/
|
||||
int bflag = 0;
|
||||
int tflag = 0;
|
||||
int wflag = 0;
|
||||
int iflag = 0;
|
||||
int rflag = 0;
|
||||
int lflag = 0;
|
||||
int sflag = 0;
|
||||
int hflag = 0;
|
||||
|
||||
/*
|
||||
* Variables for D_IFDEF option.
|
||||
*/
|
||||
int wantelses = 0; /* used with D_IFDEF */
|
||||
char *ifdef1, *ifdef2; /* hold the ifdef strings */
|
||||
char *endifname;
|
||||
int inifdef = 0;
|
||||
|
||||
/*
|
||||
* Variables for -C (-c) context option.
|
||||
*/
|
||||
int context = 0; /* number of lines specfied with the C flag */
|
||||
|
||||
char *empty = ""; /* the empty string */
|
||||
|
||||
char **diffargv; /* keep track of argv for diffdir */
|
||||
|
||||
char start[256]; /* specify where to start, used with -S */
|
||||
|
||||
FILE *input[2]; /* two input files */
|
||||
int len[2];
|
||||
struct line *sfile[2]; /* shortened by pruning common prefix and suffix */
|
||||
int slen[2];
|
||||
|
||||
struct stat stb0, stb1;
|
||||
|
||||
/*
|
||||
* Input file names.
|
||||
* With diffdir, file1 and file2 are allocated BUFSIZ space,
|
||||
* and padded with a '/', and then efile0 and efile1 point after
|
||||
* the '/'.
|
||||
*/
|
||||
char *file1, *file2, *efile1, *efile2;
|
||||
struct stat stb1, stb2;
|
||||
char *file1, *file2, *efile1, *efile2;
|
||||
|
||||
char pr[] = "/usr/bin/pr";
|
||||
char diff[] = "/usr/bin/diff";
|
||||
char diffh[] = "/usr/lib/diffh";
|
||||
int status = 2;
|
||||
int anychange = 0;
|
||||
|
||||
struct context_vec *context_vec_start,
|
||||
*context_vec_end,
|
||||
*context_vec_ptr;
|
||||
|
||||
char tempfile[2][16]; /* used when comparing against std input */
|
||||
/* or char special devices */
|
||||
int whichtemp;
|
||||
char *dummy; /* used in resetting storage search ptr */
|
||||
61
cmd/diff/diff.xcl
Executable file
61
cmd/diff/diff.xcl
Executable file
@@ -0,0 +1,61 @@
|
||||
msgid ""
|
||||
msgid " "
|
||||
msgid " "
|
||||
msgid " ****\n"
|
||||
msgid " ----\n"
|
||||
msgid "!"
|
||||
msgid "! "
|
||||
msgid "#else %s%s\n"
|
||||
msgid "#endif %s\n"
|
||||
msgid "#ifdef %s\n"
|
||||
msgid "#ifndef %s\n"
|
||||
msgid "%d"
|
||||
msgid "%ld"
|
||||
msgid "%ld,$"
|
||||
msgid "%ld,%ld"
|
||||
msgid "%s"
|
||||
msgid "%s %s"
|
||||
msgid "%s%d"
|
||||
msgid "%s%s %s\n"
|
||||
msgid "%s:%s\n"
|
||||
msgid "*** %s %s"
|
||||
msgid "***************\n*** "
|
||||
msgid "+ "
|
||||
msgid ","
|
||||
msgid "-"
|
||||
msgid "- "
|
||||
msgid "--- "
|
||||
msgid "--- %s %s"
|
||||
msgid "---\n"
|
||||
msgid "-h"
|
||||
msgid ".\n"
|
||||
msgid "/tmp/dXXXXXX"
|
||||
msgid "/usr/bin/diff"
|
||||
msgid "/usr/bin/pr"
|
||||
msgid "/usr/lib/diffh"
|
||||
msgid "1"
|
||||
msgid "2"
|
||||
msgid "3"
|
||||
msgid "5"
|
||||
msgid ":\n"
|
||||
msgid "< "
|
||||
msgid "< %s"
|
||||
msgid "> "
|
||||
msgid "> %s"
|
||||
msgid "\f"
|
||||
msgid "\n"
|
||||
msgid "\t%s\n"
|
||||
msgid "a"
|
||||
msgid "a%d %d\n"
|
||||
msgid "c"
|
||||
msgid "d"
|
||||
msgid "d%d %d\n"
|
||||
msgid "diff "
|
||||
msgid "diff: "
|
||||
msgid "diffh"
|
||||
msgid "diffh: "
|
||||
msgid "diffh: %s%s\n"
|
||||
msgid "ed - %s << '-*-END-*-'\n"
|
||||
msgid "pr"
|
||||
msgid "r"
|
||||
msgid "w\nq\n-*-END-*-\n"
|
||||
292
cmd/diff/diffh.c
Executable file
292
cmd/diff/diffh.c
Executable file
@@ -0,0 +1,292 @@
|
||||
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
|
||||
/* All Rights Reserved */
|
||||
|
||||
/* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T */
|
||||
/* The copyright notice above does not evidence any */
|
||||
/* actual or intended publication of such source code. */
|
||||
|
||||
#ident "@(#)diffh.c 1.10 95/03/22 SMI" /* SVr4.0 1.3 */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <limits.h>
|
||||
|
||||
#define C 3
|
||||
#define RANGE 30
|
||||
#define LEN 255
|
||||
#define INF 16384
|
||||
|
||||
char *text[2][RANGE];
|
||||
long lineno[2] = {1, 1}; /* no. of 1st stored line in each file */
|
||||
int ntext[2]; /* number of stored lines in each */
|
||||
long n0, n1; /* scan pointer in each */
|
||||
int bflag;
|
||||
int debug = 0;
|
||||
FILE *file[2];
|
||||
|
||||
/* return pointer to line n of file f */
|
||||
char *
|
||||
getl(f, n)
|
||||
long n;
|
||||
{
|
||||
register char *t;
|
||||
register delta, nt;
|
||||
|
||||
again:
|
||||
delta = n - lineno[f];
|
||||
nt = ntext[f];
|
||||
if (delta < 0)
|
||||
progerr("1");
|
||||
if (delta < nt)
|
||||
return (text[f][delta]);
|
||||
if (delta > nt)
|
||||
progerr("2");
|
||||
if (nt >= RANGE)
|
||||
progerr("3");
|
||||
if (feof(file[f]))
|
||||
return (NULL);
|
||||
t = text[f][nt];
|
||||
if (t == 0) {
|
||||
t = text[f][nt] = (char *)malloc(LEN+1);
|
||||
if (t == NULL)
|
||||
if (hardsynch())
|
||||
goto again;
|
||||
else
|
||||
progerr("5");
|
||||
}
|
||||
t = fgets(t, LEN, file[f]);
|
||||
if (t != NULL)
|
||||
ntext[f]++;
|
||||
return (t);
|
||||
}
|
||||
|
||||
/* remove thru line n of file f from storage */
|
||||
clrl(f, n)
|
||||
long n;
|
||||
{
|
||||
register i, j;
|
||||
|
||||
j = n-lineno[f]+1;
|
||||
for (i = 0; i+j < ntext[f]; i++)
|
||||
movstr(text[f][i+j], text[f][i]);
|
||||
lineno[f] = n+1;
|
||||
ntext[f] -= j;
|
||||
}
|
||||
|
||||
movstr(s, t)
|
||||
register char *s, *t;
|
||||
{
|
||||
while (*t++ = *s++)
|
||||
continue;
|
||||
}
|
||||
|
||||
main(argc, argv)
|
||||
char **argv;
|
||||
{
|
||||
char *s0, *s1;
|
||||
|
||||
FILE *dopen();
|
||||
if (*argv[1] == '-') {
|
||||
argc--;
|
||||
argv++;
|
||||
while (*++argv[0])
|
||||
if (*argv[0] == 'b')
|
||||
bflag++;
|
||||
}
|
||||
|
||||
(void) setlocale(LC_ALL, "");
|
||||
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
|
||||
#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
|
||||
#endif
|
||||
(void) textdomain(TEXT_DOMAIN);
|
||||
|
||||
if (argc != 3)
|
||||
error("must have 2 file arguments", "");
|
||||
file[0] = dopen(argv[1], argv[2]);
|
||||
file[1] = dopen(argv[2], argv[1]);
|
||||
for (;;) {
|
||||
s0 = getl(0, ++n0);
|
||||
s1 = getl(1, ++n1);
|
||||
if (s0 == NULL || s1 == NULL)
|
||||
break;
|
||||
if (cmp(s0, s1) != 0) {
|
||||
if (!easysynch() && !hardsynch())
|
||||
progerr("5");
|
||||
} else {
|
||||
clrl(0, n0);
|
||||
clrl(1, n1);
|
||||
}
|
||||
}
|
||||
if (s0 == NULL && s1 == NULL)
|
||||
return;
|
||||
if (s0 == NULL)
|
||||
output(-1, INF);
|
||||
if (s1 == NULL)
|
||||
output(INF, -1);
|
||||
}
|
||||
|
||||
/* synch on C successive matches */
|
||||
easysynch()
|
||||
{
|
||||
int i, j;
|
||||
register k, m;
|
||||
char *s0, *s1;
|
||||
|
||||
for (i = j = 1; i < RANGE && j < RANGE; i++, j++) {
|
||||
s0 = getl(0, n0+i);
|
||||
if (s0 == NULL)
|
||||
return (output(INF, INF));
|
||||
for (k = C-1; k < j; k++) {
|
||||
for (m = 0; m < C; m++)
|
||||
if (cmp(getl(0, n0+i-m),
|
||||
getl(1, n1+k-m)) != 0)
|
||||
goto cont1;
|
||||
return (output(i-C, k-C));
|
||||
cont1:
|
||||
;
|
||||
}
|
||||
s1 = getl(1, n1+j);
|
||||
if (s1 == NULL)
|
||||
return (output(INF, INF));
|
||||
for (k = C-1; k <= i; k++) {
|
||||
for (m = 0; m < C; m++)
|
||||
if (cmp(getl(0, n0+k-m),
|
||||
getl(1, n1+j-m)) != 0)
|
||||
goto cont2;
|
||||
return (output(k-C, j-C));
|
||||
cont2:
|
||||
;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
output(a, b)
|
||||
{
|
||||
register i;
|
||||
char *s;
|
||||
|
||||
if (a < 0)
|
||||
change(n0-1, 0, n1, b, "a");
|
||||
else if (b < 0)
|
||||
change(n0, a, n1-1, 0, "d");
|
||||
else
|
||||
change(n0, a, n1, b, "c");
|
||||
for (i = 0; i <= a; i++) {
|
||||
s = getl(0, n0+i);
|
||||
if (s == NULL)
|
||||
break;
|
||||
printf("< %s", s);
|
||||
clrl(0, n0+i);
|
||||
}
|
||||
n0 += i-1;
|
||||
if (a >= 0 && b >= 0)
|
||||
printf("---\n");
|
||||
for (i = 0; i <= b; i++) {
|
||||
s = getl(1, n1+i);
|
||||
if (s == NULL)
|
||||
break;
|
||||
printf("> %s", s);
|
||||
clrl(1, n1+i);
|
||||
}
|
||||
n1 += i-1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
change(a, b, c, d, s)
|
||||
long a, c;
|
||||
char *s;
|
||||
{
|
||||
range(a, b);
|
||||
printf("%s", s);
|
||||
range(c, d);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
range(a, b)
|
||||
long a;
|
||||
{
|
||||
if (b == INF)
|
||||
printf("%ld,$", a);
|
||||
else if (b == 0)
|
||||
printf("%ld", a);
|
||||
else
|
||||
printf("%ld,%ld", a, a+b);
|
||||
}
|
||||
|
||||
cmp(s, t)
|
||||
char *s, *t;
|
||||
{
|
||||
if (debug)
|
||||
printf("%s:%s\n", s, t);
|
||||
for (;;) {
|
||||
if (bflag && isspace(*s) && isspace(*t)) {
|
||||
while (isspace(*++s))
|
||||
;
|
||||
while (isspace(*++t))
|
||||
;
|
||||
}
|
||||
if (*s != *t || *s == 0)
|
||||
break;
|
||||
s++;
|
||||
t++;
|
||||
}
|
||||
return (*s-*t);
|
||||
}
|
||||
|
||||
FILE *
|
||||
dopen(f1, f2)
|
||||
char *f1, *f2;
|
||||
{
|
||||
FILE *f;
|
||||
char b[PATH_MAX], *bptr, *eptr;
|
||||
struct stat statbuf;
|
||||
if (cmp(f1, "-") == 0)
|
||||
if (cmp(f2, "-") == 0)
|
||||
error("can't do - -", "");
|
||||
else
|
||||
return (stdin);
|
||||
if (stat(f1, &statbuf) == -1)
|
||||
error("can't access ", f1);
|
||||
if ((statbuf.st_mode & S_IFMT) == S_IFDIR) {
|
||||
for (bptr = b; *bptr = *f1++; bptr++)
|
||||
;
|
||||
*bptr++ = '/';
|
||||
for (eptr = f2; *eptr; eptr++)
|
||||
if (*eptr == '/' && eptr[1] != 0 && eptr[1] != '/')
|
||||
f2 = eptr+1;
|
||||
while (*bptr++ = *f2++)
|
||||
;
|
||||
f1 = b;
|
||||
}
|
||||
f = fopen(f1, "r");
|
||||
if (f == NULL)
|
||||
error("can't open", f1);
|
||||
return (f);
|
||||
}
|
||||
|
||||
|
||||
progerr(s)
|
||||
char *s;
|
||||
{
|
||||
error("program error ", s);
|
||||
}
|
||||
|
||||
error(s, t)
|
||||
char *s, *t;
|
||||
{
|
||||
fprintf(stderr, "diffh: %s%s\n", gettext(s), t);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* stub for resychronization beyond limits of text buf */
|
||||
hardsynch()
|
||||
{
|
||||
change(n0, INF, n1, INF, "c");
|
||||
printf(gettext("---change record omitted\n"));
|
||||
error("can't resynchronize", "");
|
||||
return (0);
|
||||
}
|
||||
Reference in New Issue
Block a user