From 31fbbd02083b608df8c004d1a10da9c5a17f6393 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 7 Aug 2022 10:25:32 -0700 Subject: [PATCH] =?utf8?q?gvpr=20colorx:=20use=20a=20local=20agxbuf=20inst?= =?utf8?q?ead=20of=20GVPR=20state=E2=80=99s=20'tmp'?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This makes it clearer to both humans and the compiler that the data written to this buffer is not required beyond this function. This also gets us closer to removing an SFIO dependency. Gitlab: #1873 --- lib/gvpr/actions.c | 20 ++++++++++++-------- lib/gvpr/actions.h | 2 +- lib/gvpr/compile.c | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/gvpr/actions.c b/lib/gvpr/actions.c index c878c5e9e..484dac0e9 100644 --- a/lib/gvpr/actions.c +++ b/lib/gvpr/actions.c @@ -1276,8 +1276,7 @@ int colorxlate(char *str, gvcolor_t * color, color_type_t target_type) /* colorx: * RGB, RGBA, HSV, HSVA, CMYK */ -char *colorx (Expr_t* ex, char* incolor, char* fmt, Sfio_t* fp) -{ +char *colorx(Expr_t *ex, char *incolor, char *fmt) { gvcolor_t color = {{{0}},0}; color_type_t type; int rc; @@ -1310,28 +1309,33 @@ char *colorx (Expr_t* ex, char* incolor, char* fmt, Sfio_t* fp) if (rc != COLOR_OK) return ""; + agxbuf fp = {0}; + agxbinit(&fp, 0, NULL); + switch (type) { case HSVA_DOUBLE : - sfprintf (fp, "%.03f %.03f %.03f", + agxbprint(&fp, "%.03f %.03f %.03f", color.u.HSVA[0], color.u.HSVA[1], color.u.HSVA[2]); if (alpha) - sfprintf (fp, " %.03f", color.u.HSVA[3]); + agxbprint(&fp, " %.03f", color.u.HSVA[3]); break; case RGBA_BYTE : - sfprintf (fp, "#%02x%02x%02x", + agxbprint(&fp, "#%02x%02x%02x", color.u.rgba[0], color.u.rgba[1], color.u.rgba[2]); if (alpha) - sfprintf (fp, "%02x", color.u.rgba[3]); + agxbprint(&fp, "%02x", color.u.rgba[3]); break; case CMYK_BYTE : - sfprintf (fp, "#%02x%02x%02x%02x", + agxbprint(&fp, "#%02x%02x%02x%02x", color.u.cmyk[0], color.u.cmyk[1], color.u.cmyk[2], color.u.cmyk[3]); break; default : break; } - return exstring(ex, sfstruse(fp)); + char *result = exstring(ex, agxbuse(&fp)); + agxbfree(&fp); + return result; } #ifndef _WIN32 diff --git a/lib/gvpr/actions.h b/lib/gvpr/actions.h index ed12d2a0f..e9f256564 100644 --- a/lib/gvpr/actions.h +++ b/lib/gvpr/actions.h @@ -45,7 +45,7 @@ extern "C" { extern char *toLower(Expr_t *pgm, char *src); extern char *toUpper(Expr_t *pgm, char *src); extern int deleteObj(Agraph_t * g, Agobj_t * obj); - extern char *colorx (Expr_t* ex, char* incolor, char* fmt, Sfio_t* fp); + extern char *colorx (Expr_t* ex, char* incolor, char* fmt); extern void gvstart_timer(void); extern double gvelapsed_sec(void); diff --git a/lib/gvpr/compile.c b/lib/gvpr/compile.c index a080bdeec..cc11418b3 100644 --- a/lib/gvpr/compile.c +++ b/lib/gvpr/compile.c @@ -1460,7 +1460,7 @@ getval(Expr_t * pgm, Exnode_t * node, Exid_t * sym, Exref_t * ref, v.string = toLower(pgm, args[0].string); break; case F_colorx: - v.string = colorx(pgm, args[0].string, args[1].string, state->tmp); + v.string = colorx(pgm, args[0].string, args[1].string); break; case F_strcmp: if (args[0].string) { -- 2.40.0