diff --git a/ChangeLog b/ChangeLog index 2510e8fa5..a873e5b2d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2003-01-31 Stephane Corthesy + Adam Fedor + + * Headers/gnustep/base/GSCategories.h: Moved + NSString(GSCategories), NSMutableString(GSCategories), and copied + NSObject(GSCategories) to here + * Headers/gnustep/base/NSString.h, Headers/gnustep/base/NSObject: + From here. + * Headers/gnustep/base/GSMime.h: Include Foundation on MacOSX. + + * Source/Additions/GSCategories.m: Fix includes. + * Source/Additions/GSCompatibility.h: Defined DebugLog, WarnLog + macros. Add Additional NSObject, NSInvocation, NSString and + NSProcessInfo methods. Add NSStandardLibraryPaths. + * Source/Additions/GSCompatibility.m: Idem. + 2003-01-30 Richard Frith-Macdonald * Source/libgnustep-base.def.in: Regenerated diff --git a/Headers/gnustep/base/GSCategories.h b/Headers/gnustep/base/GSCategories.h index 86660d96b..0963bff80 100644 --- a/Headers/gnustep/base/GSCategories.h +++ b/Headers/gnustep/base/GSCategories.h @@ -28,14 +28,16 @@ #ifndef NO_GNUSTEP +#ifdef NeXT_Foundation_LIBRARY +#include +#endif + @interface NSCalendarDate (GSCategories) - (int) weekOfYear; @end - - @interface NSData (GSCategories) - (NSString*) hexadecimalRepresentation; @@ -44,5 +46,27 @@ @end +@interface NSString (GSCategories) +- (NSString*) stringByDeletingPrefix: (NSString*)prefix; +- (NSString*) stringByDeletingSuffix: (NSString*)suffix; +@end + +@interface NSMutableString (GSCategories) +- (void) deleteSuffix: (NSString*)suffix; +- (void) deletePrefix: (NSString*)prefix; +@end + +/* This is also defined in NSObject.h, but added here for use with the + additions library */ +#ifndef NSOBJECT_GSCATEGORIES_INTERFACE +@interface NSObject (GSCategories) +- notImplemented:(SEL)aSel; +- (id) subclassResponsibility: (SEL)aSel; +- (id) shouldNotImplement: (SEL)aSel; + +- (NSComparisonResult) compare: (id)anObject; +@end +#endif + #endif /* NO_GNUSTEP */ #endif /* INCLUDED_GS_CATEGORIES_H */ diff --git a/Headers/gnustep/base/GSMime.h b/Headers/gnustep/base/GSMime.h index abf481d58..d62c11ea4 100644 --- a/Headers/gnustep/base/GSMime.h +++ b/Headers/gnustep/base/GSMime.h @@ -28,7 +28,11 @@ #ifndef __GSMIME_H__ #define __GSMIME_H__ +#ifdef NeXT_Foundation_LIBRARY +#include +#else #include +#endif @class NSArray; @class NSMutableArray; diff --git a/Headers/gnustep/base/NSObject.h b/Headers/gnustep/base/NSObject.h index 8bf19fe77..4f15e64aa 100644 --- a/Headers/gnustep/base/NSObject.h +++ b/Headers/gnustep/base/NSObject.h @@ -291,6 +291,7 @@ GS_EXPORT NSRecursiveLock *gnustep_global_lock; - (id) write: (TypedStream*)aStream; @end +#define NSOBJECT_GSCATEGORIES_INTERFACE @interface NSObject (GSCategories) - notImplemented:(SEL)aSel; - (id) subclassResponsibility: (SEL)aSel; diff --git a/Headers/gnustep/base/NSString.h b/Headers/gnustep/base/NSString.h index 12a6db2fe..86e9a9b70 100644 --- a/Headers/gnustep/base/NSString.h +++ b/Headers/gnustep/base/NSString.h @@ -366,11 +366,6 @@ extern struct objc_class _NSConstantStringClassReference; #ifndef NO_GNUSTEP -@interface NSString (GSCategories) -- (NSString*) stringByDeletingPrefix: (NSString*)prefix; -- (NSString*) stringByDeletingSuffix: (NSString*)suffix; -@end - @interface NSString (GNUstep) - (NSString*) stringByReplacingString: (NSString*)replace withString: (NSString*)by; @@ -379,11 +374,6 @@ extern struct objc_class _NSConstantStringClassReference; - (NSString*) stringByTrimmingSpaces; @end -@interface NSMutableString (GSCategories) -- (void) deleteSuffix: (NSString*)suffix; -- (void) deletePrefix: (NSString*)prefix; -@end - @interface NSMutableString (GNUstep) - (NSString*) immutableProxy; - (void) replaceString: (NSString*)replace diff --git a/Source/Additions/GCArray.m b/Source/Additions/GCArray.m index 672c9387d..0b7483cd2 100644 --- a/Source/Additions/GCArray.m +++ b/Source/Additions/GCArray.m @@ -24,6 +24,7 @@ */ #include "config.h" +#include #include #include #include diff --git a/Source/Additions/GSCategories.m b/Source/Additions/GSCategories.m index e7a119078..40d3e2f28 100644 --- a/Source/Additions/GSCategories.m +++ b/Source/Additions/GSCategories.m @@ -22,7 +22,9 @@ */ #include "config.h" -#include +#include +#include +#include #include "GSCompatibility.h" /** diff --git a/Source/Additions/GSCompatibility.h b/Source/Additions/GSCompatibility.h index 4bd3ed34e..b0272e557 100644 --- a/Source/Additions/GSCompatibility.h +++ b/Source/Additions/GSCompatibility.h @@ -28,12 +28,91 @@ #ifdef NeXT_Foundation_LIBRARY #include #include -#include "gnustep/base/preface.h" -#include "gnustep/base/GSObjCRuntime.h" -#include "gnustep/base/GNUstep.h" +#include +#include +#include +#include -#define NSDebugMLLog(a, args...) +@class NSMutableSet; +// Following are also defined in gnustep-base/Headers/gnustep/base/NSObject.h +#define IF_NO_GC(x) \ + x + +// Following are also defined in gnustep-base/Headers/gnustep/base/NSDebug.h +#ifdef DEBUG +#define NSDebugLLog(level, format, args...) \ + do { if (GSDebugSet(level) == YES) \ + NSLog(format , ## args); } while (0) + +#define NSDebugLog(format, args...) \ + do { if (GSDebugSet(@"dflt") == YES) \ + NSLog(format , ## args); } while (0) + +#define NSDebugFLLog(level, format, args...) \ + do { if (GSDebugSet(level) == YES) { \ + NSString *fmt = GSDebugFunctionMsg( \ + __PRETTY_FUNCTION__, __FILE__, __LINE__, format); \ + NSLog(fmt , ## args); }} while (0) + +#define NSDebugFLog(format, args...) \ + do { if (GSDebugSet(@"dflt") == YES) { \ + NSString *fmt = GSDebugFunctionMsg( \ + __PRETTY_FUNCTION__, __FILE__, __LINE__, format); \ + NSLog(fmt , ## args); }} while (0) + +#define NSDebugMLLog(level, format, args...) \ + do { if (GSDebugSet(level) == YES) { \ + NSString *fmt = GSDebugMethodMsg( \ + self, _cmd, __FILE__, __LINE__, format); \ + NSLog(fmt , ## args); }} while (0) + +#define NSDebugMLog(format, args...) \ + do { if (GSDebugSet(@"dflt") == YES) { \ + NSString *fmt = GSDebugMethodMsg( \ + self, _cmd, __FILE__, __LINE__, format); \ + NSLog(fmt , ## args); }} while (0) + +#else +#define NSDebugLLog(level, format, args...) +#define NSDebugLog(format, args...) +#define NSDebugFLLog(level, format, args...) +#define NSDebugFLog(format, args...) +#define NSDebugMLLog(level, format, args...) +#define NSDebugMLog(format, args...) +#endif /* DEBUG */ + +#ifdef GSWARN +#define NSWarnLog(format, args...) \ + do { if (GSDebugSet(@"NoWarn") == NO) { \ + NSLog(format , ## args); }} while (0) + +#define NSWarnFLog(format, args...) \ + do { if (GSDebugSet(@"NoWarn") == NO) { \ + NSString *fmt = GSDebugFunctionMsg( \ + __PRETTY_FUNCTION__, __FILE__, __LINE__, format); \ + NSLog(fmt , ## args); }} while (0) + +#define NSWarnMLog(format, args...) \ + do { if (GSDebugSet(@"NoWarn") == NO) { \ + NSString *fmt = GSDebugMethodMsg( \ + self, _cmd, __FILE__, __LINE__, format); \ + NSLog(fmt , ## args); }} while (0) +#else +#define NSWarnLog(format, args...) +#define NSWarnFLog(format, args...) +#define NSWarnMLog(format, args...) +#endif /* GSWARN */ + +#define GS_RANGE_CHECK(RANGE, SIZE) \ + if (RANGE.location > SIZE || RANGE.length > (SIZE - RANGE.location)) \ + [NSException raise: NSRangeException \ + format: @"in %s, range { %u, %u } extends beyond size (%u)", \ + sel_get_name(_cmd), RANGE.location, RANGE.length, SIZE] + +GS_EXPORT NSRecursiveLock *gnustep_global_lock; + +/* Taken from gnustep-base/Headers/gnustep/base/NSString.h */ typedef enum _NSGNUstepStringEncoding { /* NB. Must not have an encoding with value zero - so we can use zero to @@ -64,20 +143,37 @@ typedef enum _NSGNUstepStringEncoding NSBIG5StringEncoding // Traditional chinese } NSGNUstepStringEncoding; -NSString *GetEncodingName(NSStringEncoding availableEncodingValue); +@interface NSObject(GNUStepGlue) ++ (id) notImplemented:(SEL)selector; +- (BOOL) isInstance; +@end -#define GS_RANGE_CHECK(RANGE, SIZE) \ - if (RANGE.location > SIZE || RANGE.length > (SIZE - RANGE.location)) \ - [NSException raise: NSRangeException \ - format: @"in %s, range { %u, %u } extends beyond size (%u)", \ - sel_get_name(_cmd), RANGE.location, RANGE.length, SIZE] +// Used only in EOFault.m, -[EOFault forward::], for Object compatibility +@interface NSInvocation(GNUStepGlue) +- (retval_t) returnFrame:(arglist_t)args; +- (id) initWithArgframe:(arglist_t)args selector:(SEL)selector; +@end -GS_EXPORT NSRecursiveLock *gnustep_global_lock; +GS_EXPORT NSArray *NSStandardLibraryPaths(); +GS_EXPORT NSString *GetEncodingName(NSStringEncoding availableEncodingValue); + +@interface NSString(GNUStepGlue) +- (BOOL) boolValue; +@end + +GS_EXPORT BOOL GSDebugSet(NSString *level); +@interface NSProcessInfo(GNUStepGlue) +- (NSMutableSet *) debugSet; +@end + +GS_EXPORT NSString *GSDebugMethodMsg(id obj, SEL sel, const char *file, int line, NSString *fmt); +GS_EXPORT NSString *GSDebugFunctionMsg(const char *func, const char *file, int line, NSString *fmt); @interface NSArray (GSCompatibility) - (id) initWithArray: (NSArray*)array copyItems: (BOOL)shouldCopy; @end + #endif /* NexT_FOUNDATION_LIB */ #endif diff --git a/Source/Additions/GSCompatibility.m b/Source/Additions/GSCompatibility.m index 9685ff488..1023bbd97 100644 --- a/Source/Additions/GSCompatibility.m +++ b/Source/Additions/GSCompatibility.m @@ -3,6 +3,7 @@ Copyright (C) 2002 Free Software Foundation, Inc. Written by: Adam Fedor + Written by: Stephane Corthesy on Sat Nov 16 2002. This file is part of the GNUstep Base Library. @@ -22,6 +23,7 @@ */ #include "config.h" +#include #include "GSCompatibility.h" /* FIXME: Need to initialize this */ @@ -32,6 +34,39 @@ NSString *GetEncodingName(NSStringEncoding availableEncodingValue) return (NSString *)CFStringGetNameOfEncoding(CFStringConvertNSStringEncodingToEncoding(availableEncodingValue)); } +NSArray *NSStandardLibraryPaths() +{ + return NSSearchPathForDirectoriesInDomains(NSAllLibrariesDirectory, NSAllDomainsMask, YES); +} + +// Defined in NSDebug.m +NSString* +GSDebugMethodMsg(id obj, SEL sel, const char *file, int line, NSString *fmt) +{ + NSString *message; + Class cls = (Class)obj; + char c = '+'; + + if ([obj isInstance] == YES) + { + c = '-'; + cls = [obj class]; + } + message = [NSString stringWithFormat: @"File %s: %d. In [%@ %c%@] %@", + file, line, NSStringFromClass(cls), c, NSStringFromSelector(sel), fmt]; + return message; +} + +NSString* +GSDebugFunctionMsg(const char *func, const char *file, int line, NSString *fmt) +{ + NSString *message; + + message = [NSString stringWithFormat: @"File %s: %d. In %s %@", + file, line, func, fmt]; + return message; +} + @implementation NSArray (GSCompatibility) /** @@ -71,3 +106,112 @@ return (NSString *)CFStringGetNameOfEncoding(CFStringConvertNSStringEncodingToEn } @end + +@implementation NSProcessInfo(GNUStepGlue) + +static NSMutableSet *_debug_set = nil; + +BOOL GSDebugSet(NSString *level) +// From GNUStep's +{ + static IMP debugImp = 0; + static SEL debugSel; + + if (debugImp == 0) + { + debugSel = @selector(member:); + if (_debug_set == nil) + { + [[NSProcessInfo processInfo] debugSet]; + } + debugImp = [_debug_set methodForSelector: debugSel]; + } + if ((*debugImp)(_debug_set, debugSel, level) == nil) + { + return NO; + } + return YES; +} + +- (NSMutableSet *) debugSet +// Derived from GNUStep's +{ + if(_debug_set == nil){ + int argc = [[self arguments] count]; + NSMutableSet *mySet; + int i; + + mySet = [NSMutableSet new]; + for (i = 0; i < argc; i++) + { + NSString *str = [[self arguments] objectAtIndex:i]; + + if ([str hasPrefix: @"--GNU-Debug="]) + [mySet addObject: [str substringFromIndex: 12]]; + } + _debug_set = mySet; + } + + return _debug_set; +} + +@end + +@implementation NSString(GNUStepGlue) + +// From GNUStep +/** + * If the string consists of the words 'true' or 'yes' (case insensitive) + * or begins with a non-zero numeric value, return YES, otherwise return + * NO. + */ +- (BOOL) boolValue +{ + if ([self caseInsensitiveCompare: @"YES"] == NSOrderedSame) + { + return YES; + } + if ([self caseInsensitiveCompare: @"true"] == NSOrderedSame) + { + return YES; + } + return [self intValue] != 0 ? YES : NO; +} + +@end + +@implementation NSInvocation(GNUStepGlue) +- (retval_t) returnFrame:(arglist_t)args +{ +#warning (stephane@sente.ch) Not implemented + return (retval_t)[self notImplemented:_cmd]; +} + +- (id) initWithArgframe:(arglist_t)args selector:(SEL)selector +{ +#warning (stephane@sente.ch) Not implemented + return [self notImplemented:_cmd]; +} + +@end + +@implementation NSObject(GNUStepGlue) + ++ (id) notImplemented:(SEL)selector +{ +#warning (stephane@sente.ch) Not implemented + [NSException raise: NSGenericException + format: @"method %s not implemented in %s(class)", +selector ? sel_get_name(selector) : "(null)", + object_get_class_name(self)]; + return nil; +} + +// In NSObject.m, category GNU +- (BOOL) isInstance +{ + return GSObjCIsInstance(self); +} + +@end +