diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2009-08-21 13:02:22 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2009-08-21 13:02:22 +0200 |
commit | c1af999ee417b7e80a828f9f7d1b39915814595a (patch) | |
tree | 824fb3f57fb0ca405064569b99912bd3dd02028b | |
parent | 431296aedecf7a05cd3332e885fc56b784ef00cb (diff) |
Implemented nick_get - nicks can now be mapped
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | nick.c | 17 | ||||
-rw-r--r-- | nick.h | 1 | ||||
-rw-r--r-- | user.c | 4 | ||||
-rw-r--r-- | user.h | 2 |
5 files changed, 23 insertions, 3 deletions
@@ -20,6 +20,7 @@ int main(int argc, char **argv) { /* Regex sets must be initialized before config. */ rs_init(); channel_init(); + nick_init(); if(!cfg_init()) { /* Free any registered regex sets and channels when config fails. Config will fail if a regex set fails to compile all parts. */ @@ -27,7 +28,6 @@ int main(int argc, char **argv) { channel_free(); return 1; } - nick_init(); /* Parsing stuff goes here. */ for(int chan_i = 0; chan_i < channel_get_count(); chan_i++) { @@ -67,6 +67,23 @@ int nick_regex_add(struct nick_t *nick, const char *re_s) { return 1; } +char *nick_get(char *name) { + struct nick_t *nick = nicks; + while(nick) { + struct nick_regex_t *nre = nick->regexes; + while(nre) { + int ovector[6]; + int rc; + rc = pcre_exec(nre->re, nre->re_e, name, strlen(name), 0, 0, ovector, 6); + if(rc > 0) + return nick->name; + nre = nre->next; + } + nick = nick->next; + } + return name; +} + void nick_free() { struct nick_t *nick = nicks; while(nick) { @@ -16,6 +16,7 @@ struct nick_t { void nick_init(); struct nick_t *nick_add(const char *name); int nick_regex_add(struct nick_t *nick, const char *re_s); +char *nick_get(char *name); void nick_free(); #endif @@ -3,6 +3,7 @@ #include "user.h" #include "sdbm.h" +#include "nick.h" struct user_t *users; @@ -11,7 +12,8 @@ void user_init() { memset(users, 0, sizeof(struct user_t) * USERS_MAX); } -struct user_t *user_get(char *nick) { +struct user_t *user_get(char *_nick) { + char *nick = nick_get(_nick); unsigned long hash = sdbm(nick); int index = hash % USERS_MAX; @@ -12,7 +12,7 @@ struct user_t { }; void user_init(); -struct user_t *user_get(char *nick); +struct user_t *user_get(char *_nick); void user_free(); extern struct user_t *users; |