-
Notifications
You must be signed in to change notification settings - Fork 13
/
binary_pack.rkt
37 lines (32 loc) · 1.28 KB
/
binary_pack.rkt
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
#lang racket
(require racket/exn)
; (require "grammar_racket.gib")
(require "./common/racket/parse.rkt")
(provide (all-defined-out))
;; ----------------------------------------
;; expects "<infile> <outfile>" lines on stdin
;; runs until it gets no more such lines (EOF)
(module+ main
(let ([errors 0])
(let loop ()
(define l (read-line))
(if (eof-object? l)
(printf "binary_pack.rkt: Reached EOF; done.\n")
(match (string-split l)
[(list infile outfile)
(printf "Converting to binary: ~a ~a\n" infile outfile)
(with-handlers ([(lambda (_) #t)
(lambda (e)
(printf "ERROR while converting:\n ~a"
(exn->string e))
(set! errors (add1 errors)))])
(call-with-output-file outfile
(lambda (outp)
(parse-pack-write (file->value infile) outp))
#:mode 'binary))
(loop)]
)))
(if (zero? errors)
(printf "Completed all conversions without error.\n")
(begin (printf "Encountered ~a errors while converting. Failing job.\n" errors)
(exit 1)))))