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