diff options
author | sanine <sanine.not@pm.me> | 2022-01-26 12:00:35 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-01-26 12:00:35 -0600 |
commit | 5734102b0adf54933230264e0b43e74f5eabf718 (patch) | |
tree | 484d6cf93a1c536c98ddfe3f60efbb475560cb94 /experimental/tectonics/tectonics.c | |
parent | 6b687b91e788b4e91a6ed30640a2477b9596b954 (diff) |
add basic logging and CLI options
Diffstat (limited to 'experimental/tectonics/tectonics.c')
-rw-r--r-- | experimental/tectonics/tectonics.c | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/experimental/tectonics/tectonics.c b/experimental/tectonics/tectonics.c index 7d5342a..0a81b45 100644 --- a/experimental/tectonics/tectonics.c +++ b/experimental/tectonics/tectonics.c @@ -2,12 +2,21 @@ #include "tectonics.h" #include "drawing.h" +#include "logging.h" #define X_RES 1024 #define Y_RES X_RES -int main() + +int parse_options(char **output_file, int argc, char **argv); + + +int main(int argc, char **argv) { + char *output_file; + if (parse_options(&output_file, argc, argv)) + return 1; + cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, X_RES, Y_RES); cairo_t *cr = cairo_create(surface); @@ -23,3 +32,53 @@ int main() cairo_surface_destroy(surface); return 0; } + + +#include <stdio.h> +#include <unistd.h> + +static void print_usage(const char *progname) +{ + printf("Usage: %s [-c config_file] [-v[v[v]]] [-q[q[q]]] [-h] [-s script]\n" + " -v Increase output verbosity (-vvv displays every log message)\n" + " -q Decrease output verbosity (-qqq suppresses even fatal errors)\n" + " -c Specify configuration file to read (default 'config.lua')\n" + " -s Override the built-in Lua script\n" + " -h Print this help message and exit\n", + progname); +} + +int parse_options(char **output_file, int argc, char **argv) +{ + int log_level = WARN; + *output_file = "output.png"; + + int opt; + while ((opt = getopt(argc, argv, "qvo:h")) != -1) { + switch (opt) { + case 'q': + log_level -= 1; + break; + + case 'v': + log_level += 1; + break; + + case 'o': + *output_file = optarg; + + case 'h': + print_usage(argv[0]); + return 2; + + default: + print_usage(argv[0]); + return 1; + } + } + + // ew, globals (sorry) + global_log_level = log_level; + + return 0; +} |