summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLieuwe Rooijakkers <lieuwerooijakkers@gmail.com>2024-07-13 22:07:53 +0200
committerLieuwe Rooijakkers <lieuwerooijakkers@gmail.com>2024-07-13 22:07:56 +0200
commit712530e52091520f8f2bf347dc9ecb4030d9c4ed (patch)
tree85fac1003e8e2b6f4722ca8ddf584612c42ed119 /src
parent582a7567c8004eab1257aae29b96804425f8ee3d (diff)
tak
Diffstat (limited to 'src')
-rw-r--r--src/tak.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/tak.c b/src/tak.c
new file mode 100644
index 0000000..dc3eda5
--- /dev/null
+++ b/src/tak.c
@@ -0,0 +1,48 @@
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "util/map.h"
+
+int entry_tak(int argc, char **argv) {
+ if (argc == 2 && strcmp(argv[1], "-h") == 0) {
+ fprintf(stderr, "Gebruik: tak [BESTAND]...\n"
+ "\n"
+ "Schakel BESTAND(en) aaneen naar standaard uitvoer omgekeerd..\n");
+ return 0;
+ }
+
+ for (int i = argc-1; i >= 1; i--) {
+ const char *fname = argv[i];
+ struct map *map = open_map(fname);
+
+ char *lstart, *lend;
+ lend = &map->addr[map->sb.st_size - 1];
+
+ while (lend > map->addr) {
+ if (*lend == '\n') {
+ lend--;
+ }
+
+ lstart = lend;
+ while (*lstart != '\n' && lstart != map->addr) {
+ lstart--;
+ }
+ if (lstart != map->addr) {
+ lstart++;
+ }
+
+ printf("%.*s\n", lend - lstart + 1, lstart);
+
+ lend = lstart-1;
+ }
+
+ close_map(map);
+ }
+
+ return 0;
+}