mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
Restore some reverted changes. Tidy up a bit
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22021 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7c0bb1668c
commit
f0b8d8eb84
5 changed files with 150 additions and 134 deletions
|
@ -1,3 +1,12 @@
|
|||
2005-11-16 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSProcessInfo.m:
|
||||
* Source/NSUserDefaults.m:
|
||||
Restore revertyed changes for code where class initialisation order
|
||||
is not a factor.
|
||||
* Source/NSUser.m: Delete unused file
|
||||
* GNUmakefile: Don't try to build NSUser.m
|
||||
|
||||
2005-11-15 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
Revert last changes ... discovered some apps where ordering of
|
||||
|
|
|
@ -214,7 +214,6 @@ NSUnarchiver.m \
|
|||
NSUndoManager.m \
|
||||
NSURL.m \
|
||||
NSURLHandle.m \
|
||||
NSUser.m \
|
||||
NSUserDefaults.m \
|
||||
NSValue.m \
|
||||
NSXMLParser.m \
|
||||
|
|
|
@ -174,7 +174,7 @@ static NSString *localLibs = nil;
|
|||
/* Internal function prototypes. */
|
||||
/* ============================= */
|
||||
|
||||
NSDictionary* GNUstepConfig(void);
|
||||
NSMutableDictionary* GNUstepConfig(NSDictionary *newConfig, NSString *userName);
|
||||
|
||||
static BOOL ParseConfigurationFile(NSString *name, NSMutableDictionary *dict);
|
||||
|
||||
|
@ -350,21 +350,25 @@ static void ExtractValuesFromConfig(NSDictionary *config)
|
|||
}
|
||||
|
||||
/*
|
||||
* Function to return the system-wide configuration
|
||||
* 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.
|
||||
*/
|
||||
NSDictionary*
|
||||
GNUstepConfig(void)
|
||||
NSMutableDictionary*
|
||||
GNUstepConfig(NSDictionary *newConfig, NSString *userName)
|
||||
{
|
||||
static NSDictionary *config = nil;
|
||||
NSMutableDictionary *conf = nil;
|
||||
BOOL changedSystemConfig = NO;
|
||||
|
||||
if (config == nil)
|
||||
[gnustep_global_lock lock];
|
||||
if (config == nil || (newConfig != nil && [config isEqual: newConfig] == NO))
|
||||
{
|
||||
[gnustep_global_lock lock];
|
||||
if (config == nil)
|
||||
NS_DURING
|
||||
{
|
||||
NSMutableDictionary *conf = nil;
|
||||
|
||||
NS_DURING
|
||||
if (newConfig == nil)
|
||||
{
|
||||
NSString *file = nil;
|
||||
|
||||
|
@ -401,98 +405,110 @@ GNUstepConfig(void)
|
|||
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);
|
||||
}
|
||||
NS_HANDLER
|
||||
else
|
||||
{
|
||||
[gnustep_global_lock unlock];
|
||||
config = nil;
|
||||
DESTROY(conf);
|
||||
[localException raise];
|
||||
conf = [newConfig mutableCopy];
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
/* 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);
|
||||
}
|
||||
[gnustep_global_lock unlock];
|
||||
NS_HANDLER
|
||||
{
|
||||
[gnustep_global_lock unlock];
|
||||
config = nil;
|
||||
DESTROY(conf);
|
||||
[localException raise];
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
}
|
||||
return config;
|
||||
}
|
||||
[gnustep_global_lock unlock];
|
||||
|
||||
/*
|
||||
* Function to return the configuration for the named user
|
||||
*/
|
||||
static NSDictionary*
|
||||
GNUstepUserConfig(NSString *name)
|
||||
{
|
||||
NSMutableDictionary *conf;
|
||||
NSString *file;
|
||||
NSString *home;
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
#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]);
|
||||
}
|
||||
}
|
||||
|
||||
/* 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
|
||||
{
|
||||
BOOL shouldLoadUserConfig = YES;
|
||||
NSString *userName;
|
||||
NSMutableDictionary *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 lock];
|
||||
userName = NSUserName();
|
||||
config = GNUstepConfig(nil, userName);
|
||||
ASSIGNCOPY(gnustepUserHome, NSHomeDirectoryForUser(userName));
|
||||
ExtractValuesFromConfig(config);
|
||||
|
||||
[gnustep_global_lock unlock];
|
||||
}
|
||||
|
@ -500,7 +516,6 @@ static void InitialisePathUtilities(void)
|
|||
{
|
||||
/* unlock then re-raise the exception */
|
||||
[gnustep_global_lock unlock];
|
||||
DESTROY(userConfig);
|
||||
[localException raise];
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
|
@ -872,21 +887,31 @@ NSUserName(void)
|
|||
#if defined(__WIN32__)
|
||||
if (theUserName == nil)
|
||||
{
|
||||
const unichar *loginName = 0;
|
||||
/* The GetUserName function returns the current user name */
|
||||
unichar buf[1024];
|
||||
DWORD n = 1024;
|
||||
|
||||
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)];
|
||||
/* Use the LOGNAME environment variable if set. */
|
||||
theUserName = [[[NSProcessInfo processInfo] environment]
|
||||
objectForKey: @"LOGNAME"];
|
||||
if ([theUserName length] > 0)
|
||||
{
|
||||
RETAIN(theUserName);
|
||||
}
|
||||
else
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Unable to determine current user name"];
|
||||
{
|
||||
/* 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"];
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* Set olduid to some invalid uid that we could never start off running
|
||||
|
@ -1041,7 +1066,7 @@ GSDefaultsRootForUser(NSString *userName)
|
|||
{
|
||||
NSDictionary *config;
|
||||
|
||||
config = GNUstepUserConfig(userName);
|
||||
config = GNUstepConfig(nil, userName);
|
||||
defaultsDir = [config objectForKey: @"GNUSTEP_USER_DEFAULTS_DIR"];
|
||||
if (defaultsDir == nil)
|
||||
{
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
/** Implementation of login-related functions for GNUstep
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Created: May 1996
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
|
||||
<title>NSUser class reference</title>
|
||||
$Date$ $Revision$
|
||||
*/
|
||||
|
|
@ -627,27 +627,36 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
|
|||
#endif
|
||||
if (currLang == nil)
|
||||
{
|
||||
const char *env_list;
|
||||
NSString *env;
|
||||
|
||||
env_list = getenv("LANGUAGES");
|
||||
if (env_list != 0)
|
||||
env = [[[NSProcessInfo processInfo] environment]
|
||||
objectForKey: @"LANGUAGES"];
|
||||
if (env != nil)
|
||||
{
|
||||
env = [NSStringClass stringWithCString: env_list];
|
||||
currLang = [env componentsSeparatedByString: @";"];
|
||||
}
|
||||
}
|
||||
|
||||
if (currLang != nil)
|
||||
{
|
||||
if ([currLang containsObject: @""] == YES)
|
||||
{
|
||||
NSMutableArray *a = [currLang mutableCopy];
|
||||
NSMutableArray *a = [currLang mutableCopy];
|
||||
unsigned c = [a count];
|
||||
|
||||
[a removeObject: @""];
|
||||
currLang = (NSArray*)AUTORELEASE(a);
|
||||
while (c-- > 0)
|
||||
{
|
||||
NSString *s = [[a objectAtIndex: c] stringByTrimmingSpaces];
|
||||
|
||||
if ([s length] == 0)
|
||||
{
|
||||
[a removeObjectAtIndex: c];
|
||||
}
|
||||
else
|
||||
{
|
||||
[a replaceObjectAtIndex: c withObject: s];
|
||||
}
|
||||
}
|
||||
[userLanguages addObjectsFromArray: currLang];
|
||||
[userLanguages addObjectsFromArray: a];
|
||||
RELEASE(a);
|
||||
}
|
||||
|
||||
/* Check if "English" is included. We do this to make sure all the
|
||||
|
|
Loading…
Reference in a new issue