diff options
author | Hugo Hörnquist <hugo@hornquist.se> | 2019-02-25 22:59:53 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@hornquist.se> | 2019-02-25 22:59:53 +0100 |
commit | 6355700d4101a6e515311c96bf8e25bb1bb51d92 (patch) | |
tree | 01b362d60f6fa58d55a0bd1e76e2c3194d2b5b1e | |
parent | Reenable guile stuff. (diff) | |
download | calp-6355700d4101a6e515311c96bf8e25bb1bb51d92.tar.gz calp-6355700d4101a6e515311c96bf8e25bb1bb51d92.tar.xz |
Add scm field to strbuf.
-rwxr-xr-x | code.scm | 42 | ||||
-rw-r--r-- | guile_interface.h | 2 | ||||
-rw-r--r-- | guile_interface.scm.c | 7 | ||||
-rw-r--r-- | guile_type_helpers.c | 9 | ||||
-rw-r--r-- | strbuf.c | 1 | ||||
-rw-r--r-- | strbuf.h | 2 |
6 files changed, 33 insertions, 30 deletions
@@ -2,37 +2,29 @@ -s !# -(add-to-load-path (dirname (current-filename))) -(load "helpers.scm") - -(use-modules (ice-9 format) - (ice-9 pretty-print)) - (begin ;; Supurflous begin block here to make sourcing into geiser easier. (setenv "LD_LIBRARY_PATH" (getcwd)) (load-extension "libguile-calendar" "init_vcomponent")) -(begin - (define root (make-vcomponent "test.ics")) - (define cal (car (vcomponent-children root))) - (define events (vcomponent-children cal))) +(define root (make-vcomponent "testcal/d1-b.ics")) +(define cal (car (vcomponent-children root))) -(define (pp-list strs) - (for-each (lambda (i str) - (format #t "~3d | ~a~%" - (1+ i) - str)) - (iota (length strs)) - strs)) +;; TODO flatten all calendars into root -(pp-list - (map (lambda (c) (car (vcomponent-get-attribute c "summary"))) - events)) +(use-modules (srfi srfi-19) + (srfi srfi-26)) -#; -(do ((i 0 (1+ i))) - ((>= i (calendar-size v))) - (format #t "~3d | ~a~%" - (1+ i) (car (calendar-get-attr v i "summary")))) +(for-each (lambda (ev) + (vcomponent-set-attribute! + ev "DTSTART" + (map (cut string->date <> "~Y~m~dT~H~M~S") + (vcomponent-get-attribute ev "DTSTART")))) + (vcomponent-children cal)) +(display (vcomponent-get-attribute (car (vcomponent-children cal)) + "DTSTART")) +(newline) +(display (vcomponent-get-attribute (car (vcomponent-children cal)) + "DTSTART")) +(newline) diff --git a/guile_interface.h b/guile_interface.h index 91e25a72..4864407f 100644 --- a/guile_interface.h +++ b/guile_interface.h @@ -3,6 +3,8 @@ #include <libguile.h> +#define SCM_IS_LIST(x) scm_is_true(scm_list_p(x)) + void init_vcomponent (); void init_vcomponent_type (void); diff --git a/guile_interface.scm.c b/guile_interface.scm.c index a4eb7f8b..6b9de8dc 100644 --- a/guile_interface.scm.c +++ b/guile_interface.scm.c @@ -47,6 +47,7 @@ SCM_DEFINE (vcomponent_get_attribute, "vcomponent-get-attribute", 2, 0, 0, if (c == NULL) return SCM_BOOL_F; + // TODO returns the car of list if list is one long. SCM llist = SCM_EOL; FOR (LLIST, content_set, v, &c->val) { llist = scm_cons(scm_from_strbuf(&v->key), llist); @@ -65,9 +66,9 @@ SCM_DEFINE (vcomponent_set_attr_x, "vcomponent-set-attribute!", 3, 0, 0, content_line* c = get_property (com, key); free(key); - c->val.cur->value->key.mem = (char*) new_value; - - + // TODO if list is a value store it as is, else wrap it in a list + // of length one. + c->val.cur->value->key.scm = new_value; return SCM_UNSPECIFIED; } diff --git a/guile_type_helpers.c b/guile_type_helpers.c index 3f76c2d4..485827a0 100644 --- a/guile_type_helpers.c +++ b/guile_type_helpers.c @@ -2,8 +2,13 @@ #include "macro.h" -SCM scm_from_strbuf(strbuf* s) - { return scm_from_utf8_stringn (s->mem, s->len - 1); } +SCM scm_from_strbuf(strbuf* s) { + if (s->scm == NULL) { + s->scm = scm_from_utf8_stringn (s->mem, s->len - 1); + } + + return s->scm; +} SCM scm_from_vector(VECT(vcomponent)* vect, SCM element_type) { SCM l = SCM_EOL; @@ -18,6 +18,7 @@ INIT_F(strbuf, size_t len) { self->alloc = len; self->ptr = 0; self->len = 0; + self->scm = NULL; return 0; } @@ -2,6 +2,7 @@ #define STRBUF_H #include <stdlib.h> +#include <libguile.h> #include "macro.h" /* @@ -14,6 +15,7 @@ */ typedef struct { char* mem; + SCM scm; /* TODO add support for negative ptr */ int ptr; unsigned int alloc; |