summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-07-10 05:54:59 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-07-10 05:54:59 -0700
commit857fe87e8772984386704776d0b09e5d571e54b6 (patch)
tree307add14ddd723adfebd94ff4d9094826d07e241
parent5b2074cbf8a2cf6ea9ee11e95a968d9d9165e721 (diff)
downloadtxr-857fe87e8772984386704776d0b09e5d571e54b6.tar.gz
txr-857fe87e8772984386704776d0b09e5d571e54b6.tar.bz2
txr-857fe87e8772984386704776d0b09e5d571e54b6.zip
txr-embeded-arg utility: use FFI types and buffers.
* txr-embedded-arg.txr: Streamline the logic by using buffers and the FFI type (zarray 128 char) which converts between a null terminated buffer of 128 UTF-8 characters and a string. We get not only null termination, as before, but clean padding ith zeros up to the size of the 128 byte area.
-rwxr-xr-xtxr-embedded-arg.txr17
1 files changed, 7 insertions, 10 deletions
diff --git a/txr-embedded-arg.txr b/txr-embedded-arg.txr
index 584a8a6e..8b48095d 100755
--- a/txr-embedded-arg.txr
+++ b/txr-embedded-arg.txr
@@ -13,20 +13,17 @@
@file
@ (eof)
@ (do
- (let ((f (stream-positioned-to-right-place file)))
- (with-in-string-byte-stream (s string)
- (mapdo (op put-byte @1 f)
- (take 127 (pad (gun (get-byte s)) 0)))
- (put-byte 0 f))))
+ (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)))
- (let ((arg-str (with-out-string-stream (u8)
- (mapdo (op put-byte @1 u8)
- (take 127 (gun (get-byte f)))))))
- (put-line arg-str))))
+ (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