about summary refs log tree commit diff
path: root/src/main.c
diff options
context:
space:
mode:
authorNakidai <plaza521@inbox.ru>2024-07-05 00:04:56 +0300
committerNakidai <plaza521@inbox.ru>2024-07-05 00:04:56 +0300
commita9c159f5f7bf3479c3236735960597b4bc36a204 (patch)
treef325e249f11a4bb8518f01151114b1239207a33b /src/main.c
download3cl-a9c159f5f7bf3479c3236735960597b4bc36a204.tar.gz
3cl-a9c159f5f7bf3479c3236735960597b4bc36a204.zip
Add code
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..36cdf5b
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,56 @@
+#include "main.h"
+#include "types.h"
+
+#include <getopt.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdnoreturn.h>
+
+
+const s8 *program_name;
+
+static const s8 *const usage_message =
+    "usage: %s [-h] file\n";
+static const s8 *const usage_description =
+    "ccl language interpreter\n"
+    "Arguments:\n"
+    "  file         file to execute\n"
+    "Options\n"
+    "  -h, --help   show this help message and quit\n";
+
+static struct option long_options[] =
+{
+    {"help",     no_argument, NULL, 'b'},
+    {0}
+};
+
+noreturn void usage(bool full)
+{
+    printf(usage_message, program_name);
+    if (full) printf(usage_description);
+    exit(full ? 0 : 1);
+}
+
+int main(i32 argc, s8 **argv)
+{
+    program_name = argv[0];
+
+    i32 ch;
+    while ((ch = getopt_long(argc, argv, "h", long_options, NULL)) != EOF)
+    {
+        switch (ch)
+        {
+        case 'h':
+            usage(true);
+            break;
+        default:
+            usage(false);
+            break;
+        }
+    }
+    if (argv[optind] == NULL)
+        usage(false);
+
+    return 0;
+}