From 818b4aad92d6d22c5ad16e98fa59121add767376 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Fri, 3 Sep 1999 08:59:07 +0000 Subject: [PATCH] Fixed [NSProcessInfo -processName] and updated places that used it. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4809 72102866-910b-0410-8b05-ffd578937521 --- Source/NSBundle.m | 2 +- Source/NSLog.m | 2 +- Source/NSProcessInfo.m | 3 ++- Source/NSUserDefaults.m | 59 ++++++++++++++++++++++++----------------- 4 files changed, 38 insertions(+), 28 deletions(-) diff --git a/Source/NSBundle.m b/Source/NSBundle.m index 9b7314923..c907c3b8d 100644 --- a/Source/NSBundle.m +++ b/Source/NSBundle.m @@ -312,7 +312,7 @@ _bundle_load_callback(Class theClass, Category *theCategory) char *output; NSString *path, *s; - path = [[NSProcessInfo processInfo] processName]; + path = [[[NSProcessInfo processInfo] arguments] objectAtIndex: 0]; output = objc_find_executable([path cString]); NSAssert(output, NSInternalInconsistencyException); path = [NSString stringWithCString: output]; diff --git a/Source/NSLog.m b/Source/NSLog.m index 216c8302c..31f8cb29f 100644 --- a/Source/NSLog.m +++ b/Source/NSLog.m @@ -109,7 +109,7 @@ NSLogv (NSString* format, va_list args) stringWithFormat: @"%@ %@[%d] ", [[NSCalendarDate calendarDate] descriptionWithCalendarFormat: @"%b %d %H:%M:%S"], - [[[NSProcessInfo processInfo] processName] lastPathComponent], + [[NSProcessInfo processInfo] processName], pid]; /* Check if there is already a newline at the end of the format */ diff --git a/Source/NSProcessInfo.m b/Source/NSProcessInfo.m index 155ffad1d..63620b3fc 100644 --- a/Source/NSProcessInfo.m +++ b/Source/NSProcessInfo.m @@ -157,7 +157,8 @@ _gnu_process_args(int argc, char *argv[], char *env[]) int i; /* Getting the process name */ - _gnu_processName = [[NSString alloc] initWithCString: argv[0]]; + _gnu_processName = [[NSString stringWithCString: argv[0]] lastPathComponent]; + RETAIN(_gnu_processName); /* Copy the argument list */ { diff --git a/Source/NSUserDefaults.m b/Source/NSUserDefaults.m index e8602411e..d42ca979c 100644 --- a/Source/NSUserDefaults.m +++ b/Source/NSUserDefaults.m @@ -326,8 +326,7 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */ RETAIN([NSDistributedLock lockWithPath: defaultsDatabaseLockName]); } if (processName == nil) - processName = RETAIN([[[NSProcessInfo processInfo] processName] - lastPathComponent]); + processName = RETAIN([[NSProcessInfo processInfo] processName]); // Create an empty search list searchList = [[NSMutableArray alloc] initWithCapacity: 10]; @@ -901,31 +900,41 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */ while (!done) { - if ([key hasPrefix: @"-"]) { - /* anything beginning with a '-' is a defaults key and we must strip - the '-' from it. As a special case, we leave the '- in place - for '-GS...' and '--GS...' for backward compatibility. */ - if ([key hasPrefix: @"-GS"] == NO && [key hasPrefix: @"--GS"] == NO) { + if ([key hasPrefix: @"-"]) + { + NSString *old = nil; + /* anything beginning with a '-' is a defaults key and we must strip + the '-' from it. As a special case, we leave the '- in place + for '-GS...' and '--GS...' for backward compatibility. */ + if ([key hasPrefix: @"-GS"] == YES || [key hasPrefix: @"--GS"] == YES) + { + old = key; + } key = [key substringFromIndex: 1]; + val = [enumerator nextObject]; + if (!val) + { // No more args + [argDict setObject: @"" forKey: key]; // arg is empty. + if (old) + [argDict setObject: @"" forKey: old]; + done = YES; + continue; + } + else if ([val hasPrefix: @"-"]) + { // Yet another argument + [argDict setObject: @"" forKey: key]; // arg is empty. + if (old) + [argDict setObject: @"" forKey: old]; + key = val; + continue; + } + else + { // Real parameter + [argDict setObject: val forKey: key]; + if (old) + [argDict setObject: val forKey: old]; + } } - val = [enumerator nextObject]; - if (!val) - { // No more args - [argDict setObject: @"" forKey: key]; // arg is empty. - done = YES; - continue; - } - else if ([val hasPrefix: @"-"]) - { // Yet another argument - [argDict setObject: @"" forKey: key]; // arg is empty. - key = val; - continue; - } - else - { // Real parameter - [argDict setObject: val forKey: key]; - } - } done = ((key = [enumerator nextObject]) == nil); }