summaryrefslogtreecommitdiff
path: root/src/options/honey_options.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-03-01 22:42:10 -0600
committersanine <sanine.not@pm.me>2022-03-01 22:42:10 -0600
commit10288765588673645c1cc0a6e3d2245aff3f9080 (patch)
tree3a56953535c3e26156b41331631d51e25ff6bdb9 /src/options/honey_options.c
parent9c238237597de90c73cc65c3fccf2f49bfaa46b4 (diff)
add basic window functions, option parsing, and main loop
Diffstat (limited to 'src/options/honey_options.c')
-rw-r--r--src/options/honey_options.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/options/honey_options.c b/src/options/honey_options.c
new file mode 100644
index 0000000..cf93588
--- /dev/null
+++ b/src/options/honey_options.c
@@ -0,0 +1,55 @@
+#include <stdio.h>
+#include <unistd.h> /* todo: create windows-compatible alternative */
+
+#include "options/honey_options.h"
+
+
+static void print_usage(const char *program_name)
+{
+ printf("Usage: %s [OPTIONS]\n"
+ " -v Increase output verbosity (-vvv displays every log message)\n"
+ " -q Decrease output verbosity (-qqq suppresses even fatal errors)\n"
+ " -h Print this help message and exit\n"
+ " -s SCRIPT Load SCRIPT as the entry point instead of 'main.lua'\n",
+ program_name);
+}
+
+
+int parse_options(struct honey_options *opts, int argc, char **argv)
+{
+ opts->main_script = "main.lua";
+ opts->log_level = WARN;
+ opts->display_help = 0;
+
+ int opt;
+ const char *flags = "hqvs:";
+ while ((opt = getopt(argc, argv, flags)) != -1) {
+ switch (opt) {
+ case 'q':
+ opts->log_level -= 1;
+ break;
+
+ case 'v':
+ opts->log_level += 1;
+ break;
+
+ case 'h':
+ print_usage(argv[0]);
+ opts->display_help = 1;
+ return 1;
+
+ case 's':
+ opts->main_script = optarg;
+ break;
+
+ default:
+ print_usage(argv[0]);
+ return 0;
+ }
+ }
+
+ honey_log_set_level(opts->log_level);
+ honey_log_set_file(stderr);
+
+ return 1;
+}