summaryrefslogtreecommitdiffstats
path: root/txr-embedded-arg.txr
blob: 8b48095dd96288b6f8c5de0934f013ef8c104466 (plain)
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
@(do
   (defun stream-positioned-to-right-place (name)
     (let* ((stream (open-file name "r+b"))
            (pre (progn (stream-set-prop stream :byte-oriented t)
                        (read-until-match #/@\(txr\)/ stream t))))
       (when (or (empty pre) (not (search-str pre "@(txr)")))
          (throwf 'error "~a isn't a TXR executable" name))
       stream)))
@(next :args)
@(cases)
-w
@string
@file
@  (eof)
@  (do
     (let* ((f (stream-positioned-to-right-place file))
            (b (ffi-put string (ffi (zarray 128 char)))))
       (put-buf b 0 f)))
@(or)
@file
@  (eof)
@  (do
     (let ((f (stream-positioned-to-right-place file))
           (b (make-buf 128)))
       (fill-buf b 0 f)
       (put-line (ffi-get b (ffi (zarray 128 char))))))
@(or)
@   (output)
usage: @{self-path} [-w string] txr-executable
@   (end)
@   (do (exit 1))
@(end)