From 23298f3a0e2426b758de3ad472abc8487ccb37f7 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Wed, 15 Apr 2015 15:49:33 +0200 Subject: degesch: fix reading in the configuration --- degesch.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'degesch.c') diff --git a/degesch.c b/degesch.c index 3733339..358e592 100644 --- a/degesch.c +++ b/degesch.c @@ -1936,38 +1936,43 @@ autofill_user_info (struct app_context *ctx, struct error **e) } static bool -load_config (struct app_context *ctx, struct error **e) +unescape_config (struct str_map *input, struct str_map *output, struct error **e) { - // TODO: employ a better configuration file format, so that we don't have - // to do this convoluted post-processing anymore. - - struct str_map map; - str_map_init (&map); - map.free = free; - - if (!read_config_file (&map, e)) - return false; - + struct error *error = NULL; struct str_map_iter iter; - str_map_iter_init (&iter, &map); + str_map_iter_init (&iter, input); while (str_map_iter_next (&iter)) { - struct error *e = NULL; struct str value; str_init (&value); - if (!unescape_string (iter.link->data, &value, &e)) + if (!unescape_string (iter.link->data, &value, &error)) { - // FIXME: use the "e" argument, don't print it - print_error ("error reading configuration: %s: %s", - iter.link->key, e->message); - error_free (e); - exit (EXIT_FAILURE); + error_set (e, "error reading configuration: %s: %s", + iter.link->key, error->message); + error_free (error); + return false; } - str_map_set (&ctx->config, iter.link->key, str_steal (&value)); + str_map_set (output, iter.link->key, str_steal (&value)); } + return true; +} + +static bool +load_config (struct app_context *ctx, struct error **e) +{ + // TODO: employ a better configuration file format, so that we don't have + // to do this convoluted post-processing anymore. + + struct str_map map; + str_map_init (&map); + map.free = free; - if (!autofill_user_info (ctx, e)) + bool success = read_config_file (&map, e) && + unescape_config (&map, &ctx->config, e) && + autofill_user_info (ctx, e); + str_map_free (&map); + if (!success) return false; if (!irc_get_boolean_from_config (ctx, "reconnect", &ctx->reconnect, e)) -- cgit v1.2.3-54-g00ecf