/* See LICENSE file for copyright and license details. */ #include #include #include #include "text.h" #include "util.h" static void uconcat(FILE *fp1, const char *s1, FILE *fp2, const char *s2) { int c; setbuf(fp2, NULL); while ((c = getc(fp1)) != EOF) putc(c, fp2); } static void usage(void) { eprintf("usage: %s [-u] [file ...]\n", argv0); } int main(int argc, char *argv[]) { FILE *fp; int ret = 0; void (*cat)(FILE *, const char *, FILE *, const char *) = &concat; ARGBEGIN { case 'u': cat = &uconcat; break; default: usage(); } ARGEND if (!argc) { cat(stdin, "", stdout, ""); } else { for (; *argv; argc--, argv++) { if (!strcmp(*argv, "-")) { *argv = ""; fp = stdin; } else if (!(fp = fopen(*argv, "r"))) { weprintf("fopen %s:", *argv); ret = 1; continue; } cat(fp, *argv, stdout, ""); if (fp != stdin && fshut(fp, *argv)) ret = 1; } } ret |= fshut(stdin, "") | fshut(stdout, ""); return ret; }