X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=OSX%2FPrefsReader.m;h=dcbd34984fe79203692f363d382c0b1502c62172;hb=50be9bb40dc60130c99ffa568e6677779904ff70;hp=9ff55bba23692d2bad162209d6632cd80991dab3;hpb=c494fd2e6b3b25582375d62e40f4f5cc984ca424;p=xscreensaver diff --git a/OSX/PrefsReader.m b/OSX/PrefsReader.m index 9ff55bba..dcbd3498 100644 --- a/OSX/PrefsReader.m +++ b/OSX/PrefsReader.m @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 2006 Jamie Zawinski +/* xscreensaver, Copyright (c) 2006-2010 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 @@ -117,11 +117,11 @@ opts++; } +#if 0 // make sure there's no resource mentioned in defaults and not options. NSEnumerator *enumerator = [defsdict keyEnumerator]; NSString *key; while ((key = [enumerator nextObject])) { -#if 0 if (! [optsdict objectForKey:key]) if (! ([key isEqualToString:@"foreground"] || // don't warn about these [key isEqualToString:@"background"] || @@ -142,8 +142,8 @@ [key isEqualToString:@"TVTint"] )) NSLog (@"warning: \"%@\" is in defaults but not options", key); -#endif /* 0 */ } +#endif /* 0 */ } @@ -188,26 +188,38 @@ !strcmp(name, "font") || !strcmp(name, "labelFont") || // grabclient.c !strcmp(name, "titleFont") || + !strcmp(name, "fpsFont") || // fps.c + !strcmp(name, "foreground") || // fps.c !strcmp(name, "background") )) NSLog(@"warning: no preference \"%s\" [string]", name); return NULL; } -#if 0 - if (! [o isKindOfClass:[NSString class]]) { - NSAssert2(0, @"%s = \"%@\" but should have been an NSString", name, o); - abort(); - } -#else if (! [o isKindOfClass:[NSString class]]) { NSLog(@"asked for %s as a string, but it is a %@", name, [o class]); o = [(NSNumber *) o stringValue]; } -#endif NSString *os = (NSString *) o; - const char *result = [os cStringUsingEncoding:NSUTF8StringEncoding]; - return strdup (result); + char *result = strdup ([os cStringUsingEncoding:NSUTF8StringEncoding]); + + // Kludge: if the string is surrounded with single-quotes, remove them. + // This happens when the .xml file says things like arg="-foo 'bar baz'" + if (result[0] == '\'' && result[strlen(result)-1] == '\'') { + result[strlen(result)-1] = 0; + strcpy (result, result+1); + } + + // Kludge: assume that any string that begins with "~" and has a "/" + // anywhere in it should be expanded as if it is a pathname. + if (result[0] == '~' && strchr (result, '/')) { + os = [NSString stringWithCString:result encoding:NSUTF8StringEncoding]; + free (result); + result = strdup ([[os stringByExpandingTildeInPath] + cStringUsingEncoding:NSUTF8StringEncoding]); + } + + return result; } @@ -227,6 +239,7 @@ !strcmp(name, "mono") || !strcmp(name, "count") || !strcmp(name, "ncolors") || + !strcmp(name, "doFPS") || // fps.c !strcmp(name, "eraseSeconds") // erase.c )) NSLog(@"warning: no preference \"%s\" [float]", name); @@ -245,7 +258,11 @@ - (int) getIntegerResource: (const char *) name { - return (int) [self getFloatResource:name]; + // Sliders might store float values for integral resources; round them. + float v = [self getFloatResource:name]; + int i = (int) (v + (v < 0 ? -0.5 : 0.5)); // ignore sign or -1 rounds to 0 + // if (i != v) NSLog(@"%s: rounded %.3f to %d", name, v, i); + return i; }