diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-07-19 13:38:42 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-07-19 13:38:42 -0400 |
commit | d86fd0355077448f4a07778c7a60bfc168f2e1bf (patch) | |
tree | 65c1e279634593c3390a8f1e0a4b9d2f8c61ab8c | |
parent | 47a013aa7dec796e9a87bf10ca5e3f4ed5d8e4db (diff) |
outline C program
-rw-r--r-- | tac | 0 | ||||
-rw-r--r-- | tac.c | 45 |
2 files changed, 45 insertions, 0 deletions
@@ -0,0 +1,45 @@ +#define _POSIX_C_SOURCE 200809L +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +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; +} |