From: Matthew Fernandez Date: Sun, 3 Oct 2021 16:35:36 +0000 (-0700) Subject: implement a 'gvputs' alternative that does XML-escaping X-Git-Tag: 2.49.2~19^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ac24f1bb5b20d9674571577f0869d96e94595a79;p=graphviz implement a 'gvputs' alternative that does XML-escaping This will be used in an upcoming commit to replace `gvputs` when used in combination with `xml_string`. Related to #1868. --- diff --git a/lib/gvc/gvc.def b/lib/gvc/gvc.def index 842ebde88..45d2b8d84 100644 --- a/lib/gvc/gvc.def +++ b/lib/gvc/gvc.def @@ -151,6 +151,7 @@ gvprintpointf gvprintpointflist gvputc gvputs +gvputs_xml gvRender gvRenderData gvFreeRenderData diff --git a/lib/gvc/gvdevice.c b/lib/gvc/gvdevice.c index 3328e2c3c..5f3d670b9 100644 --- a/lib/gvc/gvdevice.c +++ b/lib/gvc/gvdevice.c @@ -52,6 +52,7 @@ static uint64_t crc; #include #include #include +#include #include static const int PAGE_ALIGN = 4095; /* align to a 4K boundary (less one), typical for Linux, Mac OS X and Windows memory allocation */ @@ -272,6 +273,11 @@ int gvputs(GVJ_t * job, const char *s) return 1; } +int gvputs_xml(GVJ_t *job, const char *s) { + const xml_flags_t flags = {.dash = 1, .nbsp = 1}; + return xml_escape(s, flags, (int (*)(void *, const char *))gvputs, job); +} + int gvputc(GVJ_t * job, int c) { const char cc = c; diff --git a/lib/gvc/gvio.h b/lib/gvc/gvio.h index e3a8cf50f..fadc431f7 100644 --- a/lib/gvc/gvio.h +++ b/lib/gvc/gvio.h @@ -39,6 +39,10 @@ extern "C" { GVIO_API int gvferror (FILE *stream); GVIO_API int gvputc(GVJ_t * job, int c); GVIO_API int gvputs(GVJ_t * job, const char *s); + + // `gvputs`, but XML-escape the input string + GVIO_API int gvputs_xml(GVJ_t* job, const char *s); + GVIO_API int gvflush (GVJ_t * job); GVIO_API void gvprintf(GVJ_t * job, const char *format, ...); GVIO_API void gvprintdouble(GVJ_t * job, double num);