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