compare.c (schily-2021-08-14.tar.bz2) | : | compare.c (schily-2021-09-18.tar.bz2) | ||
---|---|---|---|---|
/* @(#)compare.c 1.25 18/09/27 Copyright 1985, 88, 96-99, 2000-2018 J. Sch illing */ | /* @(#)compare.c 1.27 21/08/20 Copyright 1985, 88, 96-99, 2000-2021 J. Sch illing */ | |||
#include <schily/mconfig.h> | #include <schily/mconfig.h> | |||
#ifndef lint | #ifndef lint | |||
static UConst char sccsid[] = | static UConst char sccsid[] = | |||
"@(#)compare.c 1.25 18/09/27 Copyright 1985, 88, 96-99, 2000-2018 J. Sch illing"; | "@(#)compare.c 1.27 21/08/20 Copyright 1985, 88, 96-99, 2000-2021 J. Sch illing"; | |||
#endif | #endif | |||
/* | /* | |||
* compare two file for identical contents | * compare two file for identical contents | |||
* returns: | * returns: | |||
* 0 files are the same | * 0 files are the same | |||
* 1 file 1 is longer | * 1 file 1 is longer | |||
* 2 file 2 is longer | * 2 file 2 is longer | |||
* 3 files differ before EOF is reached on either | * 3 files differ before EOF is reached on either | |||
* 4 wrong number of arguments | * 4 wrong number of arguments | |||
* 5 cannot open one of the files | * 5 cannot open one of the files | |||
* 6 I/O error on one of the files | * 6 I/O error on one of the files | |||
* | * | |||
* Copyright (c) 1985, 88, 96-99, 2000-2018 J. Schilling | * Copyright (c) 1985, 88, 96-99, 2000-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 42 | skipping to change at line 42 | |||
*/ | */ | |||
#include <schily/stdio.h> | #include <schily/stdio.h> | |||
#include <schily/types.h> | #include <schily/types.h> | |||
#include <schily/stat.h> | #include <schily/stat.h> | |||
#include <schily/fcntl.h> /* O_BINARY */ | #include <schily/fcntl.h> /* O_BINARY */ | |||
#include <schily/stdlib.h> | #include <schily/stdlib.h> | |||
#include <schily/unistd.h> | #include <schily/unistd.h> | |||
#include <schily/utypes.h> | #include <schily/utypes.h> | |||
#include <schily/standard.h> | #include <schily/standard.h> | |||
#define GT_COMERR /* #define comerr gtcomerr */ | ||||
#define GT_ERROR /* #define error gterror */ | ||||
#include <schily/schily.h> | #include <schily/schily.h> | |||
#include <schily/io.h> /* for setmode() prototype */ | #include <schily/io.h> /* for setmode() prototype */ | |||
#include <schily/nlsdefs.h> | ||||
char *n1; | char *n1; | |||
char *n2; | char *n2; | |||
int silent = 0; | int silent = 0; | |||
int allflg = 0; | int allflg = 0; | |||
int lineflg = 0; | int lineflg = 0; | |||
char buf1[8*1024]; | char buf1[8*1024]; | |||
char buf2[8*1024]; | char buf2[8*1024]; | |||
skipping to change at line 107 | skipping to change at line 110 | |||
int prversion = 0; | int prversion = 0; | |||
Llong bpos = 0; | Llong bpos = 0; | |||
Llong bpos1 = 0; | Llong bpos1 = 0; | |||
Llong bpos2 = 0; | Llong bpos2 = 0; | |||
Llong count = 0; | Llong count = 0; | |||
int ex; | int ex; | |||
int cac; | int cac; | |||
char * const * cav; | char * const * cav; | |||
save_args(ac, av); | save_args(ac, av); | |||
(void) setlocale(LC_ALL, ""); | ||||
#ifdef USE_NLS | ||||
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ | ||||
#define TEXT_DOMAIN "compare" /* 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 */ | ||||
cac = --ac; | cac = --ac; | |||
cav = ++av; | cav = ++av; | |||
if (getallargs(&cac, &cav, options, &help, &prversion, | if (getallargs(&cac, &cav, options, &help, &prversion, | |||
&silent, &silent, | &silent, &silent, | |||
getllnum, &bpos, | getllnum, &bpos, | |||
getllnum, &bpos, | getllnum, &bpos, | |||
getllnum, &bpos1, | getllnum, &bpos1, | |||
getllnum, &bpos1, | getllnum, &bpos1, | |||
getllnum, &bpos2, | getllnum, &bpos2, | |||
skipping to change at line 129 | skipping to change at line 154 | |||
getllnum, &count, | getllnum, &count, | |||
&allflg, &allflg, | &allflg, &allflg, | |||
&allflg, &allflg, | &allflg, &allflg, | |||
&lineflg, &lineflg) < 0) { | &lineflg, &lineflg) < 0) { | |||
error("Bad flag: '%s'\n", cav[0]); | error("Bad flag: '%s'\n", cav[0]); | |||
usage(4); | usage(4); | |||
} | } | |||
if (help) | if (help) | |||
usage(0); | usage(0); | |||
if (prversion) { | if (prversion) { | |||
printf("Compare release %s %s (%s-%s-%s) Copyright (C) 1985, 88, | gtprintf("Compare release %s %s (%s-%s-%s) Copyright (C) 1985, 88 | |||
96-99, 2000-2018 Jörg Schilling\n", | , 96-99, 2000-2021 %s\n", | |||
"1.25", "2018/09/27", | "1.27", "2021/08/20", | |||
HOST_CPU, HOST_VENDOR, HOST_OS); | HOST_CPU, HOST_VENDOR, HOST_OS, | |||
_("Jörg Schilling")); | ||||
exit(0); | exit(0); | |||
} | } | |||
if (silent) | if (silent) | |||
allflg = FALSE; | allflg = FALSE; | |||
cac = ac; | cac = ac; | |||
cav = av; | cav = av; | |||
if (getfiles(&cac, &cav, options) <= 0) { | if (getfiles(&cac, &cav, options) <= 0) { | |||
error("No files given.\n"); | error("No files given.\n"); | |||
skipping to change at line 182 | skipping to change at line 208 | |||
if (bpos && bpos2 == 0) | if (bpos && bpos2 == 0) | |||
bpos2 = bpos; | bpos2 = bpos; | |||
ex = fsame(f1, f2); | ex = fsame(f1, f2); | |||
switch (ex) { | switch (ex) { | |||
case -1: | case -1: | |||
/* Cannot stat try do run diff anyway */ | /* Cannot stat try do run diff anyway */ | |||
break; | break; | |||
case 0: | case 0: | |||
if (!silent) | if (!silent) | |||
printf("files are the same\n"); | gtprintf("files are the same\n"); | |||
exit(0); | exit(0); | |||
/* NOTREADCHED */ | /* NOTREADCHED */ | |||
#ifdef Length_is_more_important_than_content | #ifdef Length_is_more_important_than_content | |||
case 1: | case 1: | |||
case 2: | case 2: | |||
if (silent) { | if (silent) { | |||
exit(ex); | exit(ex); | |||
/* NOTREADCHED */ | /* NOTREADCHED */ | |||
} | } | |||
skipping to change at line 326 | skipping to change at line 352 | |||
} else { | } else { | |||
errmsg("Error reading '%s', at %ld (0x%lx)\n", | errmsg("Error reading '%s', at %ld (0x%lx)\n", | |||
n2, (long)pos2, (long)pos2); | n2, (long)pos2, (long)pos2); | |||
} | } | |||
exit(6); | exit(6); | |||
} | } | |||
if (l1 <= 0 || feof(f1)) { | if (l1 <= 0 || feof(f1)) { | |||
if (!feof(f2) && l2 > 0) { | if (!feof(f2) && l2 > 0) { | |||
if (!silent) { | if (!silent) { | |||
if (sizeof (pos1) > sizeof (long)) { | if (sizeof (pos1) > sizeof (long)) { | |||
printf("%s is longer than %s at % lld (0x%llx)\n", | gtprintf("%s is longer than %s at %lld (0x%llx)\n", | |||
n2, n1, (Llong)pos1, (Llo ng)pos1); | n2, n1, (Llong)pos1, (Llo ng)pos1); | |||
} else { | } else { | |||
printf("%s is longer than %s at % ld (0x%lx)\n", | gtprintf("%s is longer than %s at %ld (0x%lx)\n", | |||
n2, n1, (long)pos1, (long )pos1); | n2, n1, (long)pos1, (long )pos1); | |||
} | } | |||
} | } | |||
if (!exitcode) | if (!exitcode) | |||
exitcode = 2; | exitcode = 2; | |||
} | } | |||
break; | break; | |||
} else if (l2 <= 0 || feof(f2)) { | } else if (l2 <= 0 || feof(f2)) { | |||
if (!silent) { | if (!silent) { | |||
if (sizeof (pos1) > sizeof (long)) { | if (sizeof (pos1) > sizeof (long)) { | |||
printf("%s is longer than %s at %lld (0x% llx)\n", | gtprintf("%s is longer than %s at %lld (0 x%llx)\n", | |||
n1, n2, (Llong)pos2, (Llong)pos2) ; | n1, n2, (Llong)pos2, (Llong)pos2) ; | |||
} else { | } else { | |||
printf("%s is longer than %s at %ld (0x%l x)\n", | gtprintf("%s is longer than %s at %ld (0x %lx)\n", | |||
n1, n2, (long)pos2, (long)pos2); | n1, n2, (long)pos2, (long)pos2); | |||
} | } | |||
} | } | |||
if (!exitcode) | if (!exitcode) | |||
exitcode = 1; | exitcode = 1; | |||
break; | break; | |||
} else if (*p1 != *p2) { | } else if (*p1 != *p2) { | |||
if (!silent) { | if (!silent) { | |||
if (lineflg) { | if (lineflg) { | |||
if (sizeof (line) > sizeof (long)) { | if (sizeof (line) > sizeof (long)) { | |||
printf("line: %lld ", (Llong)line ); | gtprintf("line: %lld ", (Llong)li ne); | |||
} else { | } else { | |||
printf("line: %ld ", (long)line); | gtprintf("line: %ld ", (long)line ); | |||
} | } | |||
} | } | |||
if (!allflg) | if (!allflg) | |||
printf("files differ at byte "); | gtprintf("files differ at byte "); | |||
if (pos1 != pos2) { | if (pos1 != pos2) { | |||
if (sizeof (pos1) > sizeof (long)) { | if (sizeof (pos1) > sizeof (long)) { | |||
printf("%6lld (0x%06llx) / %6lld (0x%06 llx)\t0x%02x != 0x%02x%6s%6s", | printf("%6lld (0x%06llx) / %6lld (0x%06 llx)\t0x%02x != 0x%02x%6s%6s", | |||
(Llong)pos1, (Llong)pos1, | (Llong)pos1, (Llong)pos1, | |||
(Llong)pos2, (Llong)pos2, | (Llong)pos2, (Llong)pos2, | |||
*p1, *p2, | *p1, *p2, | |||
printc(*p1, cb1), printc(*p2, cb2 )); | printc(*p1, cb1), printc(*p2, cb2 )); | |||
} else { | } else { | |||
printf("%6ld (0x%06lx) / %6ld (0x%06lx) \t0x%02x != 0x%02x%6s%6s", | printf("%6ld (0x%06lx) / %6ld (0x%06lx) \t0x%02x != 0x%02x%6s%6s", | |||
(long)pos1, (long)pos1, | (long)pos1, (long)pos1, | |||
skipping to change at line 401 | skipping to change at line 427 | |||
l1--; | l1--; | |||
l2--; | l2--; | |||
p1++; | p1++; | |||
p2++; | p2++; | |||
exitcode = 3; | exitcode = 3; | |||
if (!allflg) | if (!allflg) | |||
break; | break; | |||
} | } | |||
} | } | |||
if (!exitcode && !silent) | if (!exitcode && !silent) | |||
printf("files are the same\n"); | gtprintf("files are the same\n"); | |||
exit(exitcode); | exit(exitcode); | |||
} | } | |||
LOCAL char | LOCAL char | |||
*printc(c, bp) | *printc(c, bp) | |||
register int c; | register int c; | |||
char *bp; | char *bp; | |||
{ | { | |||
prc(c, bp); | prc(c, bp); | |||
return (bp); | return (bp); | |||
End of changes. 16 change blocks. | ||||
16 lines changed or deleted | 42 lines changed or added |