aboutsummaryrefslogtreecommitdiff
path: root/module/vcomponent/util/parse-cal-path.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2021-12-21 16:17:28 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2021-12-22 22:58:30 +0100
commitd00fea566004e67161ee45246b239fff5d416b0e (patch)
tree5641c0c0d0e78b046b6045ed2440512f12259560 /module/vcomponent/util/parse-cal-path.scm
parentComplete rewrite of use2dot (diff)
downloadcalp-d00fea566004e67161ee45246b239fff5d416b0e.tar.gz
calp-d00fea566004e67161ee45246b239fff5d416b0e.tar.xz
Cleanup modules.
Primarly this moves all vcompenent input and output code to clearly labeled modules, instead of being spread out. At the same time it also removes a handfull of unused procedures.
Diffstat (limited to 'module/vcomponent/util/parse-cal-path.scm')
-rw-r--r--module/vcomponent/util/parse-cal-path.scm35
1 files changed, 35 insertions, 0 deletions
diff --git a/module/vcomponent/util/parse-cal-path.scm b/module/vcomponent/util/parse-cal-path.scm
new file mode 100644
index 00000000..94c0c6ed
--- /dev/null
+++ b/module/vcomponent/util/parse-cal-path.scm
@@ -0,0 +1,35 @@
+(define-module (vcomponent util parse-cal-path)
+ :use-module (calp util)
+ :use-module ((calp util time) :select (report-time!))
+ :use-module (vcomponent base)
+ :use-module ((vcomponent formats ical parse)
+ :select (parse-calendar))
+ :use-module ((vcomponent formats vdir parse)
+ :select (parse-vdir)))
+
+
+;; Parse a vdir or ics file at the given path.
+(define-public (parse-cal-path path)
+ ;; TODO check (access? path R_OK) ?
+ (define st (stat path))
+ (define cal
+ (case (stat:type st)
+ [(regular)
+ (let ((comp (call-with-input-file path parse-calendar)))
+ (set! (prop comp '-X-HNH-SOURCETYPE) 'file)
+ comp) ]
+ [(directory)
+ (report-time! "Parsing ~a" path)
+ (let ((comp (parse-vdir path)))
+ (set! (prop comp '-X-HNH-SOURCETYPE) 'vdir
+ (prop comp '-X-HNH-DIRECTORY) path)
+ comp)]
+ [(block-special char-special fifo socket unknown symlink)
+ => (lambda (t) (error "Can't parse file of type " t))]))
+
+ (unless (prop cal "NAME")
+ (set! (prop cal "NAME")
+ (or (prop cal "X-WR-CALNAME")
+ (string-append "[" (basename path) "]"))))
+
+ cal)