summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2009-10-20 22:39:00 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2009-10-20 22:39:00 +0200
commit4b3d1128bf96b96322e4b99da4633f44fa49e585 (patch)
treefa379e005e9db47cad073f57e8e6b1c4fb609b6c
parent27d37093ab87c2a1b8e846b4f4df83bf19ceba4c (diff)
Parse kicks and store number of kicks and times kicked per user.
-rw-r--r--config.c6
-rw-r--r--export_xml.c4
-rw-r--r--main.c12
-rw-r--r--regexset.c19
-rw-r--r--regexset.h8
-rw-r--r--user.c2
-rw-r--r--user.h2
7 files changed, 42 insertions, 11 deletions
diff --git a/config.c b/config.c
index 4fdbdcb..6cc5aad 100644
--- a/config.c
+++ b/config.c
@@ -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);
diff --git a/main.c b/main.c
index ee00240..e30e878 100644
--- a/main.c
+++ b/main.c
@@ -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);
diff --git a/regexset.c b/regexset.c
index 5e2d002..61a22be 100644
--- a/regexset.c
+++ b/regexset.c
@@ -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;
diff --git a/regexset.h b/regexset.h
index 2c49e69..3c023f1 100644
--- a/regexset.h
+++ b/regexset.h
@@ -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();
diff --git a/user.c b/user.c
index ce6f6fc..4fa0174 100644
--- a/user.c
+++ b/user.c
@@ -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;
}
diff --git a/user.h b/user.h
index a524504..27953ce 100644
--- a/user.h
+++ b/user.h
@@ -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;
};