diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-09 00:19:58 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-09 00:19:58 +0100 |
commit | c374807e9d73014ce57eacbbaa56e05460288368 (patch) | |
tree | af9974aa6b03c9e25c9e42c108d9f25277665b41 /main.c | |
parent | Fix minor memmory error. (diff) | |
download | calp-c374807e9d73014ce57eacbbaa56e05460288368.tar.gz calp-c374807e9d73014ce57eacbbaa56e05460288368.tar.xz |
Extend parsing to handle tree's of vcomponents.
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 35 |
1 files changed, 24 insertions, 11 deletions
@@ -1,6 +1,7 @@ #include <errno.h> #include <stdio.h> #include <string.h> +#include <assert.h> #include "calendar.h" #include "macro.h" @@ -28,36 +29,48 @@ int main (int argc, char* argv[argc]) { exit (1); } - SNEW(vcomponent, cal); - read_vcalendar(&cal, args.argv[0]); + char* rootpath = args.argv[0]; + SNEW(vcomponent, root, "ROOT", rootpath); + read_vcalendar(&root, rootpath); arg_shift(&args); + vcomponent* cal = FCHILD(&root); + + assert(strcmp(root.type, "ROOT") == 0); + assert(strcmp(cal->type, "VCALENDAR") == 0); + if (args.argc == 0 || strcmp(args.argv[0], "-p") == 0) { printf("\nParsed calendar file containing [%u] events\n", - cal.components.length + root.components.length ); - for (size_t i = 0; i < cal.components.length; i++) { - char* filename = cal.components.items[i]->filename; + for (size_t i = 0; i < cal->components.length; i++) { + char* filename = cal->components.items[i]->filename; + vcomponent* ev = GET(VECT(vcomponent))(&cal->components, i); + + printf("TYPE = %s\n", ev->type); + if (strcmp(ev->type, "VEVENT") != 0) continue; printf("%3lu | %s | %s\n", i + 1, filename, - get_property(cal.components.items[i], "SUMMARY")->vals.cur->value->mem); + get_property(ev, "SUMMARY")->vals.cur->value->mem); } } else if (strcmp(args.argv[0], "-g") == 0) { if (arg_shift(&args) == 0) { - for (size_t i = 0; i < cal.components.length; i++) { + for (size_t i = 0; i < cal->components.length; i++) { char target[0xFF]; target[0] = '\0'; strcat(target, "/tmp/dot/"); - strcat(target, cal.components.items[i]->filename); + vcomponent* ev = GET(VECT(vcomponent))(&cal->components, i); + strcat(target, ev->filename); strcat(target, ".dot"); - create_graph(cal.components.items[i], target); + create_graph(ev, target); } } else { - create_graph(cal.components.items[0], args.argv[0]); + create_graph(GET(VECT(vcomponent))(&cal->components, 0), args.argv[0]); } } - FREE(vcomponent)(&cal); + + FREE(vcomponent)(&root); } |