summaryrefslogtreecommitdiff
path: root/main.c
blob: 79b1eecaa891191eaee4cc6d23fa2d25994c844a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#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. */
	rs_init();
	channel_init();
	if(!cfg_init()) {
		/*	Free any registered regex sets and channels when config fails.
			Config will fail if a regex set fails to compile all parts. */
		rs_free();
		channel_free();
		return 1;
	}
	user_init();

	/* Parsing stuff goes here. */
	for(int chan_i = 0; chan_i < channel_get_count(); chan_i++) {
		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[0x2ff];
			while(fgets(line, 0x2ff, f)) {
				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();

	return 0;
}