summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'config.c')
-rw-r--r--config.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/config.c b/config.c
index 79eae42..f44937c 100644
--- a/config.c
+++ b/config.c
@@ -5,6 +5,7 @@
#include "regexset.h"
#include "channel.h"
+#include "nick.h"
config_t config;
@@ -104,6 +105,46 @@ int cfg_init() {
}
}
+ config_setting_t *nicks_setting = config_lookup(&config, "nicks");
+ if(!config_setting_is_aggregate(nicks_setting)) {
+ fprintf(stderr, "Setting \"nicks\" must be an aggregate type.\n");
+ return 0;
+ }
+
+ int nick_count = config_setting_length(nicks_setting);
+ for(int i = 0; i < nick_count; i++) {
+ config_setting_t *nick_setting = config_setting_get_elem(nicks_setting, i);
+ if(config_setting_length(nick_setting) != 2) {
+ fprintf(stderr, "Nick settings must contain exactly two elements.\n");
+ return 0;
+ }
+ const char *name = config_setting_get_string_elem(nick_setting, 0);
+ if(!name) {
+ fprintf(stderr, "First element of nick settings must be a string.\n");
+ return 0;
+ }
+ struct nick_t *nick = nick_add(name);
+ if(!nick) {
+ return 0;
+ }
+ config_setting_t *nick_re_setting = config_setting_get_elem(nick_setting, 1);
+ if(!config_setting_is_aggregate(nick_re_setting)) {
+ fprintf(stderr, "Second element of nick settings must be an aggregate type.\n");
+ return 0;
+ }
+ int re_count = config_setting_length(nick_re_setting);
+ for(int j = 0; j < re_count; j++) {
+ const char *re = config_setting_get_string_elem(nick_re_setting, j);
+ if(!re) {
+ fprintf(stderr, "Second element of nick settings must contain strings only.\n");
+ return 0;
+ }
+ if(!nick_regex_add(nick, re)) {
+ return 0;
+ }
+ }
+ }
+
return 1;
}