vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit a681f2a93fe2b1a1a11a97a5158a0d57637c3785 parent c6c11e64ebbd152b69591ec9805ea8609f9c5c8d Author: Randy Palamar <randy@rnpnr.xyz> Date: Fri, 28 Feb 2025 07:41:00 -0700 buffer: remove buffer_printf There was only a single user of this function because buffer_appendf is significantly more useful. Change that caller and reduce the code. Diffstat:
| M | buffer.c | | | 9 | --------- |
| M | buffer.h | | | 2 | -- |
| M | test/core/buffer-test.c | | | 8 | -------- |
| M | vis-registers.c | | | 3 | ++- |
4 files changed, 2 insertions(+), 20 deletions(-)
diff --git a/buffer.c b/buffer.c @@ -135,15 +135,6 @@ bool buffer_appendf(Buffer *buf, const char *fmt, ...) { return ret; } -bool buffer_printf(Buffer *buf, const char *fmt, ...) { - buf->len = 0; - va_list ap; - va_start(ap, fmt); - bool ret = buffer_vappendf(buf, fmt, ap); - va_end(ap); - return ret; -} - size_t buffer_length0(Buffer *buf) { size_t len = buf->len; if (len > 0 && buf->data[len-1] == '\0') diff --git a/buffer.h b/buffer.h @@ -46,8 +46,6 @@ bool buffer_append0(Buffer*, const char *data); bool buffer_prepend(Buffer*, const void *data, size_t len); /** Insert NUL-terminated data at the start. */ bool buffer_prepend0(Buffer*, const char *data); -/** Set formatted buffer content, ensures NUL termination on success. */ -bool buffer_printf(Buffer*, const char *fmt, ...) __attribute__((format(printf, 2, 3))); /** Append formatted buffer content, ensures NUL termination on success. */ bool buffer_appendf(Buffer*, const char *fmt, ...) __attribute__((format(printf, 2, 3))); /** Return length of a buffer without trailing NUL byte. */ diff --git a/test/core/buffer-test.c b/test/core/buffer-test.c @@ -57,14 +57,6 @@ int main(int argc, char *argv[]) { buf.len = 0; skip_if(TIS_INTERPRETER, 1, "vsnprintf not supported") { - - ok(buffer_printf(&buf, "Test: %d\n", 42) && compare0(&buf, "Test: 42\n"), "Set formatted"); - ok(buffer_printf(&buf, "%d\n", 42) && compare0(&buf, "42\n"), "Set formatted overwrite"); - buf.len = 0; - - ok(buffer_printf(&buf, "%s", "") && compare0(&buf, ""), "Set formatted empty string"); - buf.len = 0; - bool append = true; for (int i = 1; i <= 10; i++) append &= buffer_appendf(&buf, "%d", i); diff --git a/vis-registers.c b/vis-registers.c @@ -54,7 +54,8 @@ const char *register_slot_get(Vis *vis, Register *reg, size_t slot, size_t *len) Buffer *buf = array_get(®->values, 0); if (!buf) return NULL; - buffer_printf(buf, "%zu", slot+1); + buf->len = 0; + buffer_appendf(buf, "%zu", slot+1); if (len) *len = buffer_length0(buf); return buffer_content0(buf);