aboutsummaryrefslogtreecommitdiff
path: root/module/vcomponent
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-12-23 23:40:14 +0100
committerHugo Hörnquist <hugo@hornquist.se>2019-12-24 00:02:02 +0100
commit92b2f429a06ed9b052baff5e27f012397b338f6a (patch)
tree0ca9c2d8d1d72f5c898ee8384c2ef5459c1ef112 /module/vcomponent
parentMove open-{input,output}-port to (util io). (diff)
downloadcalp-92b2f429a06ed9b052baff5e27f012397b338f6a.tar.gz
calp-92b2f429a06ed9b052baff5e27f012397b338f6a.tar.xz
Rework program initialization.
Old init setup had the fancy idea to parse all files before anything could be done with them. This however led to problems when a part of the program which didn't care for the calendar files (such as text formatting). It also made testing performance almost impossible since to much code was run before I had a chance to init statprof.
Diffstat (limited to 'module/vcomponent')
-rw-r--r--module/vcomponent/base.scm2
-rw-r--r--module/vcomponent/load.scm39
2 files changed, 40 insertions, 1 deletions
diff --git a/module/vcomponent/base.scm b/module/vcomponent/base.scm
index aa5b9de9..bf15510d 100644
--- a/module/vcomponent/base.scm
+++ b/module/vcomponent/base.scm
@@ -26,7 +26,7 @@
(children children set-component-children!)
(parent get-component-parent set-component-parent!)
(attributes get-component-attributes))
-(export children type)
+(export vcomponent? children type)
;; TODO should this also update the parent
(define-public parent
diff --git a/module/vcomponent/load.scm b/module/vcomponent/load.scm
new file mode 100644
index 00000000..fb25732d
--- /dev/null
+++ b/module/vcomponent/load.scm
@@ -0,0 +1,39 @@
+(define-module (vcomponent load)
+ :export (load-calendars)
+ :use-module (util)
+ :use-module (srfi srfi-1)
+ :use-module (srfi srfi-19)
+ :use-module (srfi srfi-41)
+ :use-module (srfi srfi-41 util)
+ :use-module (parameters)
+ ;; :use-module (vcomponent)
+ :use-module (vcomponent base)
+ :use-module ((vcomponent parse) :select (parse-cal-path))
+ :use-module ((vcomponent recurrence) :select (generate-recurrence-set repeating?))
+ :use-module ((vcomponent datetime) :select (ev-time<?)))
+
+
+;; Reads all calendar files from disk, and creates a list of "regular" events,
+;; and a stream of "repeating" events, which are passed in that order to the
+;; given procedure @var{proc}.
+;;
+;; Given as a sepparate function from main to ease debugging.
+(define* (load-calendars #:key (calendar-files (calendar-files)))
+ (define calendars (map parse-cal-path calendar-files))
+ (define events (concatenate
+ ;; TODO does this drop events?
+ (map (lambda (cal) (filter (lambda (o) (eq? 'VEVENT (type o)))
+ (children cal)))
+ calendars)))
+
+ (let* ((repeating regular (partition repeating? events)))
+
+ (set! repeating (sort*! repeating time<? (extract 'DTSTART))
+ regular (sort*! regular time<? (extract 'DTSTART)))
+
+ (values
+ calendars
+ (interleave-streams
+ ev-time<?
+ (cons (list->stream regular)
+ (map generate-recurrence-set repeating))))))