diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 118 | 
1 files changed, 2 insertions, 116 deletions
| @@ -1,8 +1,3 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <wctype.h> -#include <wchar.h>  #include <locale.h>  #include "config.h" @@ -12,11 +7,7 @@  #include "word.h"  #include "export_xml.h"  #include "nick.h" - -#define NICK_BUFFER_SIZE 0x100 -#define TEXT_BUFFER_SIZE 0x400 -#define LINE_BUFFER_SIZE 0x400 -#define TIME_BUFFER_SIZE 0xf +#include "parsing.h"  int main(int argc, char **argv) {  	/* Set locale. */ @@ -34,112 +25,7 @@ int main(int argc, char **argv) {  		return 1;  	} -	/* Parsing stuff goes here. */ -	for(int chan_i = 0; chan_i < channel_get_count(); chan_i++) { -		user_init(); -		word_init(); -		struct channel_t *channel = channel_get(chan_i); -		printf("Channel %s\n", channel->name); -		struct channel_file_t *file = channel->files; -		while(file) { -			struct regexset_t *rs = file->rs; -			FILE *f = fopen(file->path, "r"); -			if(!f) { -				fprintf(stderr, "\tFailed to open %s\n", file->path); -				file = file->next; -				continue; -			} else -				printf("\tParsing %s\n", file->path); - -			char line[LINE_BUFFER_SIZE]; -			while(fgets(line, LINE_BUFFER_SIZE, f)) { -				int rc; -				int ovector[30]; - -				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], 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); - -					/* 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. */ -					wchar_t wtext[TEXT_BUFFER_SIZE]; -					mbstowcs(wtext, text, TEXT_BUFFER_SIZE); -					user->characters += wcslen(wtext); -					wchar_t word[TEXT_BUFFER_SIZE]; -					wchar_t *end = wcschr(wtext, '\0'); -					*word = '\0'; -					int len = 0; -					for(wchar_t *pos = wtext; pos < end; pos++) { -						if(iswblank(*pos)) { -							if(len) { -								user->words++; -								word[len] = '\0'; -								char mbword[TEXT_BUFFER_SIZE]; -								wcstombs(mbword, word, TEXT_BUFFER_SIZE); -								struct word_t *word_s = word_get(mbword); -								word_s->count++; -							} -							len = 0; -							*word = '\0'; -						} else if(iswalpha(*pos)) { -							word[len++] = towlower(*pos); -						} else { -							len = 0; -							*word = '\0'; -						} -					} -					if(len) { -						user->words++; -						word[len] = '\0'; -						char mbword[TEXT_BUFFER_SIZE]; -						wcstombs(mbword, word, TEXT_BUFFER_SIZE); -						struct word_t *word_s = word_get(mbword); -						word_s->count++; -					} -					continue; -				} - -				rc = pcre_exec(rs->join, rs->join_e, line, strlen(line), 0, 0, ovector, 30); -				if(rc > 0) { -					char nick[NICK_BUFFER_SIZE]; -					pcre_copy_named_substring(rs->join, line, ovector, rc, "nick", nick, NICK_BUFFER_SIZE); -					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); - -			file = file->next; -		} -		export_xml(channel, users); -		user_free(); -		word_free(); -	} +	process(ircstats_config.threads);  	nick_free();  	cfg_free(); | 
