Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Challenge:reimplement UNIX cat

Name: Anonymous 2015-02-23 16:31

Most elegant solution wins
reference bloated cats: https://gist.github.com/pete/665971

Name: Anonymous 2015-07-11 18:57

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "text.h"
#include "util.h"

static void
usage(void)
{
eprintf("usage: %s [-u] [file ...]\n", argv0);
}

int
main(int argc, char *argv[])
{
FILE *fp;
int ret = 0;

ARGBEGIN {
case 'u':
setbuf(stdout, NULL);
break;
default:
usage();
} ARGEND;

if (!argc) {
concat(stdin, "<stdin>", stdout, "<stdout>");
} 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;
}
concat(fp, *argv, stdout, "<stdout>");
if (fp != stdin && fshut(fp, *argv))
ret = 1;
}
}

ret |= fshut(stdin, "<stdin>") | fshut(stdout, "<stdout>");

return ret;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List