X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utils%2Fresources.c;h=b24a8ea07c7855a3364b5c83b3991e303a8113ad;hb=ce3185de9d9705e259f2b60dd4b5509007fa17d4;hp=01c1a1e499d32e7cb4390298072a10e7a6df6838;hpb=65740e2a8dea3d6309ae6e8914a0fb79e993ada8;p=xscreensaver diff --git a/utils/resources.c b/utils/resources.c old mode 100755 new mode 100644 index 01c1a1e4..b24a8ea0 --- a/utils/resources.c +++ b/utils/resources.c @@ -1,4 +1,5 @@ -/* xscreensaver, Copyright (c) 1992 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992, 1997, 1998 + * 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 @@ -9,27 +10,19 @@ * implied warranty. */ -#if __STDC__ -#include -#include -#endif - -#include -#include +#include "utils.h" +#include "resources.h" #include + /* Resource functions. Assumes: */ extern char *progname; extern char *progclass; extern XrmDatabase db; -#if __STDC__ -char *get_string_resource (char *res_name, char *res_class); -int parse_time (char *string, Bool seconds_default_p, Bool silent_p); static unsigned int get_time_resource (char *res_name, char *res_class, Bool sec_p); -#endif #ifndef isupper # define isupper(c) ((c) >= 'A' && (c) <= 'Z') @@ -39,8 +32,7 @@ static unsigned int get_time_resource (char *res_name, char *res_class, #endif char * -get_string_resource (res_name, res_class) - char *res_name, *res_class; +get_string_resource (char *res_name, char *res_class) { XrmValue value; char *type; @@ -62,8 +54,7 @@ get_string_resource (res_name, res_class) } Bool -get_boolean_resource (res_name, res_class) - char *res_name, *res_class; +get_boolean_resource (char *res_name, char *res_class) { char *tmp, buf [100]; char *s = get_string_resource (res_name, res_class); @@ -74,6 +65,11 @@ get_boolean_resource (res_name, res_class) *tmp = 0; free (os); + while (*buf && + (buf[strlen(buf)-1] == ' ' || + buf[strlen(buf)-1] == '\t')) + buf[strlen(buf)-1] = 0; + if (!strcmp (buf, "on") || !strcmp (buf, "true") || !strcmp (buf, "yes")) return 1; if (!strcmp (buf,"off") || !strcmp (buf, "false") || !strcmp (buf,"no")) @@ -84,17 +80,32 @@ get_boolean_resource (res_name, res_class) } int -get_integer_resource (res_name, res_class) - char *res_name, *res_class; +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", &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); @@ -102,8 +113,7 @@ get_integer_resource (res_name, res_class) } double -get_float_resource (res_name, res_class) - char *res_name, *res_class; +get_float_resource (char *res_name, char *res_class) { double val; char c, *s = get_string_resource (res_name, res_class); @@ -121,15 +131,20 @@ get_float_resource (res_name, res_class) unsigned int -get_pixel_resource (res_name, res_class, dpy, cmap) - char *res_name, *res_class; - Display *dpy; - Colormap cmap; +get_pixel_resource (char *res_name, char *res_class, + Display *dpy, Colormap cmap) { XColor color; char *s = get_string_resource (res_name, res_class); + char *s2; 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); @@ -151,13 +166,10 @@ get_pixel_resource (res_name, res_class, dpy, cmap) int -parse_time (string, seconds_default_p, silent_p) - char *string; - Bool seconds_default_p, silent_p; +parse_time (char *string, Bool seconds_default_p, Bool silent_p) { unsigned int h, m, s; char c; -#ifdef __DECC if (3 == sscanf (string, " %u : %2u : %2u %c", &h, &m, &s, &c)) ; else if (2 == sscanf (string, " : %2u : %2u %c", &m, &s, &c) || @@ -167,17 +179,6 @@ parse_time (string, seconds_default_p, silent_p) h = m = 0; else if (1 == sscanf (string, " %u %c", (seconds_default_p ? &s : &m), &c)) -#else - if (3 == sscanf (string, " %d : %2d : %2d %c", &h, &m, &s, &c)) - ; - else if (2 == sscanf (string, " : %2d : %2d %c", &m, &s, &c) || - 2 == sscanf (string, " %d : %2d %c", &m, &s, &c)) - h = 0; - else if (1 == sscanf (string, " : %2d %c", &s, &c)) - h = m = 0; - else if (1 == sscanf (string, " %d %c", - (seconds_default_p ? &s : &m), &c)) -#endif { h = 0; if (seconds_default_p) m = 0; @@ -206,9 +207,7 @@ parse_time (string, seconds_default_p, silent_p) } static unsigned int -get_time_resource (res_name, res_class, sec_p) - char *res_name, *res_class; - Bool sec_p; +get_time_resource (char *res_name, char *res_class, Bool sec_p) { int val; char *s = get_string_resource (res_name, res_class); @@ -219,15 +218,13 @@ get_time_resource (res_name, res_class, sec_p) } unsigned int -get_seconds_resource (res_name, res_class) - char *res_name, *res_class; +get_seconds_resource (char *res_name, char *res_class) { return get_time_resource (res_name, res_class, True); } unsigned int -get_minutes_resource (res_name, res_class) - char *res_name, *res_class; +get_minutes_resource (char *res_name, char *res_class) { return get_time_resource (res_name, res_class, False); }