From 985ee1776348b2068fb6470e2a2fd3442c2a0811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 26 Feb 2019 10:56:49 +0100 Subject: Start update of types. --- graphs.c | 8 ++++++-- guile_interface.scm.c | 8 ++++---- linked_list.inc.h | 1 + main.c | 2 +- parse.c | 34 +++++++++++++++++++--------------- parse.h | 1 + trie.h | 2 ++ trie.inc.h | 6 ++++++ vcal.c | 19 +++++++++---------- vcal.h | 45 ++++++++++++++++++++++----------------------- 10 files changed, 71 insertions(+), 55 deletions(-) diff --git a/graphs.c b/graphs.c index 2ed7009e..8051b226 100644 --- a/graphs.c +++ b/graphs.c @@ -98,7 +98,7 @@ int trie_to_dot_helper ( TRIE_NODE(T)* root, FILE* f ) { } else { fprintf(f, "\"%p\"[label = \"%c [%i]\" style=filled fillcolor=green];\n", (void*) root, root->c, - SIZE(LLIST(content_set))(&L(root)->val) + SIZE(LLIST(content_set))(L(root)) ); } TRIE_NODE(T)* child = root->child; @@ -107,7 +107,7 @@ int trie_to_dot_helper ( TRIE_NODE(T)* root, FILE* f ) { #if 1 /* Toggle values */ if (L(root) != NULL) { - FOR(LLIST, content_set, v, &L(root)->val) { + FOR(LLIST, content_set, v, L(root)) { char buf[0x100]; FMT(strbuf)(&v->key, buf); fprintf(f, "\"%p\" [label=\"%s\" shape=rectangle color=darkgreen];\n", @@ -115,6 +115,9 @@ int trie_to_dot_helper ( TRIE_NODE(T)* root, FILE* f ) { fprintf(f, "\"%p\" -> \"%p\";\n", root, v); /* Parameters */ + // TODO reenable this, but currently v->val is a TRIE, + // which I currently can't itterate over +#if 0 FOR(LLIST, param_set, p, &v->val) { strbuf* param_key = &p->key; @@ -128,6 +131,7 @@ int trie_to_dot_helper ( TRIE_NODE(T)* root, FILE* f ) { fprintf(f, "\"%p\" -> \"%p\";", param_key, str); } } +#endif } } #endif diff --git a/guile_interface.scm.c b/guile_interface.scm.c index 244116e3..0fd46505 100644 --- a/guile_interface.scm.c +++ b/guile_interface.scm.c @@ -47,7 +47,7 @@ SCM_DEFINE (vcomponent_get_attribute, "%vcomponent-get-attribute", 2, 0, 0, if (c == NULL) return SCM_BOOL_F; SCM llist = SCM_EOL; - FOR (LLIST, content_set, v, &c->val) { + FOR (LLIST, content_set, v, c) { llist = scm_cons(scm_from_strbuf(&v->key), llist); } @@ -70,9 +70,9 @@ SCM_DEFINE (vcomponent_set_attr_x, "%vcomponent-set-attribute!", 3, 0, 0, content_line* c = get_property (com, key); free(key); - scm_gc_unprotect_object(c->val.cur->value->key.scm); - c->val.cur->value->key.scm = new_value; - scm_gc_protect_object(c->val.cur->value->key.scm); + scm_gc_unprotect_object(c->cur->value->key.scm); + c->cur->value->key.scm = new_value; + scm_gc_protect_object(c->cur->value->key.scm); return SCM_UNSPECIFIED; } diff --git a/linked_list.inc.h b/linked_list.inc.h index 8ae720ba..499d4509 100644 --- a/linked_list.inc.h +++ b/linked_list.inc.h @@ -139,6 +139,7 @@ int EMPTY(LLIST(TYPE)) ( LLIST(TYPE)* llist ) { LLIST(TYPE)* RESOLVE(LLIST(TYPE)) (LLIST(TYPE)* dest, LLIST(TYPE)* new__) { if (dest == NULL) return new__; APPEND(LLIST(TYPE))(dest, new__); + // TODO free new__? return dest; } diff --git a/main.c b/main.c index 830eb538..3e0d005e 100644 --- a/main.c +++ b/main.c @@ -58,7 +58,7 @@ int main (int argc, char** argv) { printf("%3lu : %3lu | %s | %s\n", i + 1, j + 1, filename, - get_property(ev, "SUMMARY")->val.cur->value->key.mem); + get_property(ev, "SUMMARY")->cur->value->key.mem); } } } else if (strcmp(args.argv[0], "-g") == 0) { diff --git a/parse.c b/parse.c index 30412e1a..ead020f8 100644 --- a/parse.c +++ b/parse.c @@ -34,6 +34,8 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { * parsing. This object is constantly broken down and rebuilt. */ SNEW(content_line, cline); + SNEW(strbuf, cline_key); + SNEW(strbuf, param_key); char c; while ( (c = fgetc(f)) != EOF) { @@ -44,7 +46,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { if (fold(&ctx, c) > 0) { /* Actuall end of line, handle value */ TRANSFER(CLINE_CUR_VAL(&cline), &ctx.str); - handle_kv(&cline, &ctx); + handle_kv(¶m_key, &cline, &ctx); p_ctx = p_key; } /* Else continue on current line */ @@ -57,9 +59,8 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { /* Create a new parameter set and push the current string * as its key */ - NEW(param_set, ps); - TRANSFER (&ps->key, &ctx.str); - PUSH(LLIST(param_set))(CLINE_CUR_PARAMS(&cline), ps); + TRANSFER (¶m_key, &ctx.str); + // PUSH(LLIST(param_set))(CLINE_CUR_PARAMS(&cline), ps); p_ctx = p_param_value; @@ -79,9 +80,11 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { NEW(strbuf, s); TRANSFER(s, &ctx.str); - PUSH(LLIST(strbuf))( - & CLINE_CUR_PARAMS(&cline)->cur->value->val, - s); + + NEW(param_set, ps); + PUSH(LLIST(strbuf))(ps, s); + + PUSH(TRIE(param_set))(CLINE_CUR_PARAMS(&cline), s->mem, ps); } /* @@ -92,10 +95,10 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { */ if (p_ctx == p_key) { - TRANSFER(&cline.key, &ctx.str); + TRANSFER(&cline_key, &ctx.str); NEW(content_set, p); - PUSH(LLIST(content_set))(&cline.val, p); + PUSH(LLIST(content_set))(&cline, p); } if (c == ':') p_ctx = p_value; @@ -125,7 +128,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { */ TRANSFER(CLINE_CUR_VAL(&cline), &ctx.str); - handle_kv(&cline, &ctx); + handle_kv(¶m_key, &cline, &ctx); } @@ -144,6 +147,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { * We have a complete key value pair. */ int handle_kv ( + strbuf* key, content_line* cline, parse_ctx* ctx ) { @@ -151,7 +155,7 @@ int handle_kv ( /* * The key being BEGIN means that we decend into a new component. */ - if (strbuf_c(&cline->key, "BEGIN")) { + if (strbuf_c(key, "BEGIN")) { /* key \in { VCALENDAR, VEVENT, VALARM, VTODO, VTIMEZONE, ... } */ /* @@ -163,7 +167,7 @@ int handle_kv ( PUSH(LLIST(strbuf))(&ctx->key_stack, s); /* Clear the value list in the parse content_line */ - RESET(LLIST(content_set))(&cline->val); + RESET(LLIST(content_set))(cline); /* * Create the new curent component, link it with the current @@ -183,7 +187,7 @@ int handle_kv ( * The end of a component, go back along the stack to the previous * component. */ - } else if (strbuf_c(&cline->key, "END")) { + } else if (strbuf_c(key, "END")) { strbuf* expected_key = POP(LLIST(strbuf))(&ctx->key_stack); if (strbuf_cmp(expected_key, CLINE_CUR_VAL(cline)) != 0) { @@ -225,9 +229,9 @@ int handle_kv ( */ PUSH(TRIE(content_line))( &PEEK(LLIST(vcomponent))(&ctx->comp_stack)->clines, - c->key.mem, c); + key->mem, c); - RESET(LLIST(content_set))(&cline->val); + RESET(LLIST(content_set))(cline); } return 0; diff --git a/parse.h b/parse.h index 891936b7..238c8cd0 100644 --- a/parse.h +++ b/parse.h @@ -90,6 +90,7 @@ int parse_file(char* filename, FILE* f, vcomponent* cal); * ctx. */ int handle_kv( + strbuf* key, content_line* cline, parse_ctx* ctx ); diff --git a/trie.h b/trie.h index 404864d3..908c4e41 100644 --- a/trie.h +++ b/trie.h @@ -43,4 +43,6 @@ int EMPTY(TRIE(TYPE))(TRIE(TYPE)*); FMT_F(TRIE_NODE(TYPE)); FMT_F(TRIE(TYPE)); +int DEEP_COPY(TRIE(TYPE)) (TRIE(TYPE)* dest, TRIE(TYPE)* src); + #endif /* TYPE */ diff --git a/trie.inc.h b/trie.inc.h index 5517939e..90d9cb06 100644 --- a/trie.inc.h +++ b/trie.inc.h @@ -163,4 +163,10 @@ FMT_F(TRIE(TYPE)) { return seek; } +int DEEP_COPY(TRIE(TYPE)) (TRIE(TYPE)* dest, TRIE(TYPE)* src) { + (void) dest; (void) src; + ERR(deep copy on tries currently not implemented); + return 1; +} + #endif /* TYPE */ diff --git a/vcal.c b/vcal.c index a17f1fcc..94be9399 100644 --- a/vcal.c +++ b/vcal.c @@ -7,7 +7,7 @@ #undef TYPE #define TYPE param_set -#include "linked_list.inc.h" +#include "trie.inc.h" #undef TYPE #define TYPE content_set @@ -15,13 +15,7 @@ #undef TYPE #define T strbuf - #define V LLIST(strbuf) - #include "pair.inc.h" - #undef V - #define V LLIST(param_set) - #include "pair.inc.h" - #undef V - #define V LLIST(content_set) + #define V TRIE(param_set) #include "pair.inc.h" #undef V #undef T @@ -65,24 +59,29 @@ INIT_F(vcomponent, const char* type, const char* filename) { return 0; } +#if 0 content_line* RESOLVE(content_line) (content_line* dest, content_line* new_) { if (dest == NULL) return new_; + /* if (strbuf_cmp(&dest->key, &new_->key) != 0) { ERR("Can't resolve between these two types"); return NULL; } + */ /* This destroys new_->val. */ - APPEND(LLIST(content_set)) (&dest->val, &new_->val); + //APPEND(LLIST(content_set)) (&dest->val, &new_->val); + APPEND(LLIST(content_set)) (dest, new_); - FREE(strbuf)(&new_->key); + // FREE(strbuf)(&new_->key); free(new_); return dest; } +#endif content_line* get_property (vcomponent* ev, const char* key) { size_t len = strlen(key) + 1; diff --git a/vcal.h b/vcal.h index bedf22ee..c688bcf5 100644 --- a/vcal.h +++ b/vcal.h @@ -22,23 +22,17 @@ * A parameter key, along with a list of all its values. */ -#define T strbuf - #define V LLIST(strbuf) - #include "pair.h" - /* left := param_name | right := param_values */ - #define param_set PAIR(strbuf, LLIST(strbuf)) - #undef V -#undef T +#define param_set LLIST(strbuf) #define TYPE param_set -#include "linked_list.h" +#include "trie.h" #undef TYPE #define T strbuf - #define V LLIST(param_set) + #define V TRIE(param_set) #include "pair.h" /* left := content | right := params */ - #define content_set PAIR(strbuf, LLIST(param_set)) + #define content_set PAIR(strbuf, TRIE(param_set)) #undef V #undef T @@ -46,13 +40,15 @@ #include "linked_list.h" #undef TYPE -#define T strbuf - #define V LLIST(content_set) - #include "pair.h" - /* left := content | right := params */ - #define content_line PAIR(strbuf, LLIST(content_set)) - #undef V -#undef T +// #define T strbuf +// #define V LLIST(content_set) +// #include "pair.h" +// /* left := content | right := params */ +// #define content_line PAIR(strbuf, LLIST(content_set)) +// #undef V +// #undef T + +#define content_line LLIST(content_set) /* * Helper macros for accessing fields in @@ -62,21 +58,22 @@ */ /* ptr -> ptr */ -#define CLINE_KEY(c) (&(c)->key) -#define CLINE_CUR_CSET(c) (&((c)->val.cur->value)) +// #define CLINE_KEY(c) (&(c)->key) +// #define CLINE_CUR_CSET(c) (&((c)->val.cur->value)) /* content_set */ -#define CLINE_CUR(c) ((c)->val.cur->value) +#define CLINE_CUR(c) ((c)->cur->value) + /* strbuf */ #define CLINE_CUR_VAL(c) (& CLINE_CUR(c)->key) -/* LLIST(param_set) */ +/* TRIE(param_set) */ #define CLINE_CUR_PARAMS(c) (& CLINE_CUR(c)->val) /* strbuf */ -#define CLINE_CUR_PARAM_KEY(c) (CLINE_CUR_PARAMS(c)->cur->value->key) +// #define CLINE_CUR_PARAM_KEY(c) (CLINE_CUR_PARAMS(c)->cur->value->key) /* strbuf */ -#define CLINE_CUR_PARAM_VAL(c) (CLINE_CUR_PARAMS(c)->cur->value->val.cur->value) +// #define CLINE_CUR_PARAM_VAL(c) (CLINE_CUR_PARAMS(c)->cur->value->val.cur->value) /* * Resolves a collision in some form of structure (probably a hash-map @@ -84,8 +81,10 @@ * to have the correct form, and returns it. Destroying new_ in the * process. */ +#if 0 content_line* RESOLVE(content_line) (content_line* dest, content_line* new_); +#endif #define TYPE content_line #include "trie.h" -- cgit v1.2.3