aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-04-15 15:49:33 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-04-15 21:22:01 +0200
commit23298f3a0e2426b758de3ad472abc8487ccb37f7 (patch)
treebaadb7965d1833d90a609be03ebb528bad416d75
parent06857c6bbbffacb7f8d5a524bc0c5e090313b5c3 (diff)
downloadxK-23298f3a0e2426b758de3ad472abc8487ccb37f7.tar.gz
xK-23298f3a0e2426b758de3ad472abc8487ccb37f7.tar.xz
xK-23298f3a0e2426b758de3ad472abc8487ccb37f7.zip
degesch: fix reading in the configuration
-rw-r--r--degesch.c47
1 files changed, 26 insertions, 21 deletions
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))