From d86fd0355077448f4a07778c7a60bfc168f2e1bf Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Fri, 19 Jul 2019 13:38:42 -0400 Subject: outline C program --- tac | 0 tac.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) delete mode 100644 tac create mode 100644 tac.c diff --git a/tac b/tac deleted file mode 100644 index e69de29..0000000 diff --git a/tac.c b/tac.c new file mode 100644 index 0000000..088ebda --- /dev/null +++ b/tac.c @@ -0,0 +1,45 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include + +struct line { + struct line *prev; + struct line *next; + char *line; +}; + +int tac(const char *path) +{ + FILE *f = stdin; + if (path && strcmp(path, "-") != 0) { + f = fopen(path, "r"); + if (f == NULL) { + perror("tac:fopen"); + } + } + + /* read lines into doubly-linked list */ + /* print lines in reverse order */ + + if (f != stdin) { + fclose(f); + } + + return 0; +} + +int main(int argc, char *argv[]) +{ + while (getopt(argc, argv, "") != -1) { + /* no options supported */ + return 1; + } + + int ret = 0; + do { + ret |= tac(argv[optind]); + } while (argv[++optind]); + return 1; +} -- cgit v1.2.1