summaryrefslogtreecommitdiffstats
path: root/buf.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-07-05 06:22:38 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-07-05 06:22:38 -0700
commit5a3b0bba720a3edf72a6c85010727078ce985413 (patch)
treefbf92a354468e857abd80d90278752d14cf0b608 /buf.c
parente8472375ec4db62befaf87b1e85506234001e530 (diff)
downloadtxr-5a3b0bba720a3edf72a6c85010727078ce985413.tar.gz
txr-5a3b0bba720a3edf72a6c85010727078ce985413.tar.bz2
txr-5a3b0bba720a3edf72a6c85010727078ce985413.zip
New function: buf-put-buf.
* buf.c (buf_move_bytes): New static function. (buf_put_buf): New function. (buf_init): Register buf-put-buf intrinsic. * buf.h (buf_put_buf): Declared. * txr.1: Documented.
Diffstat (limited to 'buf.c')
-rw-r--r--buf.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/buf.c b/buf.c
index 349f0870..e991b72a 100644
--- a/buf.c
+++ b/buf.c
@@ -362,6 +362,24 @@ val replace_buf(val buf, val items, val from, val to)
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);
+ cnum p = buf_check_index(b, pos, self);
+ val req_len = plus(num(p), num(size));
+ if (gt(req_len, b->len))
+ buf_do_set_len(buf, b, req_len, nil, self);
+ memmove(b->data + p, ptr, size);
+}
+
+val buf_put_buf(val dbuf, val sbuf, val pos)
+{
+ val self = lit("buf-put-buf");
+ struct buf *sb = buf_handle(sbuf, self);
+ buf_move_bytes(dbuf, pos, sb->data, c_num(sb->len), self);
+ return sbuf;
+}
+
static void buf_put_bytes(val buf, val pos, mem_t *ptr, cnum size, val self)
{
struct buf *b = buf_handle(buf, self);
@@ -1077,6 +1095,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-put-buf"), user_package), func_n3(buf_put_buf));
#if HAVE_I8
reg_fun(intern(lit("buf-put-i8"), user_package), func_n3(buf_put_i8));