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:
CaS 2005-11-15 11:25:31 +00:00
parent bce6f267b3
commit 850facf3f5
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> 2005-11-14 Richard Frith-Macdonald <rfm@gnu.org>
* Source/win32/GSFileHandleWin32.m: Move mingw32 implementation of * Source/win32/GSFileHandleWin32.m: Move mingw32 implementation of

View file

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

View file

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

View file

@ -872,21 +872,31 @@ NSUserName(void)
#if defined(__WIN32__) #if defined(__WIN32__)
if (theUserName == nil) if (theUserName == nil)
{ {
const unichar *loginName = 0; /* Use the LOGNAME environment variable if set. */
/* The GetUserName function returns the current user name */ theUserName = [[[NSProcessInfo processInfo] environment]
unichar buf[1024]; objectForKey: @"LOGNAME"];
DWORD n = 1024; if ([theUserName length] > 0)
{
if (GetEnvironmentVariableW(L"LOGNAME", buf, 1024) != 0 && buf[0] != '\0') RETAIN(theUserName);
loginName = buf; }
else if (GetUserNameW(buf, &n) != 0 && buf[0] != '\0')
loginName = buf;
if (loginName)
theUserName = [[NSString alloc] initWithCharacters: loginName
length: wcslen(loginName)];
else 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 #else
/* Set olduid to some invalid uid that we could never start off running /* 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 * Used by NSException uncaught exception handler - must not call any
* methods/functions which might cause a recursive exception. * methods/functions which might cause a recursive exception.

View file

@ -57,6 +57,7 @@
#include "Foundation/NSFileManager.h" #include "Foundation/NSFileManager.h"
#include "Foundation/NSPortCoder.h" #include "Foundation/NSPortCoder.h"
#include "Foundation/NSPathUtilities.h" #include "Foundation/NSPathUtilities.h"
#include "Foundation/NSProcessInfo.h"
#include "Foundation/NSRange.h" #include "Foundation/NSRange.h"
#include "Foundation/NSException.h" #include "Foundation/NSException.h"
#include "Foundation/NSData.h" #include "Foundation/NSData.h"
@ -427,6 +428,8 @@ handle_printf_atsign (FILE *stream,
if (self == [NSString class] && beenHere == NO) if (self == [NSString class] && beenHere == NO)
{ {
NSString *setting;
beenHere = YES; beenHere = YES;
cMemberSel = @selector(characterIsMember:); cMemberSel = @selector(characterIsMember:);
caiSel = @selector(characterAtIndex:); caiSel = @selector(characterAtIndex:);
@ -435,17 +438,6 @@ handle_printf_atsign (FILE *stream,
_DefaultStringEncoding = GetDefEncoding(); _DefaultStringEncoding = GetDefEncoding();
_ByteEncodingOk = GSIsByteEncoding(_DefaultStringEncoding); _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; NSStringClass = self;
[self setVersion: 1]; [self setVersion: 1];
@ -475,6 +467,20 @@ handle_printf_atsign (FILE *stream,
[NSException raise: NSGenericException [NSException raise: NSGenericException
format: @"register printf handling of %%@ failed"]; format: @"register printf handling of %%@ failed"];
#endif /* HAVE_REGISTER_PRINTF_FUNCTION */ #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 #endif
if (currLang == nil) if (currLang == nil)
{ {
const char *env_list;
NSString *env; NSString *env;
env_list = getenv("LANGUAGES"); env = [[[NSProcessInfo processInfo] environment]
if (env_list != 0) objectForKey: @"LANGUAGES"];
if (env != nil)
{ {
env = [NSStringClass stringWithCString: env_list];
currLang = [env componentsSeparatedByString: @";"]; currLang = [env componentsSeparatedByString: @";"];
} }
} }
if (currLang != nil) if (currLang != nil)
{ {
if ([currLang containsObject: @""] == YES) NSMutableArray *a = [currLang mutableCopy];
{ unsigned c = [a count];
NSMutableArray *a = [currLang mutableCopy];
[a removeObject: @""]; while (c-- > 0)
currLang = (NSArray*)AUTORELEASE(a); {
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 /* 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; static BOOL beenHere = NO;
BOOL action; BOOL action;
const char *e; NSString *e;
/* /*
* Deal with recursive call of handler. * Deal with recursive call of handler.
@ -128,17 +128,11 @@ ihandler(int sig)
#else #else
action = NO; // exit() by default. action = NO; // exit() by default.
#endif #endif
e = getenv("CRASH_ON_ABORT"); e = [[[NSProcessInfo processInfo] environment] objectForKey:
if (e != 0) @"CRASH_ON_ABORT"];
if (e != nil)
{ {
if (strcasecmp(e, "yes") == 0 || strcasecmp(e, "true") == 0) action = [e boolValue];
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;
} }
if (action == YES) if (action == YES)