From d46183860c1f3f10095e95023adcb79b1896ab0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 22 Mar 2019 20:11:11 +0100 Subject: Move C and Scheme code into subdirs. --- src/main.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/main.c (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c new file mode 100644 index 00000000..791bc5d3 --- /dev/null +++ b/src/main.c @@ -0,0 +1,91 @@ +#include +#include +#include +#include + +#include "calendar.h" +#include "macro.h" +#include "vcal.h" +#include "graphs.h" +#include "err.h" + +typedef struct { + int argc; + char** argv; +} arg; + +int arg_shift (arg* a) { + if (a->argc == 0) return 0; + + ++a->argv; + return --a->argc; + +} + +int main (int argc, char** argv) { + arg args = { .argc = argc, .argv = argv }; + + if (arg_shift(&args) == 0) { + ERR("Please give vdir or a vcalendar file as first argument"); + exit (1); + } + + char* rootpath = args.argv[0]; + SNEW(vcomponent, root, "ROOT", rootpath); + read_vcalendar(&root, rootpath); + + arg_shift(&args); + + if (args.argc == 0 || strcmp(args.argv[0], "-p") == 0) { + INFO_F("Parsed calendar file containing [%u] events", + root.components.length); + + puts("CAL : OBJ | Filename | Description"); + puts("----------+----------+------------"); + + /* This loops over all VCALENDAR's in root */ + FOR (LLIST, vcomponent, cal, &root.components) { + assert(strcmp(cal->type, "VCALENDAR") == 0); + + char* filename = vcomponent_get_val(cal, "X-HNH-FILENAME"); + + /* This loop over all VEVENT's in the current VCALENDAR */ + FOR (LLIST, vcomponent, ev, &cal->components) { + if (strcmp(ev->type, "VEVENT") != 0) continue; + + printf("%s | %s\n", + filename, + get_property(ev, "SUMMARY")->cur->value->key.mem); + } + } + } else if (strcmp(args.argv[0], "-g") == 0) { + /* TODO self might be broken */ + if (arg_shift(&args) == 0) { + FOR (LLIST, vcomponent, cal, &root.components) { + assert(strcmp(cal->type, "VCALENDAR") == 0); + + vcomponent* ev = FCHILD(cal); + + char target[0xFF]; + target[0] = '\0'; + strcat(target, "/tmp/dot/"); + strcat(target, vcomponent_get_val(ev, "X-HNH-FILENAME")); + strcat(target, ".dot"); + // create_graph(ev, target); + } + } else { + // create_graph(FCHILD(FCHILD(&root)), args.argv[0]); + INFO("Creating graph for single file"); + INFO_F("output = %s\n", args.argv[0]); + create_graph_vcomponent(&root, args.argv[0]); + } + } + + /* + char buf[0x20000]; + FMT(vcomponent)(&root, buf); + puts(buf); + */ + + FREE(vcomponent)(&root); +} -- cgit v1.2.3