commit 1338dcdb67113c73ec12c0e7cdce8ba093d2e7f5
parent e1b1d240acc5248539c2d0139bfa4fb0d8b2f22a
Author: Mario Rosell R. Martinez <mario@mariorosell.es>
Date: Fri, 3 Apr 2026 14:44:22 +0200
cli: add rudimentary cli
Diffstat:
| A | cli.c | | | 85 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | cli.h | | | 6 | ++++++ |
| A | stat.c | | | 6 | ++++++ |
| A | stat.h | | | 7 | +++++++ |
4 files changed, 104 insertions(+), 0 deletions(-)
diff --git a/cli.c b/cli.c
@@ -0,0 +1,85 @@
+/*
+ * cli.h -- cli
+ */
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "stat.h"
+
+static void
+help(char* argv0)
+{
+ printf("slash: usage: %s [-o output] [-s asm] src\n", argv0);
+ puts("* -o OUTPUT\tset the output binary. . Default is ./a.out");
+ puts("* -s ASM\tset the output assembly file. - for stdout. Default is /dev/null");
+ puts("* src\t\tthe source file");
+}
+
+void
+cli(int argc, char** argv)
+{
+ bool in_opts = true;
+ char *src = NULL;
+
+ for (int i = 1; i < argc; i++) {
+ char *arg = argv[i];
+
+ if (in_opts && arg[0] == '-' && arg[1] != '\0') {
+
+ for (size_t ii = 1; arg[ii] != '\0'; ii++) {
+ switch (arg[ii]) {
+
+ case 'h':
+ help(argv[0]);
+ exit(EXIT_SUCCESS);
+
+ case 'v':
+ printf("slash %s\n", VERSION);
+ exit(EXIT_SUCCESS);
+
+ case 'o':
+ if (i + 1 >= argc) {
+ fprintf(stderr,
+ "ttmxm: missing argument for -o\n");
+ exit(2);
+ }
+ snprintf(s_file, sizeof(s_file), "%s", argv[++i]);
+ break;
+
+ case 's':
+ break;
+
+ default:
+ fprintf(stderr,
+ "ttmxm: unknown flag: -%c\n", arg[ii]);
+ help(argv[0]);
+ exit(2);
+ }
+ }
+
+ } else {
+ in_opts = false;
+
+ if (src != NULL) {
+ fprintf(stderr,
+ "ttmxm: too many input files\n");
+ exit(2);
+ }
+
+ src = arg;
+ }
+ }
+
+ if (src == NULL) {
+ fprintf(stderr, "ttmxm: missing input file\n");
+ help(argv[0]);
+ exit(2);
+ }
+
+ /* TODO: store src */
+}
+
diff --git a/cli.h b/cli.h
@@ -0,0 +1,6 @@
+/*
+ * cli.h -- cli() function
+ */
+
+void cli(int, char**);
+
diff --git a/stat.c b/stat.c
@@ -0,0 +1,6 @@
+/*
+ * stat.c -- fuck c
+ */
+
+char s_file[512];
+
diff --git a/stat.h b/stat.h
@@ -0,0 +1,7 @@
+/*
+ * stat.h -- status
+ */
+
+/* current file */
+extern char s_file[512];
+