Tool works on multiple inputs now
This commit is contained in:
parent
a1a604aee8
commit
2c5ed693f5
|
@ -10,10 +10,15 @@
|
|||
(define output-format 'binary)
|
||||
(define indent? #t)
|
||||
(define annotations? #t)
|
||||
(define count +inf.0)
|
||||
(command-line #:once-each
|
||||
["--atob" "Text to binary"
|
||||
(begin (set! input-format 'text)
|
||||
(set! output-format 'binary))]
|
||||
["--all" "Read until EOF"
|
||||
(set! count +inf.0)]
|
||||
["--count" n "Read n items"
|
||||
(set! count (string->number n))]
|
||||
["--btoa" "Binary to text"
|
||||
(begin (set! input-format 'binary)
|
||||
(set! output-format 'text))]
|
||||
|
@ -38,12 +43,19 @@
|
|||
["--no-annotations" "Strip annotations"
|
||||
(set! annotations? #f)])
|
||||
|
||||
(define v ((if annotations? values strip-annotations)
|
||||
(match input-format
|
||||
['any (read-preserve #:read-syntax? #t #:source "<stdin>")]
|
||||
['text (read-preserve/text #:read-syntax? #t #:source "<stdin>")]
|
||||
['binary (read-preserve/binary #:read-syntax? #t)])))
|
||||
(void (match output-format
|
||||
['text (write-preserve/text v #:indent indent?)]
|
||||
['binary (write-preserve/binary v #:write-annotations? #t)]))
|
||||
(flush-output))
|
||||
(let loop ((count count))
|
||||
(when (positive? count)
|
||||
(define v ((if annotations? values strip-annotations)
|
||||
(match input-format
|
||||
['any (read-preserve #:read-syntax? #t #:source "<stdin>")]
|
||||
['text (read-preserve/text #:read-syntax? #t #:source "<stdin>")]
|
||||
['binary (read-preserve/binary #:read-syntax? #t)])))
|
||||
(when (not (eof-object? v))
|
||||
(void (match output-format
|
||||
['text
|
||||
(write-preserve/text v #:indent indent?)
|
||||
(newline)]
|
||||
['binary
|
||||
(write-preserve/binary v #:write-annotations? #t)]))
|
||||
(flush-output)
|
||||
(loop (- count 1))))))
|
||||
|
|
Loading…
Reference in New Issue