diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2009-08-17 13:53:58 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2009-08-17 13:53:58 +0200 |
commit | 44f3e1486fb5fd45644683af83aaaf27047e4250 (patch) | |
tree | f46347575a37a90234233fd504f9a8173811d57d | |
parent | 27bf4f8c64eac6d969116e4c6ed8584b52badb46 (diff) |
Count lines per quarter hour for channels and users.
-rw-r--r-- | channel.c | 1 | ||||
-rw-r--r-- | channel.h | 2 | ||||
-rw-r--r-- | main.c | 16 | ||||
-rw-r--r-- | user.c | 3 | ||||
-rw-r--r-- | user.h | 2 |
5 files changed, 20 insertions, 4 deletions
@@ -23,6 +23,7 @@ struct channel_t *channel_add(const char *name) { struct channel_t *channel = &channels[channel_count-1]; channel->name = strdup(name); channel->files = NULL; + memset(channel->hours, 0, 24*4 * sizeof(unsigned long)); return channel; } @@ -12,6 +12,8 @@ struct channel_file_t { struct channel_t { char *name; struct channel_file_t *files; + + unsigned long hours[24*4]; }; void channel_init(); @@ -1,4 +1,5 @@ #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <ctype.h> @@ -11,6 +12,7 @@ #define NICK_BUFFER_SIZE 0x100 #define TEXT_BUFFER_SIZE 0x400 #define LINE_BUFFER_SIZE 0x400 +#define TIME_BUFFER_SIZE 0xf int main(int argc, char **argv) { /* Regex sets must be initialized before config. */ @@ -48,11 +50,21 @@ int main(int argc, char **argv) { rc = pcre_exec(rs->text, rs->text_e, line, strlen(line), 0, 0, ovector, 30); if(rc > 0) { - char nick[NICK_BUFFER_SIZE], text[TEXT_BUFFER_SIZE]; + char nick[NICK_BUFFER_SIZE], text[TEXT_BUFFER_SIZE], hour_s[TIME_BUFFER_SIZE], min_s[TIME_BUFFER_SIZE]; pcre_copy_named_substring(rs->text, line, ovector, rc, "nick", nick, NICK_BUFFER_SIZE); pcre_copy_named_substring(rs->text, line, ovector, rc, "text", text, TEXT_BUFFER_SIZE); + pcre_copy_named_substring(rs->text, line, ovector, rc, "hour", hour_s, TIME_BUFFER_SIZE); + pcre_copy_named_substring(rs->text, line, ovector, rc, "minute", min_s, TIME_BUFFER_SIZE); struct user_t *user = user_get(nick); - user->lines++; + + /* Calculate array index for lines. */ + int hour, min, time_i; + hour = atoi(hour_s); + min = atoi(min_s); + time_i = hour*4 + min / 15; + + user->lines[time_i]++; + channel->hours[time_i]++; /* Count words. */ char word[TEXT_BUFFER_SIZE]; @@ -30,7 +30,8 @@ struct user_t *user_get(char *nick) { if(!user->nick) { user->hash = hash; user->nick = strdup(nick); - user->lines = user->words = 0; + memset(user->lines, 0, 24*4 * sizeof(unsigned long)); + user->words = 0; user->next = NULL; } @@ -6,7 +6,7 @@ struct user_t { unsigned long hash; char *nick; - unsigned long lines; + unsigned long lines[24*4]; unsigned long long words; struct user_t *next; }; |