vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit fd06cd2e08255c90678a31dbb8662604170d2306
parent c8db465e5df535500691228012705228c950c8f0
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu, 22 Dec 2016 16:16:38 +0100

text: make text_vprintf static, it is only used within text.c

Diffstat:
Mtext.c | 26+++++++++++++-------------
Mtext.h | 1-
2 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/text.c b/text.c @@ -637,6 +637,19 @@ bool text_insert(Text *txt, size_t pos, const char *data, size_t len) { return true; } +static bool text_vprintf(Text *txt, size_t pos, const char *format, va_list ap) { + va_list ap_save; + va_copy(ap_save, ap); + int len = vsnprintf(NULL, 0, format, ap); + if (len == -1) + return false; + char *buf = malloc(len+1); + bool ret = buf && (vsnprintf(buf, len+1, format, ap_save) == len) && text_insert(txt, pos, buf, len); + free(buf); + va_end(ap_save); + return ret; +} + bool text_appendf(Text *txt, const char *format, ...) { va_list ap; va_start(ap, format); @@ -653,19 +666,6 @@ bool text_printf(Text *txt, size_t pos, const char *format, ...) { return ret; } -bool text_vprintf(Text *txt, size_t pos, const char *format, va_list ap) { - va_list ap_save; - va_copy(ap_save, ap); - int len = vsnprintf(NULL, 0, format, ap); - if (len == -1) - return false; - char *buf = malloc(len+1); - bool ret = buf && (vsnprintf(buf, len+1, format, ap_save) == len) && text_insert(txt, pos, buf, len); - free(buf); - va_end(ap_save); - return ret; -} - size_t text_insert_newline(Text *txt, size_t pos) { const char *data = text_newline_char(txt); size_t len = strlen(data); diff --git a/text.h b/text.h @@ -42,7 +42,6 @@ Text *text_load(const char *filename); struct stat text_stat(Text*); bool text_appendf(Text*, const char *format, ...); bool text_printf(Text*, size_t pos, const char *format, ...); -bool text_vprintf(Text*, size_t pos, const char *format, va_list ap); /* inserts a line ending character (depending on file type) */ size_t text_insert_newline(Text*, size_t pos); /* insert `len' bytes starting from `data' at `pos' which has to be