about summary refs log tree commit diff stats
path: root/schmaltz.scm
diff options
context:
space:
mode:
Diffstat (limited to 'schmaltz.scm')
-rw-r--r--schmaltz.scm58
1 files changed, 58 insertions, 0 deletions
diff --git a/schmaltz.scm b/schmaltz.scm new file mode 100644 index 0000000..f1d5e24 --- /dev/null +++ b/schmaltz.scm
@@ -0,0 +1,58 @@
1;;; schmaltz --- the command-line program
2;; This is not written portably.
3
4(cond-expand
5 (chicken (import r7rs utf8))
6 (else))
7
8(import (schmaltz)
9 (scheme file)
10 (scheme eval)
11 (scheme repl)
12 (srfi 1))
13
14(cond-expand
15 (chicken
16 (render-specials
17 (cons (cons #\@ (lambda (port) ; wrap the next form in `sxml->html'
18 ;; wow this is ugly ... how can i make this better?
19 (eval '(import (html-parser)) (interaction-environment))
20 `(sxml->html ,(list 'quasiquote (read port)))))
21 (render-specials)))
22 (render-unprintables
23 (list (cons "#<unspecified>" (lambda _ '()))
24 (cons "#!eof" (lambda (ch) (list ch #\#))))))
25 (else))
26
27(define (main args)
28 (define (display-render)
29 (display (render))
30 (newline))
31 (define (rout file)
32 (with-input-from-file file display-render))
33 (cond
34 ((and (null? args) ; input from stdin
35 (char-ready?))
36 (display-render))
37 ((member "-" args)
38 (let-values (((fs1 fs2)
39 (break (lambda (x) (equal? x "-"))
40 args)))
41 (for-each rout fs1)
42 (display-render)
43 (for-each rout (cdr fs2))))
44 ((< 0 (length args))
45 (for-each rout args))
46 (else
47 (display "Usage: schmaltz FILE...\n" (current-error-port))
48 (exit 1))))
49
50(cond-expand
51 ((and chicken
52 (or chicken-script compiling))
53 (import (chicken process-context))
54 (main (command-line-arguments)))
55 (chicken)
56 (else
57 (import (scheme process-context))
58 (main (cdr (command-line)))))