From c42c2834d8c7b5d81465b9d9d127d8384151b9cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 19 Jan 2019 19:06:09 +0100 Subject: [BROKEN] Work on adding hash tables. --- vcal.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 13 deletions(-) (limited to 'vcal.c') diff --git a/vcal.c b/vcal.c index a67e0246..f0be7f73 100644 --- a/vcal.c +++ b/vcal.c @@ -2,27 +2,69 @@ #include +#define TYPE content_line +#include "hash_help.inc" +#undef TYPE + +int vevent_init(vevent* ev, int init_size) { + HASH_INIT(content_line)(&ev->clines, init_size); + return 0; +} + +content_line* get_property (vevent* ev, char* key) { + return HASH_GET(content_line)(&ev->clines, key); +} + +int add_content_line (vevent* ev, content_line* c) { + return HASH_PUT(content_line)(&ev->clines, c); +} + +int init_content_line (content_line* c, int keylen, int vallen) { + init_string(&c->key, keylen); + init_string(&c->val, vallen); + // TODO remaining fields + return 0; +} + +int content_line_copy (content_line* dest, content_line* src) { + strbuf_init_copy(&dest->key, &src->key); + strbuf_init_copy(&dest->val, &src->val); + + // TODO remaining fields + + return 0; +} + +int content_line_free (content_line* c) { + free_string(&c->key); + free_string(&c->val); + + // TODO remaining fields + + return 0; +} + int copy_vevent(vevent* dest, vevent* src) { - copy_strbuf(&dest->dtstart , &src->dtstart); - copy_strbuf(&dest->dtend , &src->dtend); - copy_strbuf(&dest->summary , &src->summary); - copy_strbuf(&dest->description , &src->description); + // copy_strbuf(&dest->dtstart , &src->dtstart); + // copy_strbuf(&dest->dtend , &src->dtend); + // copy_strbuf(&dest->summary , &src->summary); + // copy_strbuf(&dest->description , &src->description); return 0; } int vevent_init_copy(vevent* dest, vevent* src) { - strbuf_init_copy(&dest->dtstart , &src->dtstart); - strbuf_init_copy(&dest->dtend , &src->dtend); - strbuf_init_copy(&dest->summary , &src->summary); - strbuf_init_copy(&dest->description , &src->description); + // strbuf_init_copy(&dest->dtstart , &src->dtstart); + // strbuf_init_copy(&dest->dtend , &src->dtend); + // strbuf_init_copy(&dest->summary , &src->summary); + // strbuf_init_copy(&dest->description , &src->description); return 0; } int free_vevent (vevent* ev) { - free_string(&ev->dtstart); - free_string(&ev->dtend); - free_string(&ev->summary); - free_string(&ev->description); + // free_string(&ev->dtstart); + // free_string(&ev->dtend); + // free_string(&ev->summary); + // free_string(&ev->description); return 0; } @@ -34,7 +76,8 @@ int push_event(vcalendar* cal, vevent* ev) { cal->events = realloc(cal->events, sizeof(*cal->events) * cal->alloc); } - vevent_init_copy(&cal->events[cal->n_events], ev); + // vevent_init_copy(&cal->events[cal->n_events], ev); + cal->events[cal->n_events] = *ev; cal->n_events++; return 0; -- cgit v1.2.3