diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-02 19:43:40 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-02 19:44:08 +0100 |
commit | 98cf44a23e4216c7e2ba156a67eabdf21a224c91 (patch) | |
tree | 7f1b437399f6103bba2133cb79633cf87c800309 /calendar.c | |
parent | Add -Wextra flag, fix resulting warnings. (diff) | |
download | calp-98cf44a23e4216c7e2ba156a67eabdf21a224c91.tar.gz calp-98cf44a23e4216c7e2ba156a67eabdf21a224c91.tar.xz |
Broke read_vcalendar of into own file.
Diffstat (limited to '')
-rw-r--r-- | calendar.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/calendar.c b/calendar.c new file mode 100644 index 00000000..f99eb775 --- /dev/null +++ b/calendar.c @@ -0,0 +1,56 @@ +#include "calendar.h" + +/* + * These three are only for some FD hacks. + */ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <dirent.h> +#include <string.h> +#include <stdio.h> +#include <errno.h> + +#include "macro.h" +#include "parse.h" + +int read_vcalendar(vcalendar* cal, char* path) { + + DIR* dir = opendir(path); + struct dirent* d; + 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); + } + + /* 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); + + } + + closedir(dir); + + return 0; +} |