udiff.c (schily-2021-08-14.tar.bz2) | : | udiff.c (schily-2021-09-18.tar.bz2) | ||
---|---|---|---|---|
/* @(#)udiff.c 1.38 20/09/25 Copyright 1985-2020 J. Schilling */ | /* @(#)udiff.c 1.42 21/08/20 Copyright 1985-2021 J. Schilling */ | |||
#include <schily/mconfig.h> | #include <schily/mconfig.h> | |||
#ifndef lint | #ifndef lint | |||
static UConst char sccsid[] = | static UConst char sccsid[] = | |||
"@(#)udiff.c 1.38 20/09/25 Copyright 1985-2020 J. Schilling"; | "@(#)udiff.c 1.42 21/08/20 Copyright 1985-2021 J. Schilling"; | |||
#endif | #endif | |||
/* | /* | |||
* line by line diff for two files | * line by line diff for two files | |||
* | * | |||
* Copyright (c) 1985-2020 J. Schilling | * Copyright (c) 1985-2021 J. Schilling | |||
*/ | */ | |||
/* | /* | |||
* The contents of this file are subject to the terms of the | * The contents of this file are subject to the terms of the | |||
* Common Development and Distribution License, Version 1.0 only | * Common Development and Distribution License, Version 1.0 only | |||
* (the "License"). You may not use this file except in compliance | * (the "License"). You may not use this file except in compliance | |||
* with the License. | * with the License. | |||
* | * | |||
* See the file CDDL.Schily.txt in this distribution for details. | * See the file CDDL.Schily.txt in this distribution for details. | |||
* A copy of the CDDL is also available via the Internet at | * A copy of the CDDL is also available via the Internet at | |||
* http://www.opensource.org/licenses/cddl1.txt | * http://www.opensource.org/licenses/cddl1.txt | |||
skipping to change at line 56 | skipping to change at line 56 | |||
* In 32 bit mode, there is no need to check for an integer overflow | * In 32 bit mode, there is no need to check for an integer overflow | |||
* as the process will run "out of memory" before. | * as the process will run "out of memory" before. | |||
*/ | */ | |||
#include <schily/stdio.h> | #include <schily/stdio.h> | |||
#include <schily/stdlib.h> | #include <schily/stdlib.h> | |||
#include <schily/unistd.h> /* Include sys/types.h, makes off_t available */ | #include <schily/unistd.h> /* Include sys/types.h, makes off_t available */ | |||
#include <schily/standard.h> | #include <schily/standard.h> | |||
#include <schily/string.h> | #include <schily/string.h> | |||
#include <schily/stat.h> | #include <schily/stat.h> | |||
#define GT_COMERR /* #define comerr gtcomerr */ | ||||
#define GT_ERROR /* #define error gterror */ | ||||
#include <schily/schily.h> | #include <schily/schily.h> | |||
#include <schily/nlsdefs.h> | ||||
#define MAXLINE 32768 | #define MAXLINE 32768 | |||
typedef struct line { | typedef struct line { | |||
off_t off; | off_t off; | |||
long hash; | long hash; | |||
} line; | } line; | |||
LOCAL char *olbf; /* "old" line buffer */ | LOCAL char *olbf; /* "old" line buffer */ | |||
LOCAL char *nlbf; /* "new" line buffer */ | LOCAL char *nlbf; /* "new" line buffer */ | |||
skipping to change at line 149 | skipping to change at line 152 | |||
off_t lineoff; | off_t lineoff; | |||
save_args(ac, av); | save_args(ac, av); | |||
if (av0[0] != 'u') { | if (av0[0] != 'u') { | |||
nmatch = 1; | nmatch = 1; | |||
posix = 1; | posix = 1; | |||
} | } | |||
if (av0[0] == 'f' && av0[1] == 's') { | if (av0[0] == 'f' && av0[1] == 's') { | |||
bdiffmode = TRUE; | bdiffmode = TRUE; | |||
} | } | |||
(void) setlocale(LC_ALL, ""); | ||||
#ifdef USE_NLS | ||||
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ | ||||
#define TEXT_DOMAIN "udiff" /* Use this only if it weren't */ | ||||
#endif | ||||
{ char *dir; | ||||
dir = searchfileinpath("share/locale", F_OK, | ||||
SIP_ANY_FILE|SIP_NO_PATH, NULL); | ||||
if (dir) | ||||
(void) bindtextdomain(TEXT_DOMAIN, dir); | ||||
else | ||||
#if defined(PROTOTYPES) && defined(INS_BASE) | ||||
(void) bindtextdomain(TEXT_DOMAIN, INS_BASE "/share/locale"); | ||||
#else | ||||
(void) bindtextdomain(TEXT_DOMAIN, "/usr/share/locale"); | ||||
#endif | ||||
(void) textdomain(TEXT_DOMAIN); | ||||
} | ||||
#endif /* USE_NLS */ | ||||
fac = --ac; | fac = --ac; | |||
fav = ++av; | fav = ++av; | |||
if (getallargs(&fac, &fav, options, &posix, &nmatch, | if (getallargs(&fac, &fav, options, &posix, &nmatch, | |||
&help, &prversion) < 0) { | &help, &prversion) < 0) { | |||
errmsgno(EX_BAD, "Bad option: '%s'\n", fav[0]); | errmsgno(EX_BAD, "Bad option: '%s'\n", fav[0]); | |||
usage(EX_BAD); | usage(EX_BAD); | |||
} | } | |||
if (help) | if (help) | |||
usage(0); | usage(0); | |||
if (nmatch <= 0) { | if (nmatch <= 0) { | |||
errmsgno(EX_BAD, "Bad nmatch value: %d\n", nmatch); | errmsgno(EX_BAD, "Bad nmatch value: %d\n", nmatch); | |||
usage(EX_BAD); | usage(EX_BAD); | |||
} | } | |||
if (prversion) { | if (prversion) { | |||
printf("Udiff release %s %s (%s-%s-%s) Copyright (C) 1985-2020 Jö | gtprintf("Udiff release %s %s (%s-%s-%s) Copyright (C) 1985-2021 | |||
rg Schilling\n", | %s\n", | |||
"1.38", "2020/09/25", | "1.42", "2021/08/20", | |||
HOST_CPU, HOST_VENDOR, HOST_OS); | HOST_CPU, HOST_VENDOR, HOST_OS, | |||
_("Jörg Schilling")); | ||||
exit(0); | exit(0); | |||
} | } | |||
fac = ac; | fac = ac; | |||
fav = av; | fav = av; | |||
if (getfiles(&fac, &fav, options) <= 0) { | if (getfiles(&fac, &fav, options) <= 0) { | |||
error("No files given.\n"); | error("No files given.\n"); | |||
usage(EX_BAD); | usage(EX_BAD); | |||
} | } | |||
oldname = fav[0]; | oldname = fav[0]; | |||
skipping to change at line 532 | skipping to change at line 558 | |||
ssize_t lo; | ssize_t lo; | |||
o += clc; | o += clc; | |||
n += clc; | n += clc; | |||
if (posix) { | if (posix) { | |||
if (c == 1) | if (c == 1) | |||
printf("%ldd%ld\n", o+1, n); | printf("%ldd%ld\n", o+1, n); | |||
else | else | |||
printf("%ld,%ldd%ld\n", o+1, o+c, n); | printf("%ld,%ldd%ld\n", o+1, o+c, n); | |||
} else if (c == 1) | } else if (c == 1) | |||
printf("\n-------- 1 line deleted at %ld:\n", o); | gtprintf("\n-------- 1 line deleted at %ld:\n", o); | |||
else | else | |||
printf("\n-------- %ld lines deleted at %ld:\n", c, o); | gtprintf("\n-------- %ld lines deleted at %ld:\n", c, o); | |||
o -= clc; | o -= clc; | |||
n -= clc; | n -= clc; | |||
for (i = 0; i < c; i++) { | for (i = 0; i < c; i++) { | |||
lp = glinep((long)(o+i), oldfile); | lp = glinep((long)(o+i), oldfile); | |||
if (ooff != lp->off) { | if (ooff != lp->off) { | |||
xfileseek(0, lp->off); | xfileseek(0, lp->off); | |||
ooff = lp->off; | ooff = lp->off; | |||
} | } | |||
lo = xgetdelim(&olbf, &olsz, '\n', 0); | lo = xgetdelim(&olbf, &olsz, '\n', 0); | |||
skipping to change at line 575 | skipping to change at line 601 | |||
ssize_t ln; | ssize_t ln; | |||
o += clc; | o += clc; | |||
n += clc; | n += clc; | |||
if (posix) { | if (posix) { | |||
if (c == 1) | if (c == 1) | |||
printf("%lda%ld\n", o, n+1); | printf("%lda%ld\n", o, n+1); | |||
else | else | |||
printf("%lda%ld,%ld\n", o, n+1, n+c); | printf("%lda%ld,%ld\n", o, n+1, n+c); | |||
} else if (c == 1) | } else if (c == 1) | |||
printf("\n-------- 1 line added at %ld:\n", o); | gtprintf("\n-------- 1 line added at %ld:\n", o); | |||
else | else | |||
printf("\n-------- %ld lines added at %ld:\n", c, o); | gtprintf("\n-------- %ld lines added at %ld:\n", c, o); | |||
o -= clc; | o -= clc; | |||
n -= clc; | n -= clc; | |||
for (i = 0; i < c; i++) { | for (i = 0; i < c; i++) { | |||
lp = glinep((long)(n+i), newfile); | lp = glinep((long)(n+i), newfile); | |||
if (noff != lp->off) { | if (noff != lp->off) { | |||
xfileseek(1, lp->off); | xfileseek(1, lp->off); | |||
noff = lp->off; | noff = lp->off; | |||
} | } | |||
ln = xgetdelim(&nlbf, &nlsz, '\n', 1); | ln = xgetdelim(&nlbf, &nlsz, '\n', 1); | |||
skipping to change at line 619 | skipping to change at line 645 | |||
ssize_t ln; | ssize_t ln; | |||
o += clc; | o += clc; | |||
n += clc; | n += clc; | |||
if (posix) { | if (posix) { | |||
if (c == 1) | if (c == 1) | |||
printf("%ldc%ld\n", o+1, n+1); | printf("%ldc%ld\n", o+1, n+1); | |||
else | else | |||
printf("%ld,%ldc%ld,%ld\n", o+1, o+c, n+1, n+c); | printf("%ld,%ldc%ld,%ld\n", o+1, o+c, n+1, n+c); | |||
} else if (c == 1) | } else if (c == 1) | |||
printf("\n-------- 1 line changed at %ld from:\n", o); | gtprintf("\n-------- 1 line changed at %ld from:\n", o); | |||
else | else | |||
printf("\n-------- %ld lines changed at %ld-%ld from:\n", | gtprintf("\n-------- %ld lines changed at %ld-%ld from:\n", | |||
c, o, o+c-1); | c, o, o+c-1); | |||
o -= clc; | o -= clc; | |||
n -= clc; | n -= clc; | |||
for (i = 0; i < c; i++) { | for (i = 0; i < c; i++) { | |||
lp = glinep((long)(o+i), oldfile); | lp = glinep((long)(o+i), oldfile); | |||
if (ooff != lp->off) { | if (ooff != lp->off) { | |||
xfileseek(0, lp->off); | xfileseek(0, lp->off); | |||
ooff = lp->off; | ooff = lp->off; | |||
} | } | |||
skipping to change at line 646 | skipping to change at line 672 | |||
#endif | #endif | |||
if (posix) | if (posix) | |||
printf("< "); | printf("< "); | |||
filewrite(stdout, olbf, lo); | filewrite(stdout, olbf, lo); | |||
if (olbf[lo-1] != '\n') | if (olbf[lo-1] != '\n') | |||
putchar('\n'); | putchar('\n'); | |||
} | } | |||
if (posix) | if (posix) | |||
printf("---\n"); | printf("---\n"); | |||
else | else | |||
printf("-------- to:\n"); | gtprintf("-------- to:\n"); | |||
for (i = 0; i < c; i++) { | for (i = 0; i < c; i++) { | |||
lp = glinep((long)(n+i), newfile); | lp = glinep((long)(n+i), newfile); | |||
if (noff != lp->off) { | if (noff != lp->off) { | |||
xfileseek(1, lp->off); | xfileseek(1, lp->off); | |||
noff = lp->off; | noff = lp->off; | |||
} | } | |||
ln = xgetdelim(&nlbf, &nlsz, '\n', 1); | ln = xgetdelim(&nlbf, &nlsz, '\n', 1); | |||
noff += ln; | noff += ln; | |||
#ifdef USE_CRLF | #ifdef USE_CRLF | |||
noff = filepos(nf); | noff = filepos(nf); | |||
skipping to change at line 688 | skipping to change at line 714 | |||
o += clc; | o += clc; | |||
n += clc; | n += clc; | |||
if (posix) { | if (posix) { | |||
if (oc == 1) | if (oc == 1) | |||
printf("%ldc%ld,%ld\n", o+1, n+1, n+nc); | printf("%ldc%ld,%ld\n", o+1, n+1, n+nc); | |||
else if (nc == 1) | else if (nc == 1) | |||
printf("%ld,%ldc%ld\n", o+1, o+oc, n+1); | printf("%ld,%ldc%ld\n", o+1, o+oc, n+1); | |||
else | else | |||
printf("%ld,%ldc%ld,%ld\n", o+1, o+oc, n+1, n+nc); | printf("%ld,%ldc%ld,%ld\n", o+1, o+oc, n+1, n+nc); | |||
} else if (oc == 1) | } else if (oc == 1) | |||
printf("\n-------- 1 line changed to %ld lines at %ld from:\n", | gtprintf("\n-------- 1 line changed to %ld lines at %ld from:\n", | |||
nc, o); | nc, o); | |||
else if (nc == 1) | else if (nc == 1) | |||
printf("\n-------- %ld lines changed to 1 line at %ld-%ld from:\n ", | gtprintf("\n-------- %ld lines changed to 1 line at %ld-%ld from: \n", | |||
oc, o, o+oc-1); | oc, o, o+oc-1); | |||
else | else | |||
printf("\n-------- %ld lines changed to %ld lines at %ld-%ld from :\n", | gtprintf("\n-------- %ld lines changed to %ld lines at %ld-%ld fr om:\n", | |||
oc, nc, o, o+oc-1); | oc, nc, o, o+oc-1); | |||
o -= clc; | o -= clc; | |||
n -= clc; | n -= clc; | |||
for (i = 0; i < oc; i++) { | for (i = 0; i < oc; i++) { | |||
lp = glinep((long)(o+i), oldfile); | lp = glinep((long)(o+i), oldfile); | |||
if (ooff != lp->off) { | if (ooff != lp->off) { | |||
xfileseek(0, lp->off); | xfileseek(0, lp->off); | |||
ooff = lp->off; | ooff = lp->off; | |||
} | } | |||
skipping to change at line 719 | skipping to change at line 745 | |||
#endif | #endif | |||
if (posix) | if (posix) | |||
printf("< "); | printf("< "); | |||
filewrite(stdout, olbf, lo); | filewrite(stdout, olbf, lo); | |||
if (olbf[lo-1] != '\n') | if (olbf[lo-1] != '\n') | |||
putchar('\n'); | putchar('\n'); | |||
} | } | |||
if (posix) | if (posix) | |||
printf("---\n"); | printf("---\n"); | |||
else | else | |||
printf("-------- to:\n"); | gtprintf("-------- to:\n"); | |||
for (i = 0; i < nc; i++) { | for (i = 0; i < nc; i++) { | |||
lp = glinep((long)(n+i), newfile); | lp = glinep((long)(n+i), newfile); | |||
if (noff != lp->off) { | if (noff != lp->off) { | |||
xfileseek(1, lp->off); | xfileseek(1, lp->off); | |||
noff = lp->off; | noff = lp->off; | |||
} | } | |||
ln = xgetdelim(&nlbf, &nlsz, '\n', 1); | ln = xgetdelim(&nlbf, &nlsz, '\n', 1); | |||
noff += ln; | noff += ln; | |||
#ifdef USE_CRLF | #ifdef USE_CRLF | |||
noff = filepos(nf); | noff = filepos(nf); | |||
End of changes. 18 change blocks. | ||||
18 lines changed or deleted | 44 lines changed or added |