about summary refs log tree commit diff stats
path: root/schmaltz.scm
blob: f1d5e244fcd85f921f5bf631e1bc83ff4b03b61e (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
;;; schmaltz --- the command-line program
;; This is not written portably.

(cond-expand
  (chicken (import r7rs utf8))
  (else))

(import (schmaltz)
        (scheme file)
        (scheme eval)
        (scheme repl)
        (srfi 1))

(cond-expand
  (chicken
   (render-specials
    (cons (cons #\@ (lambda (port)           ; wrap the next form in `sxml->html'
                      ;; wow this is ugly ... how can i make this better?
                      (eval '(import (html-parser)) (interaction-environment))
                      `(sxml->html ,(list 'quasiquote (read port)))))
          (render-specials)))
   (render-unprintables
    (list (cons "#<unspecified>" (lambda _ '()))
          (cons "#!eof" (lambda (ch) (list ch #\#))))))
  (else))

(define (main args)
  (define (display-render)
    (display (render))
    (newline))
  (define (rout file)
    (with-input-from-file file display-render))
  (cond
   ((and (null? args)                   ; input from stdin
         (char-ready?))
    (display-render))
   ((member "-" args)
    (let-values (((fs1 fs2)
                  (break (lambda (x) (equal? x "-"))
                         args)))
      (for-each rout fs1)
      (display-render)
      (for-each rout (cdr fs2))))
   ((< 0 (length args))
    (for-each rout args))
   (else
    (display "Usage: schmaltz FILE...\n" (current-error-port))
    (exit 1))))

(cond-expand
  ((and chicken
        (or chicken-script compiling))
   (import (chicken process-context))
   (main (command-line-arguments)))
  (chicken)
  (else
   (import (scheme process-context))
   (main (cdr (command-line)))))