From c42c2834d8c7b5d81465b9d9d127d8384151b9cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 19 Jan 2019 19:06:09 +0100 Subject: [BROKEN] Work on adding hash tables. --- main.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 main.c (limited to 'main.c') 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 +#include + +/* + * These three are only for some FD hacks. + */ +#include +#include +#include + +#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); +} -- cgit v1.2.3