summaryrefslogtreecommitdiffstats
path: root/txr-embedded-arg.txr
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
commit92cd494a7f37c449accf7322d2109e848f4a575d (patch)
tree307add14ddd723adfebd94ff4d9094826d07e241 /txr-embedded-arg.txr
parent51e4d7610da093d7b9ee87dfc2535a9b871490de (diff)
downloadtxr-92cd494a7f37c449accf7322d2109e848f4a575d.tar.gz
txr-92cd494a7f37c449accf7322d2109e848f4a575d.tar.bz2
txr-92cd494a7f37c449accf7322d2109e848f4a575d.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.
Diffstat (limited to 'txr-embedded-arg.txr')
-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