aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-01-19 19:06:09 +0100
committerHugo Hörnquist <hugo@hornquist.se>2019-01-19 19:06:14 +0100
commitc42c2834d8c7b5d81465b9d9d127d8384151b9cb (patch)
tree53b1a8eb0368d5f91525604eea2c3173083c1955 /main.c
parentCan now parse entire directory in one go. (diff)
downloadcalp-c42c2834d8c7b5d81465b9d9d127d8384151b9cb.tar.gz
calp-c42c2834d8c7b5d81465b9d9d127d8384151b9cb.tar.xz
[BROKEN] Work on adding hash tables.
Diffstat (limited to 'main.c')
-rw-r--r--main.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 00000000..ba6eb0e9
--- /dev/null
+++ b/main.c
@@ -0,0 +1,67 @@
+#include <dirent.h>
+#include <errno.h>
+
+/*
+ * These three are only for some FD hacks.
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "parse.h"
+
+int main (int argc, char* argv[argc]) {
+ if (argc < 2) {
+ //puts("Please give a ics file as first argument");
+ puts("Please give vdir as first argument");
+ exit (1);
+ }
+ vcalendar cal;
+ init_vcalendar(&cal);
+
+ char* dname = argv[1];
+ DIR* dir = opendir(dname);
+ struct dirent* d;
+ int fcount = 0;
+ while ((d = readdir(dir)) != NULL) {
+
+
+ /* Check that it's a regular file */
+ if (d->d_type != DT_REG) continue;
+
+ /* Check that we have an ICS file */
+ char *s, *fname;
+ s = fname = d->d_name;
+ while (*(s++) != '.');
+ if (strcmp(s, "ics") != 0) continue;
+
+ /* We now assume that it's a good file, and start parsing it */
+
+ int fd = openat(dirfd(dir), fname, O_RDONLY);
+
+ FILE* f = fdopen(fd, "r");
+ if (f == NULL) {
+ fprintf(stderr, "Error opening file [%s], errno = %i\n",
+ fname, errno);
+ exit (1);
+ }
+
+ printf("%3i | %s\n", fcount++, fname);
+ /* TODO currently the hedaers cal is overwritten each
+ * iteration (not really, since I don't save any headers).
+ * Preferably, a special case is made for vdir structures
+ * which can assume that all headers are equal. */
+ parse_file(f, &cal);
+ fclose(f);
+
+ }
+
+ printf("\nParsed calendar file containing [%lu] events\n",
+ cal.n_events);
+ for (size_t i = 0; i < cal.n_events; i++) {
+ // printf("%3lu. %s\n", i + 1, cal.events[i].summary.mem);
+ printf("%3lu. %s\n", i + 1, get_property(&cal.events[i], "SUMMARY")->val.mem);
+ }
+
+ free_vcalendar(&cal);
+}