diff options
-rw-r--r-- | linked_list.inc.h | 1 | ||||
-rw-r--r-- | parse.c | 13 | ||||
-rw-r--r-- | strbuf.c | 10 | ||||
-rw-r--r-- | trie.inc.h | 1 | ||||
-rw-r--r-- | vcal.c | 9 |
5 files changed, 28 insertions, 6 deletions
diff --git a/linked_list.inc.h b/linked_list.inc.h index 3710bc13..2622eb4b 100644 --- a/linked_list.inc.h +++ b/linked_list.inc.h @@ -19,6 +19,7 @@ FREE_F (LINK(TYPE)) { if (this->after != NULL) this->after->before = NULL; // TODO how much of value do I really wanna free? // Should I implement some form of shared pointer? + if (this->value != NULL) FFREE(TYPE, this->value); return 0; } @@ -30,6 +30,11 @@ int parse_file(char* fname, FILE* f, vcalendar* cal) { SNEW(content_line, cline, keylen, vallen); + /* + * TODO + * When a file ends with CRLF then ctx_scope == s_none, leading to + * END:VEVENT erroring as bad start of calendar. + * */ char c; while ( (c = fgetc(f)) != EOF) { /* @@ -60,7 +65,7 @@ int parse_file(char* fname, FILE* f, vcalendar* cal) { } else { /* Actuall end of line, handle values. */ if (ungetc(s[1], f) != s[1]) { - ERR_F("%s, %i", "Failed to put character back on FILE", line); + ERR_F("%s, %i", "Failed to put character back on FILE", line); exit (2); } @@ -71,7 +76,7 @@ int parse_file(char* fname, FILE* f, vcalendar* cal) { } strbuf_copy(cline.vals.cur->value, &str); - strbuf_cap(cline.vals.cur->value); + // strbuf_cap(cline.vals.cur->value); ++line; @@ -109,7 +114,7 @@ int parse_file(char* fname, FILE* f, vcalendar* cal) { if (! feof(f)) { ERR("Error parsing"); - } else { + } else if (cline.vals.cur->value->len != 0 && str.ptr != 0) { /* * The standard (3.4, l. 2675) says that each icalobject must * end with CRLF. My files however does not, so we also parse @@ -194,7 +199,7 @@ int handle_kv( } else { NEW(content_line, c); content_line_copy(c, cline); - add_content_line (ev, c); + PUSH(TRIE(content_line))(&ev->clines, c->key.mem, c); } break; } @@ -50,6 +50,12 @@ FREE_F(strbuf) { * TODO this should do bounds check */ int strbuf_append(strbuf* s, char c) { +#ifdef SAFE_STR + if (s->len > s->alloc) { + ERR("Not enough memmory allocated"); + return 1; + } +#endif s->mem[s->len] = c; s->ptr = ++s->len; return 0; @@ -62,13 +68,15 @@ int strbuf_cap(strbuf* s) { int strbuf_copy(strbuf* dest, strbuf* src) { #ifdef SAFE_STR - if (dest->alloc < src->len) { + if (dest->alloc + 1 < src->len) { ERR("Not enough memmory allocated"); return 1; } #endif dest->len = src->len; memcpy(dest->mem, src->mem, src->len); + // TODO should this be here? + strbuf_cap(dest); return 0; } @@ -47,7 +47,6 @@ int PUSH(TRIE(TYPE)) ( TRIE(TYPE)* trie, char* key, TYPE* val ) { last = t; } last->value = RESOLVE(TYPE)(last->value, val); - // last->value = val; return 0; } else if (cur->c == subkey[0]) { /* This node belongs to the key, @@ -23,6 +23,12 @@ INIT_F(vevent, char* filename) { return 0; } +/* + * Resolves a collision in some form of structure (probably a hash-map + * or a trie). If dest is NULL just return new. Otherwise mutates dest + * to have the correct form, and returns it. Destroying new in the + * process. + */ content_line* RESOLVE(content_line) (content_line* dest, content_line* new) { @@ -99,6 +105,9 @@ FREE_F(vevent) { return 0; } +/* + * TODO change this into PUSH(VCALENDAR) (vevent*) ? + */ int push_event(vcalendar* cal, vevent* ev) { ev->calendar = cal; |