about summary refs log tree commit diff stats
path: root/schmaltz.scm
blob: 16236eb0c527f180d01bdf26f90aad05348beac8 (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
#!/bin/sh
#| -*- scheme -*-
exec csi -R r7rs -R utf8 -s "$0" "$@"
schmaltz --- the command-line program
|#

(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'
                      `(begin
                         (import (html-parser))
                         (sxml->html ,(list 'quasiquote (read port))))))
          (render-specials)))
   (render-unprintables
    (list (cons "#<unspecified>" unprintable/skip)
          (cons "#!eof" unprintable/backtrack))))
  (else))

(define (main args)
  (define (rout file)
    (with-input-from-file file (lambda () (render) (newline))))
  (cond
   ((and (null? args)                   ; input from stdin
         (char-ready?))
    (render)
    (newline))
   ((member "-" args)
    (let-values (((fs1 fs2)
                  (break (lambda (x) (equal? x "-"))
                         args)))
      (for-each rout fs1)
      (render)
      (newline)
      (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)))))