This repository has been archived by the owner on Apr 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.scm
67 lines (61 loc) · 1.73 KB
/
main.scm
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
(include "loops")
(include "matchable")
(module main ()
(import chicken)
(import loops)
(import matchable)
(import scheme)
(use data-structures)
(use extras)
(use files)
(use ports)
(use posix)
(use srfi-1)
(use srfi-13)
(use srfi-69)
; Include macros first
(include "etc.scm")
; Include everything else
(include "format.scm")
; Options
(define end-options #f)
(define inplace #f)
(define files
(filt s (cdr (argv))
(or (not (string-prefix? "-" s))
end-options
(begin
(cond
((or (string-prefix? "--h" s)
(string-prefix? "-h" s))
(print "Usage: scheme-format [options] files")
(print)
(print "-h Show help")
(print "-i Inplace edit")
(print "-v Show version")
(exit 0))
((or (string-prefix? "--i" s)
(string-prefix? "-i" s))
(set! inplace #t))
((or (string-prefix? "--v" s)
(string-prefix? "-V" s)
(string-prefix? "-v" s))
(print "scheme-format version 1")
(exit 0))
((string= "--" s)
(set! end-options #t))
(else
(print s ": unknown option")
(exit 1)))
#f))))
; Format
(for file files
(define xs (with-input-from-file file read/comments))
(set! xs (tidy xs))
(define s (with-output-to-string (curry write/comments xs)))
(if inplace
(with-output-to-file file
(lambda ()
(display s))
binary:)
(display s))))