39 lines
1.4 KiB
Racket
39 lines
1.4 KiB
Racket
#lang racket/base
|
|
|
|
(require "main.rkt")
|
|
(require racket/match)
|
|
(require racket/port)
|
|
|
|
(module+ main
|
|
(require racket/cmdline)
|
|
(define input-format 'text)
|
|
(define output-format 'binary)
|
|
(define indent? #t)
|
|
(define annotations? #t)
|
|
(command-line #:once-each
|
|
[("--ib" "--input-binary") "Set binary input mode"
|
|
(set! input-format 'binary)]
|
|
[("--it" "--input-text") "Set text input mode"
|
|
(set! input-format 'text)]
|
|
[("--ob" "--output-binary") "Set binary output mode"
|
|
(set! output-format 'binary)]
|
|
[("--ot" "--output-text") "Set text output mode"
|
|
(set! output-format 'text)]
|
|
["--indent" "Enable indent for text output"
|
|
(set! indent? #t)]
|
|
["--no-indent" "Disable indent for text output"
|
|
(set! indent? #f)]
|
|
["--annotations" "Output annotations"
|
|
(set! annotations? #t)]
|
|
["--no-annotations" "Strip annotations"
|
|
(set! annotations? #f)])
|
|
|
|
(define v ((if annotations? values strip-annotations)
|
|
(match input-format
|
|
['text (read-preserve-syntax #:source "<stdin>")]
|
|
['binary (decode-syntax (port->bytes))])))
|
|
(void (match output-format
|
|
['text (write-preserve v #:indent indent?)]
|
|
['binary (write-bytes (encode v))]))
|
|
(flush-output))
|