sbase/cat.c

46 lines
750 B
C
Raw Normal View History

2011-05-22 21:36:34 -04:00
/* See LICENSE file for copyright and license details. */
#include <stdio.h>
2011-05-24 06:05:36 -04:00
#include <unistd.h>
2011-05-26 13:18:42 -04:00
#include "text.h"
2011-05-22 21:36:34 -04:00
#include "util.h"
static void
usage(void)
{
eprintf("usage: %s [-u] [file ...]\n", argv0);
}
2011-05-22 21:36:34 -04:00
int
main(int argc, char *argv[])
{
FILE *fp;
int ret = 0;
2011-05-22 21:36:34 -04:00
2012-05-31 14:38:18 -04:00
ARGBEGIN {
case 'u':
setbuf(stdout, NULL);
break;
2012-05-31 14:38:18 -04:00
default:
usage();
2012-05-31 14:38:18 -04:00
} ARGEND;
2015-03-16 05:36:36 -04:00
if (!argc) {
2011-05-26 13:18:42 -04:00
concat(stdin, "<stdin>", stdout, "<stdout>");
2014-04-22 06:43:01 -04:00
} else {
for (; *argv; argc--, argv++) {
if ((*argv)[0] == '-' && !(*argv)[1]) {
concat(stdin, "<stdin>", stdout, "<stdout>");
} else if (!(fp = fopen(*argv, "r"))) {
weprintf("fopen %s:", *argv);
ret = 1;
} else {
concat(fp, *argv, stdout, "<stdout>");
fclose(fp);
2014-04-22 06:43:01 -04:00
}
}
2011-05-22 21:36:34 -04:00
}
return ret;
2011-05-22 21:36:34 -04:00
}