Files
sbase/cat.c

48 lines
730 B
C
Raw Normal View History

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