From: Matthew Fernandez Date: Sun, 7 Aug 2022 17:25:32 +0000 (-0700) Subject: gvpr colorx: use a local agxbuf instead of GVPR state’s 'tmp' X-Git-Tag: 5.0.1~9^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=31fbbd02083b608df8c004d1a10da9c5a17f6393;p=graphviz gvpr colorx: use a local agxbuf instead of GVPR state’s 'tmp' 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 --- 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) {