diff options
author | Hugo Hörnquist <hugo@hornquist.se> | 2019-02-19 10:05:45 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-19 10:18:33 +0100 |
commit | ecd15e3f6731a8298e9cd3ebc45e1875e8c19063 (patch) | |
tree | d976a5fd710cc39350a37a2aa2f37fd08d0926f5 | |
parent | No idea, to tired. (diff) | |
download | calp-ecd15e3f6731a8298e9cd3ebc45e1875e8c19063.tar.gz calp-ecd15e3f6731a8298e9cd3ebc45e1875e8c19063.tar.xz |
Now it links, but segfaults.
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | linked_list.cpp | 26 | ||||
-rw-r--r-- | linked_list.h | 36 | ||||
-rw-r--r-- | parse.cpp | 17 | ||||
-rw-r--r-- | trie.cpp | 10 | ||||
-rw-r--r-- | trie.h | 8 | ||||
-rw-r--r-- | vcal.h | 44 |
7 files changed, 80 insertions, 67 deletions
@@ -5,9 +5,9 @@ CC := g++ OBJDIR = obj CFLAGS = -std=gnu++11 -Wall -Wextra -Wno-reorder \ - -ggdb -fPIC \ - $(shell guile-config compile) -LDFLAGS = -fPIC $(shell guile-config link) + -ggdb -fPIC # \ + # $(shell guile-config compile) +LDFLAGS = -fPIC # $(shell guile-config link) H_FILES = $(wildcard *.h) C_FILES = $(wildcard *.cpp) diff --git a/linked_list.cpp b/linked_list.cpp index b30458c9..ed37eb23 100644 --- a/linked_list.cpp +++ b/linked_list.cpp @@ -1,16 +1,6 @@ #include "linked_list.h" template <typename T> -llist<T>::llist () { - this->length = 0; - this->cur = this->head = new llink<T>; - this->tail = new llink<T>; - - head->after = tail; - tail->before = head; -} - -template <typename T> llink<T>::~llink () { this.unlink(); } @@ -22,22 +12,6 @@ void llink<T>::unlink () { } template <typename T> -void llist<T>::push(T* val) { - auto l = new llink<T>(val); - - l->after = FIRST(this); - FIRST(this) = l; - - l->after->before = l; - l->before = this->head; - - ++this->length; - - // TODO do I want to change that? - this->cur = l; -} - -template <typename T> T& llist<T>::peek() { if (this->empty()) return nullptr; diff --git a/linked_list.h b/linked_list.h index a27d82a1..7ed4c6c4 100644 --- a/linked_list.h +++ b/linked_list.h @@ -8,22 +8,20 @@ struct llink { llink<T>* after = nullptr; T* value; - llink (); + llink () { }; llink (T* val) : value(val) { } ~llink (); void unlink (); }; -// #define L(link) (link)->value - template <typename T> struct llist { llink<T>* head; llink<T>* tail; llink<T>* __cur; T* cur() { return __cur->value; } - int length; + int length = 0; llist (); @@ -43,14 +41,40 @@ struct llist { bool empty () { return length == 0; } }; -// template <typename T> -// std::ostream& std::operator<<(std::ostream&, llist<T>); +template <typename T> +llist<T>::llist () { + this->__cur = this->head = new llink<T>; + this->tail = new llink<T>; + + head->after = tail; + tail->before = head; +} + #define FIRST(lst) (lst)->head->after #define FIRST_V(lst) (lst)->head->after->value #define LAST(lst) (lst)->tail->before #define LAST_V(lst) (lst)->tail->before->value +template <typename T> +void llist<T>::push(T* val) { + auto l = new llink<T>(val); + + l->after = FIRST(this); + FIRST(this) = l; + + l->after->before = l; + l->before = this->head; + + ++this->length; + + // TODO do I want to change that? + this->__cur = l; +} + +// template <typename T> +// std::ostream& std::operator<<(std::ostream&, llist<T>); + #if 0 DEEP_COPY LINK(TYPE)* n = FIRST(src); @@ -35,11 +35,8 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { // std::string& target = cline strbuf target = ctx.str; - // DEEP_COPY(strbuf)(target, &ctx.str); target.cap(); - // strbuf_cap(target); ctx.str.soft_reset(); - // strbuf_soft_reset(&ctx.str); handle_kv(&cline, &ctx); @@ -123,9 +120,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { s->cap(); ctx.str.soft_reset(); - // llist<strbuf>* ls = & CLINE_CUR_PARAMS(&cline)->cur->value->second; - cline.push(s); - + cline.push_param_value (s); } if (p_ctx == p_key) { @@ -160,7 +155,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { */ //strbuf* target = CLINE_CUR_VAL(&cline); - strbuf* target = cline.second.cur(); + strbuf* target = cline.value(); *target = ctx.str; target->cap(); ctx.str.soft_reset(); @@ -184,14 +179,14 @@ int handle_kv ( parse_ctx* ctx ) { - if (cline->first == "BEGIN") { + if (cline->key == "BEGIN") { /* should be one of: * VCALENDAR, VEVENT, VALARM, VTODO, VTIMEZONE, * and possibly some others I forget. */ strbuf* s = new strbuf; - strbuf* type = cline->second.cur(); + strbuf* type = cline->value(); *s = *type; ctx->key_stack.push(s); @@ -202,10 +197,10 @@ int handle_kv ( e->parent = ctx->comp_stack.top(); ctx->comp_stack.push(e); - } else if (cline->first == "END") { + } else if (cline->key == "END") { // strbuf* s = POP(LLIST(strbuf))(&ctx->key_stack); strbuf* s = ctx->key_stack.top(); ctx->key_stack.pop(); - if (s == cline->second.cur()) { + if (s == cline->value()) { #if 0 ERR_P(ctx, "Expected END:%s, got END:%s.\n%s line", s->mem, @@ -1,16 +1,6 @@ #include "trie.h" template <class T> -trie<T>::trie () { - this->root = new trie_node<T> ('\0'); -} - -template <class T> -trie_node<T>::trie_node (char c) { - this->c = c; -} - -template <class T> trie_node<T>::trie_node (char c, trie_node<T>* next, trie_node<T>* child) { this->c = c; this->next = next; @@ -3,25 +3,25 @@ #include <iostream> -template <typename T> +template <class T> struct trie_node { char c; T* value = NULL; trie_node<T>* next = nullptr; trie_node<T>* child = nullptr; - trie_node (char c); + trie_node (char c) : c(c) { }; trie_node (char c, trie_node<T>* next, trie_node<T>* child); }; template <class T> std::ostream& operator<<(std::ostream&, trie_node<T>* node); -template <typename T> +template <class T> struct trie { trie_node<T>* root; - trie (); + trie () : root (new trie_node<T> ('\0')) { } int push_back (const char* key, const T&); @@ -11,10 +11,40 @@ #include "strbuf.h" #include "linked_list.h" -// typedef std::pair<strbuf, llist<strbuf> > param_set; -// typedef std::pair<strbuf, llist<param_set> > content_set; -// typedef std::pair<strbuf, llist<strbuf> > content_line; -typedef llist<strbuf> content_line; +struct __param_set { + strbuf key; + llist<strbuf> values; + + __param_set (strbuf key) : key (key) { } +}; + +/* + * A content set is a single instance of a content line, having a + * specific value and it's own (possible) set of parameters. + */ +struct __content_set { + strbuf value; + llist<__param_set> params; +}; + +/* + * A content line is the collection of all lines which share the same + * key. + */ +struct content_line { + strbuf key; + llist<__content_set> values; + + inline void push_param_key (strbuf key) { + auto p = new __param_set(key); + this->values.cur()->params.push(p); + } + + inline void push_param_value (strbuf* value) { this->values.cur()->params.cur()->values.push(value); } + + inline strbuf* value() { return &this->values.cur()->value; } + +}; struct vcomponent { std::string filename; @@ -60,16 +90,16 @@ std::ostream& operator<<(std::ostream&, vcomponent*); #define CLINE_CUR_CSET(c) (&((c)->second.cur->value)) /* content_set */ -#define CLINE_CUR(c) ((c)->second.cur->value) +#define CLINE_CUR(c) ((c)->second.cur()) /* strbuf */ #define CLINE_CUR_VAL(c) (& CLINE_CUR(c)->first) /* LLIST(param_set) */ #define CLINE_CUR_PARAMS(c) (& CLINE_CUR(c)->second) - /* strbuf */ +/* strbuf */ #define CLINE_CUR_PARAM_KEY(c) (CLINE_CUR_PARAMS(c)->cur->value->first) - /* strbuf */ +/* strbuf */ #define CLINE_CUR_PARAM_VAL(c) (CLINE_CUR_PARAMS(c)->cur->value->second.cur->value) #endif |