|
Revision 20692, 1.3 kB
(checked in by kiyoka, 5 years ago)
|
|
|
-
Property svn:executable set to
*
|
| Line | |
|---|
| 1 | #!/usr/local/bin/gosh |
|---|
| 2 | |
|---|
| 3 | (use srfi-1) |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | (define (load-td2 port) |
|---|
| 7 | (let ( |
|---|
| 8 | (body '()) |
|---|
| 9 | (str-list (port->string-list port))) |
|---|
| 10 | |
|---|
| 11 | (define (reset-body!) |
|---|
| 12 | (let1 ret (reverse body) |
|---|
| 13 | (set! body '()) |
|---|
| 14 | (if (null? ret) |
|---|
| 15 | "" |
|---|
| 16 | (string-append " ( \"" |
|---|
| 17 | (string-join ret "\n") |
|---|
| 18 | "\" )")))) |
|---|
| 19 | (define (push-body! str) |
|---|
| 20 | (push! body str)) |
|---|
| 21 | |
|---|
| 22 | (filter-map |
|---|
| 23 | (lambda (str) |
|---|
| 24 | (cond |
|---|
| 25 | ((#/^TDIARY+/ str) |
|---|
| 26 | #f) |
|---|
| 27 | ((#/^[a-zA-Z-]+: / str) |
|---|
| 28 | (let1 pair (string-split str #/[ ]+/) |
|---|
| 29 | (string-append |
|---|
| 30 | (if (#/^Date: / str) |
|---|
| 31 | (format "( \"~a\" . " (cadr pair)) |
|---|
| 32 | "") |
|---|
| 33 | (format "(~a . \"~a\")" (car pair) (cadr pair))))) |
|---|
| 34 | ((= 0 (string-length str)) |
|---|
| 35 | (reset-body!)) |
|---|
| 36 | ((#/^.$/ str) |
|---|
| 37 | (string-append (reset-body!) |
|---|
| 38 | " )")) |
|---|
| 39 | (else |
|---|
| 40 | (let1 str (regexp-replace-all #/[\"]/ str "'") |
|---|
| 41 | (push-body! str) |
|---|
| 42 | #f)))) |
|---|
| 43 | str-list))) |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | (define (main argv) |
|---|
| 47 | (let1 mode (string->symbol (cadr argv)) |
|---|
| 48 | (print "(") |
|---|
| 49 | (for-each print |
|---|
| 50 | (load-td2 |
|---|
| 51 | (current-input-port))) |
|---|
| 52 | (print ")"))) |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|