diff options
-rw-r--r-- | calendar.c | 1 | ||||
-rw-r--r-- | graphs.c | 2 | ||||
-rw-r--r-- | main.c | 5 | ||||
-rw-r--r-- | parse.c | 4 | ||||
-rw-r--r-- | vcal.c | 35 | ||||
-rw-r--r-- | vcal.h | 4 |
6 files changed, 39 insertions, 12 deletions
@@ -117,4 +117,3 @@ int open_ics (char* resolved_path, vcomponent* cal) { return 0; } - @@ -19,7 +19,7 @@ int create_graph_trie (vcomponent* ev, char* filename) { fclose(f); - INFO_F("Wrote '%s' to '%s'", ev->filename, filename); + INFO_F("Wrote '%s' to '%s'", vcomponent_get_val(ev, "X-HH-FILENAME"), filename); return 0; } @@ -48,7 +48,8 @@ int main (int argc, char** argv) { vcomponent* cal = GET(VECT(vcomponent))(&root.components, i); assert(strcmp(cal->type, "VCALENDAR") == 0); - char* filename = cal->filename; + char* filename = vcomponent_get_val(cal, "X-HH-FILENAME"); + /* This loop over all VEVENT's in the current VCALENDAR */ for (size_t j = 0; j < cal->components.length; j++) { vcomponent* ev = GET(VECT(vcomponent))(&cal->components, j); @@ -73,7 +74,7 @@ int main (int argc, char** argv) { char target[0xFF]; target[0] = '\0'; strcat(target, "/tmp/dot/"); - strcat(target, ev->filename); + strcat(target, vcomponent_get_val(ev, "X-HH-FILENAME")); strcat(target, ".dot"); // create_graph(ev, target); } @@ -198,7 +198,9 @@ int handle_kv ( ERR_P(ctx, "Expected END:%s, got END:%s.\n%s line", expected_key->mem, CLINE_CUR_VAL(cline)->mem, - PEEK(LLIST(vcomponent))(&ctx->comp_stack)->filename); + vcomponent_get_val( + PEEK(LLIST(vcomponent))(&ctx->comp_stack), + "X-HH-FILENAME")); PUSH(LLIST(strbuf))(&ctx->key_stack, expected_key); return -1; @@ -44,10 +44,8 @@ INIT_F(vcomponent, const char* type, const char* filename) { INIT(TRIE(content_line), &self->clines); INIT(VECT(vcomponent), &self->components); - self->filename = NULL; if (filename != NULL) { - self->filename = (char*) calloc(sizeof(*filename), strlen(filename) + 1); - strcpy(self->filename, filename); + vcomponent_push_val (self, "X-HH-FILENAME", filename); } self->type = (char*) calloc(sizeof(*type), strlen(type) + 1); @@ -71,12 +69,10 @@ content_line* get_property (vcomponent* ev, const char* key) { } FREE_F(vcomponent) { - if (self->filename != NULL) free(self->filename); free(self->type); if (FREE(TRIE(content_line))(&self->clines) != 0) { - fprintf(stderr, "Error freeing vcomponent belonging to file \n %s \n", - self->filename); + ERR("Error freeing vcomponent"); } FREE(VECT(vcomponent))(&self->components); @@ -112,3 +108,30 @@ FMT_F(vcomponent) { return seek; } + +int vcomponent_push_val (vcomponent* comp, const char* key, const char* val) { + NEW(content_line, cl); + NEW(content_set, cs); + strbuf_load(&cs->key, val); + PUSH(content_line)(cl, cs); + + char* key_cpy = calloc(sizeof(*key_cpy), strlen(key)); + strcpy (key_cpy, key); + PUSH(TRIE(content_line))(&comp->clines, key_cpy, cl); + free (key_cpy); + + return 0; +} + +char* vcomponent_get_val (vcomponent* comp, const char* key) { + char* key_cpy = calloc(sizeof(*key_cpy), strlen(key)); + strcpy (key_cpy, key); + content_line* cl = GET(TRIE(content_line))(&comp->clines, key_cpy); + free (key_cpy); + + if (cl != NULL && cl->cur->value != NULL) { + return cl->cur->value->key.mem; + } + + return NULL; +} @@ -67,7 +67,6 @@ typedef struct s_vcomponent vcomponent; #undef TYPE struct s_vcomponent { - char* filename; char* type; vcomponent* parent; TRIE(content_line) clines; @@ -87,6 +86,9 @@ content_line* get_property (vcomponent* ev, const char* key); int add_content_line (vcomponent* ev, content_line* c); +int vcomponent_push_val (vcomponent*, const char* key, const char* val); +char* vcomponent_get_val (vcomponent*, const char* key); + /* * Appends ev to cal. Doesn't copy ev. So make sure that it wont go * out of scope. |