mirror of
https://github.com/GnoConsortium/gno.git
synced 2024-11-15 00:05:20 +00:00
initial checkin as provided by Evan Day, except for:
- fixed some rcs identifiers - fixed location shown in describe entry, makefile
This commit is contained in:
parent
dd0de285c3
commit
c22bcee941
34
bin/cmp/Makefile
Normal file
34
bin/cmp/Makefile
Normal file
@ -0,0 +1,34 @@
|
||||
#
|
||||
# This makefile is intended for use with dmake(1) on Apple IIGS
|
||||
#
|
||||
# Created by Dave Tribby, August 1997
|
||||
# Modified by Evan Day, September 1997
|
||||
#
|
||||
# $Id: Makefile,v 1.1 1997/10/03 05:13:22 gdr Exp $
|
||||
|
||||
# Program name
|
||||
PROG= cmp
|
||||
# Source files
|
||||
SRCS= cmp.c misc.c rcmp.c special.c
|
||||
|
||||
# If optimization wasn't set on the command line use 79, since
|
||||
# cmp has been tested to work at that level.
|
||||
.IF $(OPTIMIZE) == $(NULL)
|
||||
OPTIMIZE=79
|
||||
.END
|
||||
|
||||
# Current implementation is using 960 bytes give or take
|
||||
STACK = 1280
|
||||
|
||||
# Installation point
|
||||
BINDIR = /bin
|
||||
|
||||
.INCLUDE : /src/gno/prog.mk
|
||||
|
||||
#
|
||||
# Additional dependancies
|
||||
#
|
||||
cmp.o:: extern.h
|
||||
misc.o:: extern.h
|
||||
rcmp.o:: extern.h
|
||||
special.o:: extern.h
|
114
bin/cmp/cmp.1
Normal file
114
bin/cmp/cmp.1
Normal file
@ -0,0 +1,114 @@
|
||||
.\" Copyright (c) 1987, 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" the Institute of Electrical and Electronics Engineers, Inc.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)cmp.1 8.1 (Berkeley) 6/6/93
|
||||
.\" $Id: cmp.1,v 1.1 1997/10/03 05:13:22 gdr Exp $
|
||||
.\"
|
||||
.TH CMP 1 "28 September 1997" GNO "Commands and Applications"
|
||||
.SH NAME
|
||||
.BR cmp
|
||||
\- compare two files
|
||||
.SH SYNOPSIS
|
||||
.BR cmp " [" -l " | " -s "] ["
|
||||
.BR -r
|
||||
]
|
||||
.IR file1
|
||||
.IR file2
|
||||
[
|
||||
.IR skip1
|
||||
[
|
||||
.IR skip2
|
||||
] ]
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.BR cmp
|
||||
utility compares two files of any type and writes the results
|
||||
to the standard output.
|
||||
By default,
|
||||
.BR cmp
|
||||
is silent if the files are the same; if they differ, the byte
|
||||
and line number at which the first difference occurred is reported.
|
||||
Also by default,
|
||||
.BR cmp
|
||||
also considers the resource forks of the files, and will make note
|
||||
if only one of the files has a resource fork.
|
||||
.PP
|
||||
Bytes and lines are numbered beginning with one.
|
||||
.PP
|
||||
The following options are available:
|
||||
.IP \fB-l\fR
|
||||
Print the byte number (decimal) and the differing
|
||||
byte values (octal) for each difference.
|
||||
.IP \fB-s\fR
|
||||
Print nothing for differing files; return exit
|
||||
status only.
|
||||
.IP \fB-r\fR
|
||||
Ignore resource forks when comparing.
|
||||
.PP
|
||||
The optional arguments
|
||||
.IR skip1
|
||||
and
|
||||
.IR skip2
|
||||
are the byte offsets from the beginning of
|
||||
.IR file1
|
||||
and
|
||||
.IR file2 ,
|
||||
respectively, where the comparison will begin.
|
||||
The offset is decimal by default, but may be expressed as an hexadecimal
|
||||
or octal value by preceding it with a leading ``0x'' or ``0''.
|
||||
.PP
|
||||
The
|
||||
.BR cmp
|
||||
utility exits with one of the following values:
|
||||
.IP \fB0\fR
|
||||
The files are identical.
|
||||
.IP \fB1\fR
|
||||
The files are different; this includes the case
|
||||
where one file is identical to the first part of
|
||||
the other.
|
||||
In the latter case, if the
|
||||
.IR -s
|
||||
option has not been specified,
|
||||
.BR cmp
|
||||
writes to standard output that EOF was reached in the shorter
|
||||
file (before any differences were found).
|
||||
.IP \fB>1\fR
|
||||
An error occurred.
|
||||
.SH SEE ALSO
|
||||
.BR diff(1),
|
||||
.BR diff3(1)
|
||||
.SH HISTORY
|
||||
The
|
||||
.BR cmp
|
||||
command for GNO/ME v2.0.6 is based on FreeBSD source code.
|
243
bin/cmp/cmp.c
Normal file
243
bin/cmp/cmp.c
Normal file
@ -0,0 +1,243 @@
|
||||
/*
|
||||
* Copyright (c) 1987, 1990, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* cmp for GNO/ME v2.0.6
|
||||
*
|
||||
* $Id: cmp.c,v 1.1 1997/10/03 05:13:22 gdr Exp $
|
||||
*/
|
||||
|
||||
#ifndef __GNO__
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1987, 1990, 1993, 1994\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
|
||||
#ifndef __GNO__
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)cmp.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
int lflag, sflag;
|
||||
#ifdef __GNO__
|
||||
int rflag;
|
||||
#endif
|
||||
|
||||
static void usage __P((void));
|
||||
|
||||
#ifdef __STACK_CHECK__
|
||||
#include <gno/gno.h>
|
||||
|
||||
static void cleanup(void)
|
||||
{
|
||||
(void) fprintf(stderr, "%d\n", _endStackCheck());
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
#ifndef __STDC__
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
#else
|
||||
main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
struct stat sb1, sb2;
|
||||
off_t skip1, skip2;
|
||||
int ch, fd1, fd2, special;
|
||||
char *file1, *file2;
|
||||
|
||||
#ifdef __STACK_CHECK__
|
||||
atexit(cleanup);
|
||||
_beginStackCheck();
|
||||
#endif
|
||||
|
||||
#ifdef __GNO__
|
||||
while ((ch = getopt(argc, argv, "-lsr")) != -1)
|
||||
#else
|
||||
while ((ch = getopt(argc, argv, "-ls")) != -1)
|
||||
#endif
|
||||
switch (ch) {
|
||||
case 'l': /* print all differences */
|
||||
lflag = 1;
|
||||
break;
|
||||
case 's': /* silent run */
|
||||
sflag = 1;
|
||||
break;
|
||||
#ifdef __GNO__
|
||||
case 'r':
|
||||
rflag = 1; /* ignore resource fork */
|
||||
break;
|
||||
#endif
|
||||
case '-': /* stdin (must be after options) */
|
||||
--optind;
|
||||
goto endargs;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
endargs:
|
||||
#ifndef __ORCAC__
|
||||
argv += optind;
|
||||
#else
|
||||
argv = argv + optind;
|
||||
#endif
|
||||
argc -= optind;
|
||||
|
||||
if (lflag && sflag)
|
||||
errx(ERR_EXIT, "only one of -l and -s may be specified");
|
||||
|
||||
if (argc < 2 || argc > 4)
|
||||
usage();
|
||||
|
||||
/* Backward compatibility -- handle "-" meaning stdin. */
|
||||
special = 0;
|
||||
if (strcmp(file1 = argv[0], "-") == 0) {
|
||||
special = 1;
|
||||
fd1 = 0;
|
||||
file1 = "stdin";
|
||||
}
|
||||
#ifndef __GNO__
|
||||
else if ((fd1 = open(file1, O_RDONLY, 0)) < 0) {
|
||||
#else
|
||||
/* open() for GNO/ME requires 3rd arg iff creating file */
|
||||
else if ((fd1 = open(file1, O_RDONLY)) < 0) {
|
||||
#endif
|
||||
if (!sflag)
|
||||
err(ERR_EXIT, "%s", file1);
|
||||
else
|
||||
exit(1);
|
||||
}
|
||||
if (strcmp(file2 = argv[1], "-") == 0) {
|
||||
if (special)
|
||||
errx(ERR_EXIT,
|
||||
"standard input may only be specified once");
|
||||
special = 1;
|
||||
fd2 = 0;
|
||||
file2 = "stdin";
|
||||
}
|
||||
#ifndef __GNO__
|
||||
else if ((fd2 = open(file2, O_RDONLY, 0)) < 0) {
|
||||
#else
|
||||
else if ((fd2 = open(file2, O_RDONLY)) < 0) {
|
||||
#endif
|
||||
if (!sflag)
|
||||
err(ERR_EXIT, "%s", file2);
|
||||
else
|
||||
exit(1);
|
||||
}
|
||||
|
||||
skip1 = argc > 2 ? strtol(argv[2], NULL, 10) : 0;
|
||||
skip2 = argc == 4 ? strtol(argv[3], NULL, 10) : 0;
|
||||
|
||||
#ifndef __GNO__
|
||||
if (!special) {
|
||||
if (fstat(fd1, &sb1)) {
|
||||
if (!sflag)
|
||||
err(ERR_EXIT, "%s", file1);
|
||||
else
|
||||
exit(1);
|
||||
}
|
||||
if (!S_ISREG(sb1.st_mode))
|
||||
special = 1;
|
||||
else {
|
||||
if (fstat(fd2, &sb2)) {
|
||||
if (!sflag)
|
||||
err(ERR_EXIT, "%s", file2);
|
||||
else
|
||||
exit(1);
|
||||
}
|
||||
if (!S_ISREG(sb2.st_mode))
|
||||
special = 1;
|
||||
}
|
||||
}
|
||||
#else
|
||||
special = 1; /* GNO doesn't have mmap.h, so treat every file as
|
||||
a special file and process byte by byte */
|
||||
#endif
|
||||
if (special)
|
||||
#ifdef __GNO__
|
||||
{
|
||||
#endif
|
||||
c_special(fd1, file1, skip1, fd2, file2, skip2);
|
||||
#ifdef __GNO__
|
||||
close(fd1);
|
||||
close(fd2);
|
||||
}
|
||||
|
||||
if (rflag != 1) {
|
||||
rflag = 2;
|
||||
rcmp(&fd1, &fd2, file1, file2);
|
||||
close(fd1);
|
||||
close(fd2);
|
||||
}
|
||||
#else
|
||||
else
|
||||
c_regular(fd1, file1, skip1, sb1.st_size,
|
||||
fd2, file2, skip2, sb2.st_size);
|
||||
#endif
|
||||
/* exit(0); */
|
||||
}
|
||||
|
||||
static void
|
||||
#ifndef __STDC__
|
||||
usage()
|
||||
#else
|
||||
usage(void)
|
||||
#endif
|
||||
{
|
||||
|
||||
(void)fprintf(stderr,
|
||||
#ifndef __GNO__
|
||||
"usage: cmp [-l | -s] file1 file2 [skip1 [skip2]]\n");
|
||||
#else
|
||||
"usage: cmp [-l | -s] [-r] file1 file2 [skip1 [skip2]]\n");
|
||||
#endif
|
||||
exit(ERR_EXIT);
|
||||
}
|
10
bin/cmp/cmp.desc
Normal file
10
bin/cmp/cmp.desc
Normal file
@ -0,0 +1,10 @@
|
||||
Name: cmp
|
||||
Version: 2.0 (4 Aug 97)
|
||||
Shell: GNO/ME
|
||||
Author: Evan Day (from FreeBSD source)
|
||||
Contact: day@engr.orst.edu
|
||||
Where: /bin
|
||||
FTP:
|
||||
|
||||
cmp compares and reports differences in the dataforks and resource forks
|
||||
of two files.
|
33
bin/cmp/cmp.rez
Normal file
33
bin/cmp/cmp.rez
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* $Id: cmp.rez,v 1.1 1997/10/03 05:13:23 gdr Exp $
|
||||
*/
|
||||
#include "Types.Rez"
|
||||
#include "proginfo.rez"
|
||||
|
||||
resource rVersion (0x1, purgeable3, nocrossbank) {
|
||||
|
||||
{ 2, 0, 0, /* version 1.0.0 */
|
||||
release, /* development|alpha|beta|final|release */
|
||||
0 /* non-final release number */
|
||||
},
|
||||
verUS, /* country code -- only some are avail */
|
||||
"cmp", /* name */
|
||||
/* _Very_ brief descrition. Check "file info" */
|
||||
/* shown in the Finder to see if it's too long */
|
||||
/* Note that \n is used to separate lines here. */
|
||||
"Compares two files on disk.\n"
|
||||
"Requires GNO/ME Shell.\n"
|
||||
"Evan Day <day@engr.orst.edu>"
|
||||
};
|
||||
|
||||
resource rProgramInfo (0x1, purgeable3, nocrossbank) {
|
||||
{ 6, 0, 1,
|
||||
release,
|
||||
0
|
||||
},
|
||||
30270,
|
||||
32768,
|
||||
1280,
|
||||
progRequiresGNO+progAppleTalkOK+progAllowsCDAs,
|
||||
piCompatible*ProgShellGSH+piSpecialFeatures*ProgShellGSH
|
||||
};
|
51
bin/cmp/extern.h
Normal file
51
bin/cmp/extern.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)extern.h 8.3 (Berkeley) 4/2/94
|
||||
*/
|
||||
|
||||
#define OK_EXIT 0
|
||||
#define DIFF_EXIT 1
|
||||
#define ERR_EXIT 2 /* error exit code */
|
||||
|
||||
void c_regular __P((int, char *, off_t, off_t, int, char *, off_t, off_t));
|
||||
void c_special __P((int, char *, off_t, int, char *, off_t));
|
||||
void diffmsg __P((char *, char *, off_t, off_t));
|
||||
void eofmsg __P((char *));
|
||||
#ifdef __GNO__
|
||||
void rcmp __P((int *, int *, char *, char *));
|
||||
#endif
|
||||
|
||||
extern int lflag, sflag;
|
||||
#ifdef __GNO__
|
||||
extern int rflag;
|
||||
#endif
|
85
bin/cmp/misc.c
Normal file
85
bin/cmp/misc.c
Normal file
@ -0,0 +1,85 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* part of cmp for GNO/ME v2.0.6
|
||||
*
|
||||
* $Id: misc.c,v 1.1 1997/10/03 05:13:23 gdr Exp $
|
||||
*/
|
||||
|
||||
#ifndef __GNO__
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
void
|
||||
#ifndef __STDC__
|
||||
eofmsg(file)
|
||||
char *file;
|
||||
#else
|
||||
eofmsg(char *file)
|
||||
#endif
|
||||
{
|
||||
if (!sflag)
|
||||
warnx("EOF on %s", file);
|
||||
exit(DIFF_EXIT);
|
||||
}
|
||||
|
||||
void
|
||||
#ifndef __STDC__
|
||||
diffmsg(file1, file2, byte, line)
|
||||
char *file1, *file2;
|
||||
off_t byte, line;
|
||||
#else
|
||||
diffmsg(char *file1, char *file2, off_t byte, off_t line)
|
||||
#endif
|
||||
{
|
||||
if (!sflag)
|
||||
#ifndef __ORCAC__
|
||||
(void)printf("%s %s differ: char %qd, line %qd\n",
|
||||
file1, file2, byte, line);
|
||||
#else
|
||||
(void)printf("[%s] %s differ: %s char %ld, line %ld\n",
|
||||
(rflag==2) ? "resfork" : "datafork", file1, file2, byte, line);
|
||||
#endif
|
||||
exit(DIFF_EXIT);
|
||||
}
|
52
bin/cmp/rcmp.c
Normal file
52
bin/cmp/rcmp.c
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* rcmp.c
|
||||
*
|
||||
* Opens the resource forks of two files and sets the file descriptors to
|
||||
* the open forks (if present).
|
||||
*
|
||||
* Catches files with no resource fork.
|
||||
*
|
||||
* Part of cmp for GNO/ME v2.0.6
|
||||
*
|
||||
* $Id: rcmp.c,v 1.1 1997/10/03 05:13:23 gdr Exp $
|
||||
*/
|
||||
|
||||
#include <gsos.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "extern.h"
|
||||
|
||||
static GSString255 path;
|
||||
|
||||
void rcmp(int *fd1, int *fd2, char *file1, char *file2)
|
||||
{
|
||||
OpenRecGS ropen = {4, 0, &path, readEnable, 1};
|
||||
|
||||
strcpy(path.text, file1);
|
||||
path.length = strlen(file1);
|
||||
OpenGS(&ropen);
|
||||
*fd1 = ropen.refNum;
|
||||
|
||||
strcpy(path.text, file2);
|
||||
path.length = strlen(file2);
|
||||
OpenGS(&ropen);
|
||||
*fd2 = ropen.refNum;
|
||||
|
||||
if(*fd1 == 0)
|
||||
if(*fd2 == 0)
|
||||
return;
|
||||
else {
|
||||
(void) printf("%s has a resource fork, %s does not.\n",
|
||||
file2, file1);
|
||||
return;
|
||||
}
|
||||
else if(*fd2 == 0) {
|
||||
(void) printf("%s has a resource fork, %s does not.\n", file1,
|
||||
file2);
|
||||
return;
|
||||
}
|
||||
|
||||
c_special(*fd1, file1, 0, *fd2, file2, 0);
|
||||
}
|
156
bin/cmp/regular.c
Normal file
156
bin/cmp/regular.c
Normal file
@ -0,0 +1,156 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: regular.c,v 1.1 1997/10/03 05:13:23 gdr Exp $
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)regular.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#ifndef __GNO__
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
#define ROUNDPAGE(i) ((i) & ~pagemask)
|
||||
|
||||
void
|
||||
#ifndef __STDC__
|
||||
c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2)
|
||||
int fd1, fd2;
|
||||
char *file1, *file2;
|
||||
off_t skip1, len1, skip2, len2;
|
||||
#else
|
||||
c_regular(int fd1, char *file1, off_t skip1, off_t len1, int fd2, char *file2,
|
||||
off_t skip2, off_t len2)
|
||||
#endif
|
||||
{
|
||||
#ifndef __GNO__
|
||||
u_char ch, *p1, *p2;
|
||||
#else
|
||||
u_char ch, p1, p2;
|
||||
#endif
|
||||
off_t byte, length, line;
|
||||
int dfound;
|
||||
off_t pagemask, off1, off2;
|
||||
|
||||
if (sflag && len1 != len2)
|
||||
exit(1);
|
||||
|
||||
if (skip1 > len1)
|
||||
eofmsg(file1);
|
||||
len1 -= skip1;
|
||||
if (skip2 > len2)
|
||||
eofmsg(file2);
|
||||
len2 -= skip2;
|
||||
|
||||
pagemask = (off_t)getpagesize() - 1;
|
||||
off1 = ROUNDPAGE(skip1);
|
||||
off2 = ROUNDPAGE(skip2);
|
||||
|
||||
length = MIN(len1, len2);
|
||||
#ifndef __ORCAC__
|
||||
if (length > SIZE_T_MAX)
|
||||
return (c_special(fd1, file1, skip1, fd2, file2, skip2));
|
||||
#else
|
||||
if (length > SIZE_T_MAX) {
|
||||
c_special(fd1, file1, skip1, fd2, file2, skip2);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __GNO__
|
||||
if ((p1 = (u_char *)mmap(NULL,
|
||||
(size_t)length, PROT_READ, MAP_SHARED, fd1, off1)) == (u_char *)MAP_FAILED)
|
||||
err(ERR_EXIT, "%s", file1);
|
||||
|
||||
madvise(p1, length, MADV_SEQUENTIAL);
|
||||
if ((p2 = (u_char *)mmap(NULL,
|
||||
(size_t)length, PROT_READ, MAP_SHARED, fd2, off2)) == (u_char *)MAP_FAILED)
|
||||
err(ERR_EXIT, "%s", file2);
|
||||
madvise(p2, length, MADV_SEQUENTIAL);
|
||||
|
||||
dfound = 0;
|
||||
p1 += skip1 - off1;
|
||||
p2 += skip2 - off2;
|
||||
for (byte = line = 1; length--; ++p1, ++p2, ++byte) {
|
||||
if ((ch = *p1) != *p2)
|
||||
if (lflag) {
|
||||
dfound = 1;
|
||||
(void)printf("%6qd %3o %3o\n", byte, ch, *p2);
|
||||
} else
|
||||
diffmsg(file1, file2, byte, line);
|
||||
/* NOTREACHED */
|
||||
if (ch == '\n')
|
||||
++line;
|
||||
}
|
||||
|
||||
if (len1 != len2)
|
||||
eofmsg (len1 > len2 ? file2 : file1);
|
||||
if (dfound)
|
||||
exit(DIFF_EXIT);
|
||||
#else
|
||||
dfound = 0;
|
||||
lseek(fd1, skip1, SEEK_SET);
|
||||
lseek(fd2, skip2, SEEK_SET);
|
||||
for (byte = line = 1; length--; ++byte) {
|
||||
read(fd1, (void *) &p1, 1);
|
||||
read(fd2, (void *) &p2, 1);
|
||||
if (p1 != p2)
|
||||
if (lflag) {
|
||||
dfound = 1;
|
||||
(void)printf("%6qd %3o %3o\n", byte, ch, p2);
|
||||
} else
|
||||
diffmsg(file1, file2, byte, line);
|
||||
/* NOTREACHED */
|
||||
if (p1 == '\n')
|
||||
++line;
|
||||
}
|
||||
|
||||
if (len1 != len2)
|
||||
eofmsg (len1 > len2 ? file2 : file1);
|
||||
if (dfound)
|
||||
exit(DIFF_EXIT);
|
||||
#endif
|
||||
|
||||
}
|
116
bin/cmp/special.c
Normal file
116
bin/cmp/special.c
Normal file
@ -0,0 +1,116 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Part of cmp for GNO/ME v2.0.6
|
||||
*
|
||||
* $Id: special.c,v 1.1 1997/10/03 05:13:23 gdr Exp $
|
||||
*/
|
||||
|
||||
#ifndef __GNO__
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)special.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
void
|
||||
#ifndef __STDC__
|
||||
c_special(fd1, file1, skip1, fd2, file2, skip2)
|
||||
int fd1, fd2;
|
||||
char *file1, *file2;
|
||||
off_t skip1, skip2;
|
||||
#else
|
||||
c_special(int fd1, char *file1, off_t skip1, int fd2, char *file2, off_t skip2)
|
||||
#endif
|
||||
{
|
||||
int ch1, ch2;
|
||||
off_t byte, line;
|
||||
FILE *fp1, *fp2;
|
||||
int dfound;
|
||||
|
||||
if ((fp1 = fdopen(fd1, "r")) == NULL)
|
||||
err(ERR_EXIT, "%s", file1);
|
||||
if ((fp2 = fdopen(fd2, "r")) == NULL)
|
||||
err(ERR_EXIT, "%s", file2);
|
||||
|
||||
dfound = 0;
|
||||
while (skip1--)
|
||||
if (getc(fp1) == EOF)
|
||||
goto eof;
|
||||
while (skip2--)
|
||||
if (getc(fp2) == EOF)
|
||||
goto eof;
|
||||
|
||||
for (byte = line = 1;; ++byte) {
|
||||
ch1 = getc(fp1);
|
||||
ch2 = getc(fp2);
|
||||
if (ch1 == EOF || ch2 == EOF)
|
||||
break;
|
||||
if (ch1 != ch2) {
|
||||
if (lflag) {
|
||||
dfound = 1;
|
||||
#ifndef __GNO__
|
||||
(void)printf("%6qd %3o %3o\n", byte, ch1, ch2);
|
||||
#else
|
||||
(void)printf("%c%6ld %3o %3o\n", (rflag==2)? 'R' : 'D', byte, ch1, ch2);
|
||||
#endif
|
||||
} else
|
||||
diffmsg(file1, file2, byte, line);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
if (ch1 == '\n')
|
||||
++line;
|
||||
}
|
||||
|
||||
eof: if (ferror(fp1))
|
||||
err(ERR_EXIT, "%s", file1);
|
||||
if (ferror(fp2))
|
||||
err(ERR_EXIT, "%s", file2);
|
||||
if (feof(fp1)) {
|
||||
if (!feof(fp2))
|
||||
eofmsg(file1);
|
||||
} else
|
||||
if (feof(fp2))
|
||||
eofmsg(file2);
|
||||
if (dfound)
|
||||
exit(DIFF_EXIT);
|
||||
}
|
Loading…
Reference in New Issue
Block a user