From mboxrd@z Thu Jan 1 00:00:00 1970 From: john at keeping.me.uk (John Keeping) Date: Sun, 7 Apr 2013 15:26:36 +0100 Subject: [PATCH v2 07/22] html: introduce html_txtf and html_vtxtf functions In-Reply-To: References: Message-ID: These takes a printf style format string like htmlf but escapes the resulting string. The html_vtxtf variant takes a va_list whereas html_txtf is variadic. Signed-off-by: John Keeping --- html.c | 28 +++++++++++++++++++++++++--- html.h | 8 +++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/html.c b/html.c index c0cb4b7..cac1ed3 100644 --- a/html.c +++ b/html.c @@ -88,13 +88,35 @@ void html(const char *txt) void htmlf(const char *format, ...) { - static char buf[65536]; va_list args; + struct strbuf buf = STRBUF_INIT; va_start(args, format); - vsnprintf(buf, sizeof(buf), format, args); + strbuf_vaddf(&buf, format, args); va_end(args); - html(buf); + html(buf.buf); + strbuf_release(&buf); +} + +void html_txtf(const char *format, ...) +{ + va_list args; + + va_start(args, format); + html_vtxtf(format, args); + va_end(args); +} + +void html_vtxtf(const char *format, va_list ap) +{ + va_list cp; + struct strbuf buf = STRBUF_INIT; + + va_copy(cp, ap); + strbuf_vaddf(&buf, format, cp); + va_end(cp); + html_txt(buf.buf); + strbuf_release(&buf); } void html_status(int code, const char *msg, int more_headers) diff --git a/html.h b/html.h index bb36f37..6886a46 100644 --- a/html.h +++ b/html.h @@ -1,7 +1,7 @@ #ifndef HTML_H #define HTML_H -#include +#include "cgit.h" extern void html_raw(const char *txt, size_t size); extern void html(const char *txt); @@ -9,6 +9,12 @@ extern void html(const char *txt); __attribute__((format (printf,1,2))) extern void htmlf(const char *format,...); +__attribute__((format (printf,1,2))) +extern void html_txtf(const char *format,...); + +__attribute__((format (printf,1,0))) +extern void html_vtxtf(const char *format, va_list ap); + extern void html_status(int code, const char *msg, int more_headers); extern void html_txt(const char *txt); extern void html_ntxt(int len, const char *txt); -- 1.8.2.692.g17a9715