* Copyright (c) 1989 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)comm.c 5.6 (Berkeley) %G%";
#define MAXLINELEN (_POSIX2_LINE_MAX + 1)
char *tabs
[] = { "", "\t", "\t\t" };
register int comp
, file1done
, file2done
, read1
, read2
;
register char *col1
, *col2
, *col3
;
int ch
, flag1
, flag2
, flag3
;
FILE *fp1
, *fp2
, *file();
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 */
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"))) {
(void)fprintf(stderr
, "comm: can't read %s.\n", name
);
(void)fprintf(stderr
, "usage: comm [-123] [ - ] file1 file2\n");