diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-23 21:19:32 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-23 21:19:32 +0100 |
commit | 097442ed9e3340344d7fbc021baaf0b11e7ea4fb (patch) | |
tree | e86018252bff6a8a9ac5ae2942845ccbb6ba02db | |
parent | Vill inte. (diff) | |
download | calp-c++2.tar.gz calp-c++2.tar.xz |
Everything broken, again.c++2
Diffstat (limited to '')
-rw-r--r-- | main.c | 6 | ||||
-rw-r--r-- | parse.c | 58 | ||||
-rw-r--r-- | parse.h | 10 | ||||
-rw-r--r-- | vcal.c | 8 | ||||
-rw-r--r-- | vcal.h | 18 |
5 files changed, 60 insertions, 40 deletions
@@ -1,3 +1,5 @@ +#include <string> + #include <errno.h> #include <stdio.h> #include <string.h> @@ -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); @@ -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 ); @@ -1,10 +1,12 @@ #ifndef PARSE_H #define PARSE_H +#include <string> + #include <stdio.h> #include <stdlib.h> -#include "strbuf.h" +// #include "strbuf.h" #include "vcal.h" // #define TYPE vcomponent @@ -28,7 +30,7 @@ typedef enum { */ struct parse_ctx { char* filename; - llist<strbuf> key_stack; + llist<std::string> key_stack; llist<vcomponent> 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 ); @@ -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 @@ -1,31 +1,33 @@ #ifndef VCAL_H #define VCAL_H +#include <string> + #include <stdlib.h> -#include "strbuf.h" +// #include "strbuf.h" #include "linked_list.h" #include "trie.h" #include "linked_list.h" #include "pair.h" -typedef pair<strbuf, llist<strbuf> > param_set; -typedef pair<strbuf, llist<param_set> > content_set; +typedef pair<std::string, llist<std::string> > param_set; +typedef pair<std::string, llist<param_set> > content_set; // typedef pair<strbuf, llist<content_set> > content_line; // typedef llist<content_set> content_line; struct content_line { llist<content_set> 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) |