summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'config.c')
-rw-r--r--config.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/config.c b/config.c
index ea574fb..437d993 100644
--- a/config.c
+++ b/config.c
@@ -3,6 +3,8 @@
#include <libconfig.h>
+#include "regexset.h"
+
config_t config;
int cfg_init() {
@@ -12,20 +14,19 @@ int cfg_init() {
strcpy(cfg_file, getenv("HOME"));
strcat(cfg_file, "/.ircstats/config");
- if(config_read_file(&config, cfg_file) == CONFIG_TRUE) {
- return 1;
- } else {
+ if(config_read_file(&config, cfg_file) == CONFIG_FALSE) {
int line = config_error_line(&config);
if(line == 0)
fprintf(stderr, "Could not read config: %s\n", config_error_text(&config));
else
fprintf(stderr, "Parse error on line %d: %s\n", config_error_line(&config), config_error_text(&config));
+ return 0;
}
config_setting_t *regexes_setting = config_lookup(&config, "regexes");
if(!config_setting_is_aggregate(regexes_setting)) {
fprintf(stderr, "Setting \"regexes\" must be an aggregate type.\n");
- return 1;
+ return 0;
}
int regex_count = config_setting_length(regexes_setting);
@@ -35,10 +36,12 @@ int cfg_init() {
const char *text, *join;
if(!(config_setting_lookup_string(re_setting, "text", &text) && config_setting_lookup_string(re_setting, "join", &join))) {
fprintf(stderr, "Regex set #%d missing one or more keys.\n", i+1);
- continue;
+ return 0;
}
+ if(!rs_add(text, join))
+ return 0;
}
- return 0;
+ return 1;
}