diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2009-08-14 17:07:26 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2009-08-14 17:07:26 +0200 |
commit | b8c88bbf4e928a0ac4af89dfe72f0661beb35827 (patch) | |
tree | 6fcc7b01ad0b7bec02b6b257f561ffd88889f4d9 | |
parent | 11ff809614169d26efaf9c0d0a30185cf971730c (diff) |
Parse text and join lines.
Add users from text lines.
Fixed hash table code.
-rw-r--r-- | main.c | 21 | ||||
-rw-r--r-- | user.c | 19 |
2 files changed, 37 insertions, 3 deletions
@@ -1,8 +1,10 @@ #include <stdio.h> +#include <string.h> #include "config.h" #include "regexset.h" #include "channel.h" +#include "user.h" int main(int argc, char **argv) { /* Regex sets must be initialized before config. */ @@ -15,6 +17,7 @@ int main(int argc, char **argv) { channel_free(); return 1; } + user_init(); /* Parsing stuff goes here. */ for(int chan_i = 0; chan_i < channel_get_count(); chan_i++) { @@ -33,13 +36,29 @@ int main(int argc, char **argv) { char line[0x2ff]; while(fgets(line, 0x2ff, f)) { - // TODO: Magic. + int rc; + int ovector[30]; + + rc = pcre_exec(rs->text, NULL, line, strlen(line), 0, 0, ovector, 30); + if(rc > 0) { + char nick[0x20], text[0x200]; + pcre_copy_named_substring(rs->text, line, ovector, rc, "nick", nick, 0x20); + pcre_copy_named_substring(rs->text, line, ovector, rc, "text", text, 0x200); + struct user_t *user = user_get(nick); + continue; + } + + rc = pcre_exec(rs->join, NULL, line, strlen(line), 0, 0, ovector, 30); + if(rc > 0) { + continue; + } } file = file->next; } } + user_free(); cfg_free(); channel_free(); rs_free(); @@ -24,12 +24,17 @@ struct user_t *user_get(char *nick) { int index = hash % USERS_MAX; struct user_t *user = &users[index]; - while(user->next && user->hash != hash) user = user->next; - if(user->hash != hash) { + /* If hash doesn't match and there exists another user, fetch it. */ + while(user->hash != hash && user->next) user = user->next; + /* If hash still doesn't match and the user exists, add a new user. */ + if(user->hash != hash && user->nick) { struct user_t *temp_user = malloc(sizeof(struct user_t)); user->next = temp_user; user = temp_user; + /* Initialize nick to NULL so the user can be correctly added. */ + user->nick = NULL; } + /* Add the new user data to the current pointer if none was found. */ if(!user->nick) { user->hash = hash; user->nick = strdup(nick); @@ -39,5 +44,15 @@ struct user_t *user_get(char *nick) { } void user_free() { + struct user_t *user; + for(int i = 0; i < USERS_MAX; i++) { + user = users[i].next; + while(user) { + struct user_t *temp = user->next; + free(user->nick); + free(user); + user = temp; + } + } free(users); } |