-
Notifications
You must be signed in to change notification settings - Fork 3
/
plist.rkt
66 lines (55 loc) · 3 KB
/
plist.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
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
#lang typed/racket/base
(provide (all-defined-out))
(provide PList-Stdin PList-Stdout)
(provide PList-Format PList-Datum PList-Object)
(require "digitama/plist.rkt")
(require "digitama/plist/bplist.rkt")
(require "digitama/plist/Info.plist.rkt")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define plist-datum? : (-> Any Boolean : #:+ PList-Datum)
(lambda [val]
(or (string? val)
(symbol? val)
(boolean? val)
(exact-integer? val)
(flonum? val)
(void? val)
(date? val))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define read-plist : (-> PList-Stdin PList-Object)
(lambda [/dev/bplin]
(define body : Bytes (plist-stdin->bytes /dev/bplin))
(cond [(bplist-bytes? body) (bplist-extract-object body)]
[else (void)])))
(define write-plist : (->* (Any) (PList-Stdout #:format PList-Format #:exists (U 'error 'replace)) Void)
(lambda [plst [/dev/bplout (current-output-port)] #:format [type 'bplist] #:exists [exists 'replace]]
(if (output-port? /dev/bplout)
(case type
[else (bplist-write-datum plst /dev/bplout)])
((inst call-with-output-file* Void)
/dev/bplout #:exists exists #:mode 'binary
(λ [[/dev/bplout : Output-Port]]
(write-plist plst /dev/bplout))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define bplist-dissect : (->* (PList-Stdin) (Output-Port #:offset-table-column Byte #:show-unused-field? Boolean) Void)
(lambda [/dev/bplin [/dev/stdout (current-output-port)] #:offset-table-column [offset-table-column 16] #:show-unused-field? [unused-field? #true]]
(define body : Bytes (plist-stdin->bytes /dev/bplin))
(when (bplist-bytes? body)
(bplist-pretty-hexdump body /dev/stdout offset-table-column unused-field?))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define plist-copy-info.rkt : (->* (Path-String)
(PList-Stdout #:filter (-> Symbol Any (Values Symbol Any)) #:excludes (Listof Symbol)
#:format PList-Format #:exists (U 'error 'replace)) Void)
(lambda [info.rkt [/dev/bplout (current-output-port)]
#:filter [filter apple-info.plist] #:excludes [omitted null]
#:format [type 'bplist] #:exists [exists 'replace]]
(dynamic-require info.rkt #false)
(define dict : (HashTable Symbol Any) (make-hasheq))
(define ns : Namespace (module->namespace info.rkt))
(for ([var (in-list (namespace-mapped-symbols ns))])
(unless (memq var omitted)
(define val : Any (namespace-variable-value var #false (λ [] void) ns))
(unless (procedure? val)
(define-values (key value) (filter var val))
(hash-set! dict key value))))
(write-plist dict /dev/bplout #:format type #:exists exists)))