/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1992-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* David Korn
* Glenn Fowler
* AT&T Bell Laboratories
*
* cmp
*/
static const char usage[] =
"[-?\n@(#)$Id: cmp (AT&T Research) 2009-01-05 $\n]"
"[+NAME?cmp - compare two files]"
"[+DESCRIPTION?\bcmp\b compares two files \afile1\a and \afile2\a. "
"\bcmp\b writes no output if the files are the same. By default, "
"if the files differ, the byte and line number at which the "
"first difference occurred are written to standard output. Bytes "
"and lines are numbered beginning with 1.]"
"[+?If \askip1\a or \askip2\a are specified, or the \b-i\b option is "
"specified, initial bytes of the corresponding file are skipped "
"before beginning the compare. The skip values are in bytes or "
"can have a suffix of \bk\b for kilobytes or \bm\b for megabytes.]"
"[+?If either \afile1\a or \afiles2\a is \b-\b, \bcmp\b "
"uses standard input starting at the current location.]"
"[c:print-chars?Writes control characters as a \b^\b followed by a letter of "
"the alphabet and precede characters that have the high bit set with "
"\bM-\b as with \bcat\b(1).]"
"[i:ignore-initial]#[skip:=0?Sets default skip values for the operands "
"\askip1\a and \askip2\a to \askip\a.]"
"[l:verbose?Write the decimal byte number and the differing bytes (in octal) "
"for each difference.]"
"[s:quiet|silent?Write nothing for differing files; return non-zero "
"exit status only.] ]"
"\n"
"\nfile1 file2 [skip1 [skip2]]\n"
"\n"
"[+EXIT STATUS?]{"
"[+0?The files or portions compared are identical.]"
"[+1?The files are different.]"
"[+>1?An error occurred.]"
"}"
"[+SEE ALSO?\bcomm\b(1), \bdiff\b(1), \bcat\b(1)]"
;
#include <cmd.h>
#include <ls.h>
#include <ctype.h>
{
if(c&0200)
{
c &= ~0200;
}
else if(!isprint(c))
{
c = printchar(c);
}
}
/*
* compare two files
*/
static int
{
register int c1;
register int c2;
register unsigned char* p1 = 0;
register unsigned char* p2 = 0;
register unsigned char* e1 = 0;
register unsigned char* e2 = 0;
int ret = 0;
unsigned char* last;
for (;;)
{
{
{
{
ret = 1;
if (!(flags & CMP_SILENT))
}
return(ret);
}
}
{
{
if (!(flags & CMP_SILENT))
return(1);
}
}
if (flags & CMP_SILENT)
{
return(1);
}
else
{
{
{
if (flags)
{
ret = 1;
{
}
else
}
else
{
sfprintf(sfstdout, "%s %s differ: char %I*d, line %I*u\n", file1, file2, sizeof(pos), pos - (last - p1), sizeof(lines), lines);
return(1);
}
}
if (c1 == '\n')
lines++;
}
}
}
}
int
{
char* s;
char* e;
char* file1;
char* file2;
int n;
int flags = 0;
{
case 'l':
flags |= CMP_VERBOSE;
break;
case 's':
flags |= CMP_SILENT;
break;
case 'c':
break;
case 'i':
break;
case ':':
break;
case '?':
break;
}
n = 2;
{
if (!(flags & CMP_SILENT))
goto done;
}
{
if (!(flags & CMP_SILENT))
goto done;
}
if (s = *argv++)
{
if (*e)
{
goto done;
}
if (s = *argv++)
{
if (*e)
{
goto done;
}
}
if (*argv)
{
goto done;
}
}
{
if (!(flags & CMP_SILENT))
n = 1;
goto done;
}
{
if (!(flags & CMP_SILENT))
n = 1;
goto done;
}
n = 0;
else
n = ((flags & CMP_SILENT) && S_ISREG(s1.st_mode) && S_ISREG(s2.st_mode) && (s1.st_size - o1) != (s2.st_size - o2)) ? 1 : cmp(file1, f1, file2, f2, flags);
done:
return(n);
}