aboutsummaryrefslogtreecommitdiff
path: root/module/main.scm
blob: 901746ea429e7ead94201a6ef238a420f7da97af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# -*- mode: scheme; geiser-scheme-implementation: guile -*-

. $(dirname $(dirname $(realpath $0)))/env

exec guile -e main -s $0 "$@"
!#

(use-modules (srfi srfi-1)
             (srfi srfi-19)
             (srfi srfi-41)
             (srfi srfi-41 util)
             (srfi srfi-88)             ; keyword syntax

             (util)
             (util io)

             ((entry-points html)     :prefix     html-)
             ((entry-points terminal) :prefix terminal-)
             ((entry-points import)   :prefix   import-)
             ((entry-points text)     :prefix     text-)
             ((entry-points info)     :prefix     info-)
             ((entry-points ical)     :prefix     ical-)

             ((entry-points server)   :prefix   server-)

             (ice-9 getopt-long)

             (statprof)

             (parameters))

(define options
  '((mode (value #t) (single-char #\m))
    (output (value #t) (single-char #\o))
    (statprof (value optional))))

(define (ornull a b)
  (if (null? a)
      b a))

(define (main args)
  (define opts (getopt-long args options #:stop-at-first-non-option #t))
  (define stprof (option-ref opts 'statprof #f))

  (when stprof
    (statprof-start))

  (primitive-load (format #f "~a/.config/calp/config.scm"
                          (getenv "HOME")))

  (with-output-to-port
      (open-output-port (option-ref opts 'output "-"))
    (lambda ()
      (let ((ropt (ornull (option-ref opts '() '())
                          '("term"))))
        ((case (string->symbol (car ropt))
           ((html)       html-main)
           ((term)   terminal-main)
           ((import)   import-main)
           ((text)       text-main)
           ((info)       info-main)
           ((ical)       ical-main)
           ((server)   server-main)
           (else => (lambda (s) (error "Unsupported mode of operation:" s))))
         ropt))
      (newline)))

  (when stprof
    (statprof-stop)
    (statprof-display (current-error-port)
                      style: (if (boolean? stprof)
                                 'flat
                                 (string->symbol stprof)))))