X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utils%2Fresources.c;h=980878204d78e657e0f11a8989051d8ff3228c52;hb=6a1da724858673ac40aa13a9612340d8bed8c7b9;hp=827482319cf500ea7a8451354f49d79347f6e567;hpb=f3e0240915ed9f9b3a61781f5c7002d587563fe0;p=xscreensaver diff --git a/utils/resources.c b/utils/resources.c index 82748231..98087820 100644 --- a/utils/resources.c +++ b/utils/resources.c @@ -1,4 +1,5 @@ -/* xscreensaver, Copyright (c) 1992, 1997 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992, 1997, 1998, 2001, 2003 + * Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -74,7 +75,7 @@ get_boolean_resource (char *res_name, char *res_class) if (!strcmp (buf,"off") || !strcmp (buf, "false") || !strcmp (buf,"no")) return 0; fprintf (stderr, "%s: %s must be boolean, not %s.\n", - progname, res_class, buf); + progname, res_name, buf); return 0; } @@ -83,12 +84,28 @@ get_integer_resource (char *res_name, char *res_class) { int val; char c, *s = get_string_resource (res_name, res_class); + char *ss = s; if (!s) return 0; - if (1 == sscanf (s, " %d %c", &val, &c)) + + while (*ss && *ss <= ' ') ss++; /* skip whitespace */ + + if (ss[0] == '0' && (ss[1] == 'x' || ss[1] == 'X')) /* 0x: parse as hex */ { - free (s); - return val; + if (1 == sscanf (ss+2, "%x %c", (unsigned int *) &val, &c)) + { + free (s); + return val; + } } + else /* else parse as dec */ + { + if (1 == sscanf (ss, "%d %c", &val, &c)) + { + free (s); + return val; + } + } + fprintf (stderr, "%s: %s must be an integer, not %s.\n", progname, res_name, s); free (s); @@ -120,34 +137,58 @@ get_pixel_resource (char *res_name, char *res_class, XColor color; char *s = get_string_resource (res_name, res_class); char *s2; + Bool ok = True; if (!s) goto DEFAULT; for (s2 = s + strlen(s) - 1; s2 > s; s2--) if (*s2 == ' ' || *s2 == '\t') *s2 = 0; + else + break; if (! XParseColor (dpy, cmap, s, &color)) { - fprintf (stderr, "%s: can't parse color %s\n", progname, s); + fprintf (stderr, "%s: can't parse color %s", progname, s); + ok = False; goto DEFAULT; } if (! XAllocColor (dpy, cmap, &color)) { - fprintf (stderr, "%s: couldn't allocate color %s\n", progname, s); + fprintf (stderr, "%s: couldn't allocate color %s", progname, s); + ok = False; goto DEFAULT; } free (s); return color.pixel; DEFAULT: if (s) free (s); - return (strcmp (res_class, "Background") - ? WhitePixel (dpy, DefaultScreen (dpy)) - : BlackPixel (dpy, DefaultScreen (dpy))); + + { + Bool black_p = (strlen(res_class) >= 10 && + !strcasecmp ("Background", + res_class + strlen(res_class) - 10)); + if (!ok) + fprintf (stderr, ": using %s.\n", (black_p ? "black" : "white")); + color.flags = DoRed|DoGreen|DoBlue; + color.red = color.green = color.blue = (black_p ? 0 : 0xFFFF); + if (XAllocColor (dpy, cmap, &color)) + return color.pixel; + else + { + fprintf (stderr, "%s: couldn't allocate %s either!\n", progname, + (black_p ? "black" : "white")); + /* We can't use BlackPixel/WhitePixel here, because we don't know + what screen we're allocating on (only an issue when running inside + the xscreensaver daemon: for hacks, DefaultScreen is fine.) + */ + return 0; + } + } } int -parse_time (char *string, Bool seconds_default_p, Bool silent_p) +parse_time (const char *string, Bool seconds_default_p, Bool silent_p) { unsigned int h, m, s; char c;