From b9ce4240a4d729b051acab17896f4102e0fbf123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 25 Jun 2020 22:35:48 +0200 Subject: Move stuff from output/ical to output/common./ --- module/output/common.scm | 42 ++++++++++++++++++++++++++++++++++++++++++ module/output/ical.scm | 23 +---------------------- 2 files changed, 43 insertions(+), 22 deletions(-) create mode 100644 module/output/common.scm diff --git a/module/output/common.scm b/module/output/common.scm new file mode 100644 index 00000000..c501bcae --- /dev/null +++ b/module/output/common.scm @@ -0,0 +1,42 @@ +;;; Commentary: +;; Common code between all serializers. +;; (ical and xcal). Not for graphical output stuff. +;;; Code: + +(define-module (output common) + :use-module (util) + ) + +;; TODO this is also defined @ (vcomponent parse component) +(define-public (x-property? symb) + (string=? "X-" (string-take (symbol->string symb) 2))) + +;; TODO this is also defined twice +(define (generate-uuid) + ((@ (rnrs io ports) call-with-port) + ((@ (ice-9 popen) open-input-pipe) "uuidgen") + (@ (ice-9 rdelim) read-line))) + +(define*-public (internal-field? symbol optional: (prefix "X-HNH-")) + (string=? prefix + (string-take-to (symbol->string symbol) + (string-length prefix)))) + +(define-public (->string a) + (with-output-to-string (lambda () (display a)))) + +(define-public (get-tz-names events) + (lset-difference + equal? (lset-union + equal? '("dummy") + (filter-map + (lambda (vline) (and=> (prop vline 'TZID) car)) + (filter-map (extract* 'DTSTART) + events))) + '("dummy" "local"))) + +(define-public (downcase-symbol symb) + (-> symb + symbol->string + string-downcase + string->symbol)) diff --git a/module/output/ical.scm b/module/output/ical.scm index 7773cce7..013de5fb 100644 --- a/module/output/ical.scm +++ b/module/output/ical.scm @@ -15,11 +15,9 @@ :use-module (glob) :use-module (vcomponent recurrence) :use-module (output types) + :use-module (output common) ) -;; TODO this is also defined @ (vcomponent parse component) -(define (x-property? symb) - (string=? "X-" (string-take (symbol->string symb) 2))) ;; Format value depending on key type. ;; Should NOT emit the key. @@ -94,10 +92,6 @@ fallback-string) fallback-string))) -(define (generate-uuid) - ((@ (rnrs io ports) call-with-port) - ((@ (ice-9 popen) open-input-pipe) "uuidgen") - (@ (ice-9 rdelim) read-line))) ;; Fold long lines to limit width. ;; Since this works in characters, but ics works in bytes @@ -113,13 +107,7 @@ (ical-line-fold (string-drop string wrap-len)))] [else string])) -(define* (internal-field? symbol optional: (prefix "X-HNH-")) - (string=? prefix - (string-take-to (symbol->string symbol) - (string-length prefix)))) -(define (->string a) - (with-output-to-string (lambda () (display a)))) (define (vline->string vline) (define key (vline-key vline)) @@ -206,15 +194,6 @@ CALSCALE:GREGORIAN\r (format #t "END:VCALENDAR\r\n")) -(define (get-tz-names events) - (lset-difference - equal? (lset-union - equal? '("dummy") - (filter-map - (lambda (vline) (and=> (prop vline 'TZID) car)) - (filter-map (extract* 'DTSTART) - events))) - '("dummy" "local"))) (define-public (print-components-with-fake-parent events) -- cgit v1.2.3