From: ellson Date: Sat, 27 Sep 2008 13:28:54 +0000 (+0000) Subject: abandon var_arg lists and use a ',' or ' ' separated string for schemes X-Git-Tag: LAST_LIBGRAPH~32^2~3307 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e588e967b0e3c0598c314c1a619a52cfc7ff9956;p=graphviz abandon var_arg lists and use a ',' or ' ' separated string for schemes --- diff --git a/lib/inkpot/inkpot.h b/lib/inkpot/inkpot.h index 896150153..3de0e16e5 100644 --- a/lib/inkpot/inkpot.h +++ b/lib/inkpot/inkpot.h @@ -26,8 +26,7 @@ typedef enum { INKPOT_MALLOC_FAIL, INKPOT_COLOR_UNKNOWN, INKPOT_COLOR_NONAME, - INKPOT_SCHEME_UNKNOWN, - INKPOT_FAIL + INKPOT_SCHEME_UNKNOWN } inkpot_status_t; typedef struct inkpot_s inkpot_t; @@ -44,7 +43,7 @@ extern void inkpot_destroy ( inkpot_t *inkpot ); extern inkpot_status_t inkpot_disciplines ( inkpot_t *inkpot, inkpot_disc_t disc, void *out_closure, void *err_closure ); -extern inkpot_status_t inkpot_schemes ( inkpot_t *inkpot, const char *scheme, ... ); +extern inkpot_status_t inkpot_schemes ( inkpot_t *inkpot, const char *schemes ); extern inkpot_status_t inkpot_translate ( inkpot_t *inkpot, const char *scheme ); extern inkpot_status_t inkpot_set ( inkpot_t *inkpot, const char *color ); diff --git a/lib/inkpot/inkpot_scheme.c b/lib/inkpot/inkpot_scheme.c index e51784d48..f017d2e7e 100644 --- a/lib/inkpot/inkpot_scheme.c +++ b/lib/inkpot/inkpot_scheme.c @@ -15,7 +15,6 @@ **********************************************************/ #include -#include #include #include #include @@ -146,10 +145,7 @@ static inkpot_status_t inkpot_scheme ( inkpot_t *inkpot, const char *scheme ) inkpot->default_scheme_name_idx = idx; /* first scheme is default */ inkpot->default_value_idx = TAB_NAMES[inkpot_scheme_name->default_name_idx].value_idx; } - if (! (inkpot->scheme_bits & (1 << idx))) { - inkpot->scheme_bits |= 1 << idx; -// inkpot->name = NULL; /* clear cached name */ /* FIXME */ - } + inkpot->scheme_bits |= 1 << idx; return ((inkpot->status = INKPOT_SUCCESS)); } @@ -163,31 +159,42 @@ static inkpot_status_t inkpot_scheme ( inkpot_t *inkpot, const char *scheme ) * named schemes are currently active */ inkpot->default_value_idx = TAB_IXVALUES[inkpot_scheme_index->first_value_idx]; } -// inkpot->name = NULL; /* clear cached name */ /* FIXME */ } return ((inkpot->status = INKPOT_SUCCESS)); } -inkpot_status_t inkpot_schemes ( inkpot_t *inkpot, const char *scheme, ... ) +inkpot_status_t inkpot_schemes ( inkpot_t *inkpot, const char *schemes ) { inkpot_status_t rc; - va_list argp; - const char *s; + static char *schemelist; + static int schemelist_alloc; + const char *q; + char *p, *s, c; + int len; - if (scheme == NULL) + if (schemes == NULL) return ((inkpot->status = INKPOT_SCHEME_UNKNOWN)); - rc = inkpot_clear(inkpot); - if (rc != INKPOT_SUCCESS) - return rc; + len = strlen(schemes); + if (len >= schemelist_alloc) { + schemelist_alloc = len + 1 + 10; + schemelist = realloc(schemelist, schemelist_alloc); + if (! schemelist) + return ((inkpot->status = INKPOT_MALLOC_FAIL)); + } - va_start(argp, scheme); - for (s = scheme; s; s = va_arg(argp, const char*)) { - rc = inkpot_scheme(inkpot, s); + q = schemes; + p = schemelist; + rc = inkpot_clear(inkpot); + for (c = *q; c;) { if (rc != INKPOT_SUCCESS) - break; + return rc; + s = p; + while ((c = *q++) && c != ' ' && c != '\t' && c != ',') {*p++ = c;} + *p++ = '\0'; + if (*s) + rc = inkpot_scheme(inkpot, s); } - va_end(argp); return rc; } @@ -557,7 +564,7 @@ inkpot_status_t inkpot_get ( inkpot_t *inkpot, const char **color ) } *color = NULL; - return ((inkpot->status = INKPOT_FAIL)); + return ((inkpot->status = INKPOT_COLOR_NONAME)); } static inkpot_status_t inkpot_get_RGBA ( inkpot_t *inkpot, RGBA *rgba ) @@ -629,11 +636,14 @@ inkpot_status_t inkpot_get_cmyk ( inkpot_t *inkpot, double cmyk[4] ) return rc; } +#if 0 +/* FIXME - requires palette collection and transformation */ inkpot_status_t inkpot_get_index ( inkpot_t *inkpot, unsigned int *index ) { /* FIXME */ return ((inkpot->status = INKPOT_FAIL)); } +#endif static void errputs(inkpot_t *inkpot, const char *s) { @@ -866,8 +876,6 @@ inkpot_status_t inkpot_error ( inkpot_t *inkpot ) m = "INKPOT_COLOR_NONAME\n"; break; case INKPOT_SCHEME_UNKNOWN: m = "INKPOT_SCHEME_UNKNOWN\n"; break; - case INKPOT_FAIL: - m = "INKPOT_FAIL\n"; break; } inkpot->disc.err_writer(inkpot->err_closure, m, strlen(m)); diff --git a/lib/inkpot/test.c b/lib/inkpot/test.c index 7b1119a3f..be65c313f 100644 --- a/lib/inkpot/test.c +++ b/lib/inkpot/test.c @@ -51,7 +51,7 @@ int main (int argc, char *argv[]) } if (argc < 4) { - rc = inkpot_schemes(inkpot, "x11", NULL); + rc = inkpot_schemes(inkpot, "x11"); assert(rc == INKPOT_SUCCESS); } else {