Bugfixes etc

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3353 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1998-11-30 10:04:24 +00:00
parent 758d07c90c
commit 1ede15edbc
6 changed files with 253 additions and 151 deletions

View file

@ -1,3 +1,14 @@
Mon Nov 30 10:20:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* src/NSTask: Minor bugfix -ignore SIGCHLD
* src/NSUserDefaults: bugfix in registerDefaults: was replacing rather
than addning defaults. Also changed to cache dictionaryRepresaentation.
* src/include/NSUserDefaults.h: Added ivar to cache dictionary
representation.
* src/include/NSDate.h: Updated header for a couple of fixes.
* src/NSDate.m: Initialise locale stuff.
* src/NSCalendarDate.m: Use locale stuff.
Fri Nov 27 21:30:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk> Fri Nov 27 21:30:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* src/NSPortNameServer.m: ([_open]) changed to stop attempts to restart * src/NSPortNameServer.m: ([_open]) changed to stop attempts to restart

View file

@ -47,6 +47,9 @@ typedef double NSTimeInterval;
+ (id) date; + (id) date;
+ (id) dateWithString: (NSString*)description; + (id) dateWithString: (NSString*)description;
+ (id) dateWithNaturalLanguageString: (NSString *)string;
+ (id) dateWithNaturalLanguageString: (NSString *)string
locale: (NSDictionary *)localeDictionary;
+ (id) dateWithTimeIntervalSinceNow: (NSTimeInterval)seconds; + (id) dateWithTimeIntervalSinceNow: (NSTimeInterval)seconds;
+ (id) dateWithTimeIntervalSince1970: (NSTimeInterval)seconds; + (id) dateWithTimeIntervalSince1970: (NSTimeInterval)seconds;
+ (id) dateWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds; + (id) dateWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds;
@ -69,7 +72,8 @@ typedef double NSTimeInterval;
- (NSString*) description; - (NSString*) description;
- (NSString*) descriptionWithCalendarFormat: (NSString*)format - (NSString*) descriptionWithCalendarFormat: (NSString*)format
timeZone: (NSTimeZone*)aTimeZone; timeZone: (NSTimeZone*)aTimeZone
locale: (NSDictionary *)localeDictionary;
- (NSString *) descriptionWithLocale: (NSDictionary *)locale; - (NSString *) descriptionWithLocale: (NSDictionary *)locale;
// Adding and getting intervals // Adding and getting intervals
@ -79,12 +83,13 @@ typedef double NSTimeInterval;
- (NSTimeInterval) timeIntervalSinceDate: (NSDate*)otherDate; - (NSTimeInterval) timeIntervalSinceDate: (NSDate*)otherDate;
- (NSTimeInterval) timeIntervalSinceNow; - (NSTimeInterval) timeIntervalSinceNow;
- (NSTimeInterval) timeIntervalSinceReferenceDate; - (NSTimeInterval) timeIntervalSinceReferenceDate;
- (NSTimeInterval) timeIntervalSinceReferenceDate;
// Comparing dates // Comparing dates
- (NSComparisonResult) compare: (NSDate*)otherDate; - (NSComparisonResult) compare: (NSDate*)otherDate;
- (NSDate*) earlierDate: (NSDate*)otherDate; - (NSDate*) earlierDate: (NSDate*)otherDate;
- (BOOL) isEqual: (id)other; - (BOOL) isEqualToDate: (NSDate*)otherDate;
- (NSDate*) laterDate: (NSDate*)otherDate; - (NSDate*) laterDate: (NSDate*)otherDate;
@end @end

View file

@ -1,7 +1,7 @@
/* Interface for <Class> for GNUStep /* Interface for <Class> for GNUStep
Copyright (C) 1995, 1996 Free Software Foundation, Inc. Copyright (C) 1995, 1996 Free Software Foundation, Inc.
Written by: Georg Tuparev, EMBL & Academia Naturalis, Written by: Georg Tuparev, EMBL & Academia Naturalis,
Heidelberg, Germany Heidelberg, Germany
Tuparev@EMBL-Heidelberg.de Tuparev@EMBL-Heidelberg.de
@ -62,7 +62,7 @@ extern NSString *NSCurrencyString;
extern NSString *NSDecimalDigits; extern NSString *NSDecimalDigits;
extern NSString *NSAMPMDesignation; extern NSString *NSAMPMDesignation;
/* NeXTSTEP 4.0 includes some more language-dependent constarnts: /* NeXTSTEP 4.0 includes some more language-dependent constants:
extern NSString *NSHourNameDesignations; extern NSString *NSHourNameDesignations;
extern NSString *NSYearMonthWeekDesignations; extern NSString *NSYearMonthWeekDesignations;
extern NSString *NSEarlierTimeDesignations; extern NSString *NSEarlierTimeDesignations;
@ -82,100 +82,101 @@ extern NSString *NSHomeDirectory(void);
extern NSString *NSHomeDirectoryForUser(NSString * userName); extern NSString *NSHomeDirectoryForUser(NSString * userName);
/* General implementation notes: /* General implementation notes:
OpenStep spec currently is either complete nor consitent. Therefor OpenStep spec currently is either complete nor consitent. Therefor
we had to take several implementation decisions which make vary in we had to take several implementation decisions which make vary in
different OpenStep implementations. different OpenStep implementations.
- We add a new instance method initWithFile: as a designated - We add a new instance method initWithFile: as a designated
initialization method because it allows to create user defaults initialization method because it allows to create user defaults
database from a "default user" and also it will work for various database from a "default user" and also it will work for various
non-posix implementations. non-posix implementations.
- We add two new class methods for getting and setting a list of - We add two new class methods for getting and setting a list of
user languages (userLanguages and setUserLanguages:). They are user languages (userLanguages and setUserLanguages: ). They are
somehow equivalent to the NS3.x Application's systemLanguages somehow equivalent to the NS3.x Application's systemLanguages
method. method.
- Definition of argument (command line parameters) - Definition of argument (command line parameters)
(-GSxxxx || --GSxxx) [value] (-GSxxxx || --GSxxx) [value]
Note: As far as I know, there is nothing like home directory for Note: As far as I know, there is nothing like home directory for
the M$ hell. God help the Win95/WinNT users of NSUserDefaults ;-) the M$ hell. God help the Win95/WinNT users of NSUserDefaults ;-)
To Do: To Do:
- Add writeToFile: instance method; - Add writeToFile: instance method;
- implement the description method; - implement the description method;
- test for UNIX (write test app); - test for UNIX (write test app);
- ask somebody to test it for M$; - ask somebody to test it for M$;
- polish & optimize; - polish & optimize;
- when tested, fix NSBundle (the system languages stuff); - when tested, fix NSBundle (the system languages stuff);
- write docs :-( - write docs : -(
*/ */
@interface NSUserDefaults: NSObject @interface NSUserDefaults: NSObject
{ {
@private @private
NSMutableArray *searchList; // Current search list; NSMutableArray *searchList; // Current search list;
NSMutableDictionary *persDomains; // Contains persistent defaults info; NSMutableDictionary *persDomains; // Contains persistent defaults info;
NSMutableDictionary *tempDomains; // Contains volatile defaults info; NSMutableDictionary *tempDomains; // Contains volatile defaults info;
NSMutableArray *changedDomains; /* ..after first time that persistent NSMutableArray *changedDomains; /* ..after first time that persistent
user defaults are changed */ user defaults are changed */
NSMutableString *defaultsDatabase; NSDictionary *dictionaryRep; // Cached dictionary representation
NSMutableString *defaultsDatabaseLockName; NSMutableString *defaultsDatabase;
NSDistributedLock *defaultsDatabaseLock; NSMutableString *defaultsDatabaseLockName;
BOOL tickingTimer; // for synchronization NSDistributedLock *defaultsDatabaseLock;
BOOL tickingTimer; // for synchronization
} }
/* Getting the Shared Instance */ /* Getting the Shared Instance */
+ (NSUserDefaults *)standardUserDefaults; + (NSUserDefaults*) standardUserDefaults;
+ (NSArray *)userLanguages; + (NSArray*) userLanguages;
+ (void)setUserLanguages:(NSArray *)languages; + (void) setUserLanguages: (NSArray*)languages;
/* Initializing the User Defaults */ /* Initializing the User Defaults */
- (id)init; - (id) init;
- (id)initWithUser:(NSString *)userName; - (id) initWithUser: (NSString*)userName;
- (id)initWithContentsOfFile:(NSString *)path; // This is a new method - (id) initWithContentsOfFile: (NSString*)path; // This is a new method
/* Getting and Setting a Default */ /* Getting and Setting a Default */
- (NSArray *)arrayForKey:(NSString *)defaultName; - (NSArray*) arrayForKey: (NSString*)defaultName;
- (BOOL)boolForKey:(NSString *)defaultName; - (BOOL) boolForKey: (NSString*)defaultName;
- (NSData *)dataForKey:(NSString *)defaultName; - (NSData*) dataForKey: (NSString*)defaultName;
- (NSDictionary *)dictionaryForKey:(NSString *)defaultName; - (NSDictionary*) dictionaryForKey: (NSString*)defaultName;
- (float)floatForKey:(NSString *)defaultName; - (float) floatForKey: (NSString*)defaultName;
- (int)integerForKey:(NSString *)defaultName; - (int) integerForKey: (NSString*)defaultName;
- (id)objectForKey:(NSString *)defaultName; - (id) objectForKey: (NSString*)defaultName;
- (void)removeObjectForKey:(NSString *)defaultName; - (void) removeObjectForKey: (NSString*)defaultName;
- (void)setBool:(BOOL)value forKey:(NSString *)defaultName; - (void) setBool: (BOOL)value forKey: (NSString*)defaultName;
- (void)setFloat:(float)value forKey:(NSString *)defaultName; - (void) setFloat: (float)value forKey: (NSString*)defaultName;
- (void)setInteger:(int)value forKey:(NSString *)defaultName; - (void) setInteger: (int)value forKey: (NSString*)defaultName;
- (void)setObject:(id)value forKey:(NSString *)defaultName; - (void) setObject: (id)value forKey: (NSString*)defaultName;
- (NSArray *)stringArrayForKey:(NSString *)defaultName; - (NSArray*) stringArrayForKey: (NSString*)defaultName;
- (NSString *)stringForKey:(NSString *)defaultName; - (NSString*) stringForKey: (NSString*)defaultName;
/* Returning the Search List */ /* Returning the Search List */
- (NSMutableArray *)searchList; - (NSMutableArray*) searchList;
- (void)setSearchList:(NSArray*)newList; - (void)setSearchList: (NSArray*)newList;
/* Maintaining Persistent Domains */ /* Maintaining Persistent Domains */
- (NSDictionary *)persistentDomainForName:(NSString *)domainName; - (NSDictionary*) persistentDomainForName: (NSString*)domainName;
- (NSArray *)persistentDomainNames; - (NSArray*) persistentDomainNames;
- (void)removePersistentDomainForName:(NSString *)domainName; - (void) removePersistentDomainForName: (NSString*)domainName;
- (void)setPersistentDomain:(NSDictionary *)domain - (void) setPersistentDomain: (NSDictionary*)domain
forName:(NSString *)domainName; forName: (NSString*)domainName;
- (BOOL)synchronize; - (BOOL) synchronize;
/* Maintaining Volatile Domains */ /* Maintaining Volatile Domains */
- (void)removeVolatileDomainForName:(NSString *)domainName; - (void) removeVolatileDomainForName: (NSString*)domainName;
- (void)setVolatileDomain:(NSDictionary *)domain - (void) setVolatileDomain: (NSDictionary*)domain
forName:(NSString *)domainName; forName: (NSString*)domainName;
- (NSDictionary *)volatileDomainForName:(NSString *)domainName; - (NSDictionary*) volatileDomainForName: (NSString*)domainName;
- (NSArray *)volatileDomainNames; - (NSArray*) volatileDomainNames;
/* Making Advanced Use of Defaults */ /* Making Advanced Use of Defaults */
- (NSDictionary *)dictionaryRepresentation; - (NSDictionary*) dictionaryRepresentation;
- (void)registerDefaults:(NSDictionary *)dictionary; - (void) registerDefaults: (NSDictionary*)dictionary;
@end @end
#endif /* __NSUserDefaults_h_OBJECTS_INCLUDE */ #endif /* __NSUserDefaults_h_OBJECTS_INCLUDE */

View file

@ -25,9 +25,11 @@
#include <math.h> #include <math.h>
#include <objc/objc-api.h> #include <objc/objc-api.h>
#include <Foundation/NSDate.h> #include <Foundation/NSDate.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
#include <Foundation/NSCoder.h> #include <Foundation/NSCoder.h>
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include <Foundation/NSUserDefaults.h>
#ifndef __WIN32__ #ifndef __WIN32__
#include <time.h> #include <time.h>
@ -50,49 +52,6 @@
#define GREGORIAN_REFERENCE 730486 #define GREGORIAN_REFERENCE 730486
//
// Short and long month names
// TODO: These should be localized for the language.
//
static id short_month[12] = {@"Jan",
@"Feb",
@"Mar",
@"Apr",
@"May",
@"Jun",
@"Jul",
@"Aug",
@"Sep",
@"Oct",
@"Nov",
@"Dec"};
static id long_month[12] = {@"January",
@"February",
@"March",
@"April",
@"May",
@"June",
@"July",
@"August",
@"September",
@"October",
@"November",
@"December"};
static id short_day[7] = {@"Sun",
@"Mon",
@"Tue",
@"Wed",
@"Thu",
@"Fri",
@"Sat"};
static id long_day[7] = {@"Sunday",
@"Monday",
@"Tuesday",
@"Wednesday",
@"Thursday",
@"Friday",
@"Saturday"};
@interface NSCalendarDate (Private) @interface NSCalendarDate (Private)
- (void)getYear:(int *)year month:(int *)month day:(int *)day - (void)getYear:(int *)year month:(int *)month day:(int *)day
@ -192,7 +151,7 @@ static id long_day[7] = {@"Sunday",
// //
- (id)initWithString:(NSString *)description - (id)initWithString:(NSString *)description
calendarFormat:(NSString *)format calendarFormat:(NSString *)format
locale:(NSDictionary *)dictionary locale:(NSDictionary *)locale
{ {
const char *d = [description cString]; const char *d = [description cString];
const char *f = [format cString]; const char *f = [format cString];
@ -394,7 +353,6 @@ static id long_day[7] = {@"Sunday",
yd += 1900; yd += 1900;
// Possibly convert month from string to decimal number // Possibly convert month from string to decimal number
// +++ how do we take locale into account?
if (mtag) if (mtag)
{ {
int i; int i;
@ -402,14 +360,18 @@ static id long_day[7] = {@"Sunday",
if (fullm) if (fullm)
{ {
NSArray *names = [locale objectForKey: NSMonthNameArray];
for (i = 0;i < 12; ++i) for (i = 0;i < 12; ++i)
if ([long_month[i] isEqual: m] == YES) if ([[names objectAtIndex: i] isEqual: m] == YES)
break; break;
} }
else else
{ {
NSArray *names = [locale objectForKey: NSShortMonthNameArray];
for (i = 0;i < 12; ++i) for (i = 0;i < 12; ++i)
if ([short_month[i] isEqual: m] == YES) if ([[names objectAtIndex: i] isEqual: m] == YES)
break; break;
} }
md = i + 1; md = i + 1;
@ -762,8 +724,8 @@ static id long_day[7] = {@"Sunday",
locale:(NSDictionary *)locale locale:(NSDictionary *)locale
{ {
char buf[1024]; char buf[1024];
const char *f = [format cString]; const char *f;
int lf = strlen(f); int lf;
BOOL mtag = NO, dtag = NO, ycent = NO; BOOL mtag = NO, dtag = NO, ycent = NO;
BOOL mname = NO, dname = NO; BOOL mname = NO, dname = NO;
double s; double s;
@ -771,10 +733,18 @@ static id long_day[7] = {@"Sunday",
int hd = 0, nhd; int hd = 0, nhd;
int i, j, k, z; int i, j, k, z;
if (locale == nil)
locale = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
if (format == nil)
format = [locale objectForKey: NSTimeDateFormatString];
// If the format is nil then return an empty string // If the format is nil then return an empty string
if (!format) if (!format)
return @""; return @"";
f = [format cString];
lf = strlen(f);
[self getYear: &yd month: &md day: &dom hour: &hd minute: &mnd second: &sd]; [self getYear: &yd month: &md day: &dom hour: &hd minute: &mnd second: &sd];
nhd = hd; nhd = hd;
@ -841,11 +811,16 @@ static id long_day[7] = {@"Sunday",
++i; ++i;
if (mtag) if (mtag)
{ {
// +++ Translate to locale character string NSArray *months;
NSString *name;
if (mname) if (mname)
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%s", [short_month[md-1] cString])); months = [locale objectForKey: NSShortMonthNameArray];
else else
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%s", [long_month[md-1] cString])); months = [locale objectForKey: NSMonthNameArray];
name = [months objectAtIndex: md-1];
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%s",
[name cString]));
} }
else else
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%02d", md)); k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%02d", md));
@ -887,19 +862,26 @@ static id long_day[7] = {@"Sunday",
case 'A': case 'A':
dtag = YES; // Day is character string dtag = YES; // Day is character string
case 'w': case 'w':
++i; {
if (dow < 0) dow = [self dayOfWeek]; ++i;
if (dtag) if (dow < 0) dow = [self dayOfWeek];
{ if (dtag)
// +++ Translate to locale character string {
if (dname) NSArray *days;
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%s", [short_day[dow] cString])); NSString *name;
else
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%s", [long_day[dow] cString])); if (dname)
} days = [locale objectForKey: NSShortWeekDayNameArray];
else else
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%02d", dow)); days = [locale objectForKey: NSWeekDayNameArray];
j += k; name = [days objectAtIndex: dow];
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%s",
[name cString]));
}
else
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "%02d", dow));
j += k;
}
break; break;
// is it the hour // is it the hour
@ -929,12 +911,18 @@ static id long_day[7] = {@"Sunday",
// Is it the am/pm indicator // Is it the am/pm indicator
case 'p': case 'p':
++i; {
if (hd >= 12) NSArray *a = [locale objectForKey: NSAMPMDesignation];
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "PM")); NSString *ampm;
else
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), "AM")); ++i;
j += k; if (hd >= 12)
ampm = [a objectAtIndex: 1];
else
ampm = [a objectAtIndex: 0];
k = VSPRINTF_LENGTH(sprintf(&(buf[j]), [ampm cString]));
j += k;
}
break; break;
// is it the zone name // is it the zone name

View file

@ -29,10 +29,13 @@
*/ */
#include <config.h> #include <config.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSDate.h> #include <Foundation/NSDate.h>
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
#include <Foundation/NSCoder.h> #include <Foundation/NSCoder.h>
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include <Foundation/NSUserDefaults.h>
#ifndef __WIN32__ #ifndef __WIN32__
#include <time.h> #include <time.h>
#endif /* !__WIN32__ */ #endif /* !__WIN32__ */
@ -61,6 +64,75 @@
@implementation NSDate @implementation NSDate
+ (void) initialize
{
if (self == [NSDate class])
{
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
NSDictionary *registrationDefaults;
NSArray *ampm;
NSArray *long_day;
NSArray *long_month;
NSArray *short_day;
NSArray *short_month;
ampm = [NSArray arrayWithObjects: @"AM", @"PM", nil];
short_month = [NSArray arrayWithObjects:
@"Jan",
@"Feb",
@"Mar",
@"Apr",
@"May",
@"Jun",
@"Jul",
@"Aug",
@"Sep",
@"Oct",
@"Nov",
@"Dec",
nil];
long_month = [NSArray arrayWithObjects:
@"January",
@"February",
@"March",
@"April",
@"May",
@"June",
@"July",
@"August",
@"September",
@"October",
@"November",
@"December",
nil];
short_day = [NSArray arrayWithObjects:
@"Sun",
@"Mon",
@"Tue",
@"Wed",
@"Thu",
@"Fri",
@"Sat",
nil];
long_day = [NSArray arrayWithObjects:
@"Sunday",
@"Monday",
@"Tuesday",
@"Wednesday",
@"Thursday",
@"Friday",
@"Saturday",
nil];
registrationDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
ampm, NSAMPMDesignation,
long_month, NSMonthNameArray,
long_day, NSWeekDayNameArray,
short_month, NSShortMonthNameArray,
short_day, NSShortWeekDayNameArray,
nil];
[defs registerDefaults: registrationDefaults];
}
}
// Getting current time // Getting current time
+ (NSTimeInterval) timeIntervalSinceReferenceDate + (NSTimeInterval) timeIntervalSinceReferenceDate
@ -259,23 +331,22 @@
- (NSString*) descriptionWithCalendarFormat: (NSString*)format - (NSString*) descriptionWithCalendarFormat: (NSString*)format
timeZone: (NSTimeZone*)aTimeZone timeZone: (NSTimeZone*)aTimeZone
locale: (NSDictionary*)l
{ {
// Easiest to just have NSCalendarDate do the work for us // Easiest to just have NSCalendarDate do the work for us
NSString *s; NSString *s;
NSCalendarDate *d = [NSCalendarDate alloc]; NSCalendarDate *d = [NSCalendarDate alloc];
id f, t; id f;
[d initWithTimeIntervalSinceReferenceDate: seconds_since_ref]; [d initWithTimeIntervalSinceReferenceDate: seconds_since_ref];
if (!format) if (!format)
f = [d calendarFormat]; f = [d calendarFormat];
else else
f = format; f = format;
if (!aTimeZone) if (aTimeZone)
t = [d timeZoneDetail]; [d setTimeZone: aTimeZone];
else
t = aTimeZone;
s = [d descriptionWithCalendarFormat: f timeZone: t]; s = [d descriptionWithCalendarFormat: f locale: l];
[d release]; [d release];
return s; return s;
} }
@ -349,6 +420,13 @@
return NO; return NO;
} }
- (BOOL) isEqualToDate: (NSDate*)other
{
if (1.0 > ABS(seconds_since_ref - [other timeIntervalSinceReferenceDate]))
return YES;
return NO;
}
- (NSDate*) laterDate: (NSDate*)otherDate - (NSDate*) laterDate: (NSDate*)otherDate
{ {
if (seconds_since_ref < [otherDate timeIntervalSinceReferenceDate]) if (seconds_since_ref < [otherDate timeIntervalSinceReferenceDate])

View file

@ -267,6 +267,7 @@ static NSMutableString *processName = nil;
[persDomains release]; [persDomains release];
[tempDomains release]; [tempDomains release];
[changedDomains release]; [changedDomains release];
[dictionaryRep release];
[super dealloc]; [super dealloc];
} }
@ -467,6 +468,7 @@ static NSMutableString *processName = nil;
- (void)setSearchList:(NSArray*)newList - (void)setSearchList:(NSArray*)newList
{ {
DESTROY(dictionaryRep);
[searchList release]; [searchList release];
searchList = [newList mutableCopy]; searchList = [newList mutableCopy];
} }
@ -528,6 +530,8 @@ static NSMutableString *processName = nil;
else else
return NO; return NO;
DESTROY(dictionaryRep);
// Read the persistent data from the stored database // Read the persistent data from the stored database
if ([[NSFileManager defaultManager] fileExistsAtPath: defaultsDatabase]) if ([[NSFileManager defaultManager] fileExistsAtPath: defaultsDatabase])
newDict = [[NSMutableDictionary allocWithZone:[self zone]] newDict = [[NSMutableDictionary allocWithZone:[self zone]]
@ -583,8 +587,8 @@ static NSMutableString *processName = nil;
*************************************************************************/ *************************************************************************/
- (void)removeVolatileDomainForName:(NSString *)domainName - (void)removeVolatileDomainForName:(NSString *)domainName
{ {
DESTROY(dictionaryRep);
[tempDomains removeObjectForKey:domainName]; [tempDomains removeObjectForKey:domainName];
return;
} }
- (void)setVolatileDomain:(NSDictionary *)domain - (void)setVolatileDomain:(NSDictionary *)domain
@ -599,6 +603,7 @@ static NSMutableString *processName = nil;
domainName]; domainName];
return; return;
} }
DESTROY(dictionaryRep);
[tempDomains setObject:domain forKey:domainName]; [tempDomains setObject:domain forKey:domainName];
return; return;
} }
@ -616,28 +621,41 @@ static NSMutableString *processName = nil;
/************************************************************************* /*************************************************************************
*** Making Advanced Use of Defaults *** Making Advanced Use of Defaults
*************************************************************************/ *************************************************************************/
- (NSDictionary *)dictionaryRepresentation - (NSDictionary *) dictionaryRepresentation
{ {
NSEnumerator *enumerator = [searchList reverseObjectEnumerator]; if (dictionaryRep == nil)
NSMutableDictionary *dictRep =
[NSMutableDictionary dictionaryWithCapacity:10];
id obj;
id dict;
while ((obj = [enumerator nextObject]))
{ {
if ( (dict = [persDomains objectForKey:obj]) NSEnumerator *enumerator;
|| (dict = [tempDomains objectForKey:obj]) ) NSMutableDictionary *dictRep;
[dictRep addEntriesFromDictionary:dict]; id obj;
id dict;
enumerator = [searchList reverseObjectEnumerator];
dictRep = [NSMutableDictionary allocWithZone: NSDefaultMallocZone()];
dictRep = [dictRep initWithCapacity: 512];
while ((obj = [enumerator nextObject]))
{
if ( (dict = [persDomains objectForKey: obj])
|| (dict = [tempDomains objectForKey: obj]) )
[dictRep addEntriesFromDictionary: dict];
}
dictionaryRep = [dictRep copy];
[dictRep release];
} }
// $$$ Should we return NSDictionary here ? return dictionaryRep;
return dictRep;
} }
- (void)registerDefaults:(NSDictionary *)dictionary - (void) registerDefaults: (NSDictionary*)newVals
{ {
[tempDomains setObject:dictionary forKey:NSRegistrationDomain]; NSMutableDictionary *regDefs;
return;
regDefs = [tempDomains objectForKey: NSRegistrationDomain];
if (regDefs == nil)
{
regDefs = [NSMutableDictionary dictionaryWithCapacity: [newVals count]];
}
DESTROY(dictionaryRep);
[regDefs addEntriesFromDictionary: newVals];
} }
/************************************************************************* /*************************************************************************
@ -721,7 +739,8 @@ static NSMutableString *processName = nil;
{ {
NSEnumerator *enumerator = nil; NSEnumerator *enumerator = nil;
id obj; id obj;
DESTROY(dictionaryRep);
if (!changedDomains) if (!changedDomains)
{ {
changedDomains = [[NSMutableArray arrayWithCapacity:5] retain]; changedDomains = [[NSMutableArray arrayWithCapacity:5] retain];