X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Foptions.c;h=a212d1c63ee5190c752a7a007087df6338c47087;hb=71c7e8fef1569b84eb33192cff60c57b5c22c0c6;hp=c3dcf915a87ba0ed0d192ae95b18097ad12374f7;hpb=a06dd54ab3d37656a1edfb8ee7de859cc0baac0e;p=pspp diff --git a/src/output/options.c b/src/output/options.c index c3dcf915a8..a212d1c63e 100644 --- a/src/output/options.c +++ b/src/output/options.c @@ -51,8 +51,8 @@ driver_option_create (const char *driver_name, const char *name, struct driver_option *o = xmalloc (sizeof *o); o->driver_name = xstrdup (driver_name); o->name = xstrdup (name); - o->value = value != NULL ? xstrdup (value) : NULL; - o->default_value = default_value ? xstrdup (default_value) : NULL; + o->value = xstrdup_if_nonnull (value); + o->default_value = xstrdup_if_nonnull (default_value); return o; } @@ -516,7 +516,7 @@ lookup_color_name (const char *s) return -1; } -static bool +bool parse_color__ (const char *s, struct cell_color *color) { /* #rrrrggggbbbb */ @@ -530,6 +530,7 @@ parse_color__ (const char *s, struct cell_color *color) color->r = r16 >> 8; color->g = g16 >> 8; color->b = b16 >> 8; + color->alpha = 255; return true; } @@ -542,6 +543,7 @@ parse_color__ (const char *s, struct cell_color *color) color->r = r; color->g = g; color->b = b; + color->alpha = 255; return true; } @@ -553,6 +555,7 @@ parse_color__ (const char *s, struct cell_color *color) color->r = r; color->g = g; color->b = b; + color->alpha = 255; return true; } @@ -564,17 +567,20 @@ parse_color__ (const char *s, struct cell_color *color) color->r = r; color->g = g; color->b = b; + color->alpha = 255; return true; } /* rgba(r,g,b,a), ignoring a. */ - if (sscanf (s, "rgba (%"SCNi8" , %"SCNi8" , %"SCNi8", %*f) %n", - &r, &g, &b, &len) == 3 + double alpha; + if (sscanf (s, "rgba (%"SCNi8" , %"SCNi8" , %"SCNi8", %lf) %n", + &r, &g, &b, &alpha, &len) == 4 && !s[len]) { color->r = r; color->g = g; color->b = b; + color->alpha = alpha <= 0 ? 0 : alpha >= 1 ? 255 : alpha * 255.0; return true; } @@ -584,6 +590,13 @@ parse_color__ (const char *s, struct cell_color *color) color->r = code >> 16; color->g = code >> 8; color->b = code; + color->alpha = 255; + return true; + } + + if (!strcmp (s, "transparent")) + { + *color = (struct cell_color) { .alpha = 0 }; return true; } @@ -594,20 +607,15 @@ parse_color__ (const char *s, struct cell_color *color) struct cell_color parse_color (struct driver_option *o) { + struct cell_color color = CELL_COLOR_BLACK; + parse_color__ (o->default_value, &color); if (o->value) { - struct cell_color color; - if (parse_color__ (o->value, &color)) - return color; - - msg (MW, _("%s: `%s' is `%s', which could not be parsed as a color"), - o->driver_name, o->name, o->value); + if (!parse_color__ (o->value, &color)) + msg (MW, _("%s: `%s' is `%s', which could not be parsed as a color"), + o->driver_name, o->name, o->value); } - - struct cell_color color; - if (parse_color__ (o->default_value, &color)) - return color; - - return (struct cell_color) CELL_COLOR_BLACK; + driver_option_destroy (o); + return color; }