summaryrefslogtreecommitdiffstats
path: root/buf.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-11-20 19:55:49 -0800
committerKaz Kylheku <kaz@kylheku.com>2019-11-20 19:55:49 -0800
commit68de493c2e7500fbc9df94605ff79739c51c3759 (patch)
tree61c70c86b8dd6ee851f1ad0205b0a9fb243ae9e3 /buf.c
parent98fe899f21eadf2eff1aa455c6f77edd09ff717f (diff)
downloadtxr-68de493c2e7500fbc9df94605ff79739c51c3759.tar.gz
txr-68de493c2e7500fbc9df94605ff79739c51c3759.tar.bz2
txr-68de493c2e7500fbc9df94605ff79739c51c3759.zip
New function: buf-list.
* buf.c (buf_list): New function. (buf_init): buf-list intrinsic registered. * buf.h (buf_list): Declared. * txr.1: Documented.
Diffstat (limited to 'buf.c')
-rw-r--r--buf.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/buf.c b/buf.c
index 1ed66322..fc32e199 100644
--- a/buf.c
+++ b/buf.c
@@ -362,6 +362,23 @@ val replace_buf(val buf, val items, val from, val to)
return buf;
}
+val buf_list(val list)
+{
+ val self = lit("buf-list");;
+ val len = length(list);
+ val buf = make_buf(zero, zero, len);
+ seq_iter_t iter;
+ val elem;
+ cnum i;
+
+ for (i = 0, seq_iter_init(self, &iter, list); seq_get(&iter, &elem); i++)
+ buf->b.data[i] = c_uchar(elem, self);
+
+ buf->b.len = len;
+
+ return buf;
+}
+
static void buf_move_bytes(val buf, val pos, mem_t *ptr, cnum size, val self)
{
struct buf *b = buf_handle(buf, self);
@@ -1197,6 +1214,7 @@ void buf_init(void)
reg_fun(intern(lit("copy-buf"), user_package), func_n1(copy_buf));
reg_fun(intern(lit("sub-buf"), user_package), func_n3(sub_buf));
reg_fun(intern(lit("replace-buf"), user_package), func_n4(replace_buf));
+ reg_fun(intern(lit("buf-list"), user_package), func_n1(buf_list));
reg_fun(intern(lit("buf-put-buf"), user_package), func_n3(buf_put_buf));
#if HAVE_I8