From fc5512ffa6091544d8e310ab7b7876f05f73f2de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 19 Feb 2019 11:17:16 +0100 Subject: =?UTF-8?q?Jag=20kan=20inte=20ens=20programmera=20p=C3=A5=20r?= =?UTF-8?q?=C3=A4tt=20dator...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- linked_list.h | 15 +++++++++++++++ main.cpp | 2 +- parse.cpp | 27 +++++++++------------------ vcal.cpp | 2 +- vcal.h | 3 ++- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/linked_list.h b/linked_list.h index 7ed4c6c4..75096a93 100644 --- a/linked_list.h +++ b/linked_list.h @@ -39,6 +39,8 @@ struct llist { int size () { return length; } bool empty () { return length == 0; } + + void reset (); }; template @@ -72,6 +74,19 @@ void llist::push(T* val) { this->__cur = l; } +template +void llist::reset () { + llink *link = this->first, *next; + + while (link != this->tail) { + next = link->after; + delete link; + link = next; + } + + this->__cur = this->head; +} + // template // std::ostream& std::operator<<(std::ostream&, llist); diff --git a/main.cpp b/main.cpp index 1e2c960e..d41fa258 100644 --- a/main.cpp +++ b/main.cpp @@ -23,7 +23,7 @@ int arg_shift (arg* a) { } int main (int argc, char** argv) { - arg args = { .argc = argc, .argv = argv }; + arg args = { argc, argv }; if (arg_shift(&args) == 0) { ERR("Please give vdir or a vcalendar file as first argument"); diff --git a/parse.cpp b/parse.cpp index 8d47ee72..df5aa053 100644 --- a/parse.cpp +++ b/parse.cpp @@ -64,7 +64,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { } } - /* Escaped new_line */ + /* Escaped newline */ if (esc == 'n' || esc == 'N') { target = '\n'; @@ -78,7 +78,6 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { } /* save escapade character as a normal character */ - // strbuf_append(&ctx.str, target); ctx.str += target; ++ctx.column; @@ -87,20 +86,10 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { /* Border between param {key, value} */ } else if (p_ctx == p_param_name && c == '=') { - // LLIST(param_set)* params = CLINE_CUR_PARAMS(&cline); - /* - std::list* params = cline.val.val; - - // NEW(param_set, ps); - auto ps = new param_set; - // TODO make sure this is a deep copy - ps->first = ctx.str; - ps->first.cap(); + strbuf cpy = ctx.str; + cpy.cap(); ctx.str.soft_reset(); - params += ps; - // PUSH(LLIST(param_set))(params, ps); - * - */ + cline.push_param_key (cpy); p_ctx = p_param_value; @@ -116,7 +105,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { if (p_ctx == p_param_value) { /* push kv pair */ - auto s = new strbuf(ctx.str);; + auto s = new strbuf(ctx.str); s->cap(); ctx.str.soft_reset(); @@ -124,10 +113,11 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { } if (p_ctx == p_key) { - // cline.first = ctx.str; - // cline.first.cap(); + cline.key = ctx.str; + cline.key.cap(); ctx.str.soft_reset(); + // TODO? // content_set* p = new content_set; // cline.second.push(p); } @@ -190,6 +180,7 @@ int handle_kv ( *s = *type; ctx->key_stack.push(s); + cline->values.reset(); // TODO ompty cline->second here; // RESET(LLIST(content_set))(&cline->val); diff --git a/vcal.cpp b/vcal.cpp index 8180cf80..b0ce2c82 100644 --- a/vcal.cpp +++ b/vcal.cpp @@ -8,7 +8,7 @@ vcomponent::vcomponent( const std::string& filename) : type(type) , filename(filename) -{ }; +{ } std::ostream& operator<<(std::ostream& o, vcomponent* self) { for (int i = 0; i < 40; i++) o << '_'; diff --git a/vcal.h b/vcal.h index fb767820..93699a29 100644 --- a/vcal.h +++ b/vcal.h @@ -40,7 +40,8 @@ struct content_line { this->values.cur()->params.push(p); } - inline void push_param_value (strbuf* value) { this->values.cur()->params.cur()->values.push(value); } + inline void push_param_value (strbuf* value) + { this->values.cur()->params.cur()->values.push(value); } inline strbuf* value() { return &this->values.cur()->value; } -- cgit v1.2.3