From 92cd494a7f37c449accf7322d2109e848f4a575d Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 10 Jul 2017 05:54:59 -0700 Subject: 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. --- txr-embedded-arg.txr | 17 +++++++---------- 1 file 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 -- cgit v1.2.3