From 512def0747a237976b045175d271d41280de8b15 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Fri, 19 Jul 2019 13:47:40 -0400 Subject: on second thought, an AWK script is fine --- tac | 12 ++++++++++++ tac.c | 45 --------------------------------------------- 2 files changed, 12 insertions(+), 45 deletions(-) create mode 100755 tac delete mode 100644 tac.c diff --git a/tac b/tac new file mode 100755 index 0000000..d4261a7 --- /dev/null +++ b/tac @@ -0,0 +1,12 @@ +cat "$@" | awk "$(tail -n +3 $0)" +exit $? + +{ + lines[NR] = $0; +} + +END { + for (i = NR; i > 0; i--) { + print lines[i] + } +} diff --git a/tac.c b/tac.c deleted file mode 100644 index 088ebda..0000000 --- a/tac.c +++ /dev/null @@ -1,45 +0,0 @@ -#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