aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-03-02 17:48:17 +0100
committerHugo Hörnquist <hugo@hornquist.se>2019-03-02 17:48:17 +0100
commitc5e511a8b6e4488d35e18d9d2defba5508bfb8f2 (patch)
tree3ad25b596bee2c1c553b0a9939474e1e7ee973c4
parentFix lingering strbuf off by one error. (diff)
downloadcalp-c5e511a8b6e4488d35e18d9d2defba5508bfb8f2.tar.gz
calp-c5e511a8b6e4488d35e18d9d2defba5508bfb8f2.tar.xz
Expose KEY(TRIE(content_line)) to scheme.
-rw-r--r--guile_interface.scm.c18
-rw-r--r--vcalendar.scm23
-rw-r--r--vcalendar/primitive.scm4
3 files changed, 32 insertions, 13 deletions
diff --git a/guile_interface.scm.c b/guile_interface.scm.c
index 0fd46505..41d13c3c 100644
--- a/guile_interface.scm.c
+++ b/guile_interface.scm.c
@@ -141,6 +141,24 @@ SCM scm_from_vcomponent(vcomponent* v) {
return v->scm;
}
+SCM_DEFINE(vcomponent_attr_list, "%vcomponent-attribute-list", 1, 0, 0,
+ (SCM component),
+ "Returns list of all keys in component.")
+{
+ scm_assert_foreign_object_type (vcomponent_type, component);
+ vcomponent* comp = scm_foreign_object_ref (component, 0);
+ LLIST(strbuf)* keys = KEYS(TRIE(content_line))(&comp->clines);
+
+ SCM llist = SCM_EOL;
+ FOR (LLIST, strbuf, s, keys) {
+ llist = scm_cons(scm_from_strbuf(s), llist);
+ }
+
+ FFREE(LLIST(strbuf), keys);
+
+ return llist;
+}
+
void init_lib (void) {
init_vcomponent_type();
diff --git a/vcalendar.scm b/vcalendar.scm
index c2228650..b61c6140 100644
--- a/vcalendar.scm
+++ b/vcalendar.scm
@@ -1,12 +1,9 @@
(define-module (vcalendar)
#:use-module (vcalendar primitive)
#:use-module (srfi srfi-1)
- #:use-module (srfi srfi-26)
- #:export (make-vcomponent children set-attr! get-attr type
- type-filter
- transform-attr! push-child!))
+ #:use-module (srfi srfi-26))
-(define (make-vcomponent path)
+(define-public (make-vcomponent path)
(if (string-ci=? ".ics" (string-take-right path 4))
;; == Single ICS file ==
;; Remove the abstract ROOT component,
@@ -26,7 +23,7 @@
accum)
'() (%vcomponent-children (%vcomponent-make path)))))
-(define (type-filter t lst)
+(define-public (type-filter t lst)
(filter (lambda (e) (eqv? t (type e)))
lst))
@@ -35,14 +32,16 @@
(if only-type
(type-filter only-type childs)
childs)))
+(export children)
-(define set-attr! %vcomponent-set-attribute!)
-(define get-attr %vcomponent-get-attribute)
-(define type %vcomponent-type)
-(define parent %vcomponent-parent)
-(define push-child! %vcomponent-push-child!)
+(define-public set-attr! %vcomponent-set-attribute!)
+(define-public get-attr %vcomponent-get-attribute)
+(define-public type %vcomponent-type)
+(define-public parent %vcomponent-parent)
+(define-public push-child! %vcomponent-push-child!)
+(define-public attributes %vcomponent-attribute-list)
-(define (transform-attr! ev field transformer)
+(define-public (transform-attr! ev field transformer)
"Apply transformer to field in ev, and store the result back."
(set-attr! ev field
(transformer
diff --git a/vcalendar/primitive.scm b/vcalendar/primitive.scm
index aa182040..b4ba1f38 100644
--- a/vcalendar/primitive.scm
+++ b/vcalendar/primitive.scm
@@ -10,7 +10,9 @@
%vcomponent-type
%vcomponent-set-attribute!
- %vcomponent-get-attribute))
+ %vcomponent-get-attribute
+
+ %vcomponent-attribute-list))
(setenv "LD_LIBRARY_PATH" (dirname (dirname (current-filename))))
(load-extension "libguile-calendar" "init_lib")