* Copyright (c) 1989, 1993, 1994
* The Regents of the University of California. All rights reserved.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
static char copyright
[] =
"@(#) Copyright (c) 1989, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)comm.c 8.4 (Berkeley) %G%";
#define MAXLINELEN (LINE_MAX + 1)
char *tabs
[] = { "", "\t", "\t\t" };
FILE *file
__P((char *));
void show
__P((FILE *, char *, char *));
int comp
, file1done
, file2done
, read1
, read2
;
int ch
, flag1
, flag2
, flag3
;
char *col1
, *col2
, *col3
;
char **p
, line1
[MAXLINELEN
], line2
[MAXLINELEN
];
flag1
= flag2
= flag3
= 1;
while ((ch
= getopt(argc
, argv
, "-123")) != EOF
)
/* for each column printed, add another tab offset */
col1
= col2
= col3
= NULL
;
for (read1
= read2
= 1;;) {
/* read next line, check for EOF */
file1done
= !fgets(line1
, MAXLINELEN
, fp1
);
file2done
= !fgets(line2
, MAXLINELEN
, fp2
);
/* if one file done, display the rest of the other file */
if (!(comp
= strcmp(line1
, line2
))) {
(void)printf("%s%s", col3
, line1
);
/* lines are different */
(void)printf("%s%s", col1
, line1
);
(void)printf("%s%s", col2
, line2
);
(void)printf("%s%s", offset
, buf
);
} while (fgets(buf
, MAXLINELEN
, fp
));
if ((fp
= fopen(name
, "r")) == NULL
) {
(void)fprintf(stderr
, "comm: %s: %s\n", name
, strerror(errno
));
(void)fprintf(stderr
, "usage: comm [-123] file1 file2\n");