summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.c41
-rw-r--r--nick.c4
-rw-r--r--nick.h4
3 files changed, 45 insertions, 4 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;
}
diff --git a/nick.c b/nick.c
index 17335d0..486f4fb 100644
--- a/nick.c
+++ b/nick.c
@@ -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);
diff --git a/nick.h b/nick.h
index 26613eb..7e65fc3 100644
--- a/nick.h
+++ b/nick.h
@@ -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