summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-07-19 13:38:42 -0400
committerJakob Kaivo <jkk@ung.org>2019-07-19 13:38:42 -0400
commitd86fd0355077448f4a07778c7a60bfc168f2e1bf (patch)
tree65c1e279634593c3390a8f1e0a4b9d2f8c61ab8c
parent47a013aa7dec796e9a87bf10ca5e3f4ed5d8e4db (diff)
outline C program
-rw-r--r--tac0
-rw-r--r--tac.c45
2 files changed, 45 insertions, 0 deletions
diff --git a/tac b/tac
deleted file mode 100644
index e69de29..0000000
--- a/tac
+++ /dev/null
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 <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;
+}