diff options
-rw-r--r-- | config.c | 6 | ||||
-rw-r--r-- | export_xml.c | 4 | ||||
-rw-r--r-- | main.c | 12 | ||||
-rw-r--r-- | regexset.c | 19 | ||||
-rw-r--r-- | regexset.h | 8 | ||||
-rw-r--r-- | user.c | 2 | ||||
-rw-r--r-- | user.h | 2 |
7 files changed, 42 insertions, 11 deletions
@@ -35,12 +35,12 @@ int cfg_init() { for(int i = 0; i < regex_count; i++) { config_setting_t *re_setting = config_setting_get_elem(regexes_setting, i); - const char *text, *join; - if(!(config_setting_lookup_string(re_setting, "text", &text) && config_setting_lookup_string(re_setting, "join", &join))) { + const char *text, *join, *kick; + if(!(config_setting_lookup_string(re_setting, "text", &text) && config_setting_lookup_string(re_setting, "join", &join) && config_setting_lookup_string(re_setting, "kick", &kick))) { fprintf(stderr, "Regex set #%d missing one or more keys.\n", i+1); return 0; } - if(!rs_add(text, join)) + if(!rs_add(text, join, kick)) return 0; } diff --git a/export_xml.c b/export_xml.c index db1d592..f7509c3 100644 --- a/export_xml.c +++ b/export_xml.c @@ -49,6 +49,10 @@ int export_xml(struct channel_t *channel, struct user_t *users) { xmlNewChild(user_node, NULL, "words", s); snprintf(s, 0xf, "%d", user->characters); xmlNewChild(user_node, NULL, "characters", s); + snprintf(s, 0xf, "%d", user->kicks); + xmlNewChild(user_node, NULL, "kicks", s); + snprintf(s, 0xf, "%d", user->kicked); + xmlNewChild(user_node, NULL, "kicked", s); /* Add lines for this user. */ xmlNodePtr lines_node = xmlNewChild(user_node, NULL, "lines", NULL); @@ -119,6 +119,18 @@ int main(int argc, char **argv) { struct user_t *user = user_get(nick); continue; } + + rc = pcre_exec(rs->kick, rs->kick_e, line, strlen(line), 0, 0, ovector, 30); + if(rc > 0) { + char nick[NICK_BUFFER_SIZE], victim[NICK_BUFFER_SIZE]; + pcre_copy_named_substring(rs->kick, line, ovector, rc, "nick", nick, NICK_BUFFER_SIZE); + pcre_copy_named_substring(rs->kick, line, ovector, rc, "victim", victim, NICK_BUFFER_SIZE); + struct user_t *user = user_get(nick), + *victim_user = user_get(victim); + user->kicks++; + victim_user->kicked++; + continue; + } } fclose(f); @@ -23,7 +23,7 @@ static void re_error(const char *name, const char *pattern, const char *error, i regexes = realloc(regexes, --rs_count * sizeof(struct regexset_t)); } -struct regexset_t *rs_add(const char *text, const char *join) { +struct regexset_t *rs_add(const char *text, const char *join, const char *kick) { regexes = realloc(regexes, ++rs_count * sizeof(struct regexset_t)); if(!regexes) { /* If we end up here, we cannot free any previously compiled pcre patterns. */ @@ -55,6 +55,20 @@ struct regexset_t *rs_add(const char *text, const char *join) { } rs->join_e = pcre_study(rs->join, 0, &error); + rs->kick = pcre_compile(kick, 0, &error, &erroffset, rs_pcre_tables); + if(rs->kick == NULL) { + pcre_free(rs->text); + pcre_free(rs->join); + if(rs->text_e) { + pcre_free(rs->text_e); + pcre_free(rs->join_e); + } + re_error("kick", kick, error, erroffset); + return NULL; + + } + rs->kick_e = pcre_study(rs->kick, 0, &error); + return rs; } @@ -70,6 +84,9 @@ void rs_free() { pcre_free(regexes[i].join); if(regexes[i].join_e) pcre_free(regexes[i].join_e); + pcre_free(regexes[i].kick); + if(regexes[i].kick_e) + pcre_free(regexes[i].kick_e); } free(regexes); regexes = NULL; @@ -4,14 +4,12 @@ #include <pcre.h> struct regexset_t { - pcre *text; - pcre_extra *text_e; - pcre *join; - pcre_extra *join_e; + pcre *text, *join, *kick; + pcre_extra *text_e, *join_e, *kick_e; }; void rs_init(); -struct regexset_t *rs_add(const char *text, const char *join); +struct regexset_t *rs_add(const char *text, const char *join, const char *kick); struct regexset_t *rs_get(int index); void rs_free(); @@ -33,7 +33,7 @@ struct user_t *user_get(char *_nick) { user->hash = hash; user->nick = strdup(nick); memset(user->lines, 0, 24*4 * sizeof(unsigned long)); - user->words = user->characters = 0; + user->words = user->characters = user->kicks = user->kicked = 0; user->next = NULL; } @@ -7,7 +7,7 @@ struct user_t { unsigned long hash; char *nick; unsigned long lines[24*4]; - unsigned long long words, characters; + unsigned long long words, characters, kicks, kicked; struct user_t *next; }; |