aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-02-25 22:59:53 +0100
committerHugo Hörnquist <hugo@hornquist.se>2019-02-25 22:59:53 +0100
commit6355700d4101a6e515311c96bf8e25bb1bb51d92 (patch)
tree01b362d60f6fa58d55a0bd1e76e2c3194d2b5b1e
parentReenable guile stuff. (diff)
downloadcalp-6355700d4101a6e515311c96bf8e25bb1bb51d92.tar.gz
calp-6355700d4101a6e515311c96bf8e25bb1bb51d92.tar.xz
Add scm field to strbuf.
-rwxr-xr-xcode.scm42
-rw-r--r--guile_interface.h2
-rw-r--r--guile_interface.scm.c7
-rw-r--r--guile_type_helpers.c9
-rw-r--r--strbuf.c1
-rw-r--r--strbuf.h2
6 files changed, 33 insertions, 30 deletions
diff --git a/code.scm b/code.scm
index 01832a05..fa606185 100755
--- a/code.scm
+++ b/code.scm
@@ -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;
diff --git a/strbuf.c b/strbuf.c
index 54960a54..2d101164 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -18,6 +18,7 @@ INIT_F(strbuf, size_t len) {
self->alloc = len;
self->ptr = 0;
self->len = 0;
+ self->scm = NULL;
return 0;
}
diff --git a/strbuf.h b/strbuf.h
index de4cc29b..850b0dd5 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -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;