mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
Several tweaks and fixes for fallback mechanisms
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22526 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
37b22ed963
commit
665aa3a523
1 changed files with 93 additions and 64 deletions
|
@ -922,7 +922,8 @@ static NSMapTable *absolutes = 0;
|
||||||
details = [[zone timeZoneDetailArray] objectEnumerator];
|
details = [[zone timeZoneDetailArray] objectEnumerator];
|
||||||
while ((detail = [details nextObject]) != nil)
|
while ((detail = [details nextObject]) != nil)
|
||||||
{
|
{
|
||||||
[md setObject: name forKey: [detail abbreviation]];
|
[md setObject: name
|
||||||
|
forKey: [detail timeZoneAbbreviation]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1009,48 +1010,48 @@ static NSMapTable *absolutes = 0;
|
||||||
RELEASE(ma);
|
RELEASE(ma);
|
||||||
}
|
}
|
||||||
RELEASE(the_abbrev);
|
RELEASE(the_abbrev);
|
||||||
[ma addObject: the_name];
|
if ([ma containsObject: the_name] == NO)
|
||||||
|
{
|
||||||
|
[ma addObject: the_name];
|
||||||
|
}
|
||||||
RELEASE(the_name);
|
RELEASE(the_name);
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSArray *names;
|
|
||||||
NSString *name;
|
NSString *name;
|
||||||
NSEnumerator *e;
|
NSEnumerator *names;
|
||||||
int i;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Slow fallback mechanism ... go through all time names
|
* Slow fallback mechanism ... go through all time names
|
||||||
* so we load all the time zone data and generate the info
|
* so we load all the time zone data and generate the info
|
||||||
* we need from it.
|
* we need from it.
|
||||||
*/
|
*/
|
||||||
names = [NSTimeZone knownTimeZoneNames];
|
names = [[NSTimeZone knownTimeZoneNames] objectEnumerator];
|
||||||
for (i = 0; i < 24; i++)
|
while ((name = [names nextObject]) != nil)
|
||||||
{
|
{
|
||||||
e = [[names objectAtIndex: i] objectEnumerator];
|
NSTimeZone *zone;
|
||||||
while ((name = [e nextObject]) != nil)
|
|
||||||
{
|
|
||||||
NSTimeZone *zone;
|
|
||||||
|
|
||||||
if ((zone = [NSTimeZone timeZoneWithName: name]))
|
if ((zone = [NSTimeZone timeZoneWithName: name]) != nil)
|
||||||
|
{
|
||||||
|
NSEnumerator *details;
|
||||||
|
NSTimeZoneDetail *detail;
|
||||||
|
|
||||||
|
details = [[zone timeZoneDetailArray] objectEnumerator];
|
||||||
|
while ((detail = [details nextObject]) != nil)
|
||||||
{
|
{
|
||||||
NSEnumerator *details;
|
the_abbrev = [detail timeZoneAbbreviation];
|
||||||
NSTimeZoneDetail *detail;
|
ma = [md objectForKey: the_abbrev];
|
||||||
|
if (ma == nil)
|
||||||
details = [[zone timeZoneDetailArray] objectEnumerator];
|
|
||||||
while ((detail = [details nextObject]) != nil)
|
|
||||||
{
|
{
|
||||||
the_abbrev = [detail abbreviation];
|
ma = [[NSMutableArray alloc] initWithCapacity: 1];
|
||||||
ma = [md objectForKey: the_abbrev];
|
[md setObject: ma forKey: the_abbrev];
|
||||||
if (ma == nil)
|
RELEASE(ma);
|
||||||
{
|
}
|
||||||
ma = [[NSMutableArray alloc] initWithCapacity: 1];
|
if ([ma containsObject: name] == NO)
|
||||||
[md setObject: ma forKey: the_abbrev];
|
{
|
||||||
RELEASE(ma);
|
[ma addObject: name];
|
||||||
}
|
|
||||||
[ma addObject: name];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1475,18 +1476,6 @@ static NSMapTable *absolutes = 0;
|
||||||
return zone;
|
return zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Common locations for timezone info on unix systems.
|
|
||||||
*/
|
|
||||||
static NSString *zoneDirs[] = {
|
|
||||||
@"/usr/share/zoneinfo/",
|
|
||||||
@"/usr/lib/zoneinfo/",
|
|
||||||
@"/usr/local/share/zoneinfo/",
|
|
||||||
@"/usr/local/lib/zoneinfo/",
|
|
||||||
@"/etc/zoneinfo/",
|
|
||||||
@"/usr/local/etc/zoneinfo/"
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of all the known regions.<br />
|
* Returns an array of all the known regions.<br />
|
||||||
* There are 24 elements, of course, one for each time zone.
|
* There are 24 elements, of course, one for each time zone.
|
||||||
|
@ -1553,31 +1542,15 @@ static NSString *zoneDirs[] = {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
NSString *zonedir = [NSTimeZone getTimeZoneFile: @"WET"];
|
||||||
NSString *zonedir = nil;
|
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
for (i = 0; i < sizeof(zoneDirs)/sizeof(zoneDirs[0]); i++)
|
if (tzdir != nil)
|
||||||
{
|
|
||||||
BOOL isDir;
|
|
||||||
|
|
||||||
path = [zoneDirs[i] stringByAppendingString: POSIX_TZONES];
|
|
||||||
if ([mgr fileExistsAtPath: path isDirectory: &isDir] && isDir)
|
|
||||||
{
|
|
||||||
zonedir = path;
|
|
||||||
break; // use first one
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (zonedir == nil)
|
|
||||||
{
|
|
||||||
NSLog(@"no zone directory found!");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||||
NSDirectoryEnumerator *enumerator;
|
NSDirectoryEnumerator *enumerator;
|
||||||
NSString *name;
|
NSString *name;
|
||||||
|
|
||||||
|
zonedir = [zonedir stringByDeletingLastPathComponent];
|
||||||
enumerator = [mgr enumeratorAtPath: zonedir];
|
enumerator = [mgr enumeratorAtPath: zonedir];
|
||||||
while ((name = [enumerator nextObject]) != nil)
|
while ((name = [enumerator nextObject]) != nil)
|
||||||
{
|
{
|
||||||
|
@ -1586,7 +1559,7 @@ static NSString *zoneDirs[] = {
|
||||||
|
|
||||||
// FIXME: check file validity.
|
// FIXME: check file validity.
|
||||||
|
|
||||||
path = [zonedir stringByAppendingString: name];
|
path = [zonedir stringByAppendingPathComponent: name];
|
||||||
if ([mgr fileExistsAtPath: path isDirectory: &isDir]
|
if ([mgr fileExistsAtPath: path isDirectory: &isDir]
|
||||||
&& isDir == NO)
|
&& isDir == NO)
|
||||||
{
|
{
|
||||||
|
@ -1676,9 +1649,17 @@ static NSString *zoneDirs[] = {
|
||||||
+ (NSTimeZone*) timeZoneWithAbbreviation: (NSString*)abbreviation
|
+ (NSTimeZone*) timeZoneWithAbbreviation: (NSString*)abbreviation
|
||||||
{
|
{
|
||||||
NSTimeZone *zone;
|
NSTimeZone *zone;
|
||||||
|
NSString *name;
|
||||||
|
|
||||||
zone = [self timeZoneWithName: [[self abbreviationDictionary]
|
name = [[self abbreviationDictionary] objectForKey: abbreviation];
|
||||||
objectForKey: abbreviation] data: nil];
|
if (name == nil)
|
||||||
|
{
|
||||||
|
zone = nil;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
zone = [self timeZoneWithName: name data: nil];
|
||||||
|
}
|
||||||
return zone;
|
return zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1962,20 +1943,68 @@ static NSString *zoneDirs[] = {
|
||||||
|
|
||||||
@implementation NSTimeZone (Private)
|
@implementation NSTimeZone (Private)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common locations for timezone info on unix systems.
|
||||||
|
*/
|
||||||
|
static NSString *zoneDirs[] = {
|
||||||
|
@"/usr/share/zoneinfo",
|
||||||
|
@"/usr/lib/zoneinfo",
|
||||||
|
@"/usr/local/share/zoneinfo",
|
||||||
|
@"/usr/local/lib/zoneinfo",
|
||||||
|
@"/etc/zoneinfo",
|
||||||
|
@"/usr/local/etc/zoneinfo"
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the path to the named zone info file.
|
* Returns the path to the named zone info file.
|
||||||
*/
|
*/
|
||||||
+ (NSString*) getTimeZoneFile: (NSString *)name
|
+ (NSString*) getTimeZoneFile: (NSString *)name
|
||||||
{
|
{
|
||||||
|
static BOOL beenHere = NO;
|
||||||
NSString *dir = nil;
|
NSString *dir = nil;
|
||||||
|
|
||||||
|
if (beenHere == NO && tzdir == nil)
|
||||||
|
{
|
||||||
|
if (zone_mutex != nil)
|
||||||
|
{
|
||||||
|
[zone_mutex lock];
|
||||||
|
}
|
||||||
|
if (beenHere == NO && tzdir == nil)
|
||||||
|
{
|
||||||
|
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||||
|
NSString *zonedir = nil;
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
for (i = 0; i < sizeof(zoneDirs)/sizeof(zoneDirs[0]); i++)
|
||||||
|
{
|
||||||
|
BOOL isDir;
|
||||||
|
|
||||||
|
zonedir
|
||||||
|
= [zoneDirs[i] stringByAppendingPathComponent: POSIX_TZONES];
|
||||||
|
if ([mgr fileExistsAtPath: zonedir isDirectory: &isDir] && isDir)
|
||||||
|
{
|
||||||
|
tzdir = RETAIN(zonedir);
|
||||||
|
break; // use first one
|
||||||
|
}
|
||||||
|
}
|
||||||
|
beenHere = YES;
|
||||||
|
}
|
||||||
|
if (zone_mutex != nil)
|
||||||
|
{
|
||||||
|
[zone_mutex unlock];
|
||||||
|
}
|
||||||
|
}
|
||||||
/* Use the system zone info if possible, otherwise, use our installed
|
/* Use the system zone info if possible, otherwise, use our installed
|
||||||
info. */
|
info. */
|
||||||
if (tzdir && [[NSFileManager defaultManager] fileExistsAtPath:
|
if (tzdir && [[NSFileManager defaultManager] fileExistsAtPath:
|
||||||
[tzdir stringByAppendingPathComponent: name]] == NO)
|
[tzdir stringByAppendingPathComponent: name]] == YES)
|
||||||
dir = nil;
|
{
|
||||||
|
dir = tzdir;
|
||||||
|
}
|
||||||
if (dir == nil)
|
if (dir == nil)
|
||||||
dir= _time_zone_path (ZONES_DIR, nil);
|
{
|
||||||
|
dir = _time_zone_path (ZONES_DIR, nil);
|
||||||
|
}
|
||||||
return [dir stringByAppendingPathComponent: name];
|
return [dir stringByAppendingPathComponent: name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue