sbase/cat.c

51 lines
845 B
C
Raw Normal View History

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