Try reversion again.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22017 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2005-11-15 13:07:09 +00:00
parent 3f7ebf2192
commit 7c0bb1668c
7 changed files with 153 additions and 165 deletions

View file

@ -182,6 +182,11 @@ NSDictionary *GSUserDefaultsDictionaryRepresentation(void);
*/
BOOL GSUserDefaultsFlag(GSUserDefaultFlagType type);
/**
* Get a flag from an environment variable - return def if not defined.
*/
BOOL GSEnvironmentFlag(const char *name, BOOL def);
/**

View file

@ -31,7 +31,6 @@
#include "Foundation/NSCoder.h"
#include "Foundation/NSThread.h"
#include "Foundation/NSDictionary.h"
#include "Foundation/NSProcessInfo.h"
#include <stdio.h>
/**
@ -89,8 +88,7 @@ static void _terminate()
#else
shouldAbort = NO; // exit() by default.
#endif
shouldAbort = [[[[NSProcessInfo processInfo] environment]
objectForKey: @"CRASH_ON_ABORT"] boolValue];
shouldAbort = GSEnvironmentFlag("CRASH_ON_ABORT", shouldAbort);
if (shouldAbort == YES)
{
abort();

View file

@ -954,6 +954,8 @@ GSDescriptionForClassMethod(pcl self, SEL aSel)
zombieMap = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks,
NSNonOwnedPointerMapValueCallBacks, 0);
zombieClass = [NSZombie class];
NSZombieEnabled = GSEnvironmentFlag("NSZombieEnabled", NO);
NSDeallocateZombies = GSEnvironmentFlag("NSDeallocateZombies", NO);
autorelease_class = [NSAutoreleasePool class];
autorelease_sel = @selector(addObject:);
@ -971,11 +973,6 @@ GSDescriptionForClassMethod(pcl self, SEL aSel)
selector: @selector(_becomeMultiThreaded:)
name: NSWillBecomeMultiThreadedNotification
object: nil];
NSZombieEnabled = [[[[NSProcessInfo processInfo] environment]
objectForKey: @"NSZombieEnabled"] boolValue];
NSDeallocateZombies = [[[[NSProcessInfo processInfo] environment]
objectForKey: @"NSDeallocateZombies"] boolValue];
}
return;
}

View file

@ -174,7 +174,7 @@ static NSString *localLibs = nil;
/* Internal function prototypes. */
/* ============================= */
NSMutableDictionary* GNUstepConfig(NSDictionary *newConfig, NSString *userName);
NSDictionary* GNUstepConfig(void);
static BOOL ParseConfigurationFile(NSString *name, NSMutableDictionary *dict);
@ -350,25 +350,21 @@ static void ExtractValuesFromConfig(NSDictionary *config)
}
/*
* Function to return a mutable copy of the configuration,
* either the system wide config, or (if a userName was provided)
* the config for a specific user.
* If newConfig is not nil, it is used to set a new system wide
* configuration.
* Function to return the system-wide configuration
*/
NSMutableDictionary*
GNUstepConfig(NSDictionary *newConfig, NSString *userName)
NSDictionary*
GNUstepConfig(void)
{
static NSDictionary *config = nil;
NSMutableDictionary *conf = nil;
BOOL changedSystemConfig = NO;
[gnustep_global_lock lock];
if (config == nil || (newConfig != nil && [config isEqual: newConfig] == NO))
if (config == nil)
{
NS_DURING
[gnustep_global_lock lock];
if (config == nil)
{
if (newConfig == nil)
NSMutableDictionary *conf = nil;
NS_DURING
{
NSString *file = nil;
@ -405,110 +401,98 @@ GNUstepConfig(NSDictionary *newConfig, NSString *userName)
gnustepConfigPath = [file stringByDeletingLastPathComponent];
RETAIN(gnustepConfigPath);
ParseConfigurationFile(file, conf);
/* System admins may force the user and defaults paths by
* setting GNUSTEP_USER_CONFIG_FILE to be an empty string.
* If they simply don't define it at all, we assign a default.
*/
if ([conf objectForKey: @"GNUSTEP_USER_CONFIG_FILE"] == nil)
{
NSString *tmp;
tmp = [NSString stringWithCString:\
STRINGIFY(GNUSTEP_USER_CONFIG_FILE)];
[conf setObject: tmp forKey: @"GNUSTEP_USER_CONFIG_FILE"];
}
config = [conf copy];
DESTROY(conf);
}
else
NS_HANDLER
{
conf = [newConfig mutableCopy];
[gnustep_global_lock unlock];
config = nil;
DESTROY(conf);
[localException raise];
}
/* System admins may force the user and defaults paths by
* setting GNUSTEP_USER_CONFIG_FILE to be an empty string.
* If they simply don't define it at all, we assign a default.
*/
if ([conf objectForKey: @"GNUSTEP_USER_CONFIG_FILE"] == nil)
{
NSString *tmp;
tmp = [NSString stringWithCString:\
STRINGIFY(GNUSTEP_USER_CONFIG_FILE)];
[conf setObject: tmp forKey: @"GNUSTEP_USER_CONFIG_FILE"];
}
if (config != nil)
{
changedSystemConfig = YES;
}
config = [conf copy];
DESTROY(conf);
NS_ENDHANDLER
}
NS_HANDLER
{
[gnustep_global_lock unlock];
config = nil;
DESTROY(conf);
[localException raise];
}
NS_ENDHANDLER
[gnustep_global_lock unlock];
}
[gnustep_global_lock unlock];
return config;
}
if (changedSystemConfig == YES)
{
/*
* The main configuration was changed by passing in a dictionary to
* this function, so we need to reset the path utilities system to use
* any new values from the config.
*/
ShutdownPathUtilities();
InitialisePathUtilities();
}
/*
* Function to return the configuration for the named user
*/
static NSDictionary*
GNUstepUserConfig(NSString *name)
{
NSMutableDictionary *conf;
NSString *file;
NSString *home;
#ifdef HAVE_GETEUID
if (userName != nil)
{
/*
* A program which is running setuid cannot be trusted
* to pick up user specific config, so we clear the userName
* to force the system configuration to be returned rather
* than a per-user config.
*/
if (getuid() != geteuid())
{
userName = nil;
}
}
#endif
if (config != nil && userName != nil)
{
NSString *file;
NSString *home;
conf = AUTORELEASE([config mutableCopy]);
file = RETAIN([conf objectForKey: @"GNUSTEP_USER_CONFIG_FILE"]);
home = NSHomeDirectoryForUser(userName);
ParseConfigurationFile([home stringByAppendingPathComponent: file], conf);
/*
* We don't let the user config file override the GNUSTEP_USER_CONFIG_FILE
* variable ... that would be silly/pointless.
*/
[conf setObject: file forKey: @"GNUSTEP_USER_CONFIG_FILE"];
RELEASE(file);
return conf;
}
else
{
return AUTORELEASE([config mutableCopy]);
}
conf = [GNUstepConfig() mutableCopy];
file = RETAIN([conf objectForKey: @"GNUSTEP_USER_CONFIG_FILE"]);
home = NSHomeDirectoryForUser(name);
ParseConfigurationFile([home stringByAppendingPathComponent: file], conf);
/*
* We don't let the user config file override the GNUSTEP_USER_CONFIG_FILE
* variable ... that would be silly/pointless.
*/
[conf setObject: file forKey: @"GNUSTEP_USER_CONFIG_FILE"];
RELEASE(file);
return AUTORELEASE(conf);
}
/* Initialise all things required by this module */
static void InitialisePathUtilities(void)
{
NSMutableDictionary *userConfig = nil;
if (gnustepSystemRoot != nil)
{
return; // Protect from multiple calls
}
[gnustep_global_lock lock];
/* Set up our root paths */
NS_DURING
{
NSString *userName;
NSMutableDictionary *config;
BOOL shouldLoadUserConfig = YES;
[gnustep_global_lock lock];
userName = NSUserName();
config = GNUstepConfig(nil, userName);
ASSIGNCOPY(gnustepUserHome, NSHomeDirectoryForUser(userName));
ExtractValuesFromConfig(config);
userConfig = [GNUstepConfig() mutableCopy];
ASSIGNCOPY(gnustepUserHome, NSHomeDirectoryForUser(NSUserName()));
#ifdef HAVE_GETEUID
/*
* A program which is running setuid cannot be trusted
* to pick up user specific config.
*/
if (getuid() != geteuid())
{
shouldLoadUserConfig = NO;
}
#endif
if (shouldLoadUserConfig == YES)
{
NSString *file;
file = [gnustepUserHome stringByAppendingPathComponent:
[userConfig objectForKey: @"GNUSTEP_USER_CONFIG_FILE"]];
ParseConfigurationFile(file, userConfig);
}
ExtractValuesFromConfig(userConfig);
DESTROY(userConfig);
[gnustep_global_lock unlock];
}
@ -516,6 +500,7 @@ static void InitialisePathUtilities(void)
{
/* unlock then re-raise the exception */
[gnustep_global_lock unlock];
DESTROY(userConfig);
[localException raise];
}
NS_ENDHANDLER
@ -887,31 +872,21 @@ NSUserName(void)
#if defined(__WIN32__)
if (theUserName == nil)
{
/* Use the LOGNAME environment variable if set. */
theUserName = [[[NSProcessInfo processInfo] environment]
objectForKey: @"LOGNAME"];
if ([theUserName length] > 0)
{
RETAIN(theUserName);
}
else
{
/* The GetUserName function returns the current user name */
unichar buf[1024];
DWORD n = 1024;
const unichar *loginName = 0;
/* The GetUserName function returns the current user name */
unichar buf[1024];
DWORD n = 1024;
if (GetUserNameW(buf, &n) != 0 && buf[0] != '\0')
{
theUserName = [[NSString alloc] initWithCharacters: buf
length: wcslen(buf)];
}
else
{
theUserName = nil;
[NSException raise: NSInternalInconsistencyException
format: @"Unable to determine current user name"];
}
}
if (GetEnvironmentVariableW(L"LOGNAME", buf, 1024) != 0 && buf[0] != '\0')
loginName = buf;
else if (GetUserNameW(buf, &n) != 0 && buf[0] != '\0')
loginName = buf;
if (loginName)
theUserName = [[NSString alloc] initWithCharacters: loginName
length: wcslen(loginName)];
else
[NSException raise: NSInternalInconsistencyException
format: @"Unable to determine current user name"];
}
#else
/* Set olduid to some invalid uid that we could never start off running
@ -1066,7 +1041,7 @@ GSDefaultsRootForUser(NSString *userName)
{
NSDictionary *config;
config = GNUstepConfig(nil, userName);
config = GNUstepUserConfig(userName);
defaultsDir = [config objectForKey: @"GNUSTEP_USER_DEFAULTS_DIR"];
if (defaultsDir == nil)
{

View file

@ -1178,6 +1178,34 @@ BOOL GSDebugSet(NSString *level)
}
BOOL
GSEnvironmentFlag(const char *name, BOOL def)
{
const char *c = getenv(name);
BOOL a = def;
if (c != 0)
{
a = NO;
if ((c[0] == 'y' || c[0] == 'Y') && (c[1] == 'e' || c[1] == 'E')
&& (c[2] == 's' || c[2] == 'S') && c[3] == 0)
{
a = YES;
}
else if ((c[0] == 't' || c[0] == 'T') && (c[1] == 'r' || c[1] == 'R')
&& (c[2] == 'u' || c[2] == 'U') && (c[3] == 'e' || c[3] == 'E')
&& c[4] == 0)
{
a = YES;
}
else if (isdigit(c[0]) && c[0] != '0')
{
a = YES;
}
}
return a;
}
/**
* Used by NSException uncaught exception handler - must not call any
* methods/functions which might cause a recursive exception.

View file

@ -57,7 +57,6 @@
#include "Foundation/NSFileManager.h"
#include "Foundation/NSPortCoder.h"
#include "Foundation/NSPathUtilities.h"
#include "Foundation/NSProcessInfo.h"
#include "Foundation/NSRange.h"
#include "Foundation/NSException.h"
#include "Foundation/NSData.h"
@ -428,8 +427,6 @@ handle_printf_atsign (FILE *stream,
if (self == [NSString class] && beenHere == NO)
{
NSString *setting;
beenHere = YES;
cMemberSel = @selector(characterIsMember:);
caiSel = @selector(characterAtIndex:);
@ -438,6 +435,17 @@ handle_printf_atsign (FILE *stream,
_DefaultStringEncoding = GetDefEncoding();
_ByteEncodingOk = GSIsByteEncoding(_DefaultStringEncoding);
if (getenv("GNUSTEP_PATH_HANDLING") != 0)
{
if (strcmp("unix", getenv("GNUSTEP_PATH_HANDLING")) == 0)
{
pathHandling = PH_UNIX;
}
else if (strcmp("windows", getenv("GNUSTEP_PATH_HANDLING")) == 0)
{
pathHandling = PH_WINDOWS;
}
}
NSStringClass = self;
[self setVersion: 1];
@ -467,20 +475,6 @@ handle_printf_atsign (FILE *stream,
[NSException raise: NSGenericException
format: @"register printf handling of %%@ failed"];
#endif /* HAVE_REGISTER_PRINTF_FUNCTION */
setting = [[[NSProcessInfo processInfo] environment]
objectForKey: @"GNUSTEP_PATH_HANDLING"];
if (setting != nil)
{
if ([setting isEqualToString: @"unix"] == YES)
{
pathHandling = PH_UNIX;
}
else if ([setting isEqualToString: @"windows"] == YES)
{
pathHandling = PH_WINDOWS;
}
}
}
}

View file

@ -627,36 +627,27 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
#endif
if (currLang == nil)
{
const char *env_list;
NSString *env;
env = [[[NSProcessInfo processInfo] environment]
objectForKey: @"LANGUAGES"];
if (env != nil)
env_list = getenv("LANGUAGES");
if (env_list != 0)
{
env = [NSStringClass stringWithCString: env_list];
currLang = [env componentsSeparatedByString: @";"];
}
}
if (currLang != nil)
{
NSMutableArray *a = [currLang mutableCopy];
unsigned c = [a count];
while (c-- > 0)
if ([currLang containsObject: @""] == YES)
{
NSString *s = [[a objectAtIndex: c] stringByTrimmingSpaces];
NSMutableArray *a = [currLang mutableCopy];
if ([s length] == 0)
{
[a removeObjectAtIndex: c];
}
else
{
[a replaceObjectAtIndex: c withObject: s];
}
[a removeObject: @""];
currLang = (NSArray*)AUTORELEASE(a);
}
[userLanguages addObjectsFromArray: a];
RELEASE(a);
[userLanguages addObjectsFromArray: currLang];
}
/* Check if "English" is included. We do this to make sure all the