aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-02-13 17:22:42 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-02-13 17:22:42 +0100
commit5fe78f574bab097c32738c6abad812f7ec25e79f (patch)
tree78d9d823b53aeb1434a3208b3b5a8dd22d1bf9da /src
parent15e93b55266186c159688e3b54bead26da206ee2 (diff)
Begin work on the Ahoy emulator
Diffstat (limited to 'src')
-rw-r--r--src/ahoy/main.c57
1 files changed, 57 insertions, 0 deletions
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 <fcntl.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#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)
+{
+}