From 09f15d2b8d6e6bfa8d532adaeda5c8b894394943 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Mon, 15 Feb 2016 10:10:39 +0000 Subject: [PATCH] Use defaults cleanups git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39373 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 13 ++ Headers/Foundation/NSUserDefaults.h | 11 +- Headers/GNUstepBase/NSDebug+GNUstepBase.h | 2 +- Source/NSFileManager.m | 14 +- Source/NSPropertyList.m | 4 +- Source/NSUserDefaults.m | 213 ++++++++++++++-------- 6 files changed, 168 insertions(+), 89 deletions(-) diff --git a/ChangeLog b/ChangeLog index a1c3edece..86d259fa8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2016-02-15 Richard Frith-Macdonald + + * Source/NSFileManager.m: Use NSDebugLog for most debug warnings + * Source/NSUserDefaults.m: Restructure to cache flag information + from NSProcessInfo directly on initialization, so it can be used + when parsing property lists in the argument domain, avoiding any + recursion trying to parse arguments. Remove obsolete code for + for parsing -GS and --GS argument prefixes specially. + Make sure that argument parsiong behavior matches OSX apart from + The handling of a lone '-' used as key/value, and for this case + document the difference (since the GNUstep behavior is more useful + and changing it would have a real chance of breaking existing code). + 2016-02-12 Niels Grewe * Headers/Foundation/NSObjCRuntime.h: Define macros for diff --git a/Headers/Foundation/NSUserDefaults.h b/Headers/Foundation/NSUserDefaults.h index 7aa23c8fc..54b44af55 100644 --- a/Headers/Foundation/NSUserDefaults.h +++ b/Headers/Foundation/NSUserDefaults.h @@ -46,8 +46,15 @@ extern "C" { /* Standard domains */ /** - * User defaults domain for process arguments. Command-line arguments - * (attribute-value pairs, as in "-NSFoo bar") are placed into this domain. + * User defaults domain for process arguments. Command-line arguments + * (key-value pairs, as in "-NSFoo bar") are placed in this domain.
+ * Where there is a sequence of arguments beginning with '-', only the + * last one is used (so "-a -b -c d" will produce a single user default + * 'c' with value 'd').
+ * NB. On OSX the argument "-" means a key consisting of an empty string + * (so you can't use a '-' as a default value), while in GNUstep a "-" is + * a special case which does not mean a default key (so '-' may be used + * as a value).
*/ GS_EXPORT NSString* const NSArgumentDomain; diff --git a/Headers/GNUstepBase/NSDebug+GNUstepBase.h b/Headers/GNUstepBase/NSDebug+GNUstepBase.h index dc22cfcee..9050e994a 100644 --- a/Headers/GNUstepBase/NSDebug+GNUstepBase.h +++ b/Headers/GNUstepBase/NSDebug+GNUstepBase.h @@ -303,7 +303,7 @@ GS_EXPORT NSString* GSDebugMethodMsg(id obj, SEL sel, const char *file, /** The DLog macro is a less powerful but commonly used logging macro, * defined here for convenience when porting code. It will tell you - * the function name and line number but not the fle location. + * the function name and line number but not the file location. * It performs unconditional logging but is only compiled in when the * program is built with DEBUG defined. */ diff --git a/Source/NSFileManager.m b/Source/NSFileManager.m index 89bc00c51..fbceecb70 100644 --- a/Source/NSFileManager.m +++ b/Source/NSFileManager.m @@ -1018,7 +1018,7 @@ static NSStringEncoding defaultEncoding; NSFileOwnerAccountName, NSUserName(), nil]; if (![self changeFileAttributes: attributes atPath: path]) { - NSLog(@"Failed to change ownership of '%@' to '%@'", + NSDebugLog(@"Failed to change ownership of '%@' to '%@'", path, NSUserName()); } } @@ -2105,7 +2105,7 @@ static NSStringEncoding defaultEncoding; return [NSDictionary dictionaryWithObjects: values forKeys: keys count: 5]; #else - NSLog(@"NSFileManager", @"no support for filesystem attributes"); + GSOnceMLog(@"NSFileManager", @"no support for filesystem attributes"); ASSIGN(_lastError, @"no support for filesystem attributes"); return nil; #endif @@ -2389,7 +2389,7 @@ static inline void gsedRelease(GSEnumeratedDirectory X) } else { - NSLog(@"Failed to recurse into directory '%@' - %@", path, + NSDebugLog(@"Failed to recurse into directory '%@' - %@", path, [NSError _last]); } } @@ -2540,7 +2540,7 @@ static inline void gsedRelease(GSEnumeratedDirectory X) } if (S_IFDIR == (S_IFMT & statbuf.st_mode)) { - _DIR* dir_pointer; + _DIR *dir_pointer; dir_pointer = _OPENDIR([_mgr fileSystemRepresentationWithPath: @@ -2556,7 +2556,7 @@ static inline void gsedRelease(GSEnumeratedDirectory X) } else { - NSLog(@"Failed to recurse into directory '%@' - %@", + NSDebugLog(@"Failed to recurse into directory '%@' - %@", _currentFilePath, [NSError _last]); } } @@ -2944,7 +2944,7 @@ static inline void gsedRelease(GSEnumeratedDirectory X) s = [NSString stringWithFormat: @"cannot copy file type '%@'", fileType]; ASSIGN(_lastError, s); - NSLog(@"%@: %@", sourceFile, s); + NSDebugLog(@"%@: %@", sourceFile, s); continue; } [self changeFileAttributes: attributes atPath: destinationFile]; @@ -3639,7 +3639,7 @@ static NSSet *fileKeys = nil; } if (count >= 2) { - NSLog(@"Warning ... key '%@' not handled", key); + NSDebugLog(@"Warning ... key '%@' not handled", key); } return nil; } diff --git a/Source/NSPropertyList.m b/Source/NSPropertyList.m index 3d1880347..27ef1dff3 100644 --- a/Source/NSPropertyList.m +++ b/Source/NSPropertyList.m @@ -2622,7 +2622,7 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, } if (length - index > 2 - && bytes[index] == '<' && bytes[index+1] == '?') + && bytes[index] == '<' && bytes[index+1] == '?') { // It begins with '