[PATCH v2 07/22] html: introduce html_txtf and html_vtxtf functions
John Keeping
john at keeping.me.uk
Sun Apr 7 16:26:36 CEST 2013
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 <john at keeping.me.uk>
---
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 <stddef.h>
+#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
More information about the CGit
mailing list