diff options
-rw-r--r-- | src/tak.c | 48 |
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; +} |