From 4ec130209bcd88ffde56b9b44e2de2c043519ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 2 May 2019 23:44:20 +0200 Subject: Think it's only reintroducing of set! left. --- module/vcomponent.scm | 6 +++--- module/vcomponent/primitive.scm | 3 +++ src/calendar.c | 24 ++++++++++++++++++------ src/guile_interface.scm.c | 2 +- src/parse.c | 3 --- src/vcal.c | 6 +++--- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/module/vcomponent.scm b/module/vcomponent.scm index 6df4d7b8..d1a0abff 100644 --- a/module/vcomponent.scm +++ b/module/vcomponent.scm @@ -119,7 +119,7 @@ %vcomponent-set-type!)) (define-public parent %vcomponent-parent) (define-public push-child! %vcomponent-push-child!) -(define-public (attributes component) (map string->symbol (%vcomponent-attribute-list component))) +(define-public attributes %vcomponent-attribute-list) (define-public copy-vcomponent %vcomponent-shallow-copy) @@ -148,7 +148,7 @@ (%vcomponent-make) (let* ((root (%vcomponent-make path)) (component - (case (string->symbol (or (attr root "X-HNH-SOURCETYPE") "no-type")) + (case (or (attr root "X-HNH-SOURCETYPE") 'no-type) ;; == Single ICS file == ;; Remove the abstract ROOT component, ;; returning the wanted VCALENDAR component @@ -166,7 +166,7 @@ ((vdir) (let ((accum (make-vcomponent)) (ch (children root))) - (set! (type accum) "VCALENDAR") + (set! (type accum) 'VCALENDAR) (unless (null? ch) (for key in (attributes (car ch)) diff --git a/module/vcomponent/primitive.scm b/module/vcomponent/primitive.scm index 06b6fd83..53d73652 100644 --- a/module/vcomponent/primitive.scm +++ b/module/vcomponent/primitive.scm @@ -20,3 +20,6 @@ (string-append (dirname (dirname (dirname (current-filename)))) "/lib")) (load-extension "libguile-calendar" "init_lib") + +(define (%vcomponent-attribute-list comp) + (map car (hash-map->list cons (%vcomponent-get-hash-table comp)))) diff --git a/src/calendar.c b/src/calendar.c index d7c2d7dd..2c21bd11 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -49,8 +49,12 @@ int handle_file(vcomponent* cal, char* path) { strbuf_load (&sourcetype, "X-HNH-SOURCETYPE"); const char* bname = basename(path); - vcomponent_push_val(cal, &name, scm_from_utf8_stringn (bname, strlen(bname))); - vcomponent_push_val(cal, &sourcetype, scm_from_utf8_symbol("file")); + vcomponent_push_val(cal, &name, + scm_cons (scm_from_utf8_stringn (bname, strlen(bname)), + SCM_BOOL_F)); + vcomponent_push_val(cal, &sourcetype, + scm_cons (scm_from_utf8_symbol("file"), + SCM_BOOL_F)); char* resolved_path = realpath(path, NULL); open_ics (resolved_path, cal); free (resolved_path); @@ -81,8 +85,12 @@ int handle_dir(vcomponent* cal, char* path) { const char* bname = basename(path); /* NAME is the `fancy' name of the calendar. */ - vcomponent_push_val(cal, &name, scm_from_utf8_stringn(bname, strlen(bname))); - vcomponent_push_val(cal, &sourcetype, scm_from_utf8_symbol("vdir")); + vcomponent_push_val(cal, &name, + scm_cons(scm_from_utf8_stringn(bname, strlen(bname)), + SCM_BOOL_F)); + vcomponent_push_val(cal, &sourcetype, + scm_cons(scm_from_utf8_symbol("vdir"), + SCM_BOOL_F)); FREE(strbuf)(&name); FREE(strbuf)(&sourcetype); @@ -110,7 +118,9 @@ int handle_dir(vcomponent* cal, char* path) { fclose(f); SNEW(strbuf, color); strbuf_load (&color, "COLOR"); - vcomponent_push_val(cal, &color, scm_from_utf8_stringn(info_buf, strlen(info_buf))); + vcomponent_push_val(cal, &color, + scm_cons(scm_from_utf8_stringn(info_buf, strlen(info_buf)), + SCM_BOOL_F)); FREE(strbuf)(&color); } else if (strcmp (d->d_name, "displayname") == 0) { f = fopen(resolved_path, "r"); @@ -127,7 +137,9 @@ int handle_dir(vcomponent* cal, char* path) { */ SNEW(strbuf, name); strbuf_load (&name, "NAME"); - vcomponent_push_val(cal, &name, scm_from_utf8_stringn(info_buf, strlen(info_buf))); + vcomponent_push_val(cal, &name, + scm_cons(scm_from_utf8_stringn(info_buf, strlen(info_buf)), + SCM_BOOL_F)); FREE(strbuf)(&name); } else { open_ics (resolved_path, cal); diff --git a/src/guile_interface.scm.c b/src/guile_interface.scm.c index 7828389f..e54b81d5 100644 --- a/src/guile_interface.scm.c +++ b/src/guile_interface.scm.c @@ -222,7 +222,7 @@ SCM_DEFINE(vcomponent_set_type_x, "%vcomponent-set-type!", 2, 0, 0, if (comp->type) free (comp->type); - char* ntype = scm_to_utf8_stringn (type, NULL); + char* ntype = scm_to_utf8_stringn (scm_symbol_to_string(type), NULL); comp->type = calloc(sizeof(*ntype), strlen(ntype) + 1); strcpy(comp->type, ntype); diff --git a/src/parse.c b/src/parse.c index d9a75296..cd64e192 100644 --- a/src/parse.c +++ b/src/parse.c @@ -46,9 +46,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { TRANSFER(&cline_val, &ctx.str); /* Actuall end of line, handle value */ - INFO_F("cp: %p", content_pair); handle_kv(&cline_key, &cline_val, &content_pair, &ctx); - INFO_F("cp: %p", content_pair); p_ctx = p_key; } /* Else continue on current line */ @@ -154,7 +152,6 @@ int handle_kv ( strbuf_cap (key); strbuf_cap (val); - INFO_F("%s: %s", key->mem, val->mem); /* * The key being BEGIN means that we decend into a new component. diff --git a/src/vcal.c b/src/vcal.c index f9f2cb75..208a47a9 100644 --- a/src/vcal.c +++ b/src/vcal.c @@ -47,7 +47,7 @@ INIT_F(vcomponent) { // vcomponent_push_val (self, "X-HNH-FILENAME", "VIRTUAL"); SNEW(strbuf, s); strbuf_load(&s, "X-HNH-SOURCETYPE"); - vcomponent_push_val (self, &s, scm_from_utf8_symbol("virtual")); + vcomponent_push_val (self, &s, scm_cons(scm_from_utf8_symbol("virtual"), SCM_BOOL_F)); FREE(strbuf)(&s); char* type = "VIRTUAL"; self->type = (char*) calloc(sizeof(*type), strlen(type) + 1); @@ -85,7 +85,7 @@ INIT_F(vcomponent, const char* type, const char* filename) { */ SNEW(strbuf, fname); strbuf_load (&fname, "X-HNH-FILENAME"); - vcomponent_push_val (self, &fname, scm_from_utf8_stringn(filename, strlen(filename))); + vcomponent_push_val (self, &fname, scm_cons(scm_from_utf8_stringn(filename, strlen(filename)), SCM_BOOL_F)); } self->type = (char*) calloc(sizeof(*type), strlen(type) + 1); @@ -195,7 +195,7 @@ int vcomponent_push_val (vcomponent* comp, strbuf* key, SCM val) { SCM k = scm_string_to_symbol (scm_from_utf8_stringn (key->mem, key->len)); // TODO this should cons - scm_hashq_set_x (comp->clines, k, val); + scm_hashq_set_x (comp->clines, k, scm_list_1 (val)); return 0; } -- cgit v1.2.3