From 712530e52091520f8f2bf347dc9ecb4030d9c4ed Mon Sep 17 00:00:00 2001 From: Lieuwe Rooijakkers Date: Sat, 13 Jul 2024 22:07:53 +0200 Subject: tak --- src/tak.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/tak.c 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 +#include +#include +#include +#include +#include +#include + +#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; +} -- cgit v1.2.3-70-g09d2