diff options
-rw-r--r-- | config.c | 41 | ||||
-rw-r--r-- | nick.c | 4 | ||||
-rw-r--r-- | nick.h | 4 |
3 files changed, 45 insertions, 4 deletions
@@ -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; } @@ -11,7 +11,7 @@ void nick_init() { nicks = NULL; } -struct nick_t *nick_add(char *name) { +struct nick_t *nick_add(const char *name) { struct nick_t *nick = malloc(sizeof(struct nick_t)); if(!nick) { char *error = strerror(errno); @@ -33,7 +33,7 @@ struct nick_t *nick_add(char *name) { return nick; } -int nick_regex_add(struct nick_t *nick, char *re_s) { +int nick_regex_add(struct nick_t *nick, const char *re_s) { struct nick_regex_t *nre = malloc(sizeof(struct nick_regex_t)); if(!nre) { char *error = strerror(errno); @@ -13,8 +13,8 @@ struct nick_t { }; void nick_init(); -struct nick_t *nick_add(char *name); -int nick_regex_add(struct nick_t *nick, char *re_s); +struct nick_t *nick_add(const char *name); +int nick_regex_add(struct nick_t *nick, const char *re_s); void nick_free(); #endif |