aboutsummaryrefslogtreecommitdiff
path: root/vcalendar.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-02-26 00:56:37 +0100
committerHugo Hörnquist <hugo@hornquist.se>2019-02-26 00:57:41 +0100
commit8bd1110f6b45c62f835ea69742d9e179d56ba542 (patch)
treeb47a468ab971330484e1a83845c87ae80c0a25ec /vcalendar.scm
parentAdd vcompponent_push_child_x. (diff)
downloadcalp-8bd1110f6b45c62f835ea69742d9e179d56ba542.tar.gz
calp-8bd1110f6b45c62f835ea69742d9e179d56ba542.tar.xz
Start on propper vcalendar scheme library.
Diffstat (limited to '')
-rw-r--r--vcalendar.scm38
1 files changed, 38 insertions, 0 deletions
diff --git a/vcalendar.scm b/vcalendar.scm
new file mode 100644
index 00000000..b80e40e6
--- /dev/null
+++ b/vcalendar.scm
@@ -0,0 +1,38 @@
+(define-module (vcalendar)
+ #:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-26)
+ #:export (make-vcomponent children set-attr! get-attr type
+ transform-attr! push-child!))
+
+(setenv "LD_LIBRARY_PATH" (dirname (current-filename)))
+(load-extension "libguile-calendar" "init_lib")
+
+(define (make-vcomponent path)
+ (if (string-ci=? ".ics" (string-take-right path 4))
+ ;; == Single ICS file ==
+ ;; Remove the abstract ROOT component,
+ ;; returning the wanted VCALENDAR component
+ (car (%vcomponent-children
+ (%vcomponent-make path)))
+ ;; == Assume vdir ==
+ ;; Also removes the abstract ROOT component, but also
+ ;; merges all VCALENDAR's children into the first
+ ;; VCALENDAR, and return that VCALENDAR.
+ (reduce (lambda (cal accum)
+ (for-each (cut %vcomponent-push-child! accum <>)
+ (%vcomponent-children cal))
+ accum)
+ '() (%vcomponent-children (%vcomponent-make path)))))
+
+(define children %vcomponent-children)
+(define set-attr! %vcomponent-set-attribute!)
+(define get-attr %vcomponent-get-attribute)
+(define type %vcomponent-type)
+
+(define push-child! %vcomponent-push-child!)
+
+(define (transform-attr! ev field transformer)
+ "Apply transformer to field in ev, and store the result back."
+ (set-attr! ev field
+ (transformer
+ (get-attr ev field))))