From 8bd1110f6b45c62f835ea69742d9e179d56ba542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 26 Feb 2019 00:56:37 +0100 Subject: Start on propper vcalendar scheme library. --- vcalendar.scm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 vcalendar.scm (limited to 'vcalendar.scm') 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)))) -- cgit v1.2.3