From 5fe78f574bab097c32738c6abad812f7ec25e79f Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Tue, 13 Feb 2024 17:22:42 +0100 Subject: Begin work on the Ahoy emulator --- src/ahoy/main.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/ahoy/main.c (limited to 'src') diff --git a/src/ahoy/main.c b/src/ahoy/main.c new file mode 100644 index 0000000..8cc7106 --- /dev/null +++ b/src/ahoy/main.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +#include + +#include "cerr.h" +#include "macros.h" + +static void run(int, const char *); + +int +main(int argc, char **argv) +{ + int opt; + const struct option longopts[] = { + {"help", no_argument, nullptr, 'h'}, + {nullptr, no_argument, nullptr, 0 }, + }; + + cerrinit(*argv); + while ((opt = getopt_long(argc, argv, "h", longopts, nullptr)) != -1) { + switch (opt) { + case 'h': + execlp("man", "man", "1", argv[0], nullptr); + die("execlp: man 1 %s", argv[0]); + default: + fprintf(stderr, "Usage: %s [file ...]\n", argv[0]); + exit(EXIT_FAILURE); + } + } + + argc -= optind; + argv += optind; + + if (!argc) + run(STDIN_FILENO, "-"); + for (int i = 0; i < argc; i++) { + if (streq("-", argv[i])) + run(STDIN_FILENO, "-"); + else { + int fd; + if ((fd = open(argv[i], O_RDONLY)) == -1) + die("open: %s", argv[i]); + run(fd, argv[i]); + close(fd); + } + } + + return EXIT_SUCCESS; +} + +void +run([[maybe_unused]] int fd, [[maybe_unused]] const char *fn) +{ +} -- cgit v1.2.3