From 9d255f79486b47a43ec6cb48517057120c2729df Mon Sep 17 00:00:00 2001 From: snit Date: Sat, 5 Oct 2024 02:07:11 -0500 Subject: [PATCH] add a default set of initialisation options for cli flags --- TODO.gmi | 1 + server/src/main.c | 6 +++++- server/src/opts.c | 5 +++++ server/src/opts.h | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/TODO.gmi b/TODO.gmi index 353566c..ada657b 100644 --- a/TODO.gmi +++ b/TODO.gmi @@ -22,3 +22,4 @@ A list of things I'd like to accomplish * Handle mod dependencies * Remove rendering from serverside * Client-side resource files for each mod +* Real error handling (right now I just pass up to main and immediately exit) diff --git a/server/src/main.c b/server/src/main.c index a099589..e88317a 100644 --- a/server/src/main.c +++ b/server/src/main.c @@ -9,13 +9,17 @@ int main(int argc, char **argv) { enum error_t err = ERR_OK; - struct options_t options = { false }; + struct options_t options = { 0 }; + opts_default(&options); + err = opts_parse(&options, argc, argv); if (err) goto handle_error; err = opts_init(&options); if (err) goto handle_error; + // Open a socket and connect to clients + opts_free(&options); return ERR_OK; diff --git a/server/src/opts.c b/server/src/opts.c index af37844..e6dd37c 100644 --- a/server/src/opts.c +++ b/server/src/opts.c @@ -9,6 +9,11 @@ #include "opts.h" #include "daemon.h" +void opts_default(struct options_t *options) { + options->daemonise = false; +} + + enum error_t opts_parse(struct options_t *options, int argc, char **argv) { struct option const long_options[] = { { "daemon", no_argument, 0, 'd' }, diff --git a/server/src/opts.h b/server/src/opts.h index b6b6712..a4dac14 100644 --- a/server/src/opts.h +++ b/server/src/opts.h @@ -9,6 +9,7 @@ struct options_t { bool daemonise; }; +void opts_default(struct options_t *); enum error_t opts_parse(struct options_t *, int, char **); enum error_t opts_init(struct options_t const *); void opts_free(struct options_t const *);