From 097442ed9e3340344d7fbc021baaf0b11e7ea4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 23 Feb 2019 21:19:32 +0100 Subject: Everything broken, again. --- main.c | 6 ++++-- parse.c | 58 +++++++++++++++++++++++++++++++++++----------------------- parse.h | 10 ++++++---- vcal.c | 8 +++++--- vcal.h | 18 ++++++++++-------- 5 files changed, 60 insertions(+), 40 deletions(-) diff --git a/main.c b/main.c index 78e631e8..ea48035f 100644 --- a/main.c +++ b/main.c @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -61,8 +63,8 @@ int main (int argc, char** argv) { if (strcmp(ev->type, "VEVENT") != 0) continue; content_line* cl = get_property(ev, "SUMMARY"); - strbuf* s = cl->data.cur->value->key; - char* m = s->mem; + std::string* s = cl->data.cur->value->key; + const char* m = s->c_str(); printf("%3lu : %3lu | %s | %s\n", i + 1, j + 1, filename, m); diff --git a/parse.c b/parse.c index 1f2150a2..9f6bdca6 100644 --- a/parse.c +++ b/parse.c @@ -21,7 +21,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { parse_ctx ctx(filename); ctx.comp_stack.push(root); - strbuf key; + std::string key; param_set* ps; char c; @@ -33,9 +33,11 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { if (fold(f, &ctx, c) > 0) { /* Actuall end of line, handle value */ - strbuf_cap(&ctx.str); + // strbuf_cap(&ctx.str); + ctx.str += '\0'; handle_kv(&key, &ctx); - strbuf_soft_reset(&ctx.str); + // strbuf_soft_reset(&ctx.str); + ctx.str.clear(); p_ctx = p_key; } /* Else continue on current line */ @@ -75,7 +77,8 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { } /* save escapade character as a normal character */ - strbuf_append(&ctx.str, target); + // strbuf_append(&ctx.str, target); + ctx.str += target; ++ctx.column; ++ctx.pcolumn; @@ -83,11 +86,13 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { /* Border between param {key, value} */ } else if (p_ctx == p_param_name && c == '=') { - strbuf_cap(&ctx.str); + // strbuf_cap(&ctx.str); + ctx.str += '\0'; ps = new param_set; *ps->key = ctx.str; - strbuf_soft_reset(&ctx.str); + ctx.str.clear(); + // strbuf_soft_reset(&ctx.str); p_ctx = p_param_value; @@ -101,19 +106,23 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { } else if ((p_ctx == p_key || p_ctx == p_param_value) && (c == ':' || c == ';')) { /* We have the end of the initial key, or the end of a * parameter value */ - strbuf_cap(&ctx.str); + // strbuf_cap(&ctx.str); + ctx.str += '\0'; if (p_ctx == p_param_value) { /* push kv pair */ - ps->val->push(new strbuf(ctx.str)); - strbuf_soft_reset(&ctx.str); + ps->val->push(new std::string(ctx.str)); + ctx.str.clear(); + // strbuf_soft_reset(&ctx.str); } if (p_ctx == p_key) { - strbuf_cap(&ctx.str); + // strbuf_cap(&ctx.str); + ctx.str += '\0'; key = ctx.str; - strbuf_soft_reset(&ctx.str); + // strbuf_soft_reset(&ctx.str); + ctx.str.clear(); } if (c == ':') p_ctx = p_value; @@ -122,7 +131,8 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { } else { /* Regular character, append it to the current read * buffer */ - strbuf_append(&ctx.str, c); + // strbuf_append(&ctx.str, c); + ctx.str += c; ++ctx.column; ++ctx.pcolumn; @@ -133,16 +143,18 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { ERR("Error parsing"); } /* Check to see if empty line */ - else if (ctx.str.ptr != 0) { + else if (ctx.str.length() != 0) { /* * The standard (3.4, l. 2675) says that each icalobject must * end with CRLF. My files however does not, so we also parse * the end here. */ - strbuf_cap(&ctx.str); + // strbuf_cap(&ctx.str); + ctx.str += '\0'; handle_kv(&key, &ctx); - strbuf_soft_reset(&ctx.str); + ctx.str.clear(); + // strbuf_soft_reset(&ctx.str); ++ctx.line; ++ctx.pline; @@ -159,12 +171,12 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { } int handle_kv ( - strbuf* key, + std::string* key, // content_line* cline, parse_ctx* ctx ) { - strbuf* val = &ctx->str; + std::string* val = &ctx->str; // std::cout << *key << ':' << *val << std::endl; if (*key == "BEGIN") { @@ -172,7 +184,7 @@ int handle_kv ( ctx->key_stack.push(val); - auto e = new vcomponent(val->mem, ctx->filename); + auto e = new vcomponent(val->c_str(), ctx->filename); e->parent = ctx->comp_stack.peek(); ctx->comp_stack.push(e); @@ -180,14 +192,14 @@ int handle_kv ( } else if (*key == "END") { /* Fetch what we are supposed to end */ - strbuf* s = ctx->key_stack.pop(); + std::string* s = ctx->key_stack.pop(); /* Error if we got something else */ - if (*val != *s) { + if ( ! (*val == *s) ) { ERR_P(ctx, "Expected END:%s, got %s:%s.\n%s", - s->mem, - key->mem, - val->mem, + s->c_str(), + key->c_str(), + val->c_str(), ctx->comp_stack.peek()->filename ); diff --git a/parse.h b/parse.h index 01863369..9d2ab2e5 100644 --- a/parse.h +++ b/parse.h @@ -1,10 +1,12 @@ #ifndef PARSE_H #define PARSE_H +#include + #include #include -#include "strbuf.h" +// #include "strbuf.h" #include "vcal.h" // #define TYPE vcomponent @@ -28,7 +30,7 @@ typedef enum { */ struct parse_ctx { char* filename; - llist key_stack; + llist key_stack; llist comp_stack; /* Number for unfolded lines */ @@ -39,7 +41,7 @@ struct parse_ctx { int pline; int pcolumn; - strbuf str; + std::string str; parse_ctx (const char* filename); @@ -47,7 +49,7 @@ struct parse_ctx { }; int handle_kv( - strbuf* key, + std::string* key, // content_line* cline, parse_ctx* ctx ); diff --git a/vcal.c b/vcal.c index fa0649e6..0e4061c3 100644 --- a/vcal.c +++ b/vcal.c @@ -57,14 +57,16 @@ int DEEP_COPY(vcomponent)(vcomponent* a, vcomponent* b) { return -1; } -content_line::content_line (strbuf* key, strbuf* val) { +content_line::content_line (std::string* key, std::string* val) { this->key = key; this->push_value(val); } -void vcomponent:: push_kv (strbuf* key, strbuf* val) { +void vcomponent:: push_kv (std::string* key, std::string* val) { auto cl = new content_line (key, val); - this->clines.push(key->mem, cl); + char * mem = (char*) malloc(key->length()); + memcpy (mem, key->c_str(), key->length() + 1); + this->clines.push(mem, cl); } #if 0 diff --git a/vcal.h b/vcal.h index 5ec20f17..2af64cd5 100644 --- a/vcal.h +++ b/vcal.h @@ -1,31 +1,33 @@ #ifndef VCAL_H #define VCAL_H +#include + #include -#include "strbuf.h" +// #include "strbuf.h" #include "linked_list.h" #include "trie.h" #include "linked_list.h" #include "pair.h" -typedef pair > param_set; -typedef pair > content_set; +typedef pair > param_set; +typedef pair > content_set; // typedef pair > content_line; // typedef llist content_line; struct content_line { llist data; - content_line (strbuf* key, strbuf* val); + content_line (std::string* key, std::string* val); - void push_value (strbuf* s) { + void push_value (std::string* s) { auto cs = new content_set(); cs->key = s; this->data.push(cs); } - strbuf* cur_val () { + std::string* cur_val () { return this->data.peek()->key; } @@ -51,7 +53,7 @@ struct content_line { } private: - strbuf* key; + std::string* key; }; /* @@ -99,7 +101,7 @@ struct vcomponent { ~vcomponent (); - void push_kv (strbuf* key, strbuf* val); + void push_kv (std::string* key, std::string* val); }; // #define FCHILD(v) GET(VECT(vcomponent))(&(v)->components, 0) -- cgit v1.2.3