summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile17
-rw-r--r--config.c44
-rw-r--r--config.h6
-rw-r--r--main.c10
5 files changed, 79 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..75b1567
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.swp
+*.o
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..df491b2
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,17 @@
+CC = gcc
+LD = gcc
+CFLAGS += -std=c99 $(shell pkg-config --cflags libconfig)
+LDFLAGS += $(shell pkg-config --libs libconfig)
+OBJECTS = main.o config.o
+TARGET = ircstats
+
+all: $(TARGET)
+
+$(TARGET): $(OBJECTS)
+ $(LD) $(LDFLAGS) -o $@ $^
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+clean:
+ rm -f $(OBJECTS) $(TARGET)
diff --git a/config.c b/config.c
new file mode 100644
index 0000000..ea574fb
--- /dev/null
+++ b/config.c
@@ -0,0 +1,44 @@
+#include <string.h>
+#include <stdlib.h>
+
+#include <libconfig.h>
+
+config_t config;
+
+int cfg_init() {
+ config_init(&config);
+
+ char cfg_file[0xff];
+ strcpy(cfg_file, getenv("HOME"));
+ strcat(cfg_file, "/.ircstats/config");
+
+ if(config_read_file(&config, cfg_file) == CONFIG_TRUE) {
+ return 1;
+ } else {
+ int line = config_error_line(&config);
+ if(line == 0)
+ fprintf(stderr, "Could not read config: %s\n", config_error_text(&config));
+ else
+ fprintf(stderr, "Parse error on line %d: %s\n", config_error_line(&config), config_error_text(&config));
+ }
+
+ config_setting_t *regexes_setting = config_lookup(&config, "regexes");
+ if(!config_setting_is_aggregate(regexes_setting)) {
+ fprintf(stderr, "Setting \"regexes\" must be an aggregate type.\n");
+ return 1;
+ }
+
+ int regex_count = config_setting_length(regexes_setting);
+
+ 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))) {
+ fprintf(stderr, "Regex set #%d missing one or more keys.\n", i+1);
+ continue;
+ }
+ }
+
+ return 0;
+}
+
diff --git a/config.h b/config.h
new file mode 100644
index 0000000..21c2651
--- /dev/null
+++ b/config.h
@@ -0,0 +1,6 @@
+#ifndef _CONFIG_H_
+#define _CONFIG_H_
+
+int cfg_init();
+
+#endif
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..a6e9019
--- /dev/null
+++ b/main.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+#include "config.h"
+
+int main(int argc, char **argv) {
+ if(!cfg_init()) {
+ return 1;
+ }
+ return 0;
+}