2013-06-18 10:19:47 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-11-13 17:29:30 +00:00
|
|
|
|
2013-06-18 10:19:47 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2013-06-19 19:09:50 +00:00
|
|
|
static int show = 0x07;
|
2013-06-18 10:19:47 +00:00
|
|
|
|
2015-01-17 23:07:29 +00:00
|
|
|
static void
|
|
|
|
printline(int pos, char *line)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!(show & (0x1 << pos)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < pos; i++) {
|
|
|
|
if (show & (0x1 << i))
|
|
|
|
putchar('\t');
|
|
|
|
}
|
2015-03-11 12:39:08 +00:00
|
|
|
fputs(line, stdout);
|
2015-01-17 23:07:29 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 10:19:47 +00:00
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
eprintf("usage: %s [-123] file1 file2\n", argv0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2013-06-19 19:09:50 +00:00
|
|
|
FILE *fp[2];
|
2015-03-11 12:39:08 +00:00
|
|
|
size_t linelen[2] = { 0, 0 };
|
|
|
|
int i, diff = 0;
|
|
|
|
char *line[2] = { NULL, NULL };
|
2013-06-18 10:19:47 +00:00
|
|
|
|
|
|
|
ARGBEGIN {
|
|
|
|
case '1':
|
|
|
|
case '2':
|
|
|
|
case '3':
|
2013-06-19 19:09:50 +00:00
|
|
|
show &= 0x07 ^ (1 << (ARGC() - '1'));
|
2013-06-18 10:19:47 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
2014-11-13 17:29:30 +00:00
|
|
|
if (argc != 2)
|
2013-06-18 10:19:47 +00:00
|
|
|
usage();
|
|
|
|
|
2015-03-11 12:39:08 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (argv[i][0] == '-' && !argv[i][1]) {
|
|
|
|
argv[i] = "<stdin>";
|
|
|
|
fp[i] = stdin;
|
|
|
|
} else if (!(fp[i] = fopen(argv[i], "r"))) {
|
2014-11-17 16:22:01 +00:00
|
|
|
eprintf("fopen %s:", argv[i]);
|
2015-03-11 12:39:08 +00:00
|
|
|
}
|
2013-06-19 19:09:50 +00:00
|
|
|
}
|
2013-06-18 10:19:47 +00:00
|
|
|
|
2014-11-13 17:29:30 +00:00
|
|
|
for (;;) {
|
2015-03-11 12:39:08 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (diff && i == (diff < 0))
|
|
|
|
continue;
|
|
|
|
if (getline(&line[i], &linelen[i], fp[i]) >= 0)
|
|
|
|
continue;
|
|
|
|
if (ferror(fp[i]))
|
|
|
|
eprintf("getline %s:", argv[i]);
|
|
|
|
if (diff && strlen(line[!i]))
|
|
|
|
printline(!i, line[!i]);
|
|
|
|
while (getline(&line[!i], &linelen[!i], fp[!i]) >= 0)
|
|
|
|
printline(!i, line[!i]);
|
|
|
|
if (ferror(fp[!i]))
|
|
|
|
eprintf("getline %s:", argv[!i]);
|
|
|
|
goto end;
|
2013-06-19 19:09:50 +00:00
|
|
|
}
|
2015-03-11 12:39:08 +00:00
|
|
|
diff = strcmp(line[0], line[1]);
|
|
|
|
LIMIT(diff, -1, 1);
|
|
|
|
printline((2-diff) % 3, line[MAX(0, diff)]);
|
2013-06-19 19:09:50 +00:00
|
|
|
}
|
2015-03-11 12:39:08 +00:00
|
|
|
end:
|
2014-10-02 22:46:04 +00:00
|
|
|
return 0;
|
2013-06-18 10:19:47 +00:00
|
|
|
}
|