Consistency improvements.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22012 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2005-11-15 11:25:31 +00:00
parent 25fb578f1c
commit 07e83d38c1
9 changed files with 87 additions and 82 deletions

View file

@ -1,3 +1,17 @@
2005-11-15 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/gdnc.m:
* Source/GSPrivate.h:
* Source/NSException.m:
* Source/NSObject.m:
* Source/NSPathUtilities.m:
* Source/NSProcessInfo.m:
* Source/NSString.m:
* Source/NSUserDefaults.m:
Be consistent and access environment variables only via the
NSProcessInfo class ...so a program which uses a category to
override it can effectively change the environment safely.
2005-11-14 Richard Frith-Macdonald <rfm@gnu.org>
* Source/win32/GSFileHandleWin32.m: Move mingw32 implementation of

View file

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

View file

@ -954,8 +954,6 @@ 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:);
@ -973,6 +971,11 @@ 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

@ -872,21 +872,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

View file

@ -1178,34 +1178,6 @@ 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,6 +57,7 @@
#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"
@ -427,6 +428,8 @@ handle_printf_atsign (FILE *stream,
if (self == [NSString class] && beenHere == NO)
{
NSString *setting;
beenHere = YES;
cMemberSel = @selector(characterIsMember:);
caiSel = @selector(characterAtIndex:);
@ -435,17 +438,6 @@ 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];
@ -475,6 +467,20 @@ 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,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

View file

@ -104,7 +104,7 @@ ihandler(int sig)
{
static BOOL beenHere = NO;
BOOL action;
const char *e;
NSString *e;
/*
* Deal with recursive call of handler.
@ -128,17 +128,11 @@ ihandler(int sig)
#else
action = NO; // exit() by default.
#endif
e = getenv("CRASH_ON_ABORT");
if (e != 0)
e = [[[NSProcessInfo processInfo] environment] objectForKey:
@"CRASH_ON_ABORT"];
if (e != nil)
{
if (strcasecmp(e, "yes") == 0 || strcasecmp(e, "true") == 0)
action = YES;
else if (strcasecmp(e, "no") == 0 || strcasecmp(e, "false") == 0)
action = NO;
else if (isdigit(*e) && *e != '0')
action = YES;
else
action = NO;
action = [e boolValue];
}
if (action == YES)