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