From c5455620111b31008e6ab00cfcdedf343466f82b Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Mon, 11 May 2020 21:10:32 -0400 Subject: [PATCH] Move Cocotron Code To Foundation --- include/Foundation/NSDebug.h | 26 +- include/Foundation/NSPlatform.h | 78 +++- include/Foundation/NSPlatform_darwin.h | 16 +- include/Foundation/NSPlatform_posix.h | 20 +- include/Foundation/NSRaise.h | 36 +- include/Foundation/NSRaiseException.h | 24 +- include/Foundation/NSRangeEntries.h | 39 +- include/Foundation/NSSpellEngine.h | 37 +- include/Foundation/NSSpellServer.h | 44 +- include/Foundation/NSUndoGroup.h | 32 +- include/Foundation/NSUndoManager.h | 87 +++- include/Foundation/NSXMLDTD.h | 43 +- include/Foundation/NSXMLDTDNode.h | 34 +- include/Foundation/NSXMLDocument.h | 80 +++- include/Foundation/NSXMLElement.h | 54 ++- include/Foundation/NSXMLNode.h | 118 ++++- include/Foundation/NSXMLNodeOptions.h | 5 +- include/Foundation/NSXMLParser.h | 94 +++- src/NSDebug.m | 153 ++++++- src/NSPlatform.m | 163 ++++++- src/NSPlatform_darwin.m | 130 +++++- src/NSPlatform_posix.m | 374 +++++++++++++++- src/NSRaise.m | 71 ++- src/NSRangeEntries.m | 420 +++++++++++++++++- src/NSSpellEngine.m | 116 ++++- src/NSSpellServer.m | 7 +- src/NSUndoGroup.m | 83 +++- src/NSUndoManager.m | 469 +++++++++++++++++++- src/NSXMLDTD.m | 98 ++++- src/NSXMLDTDNode.m | 61 ++- src/NSXMLDocument.m | 260 ++++++++++- src/NSXMLElement.m | 242 +++++++++- src/NSXMLNode.m | 362 ++++++++++++++- src/NSXMLParser.m | 588 ++++++++++++++++++++++++- 34 files changed, 4430 insertions(+), 34 deletions(-) mode change 120000 => 100755 include/Foundation/NSDebug.h mode change 120000 => 100755 include/Foundation/NSPlatform.h mode change 120000 => 100755 include/Foundation/NSPlatform_darwin.h mode change 120000 => 100755 include/Foundation/NSPlatform_posix.h mode change 120000 => 100755 include/Foundation/NSRaise.h mode change 120000 => 100644 include/Foundation/NSRaiseException.h mode change 120000 => 100755 include/Foundation/NSRangeEntries.h mode change 120000 => 100644 include/Foundation/NSSpellEngine.h mode change 120000 => 100644 include/Foundation/NSSpellServer.h mode change 120000 => 100755 include/Foundation/NSUndoGroup.h mode change 120000 => 100755 include/Foundation/NSUndoManager.h mode change 120000 => 100644 include/Foundation/NSXMLDTD.h mode change 120000 => 100644 include/Foundation/NSXMLDTDNode.h mode change 120000 => 100644 include/Foundation/NSXMLDocument.h mode change 120000 => 100644 include/Foundation/NSXMLElement.h mode change 120000 => 100644 include/Foundation/NSXMLNode.h mode change 120000 => 100644 include/Foundation/NSXMLNodeOptions.h mode change 120000 => 100644 include/Foundation/NSXMLParser.h mode change 120000 => 100644 src/NSDebug.m mode change 120000 => 100644 src/NSPlatform.m mode change 120000 => 100644 src/NSPlatform_darwin.m mode change 120000 => 100644 src/NSPlatform_posix.m mode change 120000 => 100644 src/NSRaise.m mode change 120000 => 100644 src/NSRangeEntries.m mode change 120000 => 100644 src/NSSpellEngine.m mode change 120000 => 100644 src/NSSpellServer.m mode change 120000 => 100644 src/NSUndoGroup.m mode change 120000 => 100644 src/NSUndoManager.m mode change 120000 => 100644 src/NSXMLDTD.m mode change 120000 => 100644 src/NSXMLDTDNode.m mode change 120000 => 100644 src/NSXMLDocument.m mode change 120000 => 100644 src/NSXMLElement.m mode change 120000 => 100644 src/NSXMLNode.m mode change 120000 => 100644 src/NSXMLParser.m diff --git a/include/Foundation/NSDebug.h b/include/Foundation/NSDebug.h deleted file mode 120000 index 141d98904..000000000 --- a/include/Foundation/NSDebug.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/NSDebug.h \ No newline at end of file diff --git a/include/Foundation/NSDebug.h b/include/Foundation/NSDebug.h new file mode 100755 index 000000000..f06d152a9 --- /dev/null +++ b/include/Foundation/NSDebug.h @@ -0,0 +1,25 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import + +FOUNDATION_EXPORT BOOL NSZombieEnabled; +FOUNDATION_EXPORT BOOL NSDebugEnabled; +FOUNDATION_EXPORT BOOL NSCooperativeThreadsEnabled; + +void NSCooperativeThreadBlocking(); +void NSCooperativeThreadWaiting(); + +FOUNDATION_EXPORT void *NSFrameAddress(NSUInteger level); +FOUNDATION_EXPORT unsigned NSCountFrames(void); +FOUNDATION_EXPORT void *NSReturnAddress(int level); + +#if defined(__WIN32__) || defined(SOLARIS) +int backtrace(void **array, int size); +char **backtrace_symbols(void *const *array, int size); +#endif \ No newline at end of file diff --git a/include/Foundation/NSPlatform.h b/include/Foundation/NSPlatform.h deleted file mode 120000 index 11ac66cf8..000000000 --- a/include/Foundation/NSPlatform.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/NSPlatform.h \ No newline at end of file diff --git a/include/Foundation/NSPlatform.h b/include/Foundation/NSPlatform.h new file mode 100755 index 000000000..dccdb48c2 --- /dev/null +++ b/include/Foundation/NSPlatform.h @@ -0,0 +1,77 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import +#import +#import + +@class NSTimeZone, NSThread, NSInputSource, NSInputSourceSet, NSError; + +FOUNDATION_EXPORT NSString *const NSPlatformExecutableFileExtension; +FOUNDATION_EXPORT NSString *const NSPlatformLoadableObjectFileExtension; +FOUNDATION_EXPORT NSString *const NSPlatformLoadableObjectFilePrefix; +FOUNDATION_EXPORT NSString *const NSPlatformExecutableDirectory; +FOUNDATION_EXPORT NSString *const NSPlatformResourceNameSuffix; + +@interface NSPlatform : NSObject + ++ currentPlatform; + +- (NSInputSource *)parentDeathInputSource; + +- (Class)taskClass; +- (Class)socketClass; +- (Class)socketPortClass; +- (Class)pipeClass; +- (Class)lockClass; +- (Class)recursiveLockClass; +- (Class)conditionLockClass; +- (Class)persistantDomainClass; +- (Class)timeZoneClass; +- (Class)conditionClass; + +- (NSString *)userName; +- (NSString *)fullUserName; +- (NSString *)homeDirectory; +- (NSString *)libraryDirectory; +- (NSString *)temporaryDirectory; + +- (NSArray *)arguments; +- (NSDictionary *)environment; + +- (NSString *)hostName; + +- (NSString *)DNSHostName; +- (NSArray *)addressesForDNSHostName:(NSString *)name; +- (NSString *)hostNameByAddress:(NSString *)address; + +- (void *)mapContentsOfFile:(NSString *)path length:(NSUInteger *)length; +- (void)unmapAddress:(void *)ptr length:(NSUInteger)length; + +- (BOOL)writeContentsOfFile:(NSString *)path bytes:(const void *)bytes length:(NSUInteger)length options:(NSUInteger)options error:(NSError **)errorp; + +- (void)checkEnvironmentKey:(NSString *)key value:(NSString *)value; +@end + +FOUNDATION_EXPORT int NSPlatformProcessorCount(); +FOUNDATION_EXPORT int NSPlatformProcessID(); +FOUNDATION_EXPORT NSUInteger NSPlatformThreadID(); +FOUNDATION_EXPORT NSTimeInterval NSPlatformTimeIntervalSinceReferenceDate(); +FOUNDATION_EXPORT void NSPlatformLogString(NSString *string); +FOUNDATION_EXPORT void NSPlatformSleepThreadForTimeInterval(NSTimeInterval interval); +FOUNDATION_EXPORT void *NSPlatformContentsOfFile(NSString *path, NSUInteger *length); + +// These functions are implemented in the platform subproject + +NSThread *NSPlatformCurrentThread(); +void NSPlatformSetCurrentThread(NSThread *thread); +#ifdef WINDOWS +NSUInteger NSPlatformDetachThread(unsigned (*__stdcall func)(void *arg), void *arg, NSError **errorp); +#else +NSUInteger NSPlatformDetachThread(void *(*func)(void *arg), void *arg, NSError **errorp); +#endif diff --git a/include/Foundation/NSPlatform_darwin.h b/include/Foundation/NSPlatform_darwin.h deleted file mode 120000 index 555121136..000000000 --- a/include/Foundation/NSPlatform_darwin.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/platform_darwin/NSPlatform_darwin.h \ No newline at end of file diff --git a/include/Foundation/NSPlatform_darwin.h b/include/Foundation/NSPlatform_darwin.h new file mode 100755 index 000000000..70c1f3b19 --- /dev/null +++ b/include/Foundation/NSPlatform_darwin.h @@ -0,0 +1,15 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import +#import + +@interface NSPlatform_darwin : NSPlatform_posix { +} + +@end diff --git a/include/Foundation/NSPlatform_posix.h b/include/Foundation/NSPlatform_posix.h deleted file mode 120000 index 249d079fb..000000000 --- a/include/Foundation/NSPlatform_posix.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/platform_posix/NSPlatform_posix.h \ No newline at end of file diff --git a/include/Foundation/NSPlatform_posix.h b/include/Foundation/NSPlatform_posix.h new file mode 100755 index 000000000..bdaaecfd9 --- /dev/null +++ b/include/Foundation/NSPlatform_posix.h @@ -0,0 +1,19 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import + +#define FOUNDATION_FILE_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH +#define FOUNDATION_DIR_MODE S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH + +@interface NSPlatform_posix : NSPlatform { +} + +@end + +extern char **NSPlatform_environ(); diff --git a/include/Foundation/NSRaise.h b/include/Foundation/NSRaise.h deleted file mode 120000 index d4fc3febe..000000000 --- a/include/Foundation/NSRaise.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/NSException/NSRaise.h \ No newline at end of file diff --git a/include/Foundation/NSRaise.h b/include/Foundation/NSRaise.h new file mode 100755 index 000000000..cbd3711b8 --- /dev/null +++ b/include/Foundation/NSRaise.h @@ -0,0 +1,35 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +// *** FOR INTERNAL COCOTRON USE ONLY + +#import +#import + +static inline void _NSInvalidAbstractInvocation(SEL selector, id object, const char *file, int line) { + [NSException raise:NSInvalidArgumentException + format:@"-%s only defined for abstract class. Define -[%@ %s] in %s:%d!", + sel_getName(selector), [object class], sel_getName(selector), file, line]; +} + +static inline void _NSUnimplementedMethod(SEL selector, id object, const char *file, int line) { + NSLog(@"-[%@ %s] unimplemented in %s at %d", [object class], sel_getName(selector), file, line); +} + +static inline void _NSUnimplementedFunction(const char *function, const char *file, int line) { + NSLog(@"%s() unimplemented in %s at %d", function, file, line); +} + +#define NSInvalidAbstractInvocation() \ + _NSInvalidAbstractInvocation(_cmd, self, __FILE__, __LINE__) + +#define NSUnimplementedMethod() \ + _NSUnimplementedMethod(_cmd, self, __FILE__, __LINE__) + +#define NSUnimplementedFunction() \ + _NSUnimplementedFunction(__PRETTY_FUNCTION__, __FILE__, __LINE__) diff --git a/include/Foundation/NSRaiseException.h b/include/Foundation/NSRaiseException.h deleted file mode 120000 index 45abc6868..000000000 --- a/include/Foundation/NSRaiseException.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/NSException/NSRaiseException.h \ No newline at end of file diff --git a/include/Foundation/NSRaiseException.h b/include/Foundation/NSRaiseException.h new file mode 100644 index 000000000..d36f2d9fb --- /dev/null +++ b/include/Foundation/NSRaiseException.h @@ -0,0 +1,23 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +// *** FOR INTERNAL COCOTRON USE ONLY + +#import +#import + +// DO NOT USE IN NEW CODE AND REPLACE USAGE. Use NSAssert(). +FOUNDATION_EXPORT void NSRaiseException(NSString *name, id self, SEL cmd, NSString *fmt, ...); + +// This is just a wrapper for fprintf, it doesn't handle %@ +// There are situations (such as localization inside NSLog) where you don't want to use NSLog +FOUNDATION_EXPORT void NSCLogv(const char *format, va_list arguments); +FOUNDATION_EXPORT void NSCLog(const char *format, ...); +FOUNDATION_EXPORT void NSCLogThreadId(); +FOUNDATION_EXPORT void NSCLogNewline(); +FOUNDATION_EXPORT void NSCLogFormat(const char *format, ...); diff --git a/include/Foundation/NSRangeEntries.h b/include/Foundation/NSRangeEntries.h deleted file mode 120000 index 2dafacb20..000000000 --- a/include/Foundation/NSRangeEntries.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/NSAttributedString/NSRangeEntries.h \ No newline at end of file diff --git a/include/Foundation/NSRangeEntries.h b/include/Foundation/NSRangeEntries.h new file mode 100755 index 000000000..3f22f2a6b --- /dev/null +++ b/include/Foundation/NSRangeEntries.h @@ -0,0 +1,38 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import +#import + +// an ordered, nonoverlapping set of NSRanges and related value +typedef struct NSRangeEntries NSRangeEntries; + +typedef struct { + NSRangeEntries *self; + NSUInteger index; +} NSRangeEnumerator; + +FOUNDATION_EXPORT NSRangeEntries *NSCreateRangeToOwnedPointerEntries(NSUInteger capacity); +FOUNDATION_EXPORT NSRangeEntries *NSCreateRangeToCopiedObjectEntries(NSUInteger capacity); + +FOUNDATION_EXPORT void NSFreeRangeEntries(NSRangeEntries *self); +FOUNDATION_EXPORT void NSResetRangeEntries(NSRangeEntries *self); +FOUNDATION_EXPORT NSUInteger NSCountRangeEntries(NSRangeEntries *self); +FOUNDATION_EXPORT void NSRangeEntriesRemoveEntryAtIndex(NSRangeEntries *self, NSUInteger index); + +FOUNDATION_EXPORT void NSRangeEntryInsert(NSRangeEntries *self, NSRange range, void *value); +FOUNDATION_EXPORT void *NSRangeEntryAtIndex(NSRangeEntries *self, NSUInteger index, NSRange *effectiveRange); +FOUNDATION_EXPORT void *NSRangeEntryAtRange(NSRangeEntries *self, NSRange range); + +FOUNDATION_EXPORT NSRangeEnumerator NSRangeEntryEnumerator(NSRangeEntries *self); +FOUNDATION_EXPORT BOOL NSNextRangeEnumeratorEntry(NSRangeEnumerator *state, NSRange *rangep, void **value); + +FOUNDATION_EXPORT void NSRangeEntriesExpandAndWipe(NSRangeEntries *self, NSRange range, NSInteger delta); +FOUNDATION_EXPORT void NSRangeEntriesDivideAndConquer(NSRangeEntries *self, NSRange range); +FOUNDATION_EXPORT void NSRangeEntriesDump(NSRangeEntries *self); +FOUNDATION_EXPORT void NSRangeEntriesVerify(NSRangeEntries *self, NSUInteger length); diff --git a/include/Foundation/NSSpellEngine.h b/include/Foundation/NSSpellEngine.h deleted file mode 120000 index 27b557f04..000000000 --- a/include/Foundation/NSSpellEngine.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/NSSpellEngine.h \ No newline at end of file diff --git a/include/Foundation/NSSpellEngine.h b/include/Foundation/NSSpellEngine.h new file mode 100644 index 000000000..a9c96ff8c --- /dev/null +++ b/include/Foundation/NSSpellEngine.h @@ -0,0 +1,36 @@ +// +// NSSpellEngine.h +// Foundation +// +// Created by Christopher Lloyd on 8/23/11. +// Copyright 2011 __MyCompanyName__. All rights reserved. +// + +#import +#import + +/* Private class which implements the delegate behavior of NSSpellServer directly, used for in-process spell checking. */ + +@interface NSSpellEngine : NSObject + ++ (NSArray *)allSpellEngines; ++ (NSArray *)spellEngines; + +- (NSString *)vendor; +- (NSArray *)languages; + +- (NSRange)checkGrammarInString:(NSString *)string language:(NSString *)language details:(NSArray **)outDetails; + +- (NSArray *)checkString:(NSString *)stringToCheck offset:(NSUInteger)offset types:(NSTextCheckingTypes)checkingTypes options:(NSDictionary *)options orthography:(NSOrthography *)orthography wordCount:(NSInteger *)wordCount; + +- (void)didForgetWord:(NSString *)word inLanguage:(NSString *)language; + +- (void)didLearnWord:(NSString *)word inLanguage:(NSString *)language; + +- (NSRange)findMisspelledWordInString:(NSString *)stringToCheck language:(NSString *)language wordCount:(NSInteger *)wordCount countOnly:(BOOL)countOnly; + +- (NSArray *)suggestCompletionsForPartialWordRange:(NSRange)range inString:(NSString *)string language:(NSString *)language; + +- (NSArray *)suggestGuessesForWord:(NSString *)word inLanguage:(NSString *)language; + +@end diff --git a/include/Foundation/NSSpellServer.h b/include/Foundation/NSSpellServer.h deleted file mode 120000 index 68c2aed82..000000000 --- a/include/Foundation/NSSpellServer.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/NSSpellServer.h \ No newline at end of file diff --git a/include/Foundation/NSSpellServer.h b/include/Foundation/NSSpellServer.h new file mode 100644 index 000000000..6f9e5f79a --- /dev/null +++ b/include/Foundation/NSSpellServer.h @@ -0,0 +1,43 @@ +#import +#import +#import + +@class NSSpellServer, NSArray, NSDictionary, NSOrthography; + +FOUNDATION_EXPORT NSString *const NSGrammarRange; +FOUNDATION_EXPORT NSString *const NSGrammarUserDescription; +FOUNDATION_EXPORT NSString *const NSGrammarCorrections; + +@protocol NSSpellServerDelegate +//@optional + +- (NSRange)spellServer:(NSSpellServer *)sender checkGrammarInString:(NSString *)string language:(NSString *)language details:(NSArray **)outDetails; + +- (NSArray *)spellServer:(NSSpellServer *)sender checkString:(NSString *)stringToCheck offset:(NSUInteger)offset types:(NSTextCheckingTypes)checkingTypes options:(NSDictionary *)options orthography:(NSOrthography *)orthography wordCount:(NSInteger *)wordCount; + +- (void)spellServer:(NSSpellServer *)sender didForgetWord:(NSString *)word inLanguage:(NSString *)language; + +- (void)spellServer:(NSSpellServer *)sender didLearnWord:(NSString *)word inLanguage:(NSString *)language; + +- (NSRange)spellServer:(NSSpellServer *)sender findMisspelledWordInString:(NSString *)stringToCheck language:(NSString *)language wordCount:(NSInteger *)wordCount countOnly:(BOOL)countOnly; + +- (NSArray *)spellServer:(NSSpellServer *)sender suggestCompletionsForPartialWordRange:(NSRange)range inString:(NSString *)string language:(NSString *)language; + +- (NSArray *)spellServer:(NSSpellServer *)sender suggestGuessesForWord:(NSString *)word inLanguage:(NSString *)language; + +@end + +@interface NSSpellServer : NSObject { +} + +- (id)delegate; + +- (BOOL)isWordInUserDictionaries:(NSString *)word caseSensitive:(BOOL)caseSensitive; + +- (BOOL)registerLanguage:(NSString *)language byVendor:(NSString *)vendor; + +- (void)run; + +- (void)setDelegate:(id)delegate; + +@end diff --git a/include/Foundation/NSUndoGroup.h b/include/Foundation/NSUndoGroup.h deleted file mode 120000 index d842906f8..000000000 --- a/include/Foundation/NSUndoGroup.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/NSUndoManager/NSUndoGroup.h \ No newline at end of file diff --git a/include/Foundation/NSUndoGroup.h b/include/Foundation/NSUndoGroup.h new file mode 100755 index 000000000..800352ab6 --- /dev/null +++ b/include/Foundation/NSUndoGroup.h @@ -0,0 +1,31 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import + +@class NSArray, NSMutableArray, NSInvocation; + +@interface NSUndoGroup : NSObject { + NSUndoGroup *_parentGroup; + NSMutableArray *_invocations; +} + ++ (NSUndoGroup *)undoGroupWithParentGroup:(NSUndoGroup *)parentGroup; +- (id)initWithParentGroup:(NSUndoGroup *)parentGroup; + +- (NSUndoGroup *)parentGroup; + +- (void)addInvocation:(NSInvocation *)invocation; +- (void)addInvocationsFromArray:(NSArray *)array; +- (NSArray *)invocations; + +- (void)removeInvocationsWithTarget:(id)target; + +- (void)invokeInvocations; + +@end diff --git a/include/Foundation/NSUndoManager.h b/include/Foundation/NSUndoManager.h deleted file mode 120000 index 5197ac7e5..000000000 --- a/include/Foundation/NSUndoManager.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/NSUndoManager/NSUndoManager.h \ No newline at end of file diff --git a/include/Foundation/NSUndoManager.h b/include/Foundation/NSUndoManager.h new file mode 100755 index 000000000..f02068e3f --- /dev/null +++ b/include/Foundation/NSUndoManager.h @@ -0,0 +1,86 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import + +@class NSArray, NSMutableArray, NSInvocation; + +enum { + NSUndoCloseGroupingRunLoopOrdering = 350000, +}; + +FOUNDATION_EXPORT NSString *const NSUndoManagerCheckpointNotification; + +FOUNDATION_EXPORT NSString *const NSUndoManagerDidOpenUndoGroupNotification; +FOUNDATION_EXPORT NSString *const NSUndoManagerWillCloseUndoGroupNotification; + +FOUNDATION_EXPORT NSString *const NSUndoManagerWillUndoChangeNotification; +FOUNDATION_EXPORT NSString *const NSUndoManagerDidUndoChangeNotification; + +FOUNDATION_EXPORT NSString *const NSUndoManagerWillRedoChangeNotification; +FOUNDATION_EXPORT NSString *const NSUndoManagerDidRedoChangeNotification; + +@interface NSUndoManager : NSObject { + NSMutableArray *_undoStack; + NSMutableArray *_redoStack; + BOOL _groupsByEvent; + NSArray *_modes; + int _disableCount; + NSInteger _levelsOfUndo; + id _currentGroup; + int _state; + NSString *_actionName; + id _preparedTarget; + BOOL _performRegistered; +} + +- (NSArray *)runLoopModes; +- (NSUInteger)levelsOfUndo; +- (BOOL)groupsByEvent; + +- (void)setRunLoopModes:(NSArray *)modes; +- (void)setLevelsOfUndo:(NSUInteger)levels; +- (void)setGroupsByEvent:(BOOL)flag; + +- (BOOL)isUndoRegistrationEnabled; +- (void)disableUndoRegistration; +- (void)enableUndoRegistration; + +- (void)beginUndoGrouping; +- (void)endUndoGrouping; + +- (NSInteger)groupingLevel; + +- (BOOL)canUndo; +- (void)undo; +- (void)undoNestedGroup; +- (BOOL)isUndoing; + +- (BOOL)canRedo; +- (void)redo; +- (BOOL)isRedoing; + +- (void)registerUndoWithTarget:(id)target selector:(SEL)selector object:(id)object; + +- (void)removeAllActions; +- (void)removeAllActionsWithTarget:(id)target; + +- (id)prepareWithInvocationTarget:(id)target; +- (void)forwardInvocation:(NSInvocation *)invocation; + +- (NSString *)undoActionName; +- (NSString *)undoMenuItemTitle; +- (NSString *)undoMenuTitleForUndoActionName:(NSString *)name; +- (void)setActionName:(NSString *)name; + +- (NSString *)redoActionName; +- (NSString *)redoMenuItemTitle; +- (NSString *)redoMenuTitleForUndoActionName:(NSString *)name; + +- (void)clearRedoStackIfStateIsNormal; +@end diff --git a/include/Foundation/NSXMLDTD.h b/include/Foundation/NSXMLDTD.h deleted file mode 120000 index de7f9b490..000000000 --- a/include/Foundation/NSXMLDTD.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/xml/NSXMLDTD.h \ No newline at end of file diff --git a/include/Foundation/NSXMLDTD.h b/include/Foundation/NSXMLDTD.h new file mode 100644 index 000000000..8a6938ced --- /dev/null +++ b/include/Foundation/NSXMLDTD.h @@ -0,0 +1,42 @@ +/* Copyright (c) 2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import + +@class NSXMLDTDNode, NSURL, NSData, NSMutableArray; + +@interface NSXMLDTD : NSXMLNode { + NSString *_publicID; + NSString *_systemID; +} + ++ (NSXMLDTDNode *)predefinedEntityDeclarationForName:(NSString *)name; + +- (instancetype)initWithData:(NSData *)data options:(NSUInteger)options error:(NSError **)error; +- (instancetype)initWithContentsOfURL:(NSURL *)url options:(NSUInteger)options error:(NSError **)error; + +- (NSString *)publicID; +- (NSString *)systemID; + +- (NSXMLDTDNode *)attributeDeclarationForName:(NSString *)attributeName elementName:(NSString *)elementName; +- (NSXMLDTDNode *)elementDeclarationForName:(NSString *)name; +- (NSXMLDTDNode *)entityDeclarationForName:(NSString *)name; +- (NSXMLDTDNode *)notationDeclarationForName:(NSString *)name; + +- (void)setPublicID:(NSString *)publicID; +- (void)setSystemID:(NSString *)systemID; + +- (void)setChildren:(NSArray *)children; + +- (void)addChild:(NSXMLNode *)node; +- (void)insertChild:(NSXMLNode *)child atIndex:(NSUInteger)index; +- (void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index; +- (void)removeChildAtIndex:(NSUInteger)index; +- (void)replaceChildAtIndex:(NSUInteger)index withNode:(NSXMLNode *)node; + +@end diff --git a/include/Foundation/NSXMLDTDNode.h b/include/Foundation/NSXMLDTDNode.h deleted file mode 120000 index 1ffa2baa2..000000000 --- a/include/Foundation/NSXMLDTDNode.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/xml/NSXMLDTDNode.h \ No newline at end of file diff --git a/include/Foundation/NSXMLDTDNode.h b/include/Foundation/NSXMLDTDNode.h new file mode 100644 index 000000000..a689ca4cf --- /dev/null +++ b/include/Foundation/NSXMLDTDNode.h @@ -0,0 +1,33 @@ +/* Copyright (c) 2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import + +typedef int NSXMLDTDNodeKind; + +@interface NSXMLDTDNode : NSXMLNode { + NSXMLDTDNodeKind _dtdKind; + NSString *_notationName; + NSString *_publicID; + NSString *_systemID; +} + +- (instancetype)initWithXMLString:(NSString *)string; + +- (NSXMLDTDNodeKind)DTDKind; +- (BOOL)isExternal; +- (NSString *)notationName; +- (NSString *)publicID; +- (NSString *)systemID; + +- (void)setDTDKind:(NSXMLDTDNodeKind)kind; +- (void)setNotationName:(NSString *)name; +- (void)setPublicID:(NSString *)publicID; +- (void)setSystemID:(NSString *)systemID; + +@end diff --git a/include/Foundation/NSXMLDocument.h b/include/Foundation/NSXMLDocument.h deleted file mode 120000 index f81415407..000000000 --- a/include/Foundation/NSXMLDocument.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/xml/NSXMLDocument.h \ No newline at end of file diff --git a/include/Foundation/NSXMLDocument.h b/include/Foundation/NSXMLDocument.h new file mode 100644 index 000000000..a6babea22 --- /dev/null +++ b/include/Foundation/NSXMLDocument.h @@ -0,0 +1,79 @@ +/* Copyright (c) 2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import +#import + +@class NSXMLDTD, NSURL, NSData, NSMutableArray; + +enum { + NSXMLDocumentXMLKind = 0, + NSXMLDocumentXHTMLKind = 1, + NSXMLDocumentHTMLKind = 2, + NSXMLDocumentTextKind = 3, +}; + +typedef NSUInteger NSXMLDocumentContentKind; + +@interface NSXMLDocument : NSXMLNode { + NSXMLDocumentContentKind _contentKind; + NSString *_version; + NSString *_characterEncoding; + NSString *_mimeType; + BOOL _isStandalone; + + NSXMLElement *_rootElement; + NSXMLDTD *_dtd; + NSString *_uri; + + // parsing state, should be moved out + NSMutableArray *_elementStack; +} + ++ (Class)replacementClassForClass:(Class)aClass; + +- (instancetype)initWithRootElement:(NSXMLElement *)element; +- (instancetype)initWithXMLString:(NSString *)string options:(NSUInteger)options error:(NSError **)error; +- (instancetype)initWithData:(NSData *)data options:(NSUInteger)options error:(NSError **)error; +- (instancetype)initWithContentsOfURL:(NSURL *)url options:(NSUInteger)options error:(NSError **)error; + +- (NSXMLDocumentContentKind)documentContentKind; +- (NSString *)version; +- (NSString *)characterEncoding; +- (NSString *)MIMEType; +- (BOOL)isStandalone; +- (NSXMLElement *)rootElement; +- (NSXMLDTD *)DTD; +- (NSString *)URI; + +- (void)setDocumentContentKind:(NSXMLDocumentContentKind)kind; +- (void)setCharacterEncoding:(NSString *)encoding; +- (void)setVersion:(NSString *)version; +- (void)setMIMEType:(NSString *)mimeType; +- (void)setStandalone:(BOOL)flag; +- (void)setRootElement:(NSXMLNode *)element; +- (void)setDTD:(NSXMLDTD *)dtd; +- (void)setURI:(NSString *)uri; + +- (void)setChildren:(NSArray *)children; +- (void)addChild:(NSXMLNode *)child; +- (void)insertChild:(NSXMLNode *)child atIndex:(NSUInteger)index; +- (void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index; +- (void)removeChildAtIndex:(NSUInteger)index; +- (void)replaceChildAtIndex:(NSUInteger)index withNode:(NSXMLNode *)node; + +- (BOOL)validateAndReturnError:(NSError **)error; + +- (NSData *)XMLData; +- (NSData *)XMLDataWithOptions:(NSUInteger)options; + +- (id)objectByApplyingXSLT:(NSData *)xslt arguments:(NSDictionary *)arguments error:(NSError *)error; +- (id)objectByApplyingXSLTAtURL:(NSURL *)url arguments:(NSDictionary *)arguments error:(NSError *)error; +- (id)objectByApplyingXSLTString:(NSString *)string arguments:(NSDictionary *)arguments error:(NSError *)error; + +@end diff --git a/include/Foundation/NSXMLElement.h b/include/Foundation/NSXMLElement.h deleted file mode 120000 index 879dc2108..000000000 --- a/include/Foundation/NSXMLElement.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/xml/NSXMLElement.h \ No newline at end of file diff --git a/include/Foundation/NSXMLElement.h b/include/Foundation/NSXMLElement.h new file mode 100644 index 000000000..617585d59 --- /dev/null +++ b/include/Foundation/NSXMLElement.h @@ -0,0 +1,53 @@ +/* Copyright (c) 2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import + +@class NSXMLNode, NSArray, NSError, NSDictionary, NSMutableDictionary, NSMutableArray; + +@interface NSXMLElement : NSXMLNode { + NSMutableDictionary *_attributes; + NSMutableDictionary *_namespaces; +} + +- (instancetype)initWithName:(NSString *)name; +- (instancetype)initWithName:(NSString *)name stringValue:(NSString *)string; +- (instancetype)initWithName:(NSString *)name URI:(NSString *)uri; +- (instancetype)initWithXMLString:(NSString *)xml error:(NSError **)error; + +- (NSArray *)attributes; +- (NSXMLNode *)attributeForLocalName:(NSString *)name URI:(NSString *)uri; +- (NSXMLNode *)attributeForName:(NSString *)name; +- (NSArray *)elementsForLocalName:(NSString *)localName URI:(NSString *)uri; +- (NSArray *)elementsForName:(NSString *)name; +- (NSArray *)namespaces; +- (NSXMLNode *)namespaceForPrefix:(NSString *)prefix; + +- (void)setAttributes:(NSArray *)attributes; +- (void)setAttributesAsDictionary:(NSDictionary *)attributes; +- (void)setChildren:(NSArray *)children; +- (void)setNamespaces:(NSArray *)namespaces; + +- (void)addChild:(NSXMLNode *)child; +- (void)insertChild:(NSXMLNode *)child atIndex:(NSUInteger)index; +- (void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index; +- (void)removeChildAtIndex:(NSUInteger)index; +- (void)replaceChildAtIndex:(NSUInteger)index withNode:(NSXMLNode *)node; + +- (void)addAttribute:(NSXMLNode *)attribute; +- (void)removeAttributeForName:(NSString *)name; + +- (void)addNamespace:(NSXMLNode *)aNamespace; +- (void)removeNamespaceForPrefix:(NSString *)prefix; + +- (void)resolveNamespaceForName:(NSString *)name; +- (void)resolvePrefixForNamespaceURI:(NSString *)uri; + +- (void)normalizeAdjacentTextNodesPreservingCDATA:(BOOL)preserve; + +@end diff --git a/include/Foundation/NSXMLNode.h b/include/Foundation/NSXMLNode.h deleted file mode 120000 index 2405f7952..000000000 --- a/include/Foundation/NSXMLNode.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/xml/NSXMLNode.h \ No newline at end of file diff --git a/include/Foundation/NSXMLNode.h b/include/Foundation/NSXMLNode.h new file mode 100644 index 000000000..bc0ebf8e2 --- /dev/null +++ b/include/Foundation/NSXMLNode.h @@ -0,0 +1,117 @@ +/* +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import +#import + +@class NSArray, NSError, NSDictionary, NSXMLElement, NSXMLNode, NSXMLDocument, NSMutableArray; + +typedef enum { + NSXMLInvalidKind, + NSXMLDocumentKind, + NSXMLElementKind, + NSXMLAttributeKind, + NSXMLNamespaceKind, + NSXMLProcessingInstructionKind, + NSXMLCommentKind, + NSXMLTextKind, + NSXMLDTDKind, + NSXMLEntityDeclarationKind, + NSXMLAttributeDeclarationKind, + NSXMLElementDeclarationKind, + NSXMLNotationDeclarationKind +} NSXMLNodeKind; + +enum { + NSXMLNodeOptionsNone, + NSXMLNodeIsCDATA, + NSXMLNodeExpandEmptyElement, + NSXMLNodeCompactEmptyElement, + NSXMLNodeUseSingleQuotes, + NSXMLNodeUseDoubleQuotes, + NSXMLNodePrettyPrint, + NSXMLNodePreserveNamespaceOrder, + NSXMLNodePreserveAttributeOrder, + NSXMLNodePreserveEntities, + NSXMLNodePreserveCharacterReferences, + NSXMLNodePreservePrefixes, + NSXMLNodePreserveCDATA, + NSXMLNodePreserveWhitespace, + NSXMLNodePreserveEmptyElements, + NSXMLNodePreserveQuotes, + NSXMLNodePreserveDTD, + NSXMLNodePreserveAll, +}; + +@interface NSXMLNode : NSObject { + NSXMLNode *_parent; + NSMutableArray *_children; + NSUInteger _index; + NSXMLNodeKind _kind; + NSUInteger _options; + NSString *_name; + id _value; +} + ++ (id)document; ++ (id)documentWithRootElement:(NSXMLElement *)element; + ++ (id)elementWithName:(NSString *)name; ++ (id)elementWithName:(NSString *)name children:(NSArray *)children attributes:(NSArray *)attributes; ++ (id)elementWithName:(NSString *)name stringValue:(NSString *)string; + ++ (id)attributeWithName:(NSString *)name stringValue:(NSString *)string; + ++ (id)commentWithStringValue:(NSString *)string; ++ (id)textWithStringValue:(NSString *)string; ++ (id)processingInstructionWithName:(NSString *)name stringValue:(NSString *)string; + ++ (id)DTDNodeWithXMLString:(NSString *)string; ++ (id)namespaceWithName:(NSString *)name stringValue:(NSString *)string; ++ (NSXMLNode *)predefinedNamespaceForPrefix:(NSString *)prefix; + ++ (NSString *)prefixForName:(NSString *)name; ++ (NSString *)localNameForName:(NSString *)name; + +- (instancetype)initWithKind:(NSXMLNodeKind)kind; +- (instancetype)initWithKind:(NSXMLNodeKind)kind options:(NSUInteger)options; + +- (NSUInteger)index; +- (NSXMLNodeKind)kind; +- (NSUInteger)level; +- (NSString *)localName; +- (NSString *)name; +- (NSXMLNode *)nextNode; +- (NSXMLNode *)nextSibling; +- (NSString *)stringValue; +- (NSString *)URI; +- (id)objectValue; +- (NSXMLNode *)parent; +- (NSString *)prefix; +- (NSXMLNode *)previousNode; +- (NSXMLNode *)previousSibling; +- (NSXMLDocument *)rootDocument; + +- (NSUInteger)childCount; +- (NSArray *)children; +- (NSXMLNode *)childAtIndex:(NSUInteger)index; + +- (void)setName:(NSString *)name; +- (void)setObjectValue:object; +- (void)setStringValue:(NSString *)string; +- (void)setStringValue:(NSString *)string resolvingEntities:(BOOL)resolveEntities; + +- (void)detach; +- (NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error; +- (NSArray *)objectsForXQuery:(NSString *)xquery constants:(NSDictionary *)constants error:(NSError **)error; +- (NSArray *)objectsForXQuery:(NSString *)xquery error:(NSError **)error; +- (NSString *)XMLString; +- (NSString *)XMLStringWithOptions:(NSUInteger)options; +- (NSString *)XPath; +- (NSString *)canonicalXMLStringPreservingComments:(BOOL)comments; + +@end diff --git a/include/Foundation/NSXMLNodeOptions.h b/include/Foundation/NSXMLNodeOptions.h deleted file mode 120000 index be5db2008..000000000 --- a/include/Foundation/NSXMLNodeOptions.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/xml/NSXMLNodeOptions.h \ No newline at end of file diff --git a/include/Foundation/NSXMLNodeOptions.h b/include/Foundation/NSXMLNodeOptions.h new file mode 100644 index 000000000..8568571ee --- /dev/null +++ b/include/Foundation/NSXMLNodeOptions.h @@ -0,0 +1,4 @@ +enum { + NSXMLDocumentTidyHTML = 1UL << 9, + NSXMLDocumentTidyXML = 1UL << 10 +}; diff --git a/include/Foundation/NSXMLParser.h b/include/Foundation/NSXMLParser.h deleted file mode 120000 index 37402c00e..000000000 --- a/include/Foundation/NSXMLParser.h +++ /dev/null @@ -1 +0,0 @@ -../../../cocotron/Foundation/xml/NSXMLParser.h \ No newline at end of file diff --git a/include/Foundation/NSXMLParser.h b/include/Foundation/NSXMLParser.h new file mode 100644 index 000000000..fcb5731f0 --- /dev/null +++ b/include/Foundation/NSXMLParser.h @@ -0,0 +1,93 @@ +/* Copyright (c) 2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import +#import +#import + +@class NSURL, NSData, NSError, NSXMLParser, NSDictionary, NSMutableArray, NSMutableDictionary; + +@protocol NSXMLParserDelegate + +- (void)parserDidStartDocument:(NSXMLParser *)parser; +- (void)parserDidEndDocument:(NSXMLParser *)parser; + +- (void)parser:(NSXMLParser *)parser foundElementDeclarationWithName:(NSString *)elementName model:(NSString *)model; +- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributes; +- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName; + +- (void)parser:(NSXMLParser *)parser foundAttributeDeclarationWithName:(NSString *)attributeName forElement:(NSString *)elementName type:(NSString *)type defaultValue:(NSString *)defaultValue; + +- (void)parser:(NSXMLParser *)parser didStartMappingPrefix:(NSString *)prefix toURI:(NSString *)uri; +- (void)parser:(NSXMLParser *)parser didEndMappingPrefix:(NSString *)prefix; + +- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)cdata; +- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string; +- (void)parser:(NSXMLParser *)parser foundComment:(NSString *)comment; +- (void)parser:(NSXMLParser *)parser foundIgnorableWhitespace:(NSString *)whitespace; + +- (void)parser:(NSXMLParser *)parser foundExternalEntityDeclarationWithName:(NSString *)entityName publicID:(NSString *)publicID systemID:(NSString *)systemID; +- (void)parser:(NSXMLParser *)parser foundInternalEntityDeclarationWithName:(NSString *)entityName value:(NSString *)value; +- (void)parser:(NSXMLParser *)parser foundNotationDeclarationWithName:(NSString *)name publicID:(NSString *)publicID systemID:(NSString *)systemID; +- (void)parser:(NSXMLParser *)parser foundProcessingInstructionWithTarget:(NSString *)target data:(NSString *)data; +- (void)parser:(NSXMLParser *)parser foundUnparsedEntityDeclarationWithName:(NSString *)name publicID:(NSString *)publicID systemID:(NSString *)systemID notationName:(NSString *)notationName; +- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError; +- (NSData *)parser:(NSXMLParser *)parser resolveExternalEntityName:(NSString *)entityName systemID:(NSString *)systemID; +- (void)parser:(NSXMLParser *)parser validationErrorOccurred:(NSError *)validationError; + +@end + +@interface NSXMLParser : NSObject { + NSData *_data; + id _delegate; + BOOL _shouldProcessNamespaces; + BOOL _shouldReportNamespacePrefixes; + BOOL _shouldResolveExternalEntities; + NSError *_parserError; + NSString *_systemID; + NSString *_publicID; + NSInteger _columnNumber; + NSInteger _lineNumber; + + // parsing state + const uint8_t *_bytes; + NSUInteger _length; + NSRange _range; + + NSMutableDictionary *_entityRefContents; + + int _state; + unichar _charRef; + NSMutableArray *_elementNameStack; + NSString *_currentAttributeName; + NSMutableDictionary *_currentAttributes; +} + +- (instancetype)initWithData:(NSData *)data; +- (instancetype)initWithContentsofURL:(NSURL *)url; + +- (id)delegate; +- (BOOL)shouldProcessNamespaces; +- (BOOL)shouldReportNamespacePrefixes; +- (BOOL)shouldResolveExternalEntities; + +- (void)setDelegate:delegate; +- (void)setShouldProcessNamespaces:(BOOL)flag; +- (void)setShouldReportNamespacePrefixes:(BOOL)flag; +- (void)setShouldResolveExternalEntities:(BOOL)flag; + +- (BOOL)parse; +- (void)abortParsing; +- (NSError *)parserError; + +- (NSString *)systemID; +- (NSString *)publicID; +- (NSInteger)columnNumber; +- (NSInteger)lineNumber; + +@end diff --git a/src/NSDebug.m b/src/NSDebug.m deleted file mode 120000 index e576eda3d..000000000 --- a/src/NSDebug.m +++ /dev/null @@ -1 +0,0 @@ -../../cocotron/Foundation/NSDebug.m \ No newline at end of file diff --git a/src/NSDebug.m b/src/NSDebug.m new file mode 100644 index 000000000..790bb0e37 --- /dev/null +++ b/src/NSDebug.m @@ -0,0 +1,152 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import +#import +#ifdef WINDOWS +#include +#endif + +#if defined(LINUX) || defined(__APPLE__) || defined(FREEBSD) +#include +#endif + +BOOL NSZombieEnabled=NO; +BOOL NSDebugEnabled=NO; +BOOL NSCooperativeThreadsEnabled=NO; + +#ifndef DARLING +// Under Darling, this file is symlinked from external/foundation +// But _NSPrintForDebugger is already implemented in NSLog.m +const char* _NSPrintForDebugger(id object) { + if(object && [object respondsToSelector:@selector(description)]) { + return [[object description] UTF8String]; + } + return NULL; +} +#endif + +#ifndef WINDOWS +void NSCooperativeThreadBlocking() { +} + +void NSCooperativeThreadWaiting() { +} +#else + + +static HANDLE NSCooperativeEvent(){ + static HANDLE handle=NULL; + + if(handle==NULL) + handle=CreateEvent(NULL,FALSE,FALSE,NULL); + + return handle; +} + +void NSCooperativeThreadBlocking() { + if(NSCooperativeThreadsEnabled){ + SetEvent(NSCooperativeEvent()); + } +} + +void NSCooperativeThreadWaiting() { + if(NSCooperativeThreadsEnabled){ + WaitForSingleObject(NSCooperativeEvent(),0); + } +} +#endif + +#define _NS_RETURN_ADDRESS(x) case x: return __builtin_return_address(x + 1) + +void *NSFrameAddress(NSUInteger level) +{ + void* callstack[128]; + + if (level > 128) { + return NULL; + } + + int i, frameCount = backtrace(callstack, level + 1); + if (frameCount < level + 1) { + return NULL; + } + + return callstack[level + 1]; +} + +unsigned NSCountFrames(void) +{ + unsigned x = 0; + + while (NSFrameAddress(x + 1) != NULL){ + x++; + } + + return x; +} + +void *NSReturnAddress(int level) +{ + switch (level) { + _NS_RETURN_ADDRESS(0); + _NS_RETURN_ADDRESS(1); + _NS_RETURN_ADDRESS(2); + _NS_RETURN_ADDRESS(3); + _NS_RETURN_ADDRESS(4); + _NS_RETURN_ADDRESS(5); + _NS_RETURN_ADDRESS(6); + _NS_RETURN_ADDRESS(7); + _NS_RETURN_ADDRESS(8); + _NS_RETURN_ADDRESS(9); + _NS_RETURN_ADDRESS(10); + _NS_RETURN_ADDRESS(11); + _NS_RETURN_ADDRESS(12); + _NS_RETURN_ADDRESS(13); + _NS_RETURN_ADDRESS(14); + _NS_RETURN_ADDRESS(15); + _NS_RETURN_ADDRESS(16); + _NS_RETURN_ADDRESS(17); + _NS_RETURN_ADDRESS(18); + _NS_RETURN_ADDRESS(19); + _NS_RETURN_ADDRESS(20); + _NS_RETURN_ADDRESS(21); + _NS_RETURN_ADDRESS(22); + _NS_RETURN_ADDRESS(23); + _NS_RETURN_ADDRESS(24); + _NS_RETURN_ADDRESS(25); + _NS_RETURN_ADDRESS(26); + _NS_RETURN_ADDRESS(27); + _NS_RETURN_ADDRESS(28); + _NS_RETURN_ADDRESS(29); + _NS_RETURN_ADDRESS(30); + _NS_RETURN_ADDRESS(31); + _NS_RETURN_ADDRESS(32); + _NS_RETURN_ADDRESS(33); + _NS_RETURN_ADDRESS(34); + _NS_RETURN_ADDRESS(35); + _NS_RETURN_ADDRESS(36); + _NS_RETURN_ADDRESS(37); + _NS_RETURN_ADDRESS(38); + _NS_RETURN_ADDRESS(39); + _NS_RETURN_ADDRESS(40); + _NS_RETURN_ADDRESS(41); + _NS_RETURN_ADDRESS(42); + _NS_RETURN_ADDRESS(43); + _NS_RETURN_ADDRESS(44); + _NS_RETURN_ADDRESS(45); + _NS_RETURN_ADDRESS(46); + _NS_RETURN_ADDRESS(47); + _NS_RETURN_ADDRESS(48); + _NS_RETURN_ADDRESS(49); + _NS_RETURN_ADDRESS(50); + default: return NULL; + } + + return NULL; +} diff --git a/src/NSPlatform.m b/src/NSPlatform.m deleted file mode 120000 index 24003e888..000000000 --- a/src/NSPlatform.m +++ /dev/null @@ -1 +0,0 @@ -../../cocotron/Foundation/NSPlatform.m \ No newline at end of file diff --git a/src/NSPlatform.m b/src/NSPlatform.m new file mode 100644 index 000000000..d07c07ee1 --- /dev/null +++ b/src/NSPlatform.m @@ -0,0 +1,162 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import + +extern NSString *NSPlatformClassName; + +@implementation NSPlatform + ++currentPlatform { + return NSThreadSharedInstance(NSPlatformClassName); +} + +-(NSInputSource *)parentDeathInputSource { + return nil; +} + +-(Class)taskClass { + NSInvalidAbstractInvocation(); + return Nil; +} + +-(Class)socketClass { + NSInvalidAbstractInvocation(); + return Nil; +} + +-(Class)socketPortClass { + NSInvalidAbstractInvocation(); + return Nil; +} + +-(Class)pipeClass { + NSInvalidAbstractInvocation(); + return Nil; +} + +-(Class)lockClass { + NSInvalidAbstractInvocation(); + return Nil; +} + +-(Class)recursiveLockClass +{ + NSInvalidAbstractInvocation(); + return Nil; +} + +-(Class)conditionLockClass { + NSInvalidAbstractInvocation(); + return Nil; +} + +-(Class)conditionClass; +{ + NSInvalidAbstractInvocation(); + return Nil; +} + +-(Class)persistantDomainClass { + NSInvalidAbstractInvocation(); + return Nil; +} + +-(Class)timeZoneClass { + NSInvalidAbstractInvocation(); + return Nil; +} + +-(NSString *)userName { + NSInvalidAbstractInvocation(); + return nil; +} + +-(NSString *)fullUserName { + NSInvalidAbstractInvocation(); + return nil; +} + +-(NSString *)homeDirectory { + NSInvalidAbstractInvocation(); + return nil; +} + +-(NSString *)libraryDirectory { + NSInvalidAbstractInvocation(); + return nil; +} + +-(NSString *)temporaryDirectory { + NSInvalidAbstractInvocation(); + return nil; +} + +-(NSArray *)arguments { + NSInvalidAbstractInvocation(); + return nil; +} + +-(NSDictionary *)environment { + NSInvalidAbstractInvocation(); + return nil; +} + +-(NSString *)hostName { + NSInvalidAbstractInvocation(); + return nil; +} + +-(NSString *)DNSHostName { + NSInvalidAbstractInvocation(); + return nil; +} + +-(NSArray *)addressesForDNSHostName:(NSString *)name { + NSInvalidAbstractInvocation(); + return nil; +} + +-(NSString *)hostNameByAddress:(NSString *)address{ + NSInvalidAbstractInvocation(); + return nil; +} + +-(void *)mapContentsOfFile:(NSString *)path length:(NSUInteger *)length { + NSInvalidAbstractInvocation(); + return NULL; +} + +-(void)unmapAddress:(void *)ptr length:(NSUInteger)length { + NSInvalidAbstractInvocation(); +} + +-(BOOL)writeContentsOfFile:(NSString *)path bytes:(const void *)bytes length:(NSUInteger)length options:(NSUInteger)options error:(NSError **)errorp { + NSInvalidAbstractInvocation(); + return NO; +} + +-(void)checkEnvironmentKey:(NSString *)key value:(NSString *)value { + if([key isEqualToString:@"NSZombieEnabled"]){ + if((NSZombieEnabled=[value isEqual:@"YES"])) + NSCLog("NSZombieEnabled=YES"); + } +} +@end diff --git a/src/NSPlatform_darwin.m b/src/NSPlatform_darwin.m deleted file mode 120000 index de4f1315b..000000000 --- a/src/NSPlatform_darwin.m +++ /dev/null @@ -1 +0,0 @@ -../../cocotron/Foundation/platform_darwin/NSPlatform_darwin.m \ No newline at end of file diff --git a/src/NSPlatform_darwin.m b/src/NSPlatform_darwin.m new file mode 100644 index 000000000..2e4cb7f43 --- /dev/null +++ b/src/NSPlatform_darwin.m @@ -0,0 +1,129 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#ifdef __APPLE__ +#import +#import +#import + +#import +#include +#import +#include +#include +#include +#import + +// Handy functions for extracting various values from sysctl. +// These should work on FreeBSD as well, though the sysctl names might be different. + +static int int32SysctlByName(const char *sysctlName) { + int32_t sysctlInt32Value = 0; size_t len = sizeof(int32_t); + sysctlbyname(sysctlName, &sysctlInt32Value, &len, NULL, 0); + return(sysctlInt32Value); +} + +static int64_t int64SysctlByName(const char *sysctlName) { + int64_t sysctlInt64Value = 0; size_t len = sizeof(int64_t); + sysctlbyname(sysctlName, &sysctlInt64Value, &len, NULL, 0); + return(sysctlInt64Value); +} + +static NSString *stringSysctlByName(const char *sysctlName) { + char sysctlBuffer[1024]; size_t len = 1020; memset(sysctlBuffer, 0, 1024); + sysctlbyname(sysctlName, &sysctlBuffer[0], &len, NULL, 0); + return([NSString stringWithUTF8String:sysctlBuffer]); +} + + +NSString *NSPlatformClassName=@"NSPlatform_darwin"; + +@implementation NSPlatform_darwin + +// nanosleep() is IEEE Std 1003.1b-1993, POSIX.1 +// This can probably move down to NSPlatform_posix + +void NSPlatformSleepThreadForTimeInterval(NSTimeInterval interval) { + double intervalIntegralPart, intervalFractionalPart; + struct timespec intervalTimeSpec; + + intervalFractionalPart = modf((double)interval, &intervalIntegralPart); + intervalTimeSpec.tv_sec = (long)(intervalIntegralPart); + intervalTimeSpec.tv_nsec = (long)(intervalFractionalPart * 1.0E9); + + nanosleep(&intervalTimeSpec, NULL); +} + +/* + SVr4, 4.4BSD (this function first appeared in 4.2BSD). + POSIX.1 does not define these functions, but ISO/IEC + 9945-1:1990 mentions them in B.4.4.1. + */ +-(NSString *)hostName { + char buf[MAXHOSTNAMELEN]; + gethostname(buf, MAXHOSTNAMELEN); + return [NSString stringWithCString:buf]; +} + +-(NSString *)DNSHostName { + // if we wanted to get crazy, we could open a dummy socket + // and then get its local address, the do a gethostbyaddr on that... + return [self hostName]; +} + +NSString * const NSPlatformExecutableDirectory=@"Darwin"; +NSString * const NSPlatformResourceNameSuffix=@"darwin"; + +NSString * const NSPlatformExecutableFileExtension=@""; +NSString * const NSPlatformLoadableObjectFileExtension=@"dylib"; +NSString * const NSPlatformLoadableObjectFilePrefix=@""; + +- (NSUInteger)processorCount +{ + return((NSUInteger)int32SysctlByName("hw.ncpu")); +} + +- (NSUInteger)activeProcessorCount +{ + return((NSUInteger)int32SysctlByName("hw.activecpu")); +} + +-(uint64_t)physicalMemory { + return((uint64_t)int64SysctlByName("hw.memsize")); +} + +-(NSUInteger)operatingSystem { + return(NSMACHOperatingSystem); +} + +-(NSString *)operatingSystemName { + return(@"NSMACHOperatingSystem"); +} + +-(NSString *)operatingSystemVersionString { + static NSString *operatingSystemVersionString = NULL; + + if(operatingSystemVersionString == NULL) { + NSDictionary *operatingSystemVersionDictionary = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]; + if(operatingSystemVersionDictionary == NULL) { operatingSystemVersionDictionary = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/ServerVersion.plist"]; } + if(operatingSystemVersionDictionary != NULL) { + operatingSystemVersionString = [[NSString alloc] initWithFormat:@"Version %@ (Build %@)", [operatingSystemVersionDictionary objectForKey:@"ProductVersion"], [operatingSystemVersionDictionary objectForKey:@"ProductBuildVersion"]]; + } else { + operatingSystemVersionString = [[NSString alloc] initWithFormat:@"%@ Version %@ (Build %@)", stringSysctlByName("kern.ostype"), stringSysctlByName("kern.osrelease"), stringSysctlByName("kern.osversion")]; + } + } + + return(operatingSystemVersionString); +} + +@end + +char **NSPlatform_environ() { + return *_NSGetEnviron(); +} +#endif + diff --git a/src/NSPlatform_posix.m b/src/NSPlatform_posix.m deleted file mode 120000 index f7eaade20..000000000 --- a/src/NSPlatform_posix.m +++ /dev/null @@ -1 +0,0 @@ -../../cocotron/Foundation/platform_posix/NSPlatform_posix.m \ No newline at end of file diff --git a/src/NSPlatform_posix.m b/src/NSPlatform_posix.m new file mode 100644 index 000000000..299345654 --- /dev/null +++ b/src/NSPlatform_posix.m @@ -0,0 +1,373 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#if defined(LINUX) || defined(__APPLE__) +#import +#import + +#ifndef DARLING +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#endif + +#import +#import + +#include +#include +#import +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#import +#include + +BOOL NSCurrentLocaleIsMetric(){ + return NO; +} + +@implementation NSPlatform_posix + +#ifndef DARLING +-(Class)taskClass { + return [NSTask_posix class]; +} + +-(Class)socketPortClass { + return [NSSocketPort_posix class]; +} + +-(Class)pipeClass { + return [NSPipe_posix class]; +} + +-(Class)lockClass { + return [NSLock_posix class]; +} + +-(Class)conditionLockClass { + return [NSConditionLock_posix class]; +} + +-(Class)recursiveLockClass { + return [NSRecursiveLock_posix class]; +} + +-(Class)persistantDomainClass { + return [NSPersistantDomain_posix class]; +} + +-(Class)timeZoneClass { + return [NSTimeZone_posix class]; +} + +-(Class)conditionClass { + return [NSCondition_posix class]; +} +#endif + +static struct passwd *pwent = NULL; + +-(void)_checkAndGetPWEnt { + if (pwent == NULL) { + pwent = getpwuid(getuid()); + if (pwent == NULL) + NSRaiseException(NSInternalInconsistencyException, self, _cmd, @"Can't obtain user's information from system"); + } +} + +-(NSString *)userName { + [self _checkAndGetPWEnt]; + return [NSString stringWithCString:pwent->pw_name]; +} + +-(NSString *)fullUserName { + [self _checkAndGetPWEnt]; + return [NSString stringWithCString:pwent->pw_gecos]; +} + +-(NSString *)homeDirectory { + [self _checkAndGetPWEnt]; + return [NSString stringWithCString:pwent->pw_dir]; +} + +-(NSString *)libraryDirectory { + return [[self homeDirectory] stringByAppendingPathComponent:@".CocotronLibrary"]; +} + +-(NSString *)temporaryDirectory { + return @"/tmp"; +} + +-(NSArray *)arguments { +#ifndef DARLING + extern int NSProcessInfoArgc; + extern const char *const *NSProcessInfoArgv; + NSMutableArray *result=[NSMutableArray array]; + int i; + + for(i=0;imax) + max=len; + + keyValue=__builtin_alloca(max+1); + objects=__builtin_alloca(sizeof(id)*count); + keys=__builtin_alloca(sizeof(id)*count); + + for(count=0;env[count];count++){ + len=strlen(strcpy(keyValue,env[count])); + + for(i=0;ih_addr_list; + int i; + + for(i=0;addr_list[i]!=NULL;i++){ + struct in_addr addr; + NSString *string; + + addr.s_addr=*addr_list[i]; + + string=[NSString stringWithCString:inet_ntoa(addr)]; + + [result addObject:string]; + } + + return result; + } +} + +-(NSString *)hostNameByAddress:(NSString *)address +{ + struct in_addr addr; + struct hostent *remoteHost; + + if ([address length] == 0) { + return nil; + } + + addr.s_addr = inet_addr([address cString]); + if (addr.s_addr == INADDR_NONE) { + return nil; + } + remoteHost = gethostbyaddr((char *) &addr, 4, AF_INET); + if(remoteHost == NULL) + return nil; + + return [NSString stringWithCString:remoteHost->h_name]; +} + +void NSPlatformLogString(NSString *string) { + fprintf(stderr, "%s\n", [string UTF8String]); +} + +void *NSPlatformContentsOfFile(NSString *path,NSUInteger *lengthp) { + int fd = open([path fileSystemRepresentation], O_RDONLY); + char *buf; + off_t pos, total = 0; + + *lengthp = 0; + + if (fd == -1) + return NULL; + + pos = lseek(fd, 0, SEEK_END); + if (pos == -1) + return NULL; + + if (lseek(fd, 0, SEEK_SET) == -1) + return NULL; + + if ((buf = malloc(pos)) == NULL) + return NULL; + + do { + off_t bytesRead = read(fd, buf+total, pos); + + if (bytesRead == -1) { + close(fd); + return NULL; + } + + total += bytesRead; + } while (total < pos); + + close(fd); + + *lengthp = pos; + + return buf; +} + +/* + SVr4, POSIX.1b (formerly POSIX.4), 4.4BSD. Svr4 documents + additional error codes ENXIO and ENODEV. + */ +-(void *)mapContentsOfFile:(NSString *)path length:(NSUInteger *)lengthp { + int fd = open([path fileSystemRepresentation], O_RDONLY); + void *result; + + *lengthp = 0; + if (fd == -1) + return NULL; + + *lengthp = lseek(fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + result = mmap(NULL, *lengthp, PROT_READ, MAP_SHARED, fd, 0); + if (result == MAP_FAILED) + result = NULL; + + close(fd); + + return result; +} + +-(void)unmapAddress:(void *)ptr length:(NSUInteger)length { + if(length>0){ + if (munmap(ptr, length) == -1) + NSRaiseException(NSInvalidArgumentException, self, _cmd, @"munmap() returned -1"); + } +} + +-(BOOL)writeContentsOfFile:(NSString *)path bytes:(const void *)bytes length:(NSUInteger)length options:(NSUInteger)options error:(NSError **)errorp { + BOOL atomically = (options & NSAtomicWrite); + NSString *atomic = nil; + int fd; + size_t total = 0; + + if (atomically) { + do { + atomic = [path stringByAppendingString:@"1"]; + } while ([[NSFileManager defaultManager] fileExistsAtPath:atomic] == YES); + + fd = open([atomic fileSystemRepresentation], O_WRONLY|O_CREAT, FOUNDATION_FILE_MODE); + if (fd == -1) { + if (errorp) *errorp = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:nil]; + return NO; + } + } + else { + fd = open([path fileSystemRepresentation], O_WRONLY|O_CREAT, FOUNDATION_FILE_MODE); + if (fd == -1) { + if (errorp) *errorp = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:nil]; + return NO; + } + } + + do { + size_t written = write(fd, bytes+total, length); + + if (written == -1) { + if (errorp) *errorp = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:nil]; + close(fd); + return NO; + } + + total += written; + } while (total < length); + + close(fd); + + if (atomically) + if (rename([atomic fileSystemRepresentation], [path fileSystemRepresentation]) == -1) { + if (errorp) *errorp = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:nil]; + return NO; + } + + return YES; +} +@end +#endif + + diff --git a/src/NSRaise.m b/src/NSRaise.m deleted file mode 120000 index 70d939ae4..000000000 --- a/src/NSRaise.m +++ /dev/null @@ -1 +0,0 @@ -../../cocotron/Foundation/NSException/NSRaise.m \ No newline at end of file diff --git a/src/NSRaise.m b/src/NSRaise.m new file mode 100644 index 000000000..0f4c40d23 --- /dev/null +++ b/src/NSRaise.m @@ -0,0 +1,70 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#import +#import +#import +#include +#ifdef WINDOWS +#include +#endif + +// DO NOT USE IN NEW CODE AND REPLACE USAGE. Use NSAssert(). +void NSRaiseException(NSString *name,id self,SEL cmd,NSString *fmt,...) { + NSString *where=[NSString stringWithFormat:@"-[%@ %s]",[self class],sel_getName(cmd)]; + NSString *why; + va_list args; + + va_start(args,fmt); + + why=[[[NSString allocWithZone:NULL] initWithFormat:fmt arguments:args] autorelease]; + + va_end(args); + [NSException raise:name format:@"%@ %@",where,why]; +} + +void NSCLogThreadId(){ +#ifdef WINDOWS + fprintf(stderr,"threadId=%p:tick=%d:",GetCurrentThreadId(),GetTickCount()); +#endif +} + +void NSCLogNewline(){ +#ifdef WINDOWS + fprintf(stderr,"\n",GetCurrentThreadId()); +#else + fprintf(stderr,"\n"); +#endif + fflush(stderr); +} + +void NSCLogFormatWithArguments(const char *format,va_list arguments){ + vfprintf(stderr,format,arguments); + fflush(stderr); +} + +void NSCLogFormat(const char *format,...){ + va_list arguments; + + va_start(arguments,format); + NSCLogFormatWithArguments(format,arguments); + va_end(arguments); +} + +void NSCLogv(const char *format,va_list arguments) { + NSCLogThreadId(); + NSCLogFormatWithArguments(format,arguments); + NSCLogNewline(); +} + +void NSCLog(const char *format,...) { + va_list arguments; + + va_start(arguments,format); + NSCLogv(format,arguments); + va_end(arguments); +} diff --git a/src/NSRangeEntries.m b/src/NSRangeEntries.m deleted file mode 120000 index 50ddcd9f4..000000000 --- a/src/NSRangeEntries.m +++ /dev/null @@ -1 +0,0 @@ -../../cocotron/Foundation/NSAttributedString/NSRangeEntries.m \ No newline at end of file diff --git a/src/NSRangeEntries.m b/src/NSRangeEntries.m new file mode 100644 index 000000000..30fd771ae --- /dev/null +++ b/src/NSRangeEntries.m @@ -0,0 +1,419 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import +#import + +/* this could be improved with more merging of adjacent entries after insert/remove */ + +typedef struct NSRangeEntry { + NSRange range; + void *value; +} NSRangeEntry; + +struct NSRangeEntries { + NSUInteger capacity; + NSUInteger count; + struct NSRangeEntry *entries; + BOOL objects; +}; + + NSRangeEntries *NSCreateRangeToOwnedPointerEntries(NSUInteger capacity) { + NSRangeEntries *result=NSZoneMalloc(NULL,sizeof(NSRangeEntries)); + + result->capacity=(capacity<4)?4:capacity; + result->count=0; + result->entries=NSZoneMalloc(NULL,sizeof(NSRangeEntry)*result->capacity); + result->objects=NO; + + return result; +} + + NSRangeEntries *NSCreateRangeToCopiedObjectEntries(NSUInteger capacity) { + NSRangeEntries *result=NSCreateRangeToOwnedPointerEntries(capacity); + + result->objects=YES; + + return result; +} + + +void NSFreeRangeEntries(NSRangeEntries *self) +{ + if (self == NULL) { + return; + } + NSResetRangeEntries(self); + NSZoneFree(NULL, self->entries); + NSZoneFree(NULL, self); +} + + + void NSResetRangeEntries(NSRangeEntries *self) { + NSInteger i; + + for(i=0;icount;i++) + if(self->objects) + [(id)self->entries[i].value release]; + else + NSZoneFree(NULL,self->entries[i].value); + + self->count=0; +} + + NSUInteger NSCountRangeEntries(NSRangeEntries *self) { + return self->count; +} + +static inline void removeEntryAtIndex(NSRangeEntries *self,NSUInteger index){ + if(self->objects) + [(id)self->entries[index].value release]; + else + NSZoneFree(NULL,self->entries[index].value); + + self->count--; + for(;indexcount;index++) + self->entries[index]=self->entries[index+1]; +} + +static inline void insertEntryAtIndex(NSRangeEntries *self,NSUInteger index,NSRange range,void *value){ + NSInteger i; + + self->count++; + if(self->count>self->capacity){ + self->capacity*=2; + self->entries=NSZoneRealloc(NULL,self->entries,sizeof(NSRangeEntry)*self->capacity); + } + + for(i=self->count;--i>index;) + self->entries[i]=self->entries[i-1]; + + if(self->objects) + value=[(id)value copy]; + + self->entries[index].range=range; + self->entries[index].value=value; +} + +void NSRangeEntryInsert(NSRangeEntries *self,NSRange range,void *value) { + NSInteger count=self->count; + NSInteger bottom=0,top=count; + NSInteger insertAt=0; + + if(count>0){ + while(top>=bottom){ + NSInteger mid=(bottom+top)/2; + NSRange check=self->entries[mid].range; + + if(range.location>=NSMaxRange(check)){ + NSInteger next=mid+1; + + if(next>=count || NSMaxRange(range)<=self->entries[next].range.location){ + insertAt=next; + break; + } + bottom=mid+1; + } + else { + NSInteger prev=mid-1; + + if(prev<0 || range.location>=NSMaxRange(self->entries[prev].range)){ + insertAt=mid; + break; + } + top=mid-1; + } + } + } + BOOL merged = NO; + if (range.length == 0) { + // We'll just try to merge entries around the location + if(self->objects && insertAt>0 && insertAtcount){ + id prev = self->entries[insertAt-1].value; + id next = self->entries[insertAt].value; + if ([prev isEqual:next]) { + range = NSUnionRange(self->entries[insertAt].range,self->entries[insertAt-1].range); + self->entries[insertAt-1].range=range; + removeEntryAtIndex(self, insertAt); + } + } + // We don't really want to insert a 0 length entry + return; + } else { + if(self->objects){ + if(insertAt>0){ + // Check if we can just merge the new entry with the previous one + if(range.length == 0 || [(id)(self->entries[insertAt-1].value) isEqual:value]){ + range = NSUnionRange(self->entries[insertAt-1].range,range); + self->entries[insertAt-1].range=range; + merged = YES; + } + } + if(insertAtcount){ + // Check if we can just merge the new entry with the next one + if(range.length == 0 || [(id)(self->entries[insertAt].value) isEqual:value]){ + range = NSUnionRange(self->entries[insertAt].range,range); + if (merged) { + // We merged with both the previous entry and the next one - the next one isn't needed anymore + // so just merge it with the previous one + self->entries[insertAt-1].range=range; + removeEntryAtIndex(self, insertAt); + } else { + self->entries[insertAt].range=range; + } + merged = YES;; + } + } + } + } + if (merged == NO) { + insertEntryAtIndex(self,insertAt,range,value); + } + + } + + void *NSRangeEntryAtIndex(NSRangeEntries *self,NSUInteger location,NSRange *effectiveRangep) { + NSInteger count=self->count; + NSInteger bottom=0,top=count; + + if(top==0){ + if(effectiveRangep!=NULL) + *effectiveRangep=NSMakeRange(0,NSNotFound); + return NULL; + } + + while(top>=bottom){ + NSInteger mid=(bottom+top)/2; + NSRange check=self->entries[mid].range; + + if(NSLocationInRange(location,check)){ + if(effectiveRangep!=NULL) + *effectiveRangep=check; + return self->entries[mid].value; + } + else if(location>=NSMaxRange(check)){ + NSInteger next=mid+1; + + if(next>=count){ + if(effectiveRangep!=NULL){ + effectiveRangep->location=NSMaxRange(check); + effectiveRangep->length=NSNotFound; + } + return NULL; + } + else if(locationentries[next].range.location){ + if(effectiveRangep!=NULL){ + effectiveRangep->location=NSMaxRange(check); + effectiveRangep->length=self->entries[next].range.location-NSMaxRange(check); + } + return NULL; + } + bottom=mid+1; + } + else { + NSInteger prev=mid-1; + + if(prev<0){ + if(effectiveRangep!=NULL){ + effectiveRangep->location=0; + effectiveRangep->length=check.location; + } + return NULL; + } + else if(location>=NSMaxRange(self->entries[prev].range)){ + if(effectiveRangep!=NULL){ + effectiveRangep->location=NSMaxRange(self->entries[prev].range); + effectiveRangep->length=check.location-effectiveRangep->location; + } + return NULL; + } + top=mid-1; + } + } + + NSLog(@"not supposed to get here %d",__LINE__); + return NULL; +} + + void *NSRangeEntryAtRange(NSRangeEntries *self,NSRange range) { + NSInteger bottom=0,top=self->count; + + if(top>0){ + while(top>=bottom){ + NSInteger mid=(bottom+top)/2; + NSRange check=self->entries[mid].range; + + if(NSEqualRanges(range,check)) + return self->entries[mid].value; + else if(range.location>=NSMaxRange(check)) + bottom=mid+1; + else + top=mid-1; + } + } + + return NULL; +} + + NSRangeEnumerator NSRangeEntryEnumerator(NSRangeEntries *self) { + NSRangeEnumerator result; + + result.self=self; + result.index=0; + + return result; +} + + BOOL NSNextRangeEnumeratorEntry(NSRangeEnumerator *state,NSRange *rangep,void **valuep) { + NSRangeEntries *self=state->self; + + if(state->index>=self->count) + return NO; + + *rangep=self->entries[state->index].range; + *valuep=self->entries[state->index].value; + state->index++; + + return YES; +} + +void NSRangeEntriesRemoveEntryAtIndex(NSRangeEntries *self,NSUInteger index) +{ + removeEntryAtIndex(self, index); +} + + void NSRangeEntriesExpandAndWipe(NSRangeEntries *self,NSRange range,NSInteger delta) { + NSInteger count=self->count; + NSUInteger max=NSMaxRange(range); + enum { useBefore, useFirst, useAfter, useNone } useAttributes; + +//NSLog(@"expand wipe %d %d by %d",range.location,range.length,delta); + + if(range.length>0) + useAttributes=useFirst; + else if(range.location>0) + useAttributes=useBefore; + else + useAttributes=useAfter; + + while(--count>=0){ + NSRange check=self->entries[count].range; + + if(check.location>max) + self->entries[count].range.location+=delta; + else if(check.location==max){ + if(useAttributes==useAfter) + self->entries[count].range.length+=delta; + else + self->entries[count].range.location+=delta; + } + else if(check.location>range.location){ + if(NSMaxRange(check)<=max) + removeEntryAtIndex(self,count); + else + self->entries[count].range=NSMakeRange(max+delta,NSMaxRange(check)-max); + } + else if(check.location==range.location){ + if(delta<0 && -delta>=check.length) + removeEntryAtIndex(self,count); + else if(useAttributes==useFirst){ + self->entries[count].range.length=MAX(max+delta,NSMaxRange(check)+delta)-check.location; + useAttributes=useNone; + } + } + else if(check.location=max) + self->entries[count].range.length+=delta; + else if(useAttributes==useBefore || useAttributes==useFirst) + self->entries[count].range.length=(max+delta)-check.location; + else + self->entries[count].range.length=range.location-check.location; + } + } +} + +void NSRangeEntriesDivideAndConquer(NSRangeEntries *self,NSRange range) { + NSInteger count=self->count; + NSUInteger max=NSMaxRange(range); + + while(--count>=0){ + NSRange check=self->entries[count].range; + + if(check.location=range.location){ + if(maxCheck<=max) { + // The entry is completely covered by the added range - it's not needed anymore + removeEntryAtIndex(self,count); + } else { + // Remove the part of the entry covered by the added range + self->entries[count].range.length=maxCheck-max; + self->entries[count].range.location=max; + } + } else if(maxCheck<=range.location) { + // The entry is completely before the new range - we're done + break; + } else { + // The end of the entry is covered by the added one + if(maxCheck>max) { + insertEntryAtIndex(self,count+1,NSMakeRange(max,maxCheck-max),self->entries[count].value); + } + // Shorten the entry to make room for the added one + self->entries[count].range.length=range.location-check.location; + } + } + } +} + + void NSRangeEntriesDump(NSRangeEntries *self) { + NSInteger i; + +NSLog(@"DUMP BEGIN"); + for(i=0;icount;i++) + NSLog(@"**** %d %d %p",self->entries[i].range.location, self->entries[i].range.length,self->entries[i].value); +NSLog(@"DUMP END"); +} + + +void NSRangeEntriesDumpAndAbort(NSRangeEntries *self) +{ + NSRangeEntriesDump(self); + __builtin_trap(); +} + + + void NSRangeEntriesVerify(NSRangeEntries *self,NSUInteger length) { +#if 0 + NSUInteger last=0; + NSInteger i; + + for(i=0;icount;i++){ + NSRange range=self->entries[i].range; + + if(range.length==0 && length>0){ + NSLog(@"ZERO RANGE"); + NSRangeEntriesDumpAndAbort (self); + } + if(range.location!=last){ + NSLog(@"RANGE GAP"); + NSRangeEntriesDumpAndAbort (self); + } + last=NSMaxRange(range); + } + if(last!=length){ + NSLog(@"SHORT RANGES %d",length); + NSRangeEntriesDumpAndAbort (self); + } + if(self->count==0) + NSLog(@"EMPTY"); +#endif +} + diff --git a/src/NSSpellEngine.m b/src/NSSpellEngine.m deleted file mode 120000 index 2631c62fe..000000000 --- a/src/NSSpellEngine.m +++ /dev/null @@ -1 +0,0 @@ -../../cocotron/Foundation/NSSpellEngine.m \ No newline at end of file diff --git a/src/NSSpellEngine.m b/src/NSSpellEngine.m new file mode 100644 index 000000000..eeeca9f12 --- /dev/null +++ b/src/NSSpellEngine.m @@ -0,0 +1,115 @@ +// +// NSSpellEngine.m +// Foundation +// +// Created by Christopher Lloyd on 8/23/11. +// Copyright 2011 __MyCompanyName__. All rights reserved. +// + +#import +#import +#import +#import + +@implementation NSSpellEngine + +static NSMutableArray *_allSpellEngines=nil; + ++(void)initialize { + if(self==[NSSpellEngine class]){ + + NSArray *allPaths=[[NSBundle bundleForClass:self] pathsForResourcesOfType:@"spellEngine" inDirectory:nil]; + int i,count=[allPaths count]; + + _allSpellEngines=[[NSMutableArray alloc] init]; + + for(i=0;i +#import + +NSString *const NSGrammarRange=@"NSGrammarRange"; +NSString *const NSGrammarUserDescription=@"NSGrammarUserDescription"; +NSString *const NSGrammarCorrections=@"NSGrammarCorrections"; diff --git a/src/NSUndoGroup.m b/src/NSUndoGroup.m deleted file mode 120000 index 459cb67e5..000000000 --- a/src/NSUndoGroup.m +++ /dev/null @@ -1 +0,0 @@ -../../cocotron/Foundation/NSUndoManager/NSUndoGroup.m \ No newline at end of file diff --git a/src/NSUndoGroup.m b/src/NSUndoGroup.m new file mode 100644 index 000000000..c06e8d338 --- /dev/null +++ b/src/NSUndoGroup.m @@ -0,0 +1,82 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +// Original - David Young +#import +#import +#import +#import + +@implementation NSUndoGroup + ++ (NSUndoGroup *)undoGroupWithParentGroup:(NSUndoGroup *)parentGroup +{ + return [[[self alloc] initWithParentGroup:parentGroup] autorelease]; +} + +- (id)initWithParentGroup:(NSUndoGroup *)parentGroup +{ + _parentGroup = [parentGroup retain]; + _invocations = [[NSMutableArray alloc] init]; + + return self; +} + +- (void)dealloc +{ + [_parentGroup release]; + [_invocations release]; + + [super dealloc]; +} + +- (NSUndoGroup *)parentGroup +{ + return _parentGroup; +} + +- (void)addInvocation:(NSInvocation *)invocation +{ + [_invocations addObject:invocation]; +} + +- (void)addInvocationsFromArray:(NSArray *)array +{ + [_invocations addObjectsFromArray:array]; +} + +- (NSArray *)invocations +{ + return _invocations; +} + +- (void)removeInvocationsWithTarget:(id)target +{ + int i; + + for (i = 0; i < [_invocations count]; ++i) + if ([[_invocations objectAtIndex:i] target] == target) + [_invocations removeObjectAtIndex:i]; +} + +- (void)invokeInvocations +{ + // LIFO + while ([_invocations count] > 0) { + [[_invocations lastObject] invoke]; + [_invocations removeLastObject]; + } +} + +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@[0x%lx] parentGroup: %@, %d invocations>", + [self class], self, _parentGroup, [_invocations count]]; +} + +@end diff --git a/src/NSUndoManager.m b/src/NSUndoManager.m deleted file mode 120000 index c6422108d..000000000 --- a/src/NSUndoManager.m +++ /dev/null @@ -1 +0,0 @@ -../../cocotron/Foundation/NSUndoManager/NSUndoManager.m \ No newline at end of file diff --git a/src/NSUndoManager.m b/src/NSUndoManager.m new file mode 100644 index 000000000..259eeaacd --- /dev/null +++ b/src/NSUndoManager.m @@ -0,0 +1,468 @@ +/* Copyright (c) 2006-2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#import +#import +#import +#import +#import +#import +#import +#import +#import + +enum _NSUndoManagerState { + NSUndoManagerNormal, + NSUndoManagerUndoing, + NSUndoManagerRedoing +}; + +NSString * const NSUndoManagerCheckpointNotification=@"NSUndoManagerCheckpointNotification"; +NSString * const NSUndoManagerDidOpenUndoGroupNotification=@"NSUndoManagerDidOpenUndoGroupNotification"; +NSString * const NSUndoManagerWillCloseUndoGroupNotification=@"NSUndoManagerWillCloseUndoGroupNotification"; +NSString * const NSUndoManagerWillUndoChangeNotification=@"NSUndoManagerWillUndoChangeNotification"; +NSString * const NSUndoManagerDidUndoChangeNotification=@"NSUndoManagerDidUndoChangeNotification"; +NSString * const NSUndoManagerWillRedoChangeNotification=@"NSUndoManagerWillRedoChangeNotification"; +NSString * const NSUndoManagerDidRedoChangeNotification=@"NSUndoManagerDidRedoChangeNotification"; + +@implementation NSUndoManager + +-(void)_registerPerform { + if(!_performRegistered){ + _performRegistered=YES; + [[NSRunLoop currentRunLoop] performSelector:@selector(runLoopUndo:) target:self argument:nil order:NSUndoCloseGroupingRunLoopOrdering modes:_modes]; + + } +} + +-(void)_unregisterPerform { + if(_performRegistered){ + _performRegistered=NO; + [[NSRunLoop currentRunLoop] cancelPerformSelector:@selector(runLoopUndo:) target:self argument:nil]; + } +} + + +- (id)init +{ + _undoStack = [[NSMutableArray alloc] init]; + _redoStack = [[NSMutableArray alloc] init]; + _state = NSUndoManagerNormal; + + [self setRunLoopModes:[NSArray arrayWithObject:NSDefaultRunLoopMode]]; + [self setGroupsByEvent:YES]; + _performRegistered=NO; + + return self; +} + +- (void)dealloc +{ + [self _unregisterPerform]; + + [_undoStack release]; + [_redoStack release]; + [_currentGroup release]; + [_modes release]; + [_actionName release]; + + [super dealloc]; +} + +- (NSArray *)runLoopModes +{ + return _modes; +} + +- (NSUInteger)levelsOfUndo +{ + return _levelsOfUndo; +} + +- (BOOL)groupsByEvent +{ + return _groupsByEvent; +} + +- (void)setRunLoopModes:(NSArray *)modes +{ + [_modes release]; + _modes = [modes retain]; + [self _unregisterPerform]; + if (_groupsByEvent) + [self _registerPerform]; +} + +- (void)setLevelsOfUndo:(NSUInteger)levels +{ + _levelsOfUndo = levels; + while ([_undoStack count] > _levelsOfUndo) + [_undoStack removeObjectAtIndex:0]; + while ([_redoStack count] > _levelsOfUndo) + [_redoStack removeObjectAtIndex:0]; +} + +- (void)setGroupsByEvent:(BOOL)flag { + _groupsByEvent = flag; + if (_groupsByEvent) + [self _registerPerform]; + else + [self _unregisterPerform]; +} + +- (BOOL)isUndoRegistrationEnabled +{ + return (_disableCount == 0); +} + +- (void)disableUndoRegistration +{ + _disableCount++; +} + +- (void)enableUndoRegistration +{ + if (_disableCount == 0) + [NSException raise:NSInternalInconsistencyException + format:@"Attempt to enable registration with no disable message in effect"]; + + _disableCount--; +} + +- (void)beginUndoGrouping +{ + NSUndoGroup *undoGroup = [NSUndoGroup undoGroupWithParentGroup:_currentGroup]; + + if (!([_currentGroup parentGroup] == nil && _state == NSUndoManagerUndoing)) + [[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerCheckpointNotification + object:self]; + + [_currentGroup release]; + _currentGroup = [undoGroup retain]; + + [[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerDidOpenUndoGroupNotification object:self]; +} + +- (void)endUndoGrouping +{ + NSMutableArray *stack = nil; + NSUndoGroup *parentGroup = [[_currentGroup parentGroup] retain]; + + if (_currentGroup == nil) + [NSException raise:NSInternalInconsistencyException + format:@"endUndoGrouping called without first calling beginUndoGrouping"]; + + [[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerCheckpointNotification + object:self]; + + if (parentGroup == nil && [[_currentGroup invocations] count] > 0) { + switch (_state) { + case NSUndoManagerNormal: + [[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerWillCloseUndoGroupNotification object:self]; + + case NSUndoManagerRedoing: + stack = _undoStack; + break; + + case NSUndoManagerUndoing: + stack = _redoStack; + break; + } + + [stack addObject:_currentGroup]; + if (_levelsOfUndo > 0) + if ([stack count] > _levelsOfUndo) + [stack removeObjectAtIndex:0]; + } + else { + // a nested group was closed. fold its invocations into its parent, preserving the + // order for future changes on the parent. + [parentGroup addInvocationsFromArray:[_currentGroup invocations]]; + } + + [_currentGroup release]; + _currentGroup = parentGroup; +} + +- (NSInteger)groupingLevel +{ + NSUndoGroup *temp = _currentGroup; + int level = (_currentGroup != nil); + + while ((temp = [temp parentGroup])!=nil) + level++; + + return level; +} + +- (void)runLoopUndo:(id)dummy +{ + if (_groupsByEvent == YES) { + if (_currentGroup != nil) + [self endUndoGrouping]; + _performRegistered=NO; + } +} + +- (BOOL)canUndo +{ + if ([_undoStack count] > 0) + return YES; + + if ([[_currentGroup invocations] count] > 0) + return YES; + + return NO; +} + +- (void)undoNestedGroup +{ + NSUndoGroup *undoGroup; + + if (_currentGroup != nil) + [NSException raise:NSInternalInconsistencyException + format:@"undo called with open nested group"]; + + [[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerCheckpointNotification + object:self]; + + [[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerWillUndoChangeNotification + object:self]; + + _state = NSUndoManagerUndoing; + undoGroup = [[_undoStack lastObject] retain]; + [_undoStack removeLastObject]; + [self beginUndoGrouping]; + [undoGroup invokeInvocations]; + [self endUndoGrouping]; + [undoGroup release]; + _state = NSUndoManagerNormal; + + [[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerDidUndoChangeNotification + object:self]; +} + +- (void)undo +{ + if ([self groupingLevel] == 1) + [self endUndoGrouping]; + + [self undoNestedGroup]; +} + +- (BOOL)isUndoing +{ + return (_state == NSUndoManagerUndoing); +} + + +- (BOOL)canRedo +{ + [[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerCheckpointNotification + object:self]; + return ([_redoStack count] > 0); +} + +- (void)redo +{ + NSUndoGroup *undoGroup; + + if (_state == NSUndoManagerUndoing) + [NSException raise:NSInternalInconsistencyException + format:@"redo called while undoing"]; + + [[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerCheckpointNotification + object:self]; + + [[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerWillRedoChangeNotification + object:self]; + + _state = NSUndoManagerRedoing; + undoGroup = [[_redoStack lastObject] retain]; + [_redoStack removeLastObject]; + [self beginUndoGrouping]; + [undoGroup invokeInvocations]; + [self endUndoGrouping]; + [undoGroup release]; + _state = NSUndoManagerNormal; + + [[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerDidRedoChangeNotification + object:self]; +} + + +- (BOOL)isRedoing +{ + return (_state == NSUndoManagerRedoing); +} + +- (void)registerUndoWithTarget:(id)target selector:(SEL)selector object:(id)object +{ + NSInvocation *invocation; + NSMethodSignature *signature; + + if (_disableCount > 0) + return; + + if (_groupsByEvent && _currentGroup == nil) { + [self _registerPerform]; + [self beginUndoGrouping]; + } + + if (_currentGroup == nil) + [NSException raise:NSInternalInconsistencyException + format:@"forwardInvocation called without first opening an undo group"]; + + signature = [target methodSignatureForSelector:selector]; + invocation = [NSInvocation invocationWithMethodSignature:signature]; + + [invocation setTarget:target]; + [invocation setSelector:selector]; + [invocation setArgument:&object atIndex:2]; + [invocation retainArguments]; + + [_currentGroup addInvocation:invocation]; + + if (_state == NSUndoManagerNormal) + [_redoStack removeAllObjects]; +} + +- (void)removeAllActions +{ + [_undoStack removeAllObjects]; + [_redoStack removeAllObjects]; + _disableCount = 0; +} + +- (void)removeAllActionsWithTarget:(id)target +{ + NSUndoGroup *undoGroup; + int i; + + [_currentGroup removeInvocationsWithTarget:target]; + + for (i = 0; i < [_undoStack count]; ++i) { + undoGroup = [_undoStack objectAtIndex:i]; + + [undoGroup removeInvocationsWithTarget:target]; + if ([[undoGroup invocations] count] == 0) + [_undoStack removeObject:undoGroup]; + } + for (i = 0; i < [_redoStack count]; ++i) { + undoGroup = [_redoStack objectAtIndex:i]; + + [undoGroup removeInvocationsWithTarget:target]; + if ([[undoGroup invocations] count] == 0) + [_redoStack removeObject:undoGroup]; + } +} + +- (id)prepareWithInvocationTarget:(id)target +{ + _preparedTarget = [target retain]; + + return self; +} + +-(NSMethodSignature *)methodSignatureForSelector:(SEL)selector { + return [_preparedTarget methodSignatureForSelector:selector]; +} + +- (void)forwardInvocation:(NSInvocation *)invocation +{ + if (_disableCount > 0) + return; + + if (_preparedTarget == nil) + [NSException raise:NSInternalInconsistencyException + format:@"forwardInvocation called without first preparing a target"]; + + if (_groupsByEvent && _currentGroup == nil) { + [self _registerPerform]; + [self beginUndoGrouping]; + } + + if (_currentGroup == nil) + [NSException raise:NSInternalInconsistencyException + format:@"forwardInvocation called without first opening an undo group"]; + + [invocation setTarget:_preparedTarget]; + [_currentGroup addInvocation:invocation]; + [invocation retainArguments]; + + if (_state == NSUndoManagerNormal) + [_redoStack removeAllObjects]; + + [_preparedTarget release]; + _preparedTarget = nil; +} + +- (void)setActionName:(NSString *)name +{ + [_actionName release]; + _actionName = [name retain]; +} + +- (NSString *)undoActionName +{ + if ([self canUndo]) + return _actionName; + + return nil; +} + +- (NSString *)undoMenuItemTitle +{ + return [self undoMenuTitleForUndoActionName:[self undoActionName]]; +} + +// needs localization +- (NSString *)undoMenuTitleForUndoActionName:(NSString *)name +{ + if (name != nil) { + if ([name length] > 0) + return [NSString stringWithFormat:@"Undo %@", name]; + + return @"Undo"; + } + + return name; +} + +- (NSString *)redoActionName +{ + if ([self canRedo]) + return _actionName; + + return nil; +} + +- (NSString *)redoMenuItemTitle +{ + return [self redoMenuTitleForUndoActionName:[self redoActionName]]; +} + +- (NSString *)redoMenuTitleForUndoActionName:(NSString *)name +{ + if (name != nil) { + if ([name length] > 0) + return [NSString stringWithFormat:@"Redo %@", name]; + + return @"Redo"; + } + + return name; +} + +- (void)clearRedoStackIfStateIsNormal +{ + if (_state == NSUndoManagerNormal) + [_redoStack removeAllObjects]; +} + +@end + diff --git a/src/NSXMLDTD.m b/src/NSXMLDTD.m deleted file mode 120000 index e994ae64a..000000000 --- a/src/NSXMLDTD.m +++ /dev/null @@ -1 +0,0 @@ -../../cocotron/Foundation/xml/NSXMLDTD.m \ No newline at end of file diff --git a/src/NSXMLDTD.m b/src/NSXMLDTD.m new file mode 100644 index 000000000..2ed5a8423 --- /dev/null +++ b/src/NSXMLDTD.m @@ -0,0 +1,97 @@ +/* Copyright (c) 2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import +#import +#import + +@implementation NSXMLDTD + ++(NSXMLDTDNode *)predefinedEntityDeclarationForName:(NSString *)name { + NSUnimplementedMethod(); + return nil; +} + +-initWithData:(NSData *)data options:(NSUInteger)options error:(NSError **)error { + NSUnimplementedMethod(); + return nil; +} + +-initWithContentsOfURL:(NSURL *)url options:(NSUInteger)options error:(NSError **)error { + NSUnimplementedMethod(); + return nil; +} + +-(NSString *)publicID { + return _publicID; +} + +-(NSString *)systemID { + return _systemID; +} + +-(NSXMLDTDNode *)attributeDeclarationForName:(NSString *)attributeName elementName:(NSString *)elementName { + NSUnimplementedMethod(); + return nil; +} + +-(NSXMLDTDNode *)elementDeclarationForName:(NSString *)name { + NSUnimplementedMethod(); + return nil; +} + +-(NSXMLDTDNode *)entityDeclarationForName:(NSString *)name { + NSUnimplementedMethod(); + return nil; +} + +-(NSXMLDTDNode *)notationDeclarationForName:(NSString *)name { + NSUnimplementedMethod(); + return nil; +} + +-(void)setPublicID:(NSString *)publicID { + publicID=[publicID copy]; + [_publicID release]; + _publicID=publicID; +} + +-(void)setSystemID:(NSString *)systemID { + systemID=[systemID copy]; + [_systemID release]; + _systemID=systemID; +} + +-(void)setChildren:(NSArray *)children { + [_children setArray:children]; +} + +-(void)addChild:(NSXMLNode *)node { + [_children addObject:node]; +} + +-(void)insertChild:(NSXMLNode *)child atIndex:(NSUInteger)index { + [_children insertObject:child atIndex:index]; +} + +-(void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index { + NSInteger i,count=[children count]; + + for(i=0;i +#import + +@implementation NSXMLDTDNode + +-initWithXMLString:(NSString *)string { + return nil; +} + +-(NSXMLDTDNodeKind)DTDKind { + return _dtdKind; +} + +-(BOOL)isExternal { + return 0; +} + +-(NSString *)notationName { + return _notationName; +} + +-(NSString *)publicID { + return _publicID; +} + +-(NSString *)systemID { + return _systemID; +} + +-(void)setDTDKind:(NSXMLDTDNodeKind)kind { + _dtdKind=kind; +} + +-(void)setNotationName:(NSString *)name { + name=[name copy]; + [_notationName release]; + _notationName=name; +} + +-(void)setPublicID:(NSString *)publicID { + publicID=[publicID copy]; + [_publicID release]; + _publicID=publicID; +} + +-(void)setSystemID:(NSString *)systemID { + systemID=[systemID copy]; + [_systemID release]; + _systemID=systemID; +} + +@end diff --git a/src/NSXMLDocument.m b/src/NSXMLDocument.m deleted file mode 120000 index b990304ff..000000000 --- a/src/NSXMLDocument.m +++ /dev/null @@ -1 +0,0 @@ -../../cocotron/Foundation/xml/NSXMLDocument.m \ No newline at end of file diff --git a/src/NSXMLDocument.m b/src/NSXMLDocument.m new file mode 100644 index 000000000..2496f96b8 --- /dev/null +++ b/src/NSXMLDocument.m @@ -0,0 +1,259 @@ +/* Copyright (c) 2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import +#import +#import +#import +#import +#import +#import + +@implementation NSXMLDocument + ++(Class)replacementClassForClass:(Class)class { + return class; +} + +-init { + [super initWithKind:NSXMLDocumentKind options:NSXMLNodeOptionsNone]; + return self; +} + +-initWithRootElement:(NSXMLElement *)element { + NSUnimplementedMethod(); + return nil; +} + +-initWithXMLString:(NSString *)string options:(NSUInteger)options error:(NSError **)error { + NSUnimplementedMethod(); + return nil; +} + +-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributes { + NSXMLElement *element=[[NSXMLElement alloc] initWithName:elementName]; + + // NSLog(@"element=%@",[element name]); + + [element setAttributesAsDictionary:attributes]; + + NSXMLElement *parent=[_elementStack lastObject]; + // NSLog(@"parent=%@",[parent name]); + [parent addChild:element]; + + [_elementStack addObject:element]; + + if([_elementStack count]==1) + [self addChild:element]; +} + +-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName { + [_elementStack removeLastObject]; +} + +-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { + NSXMLElement *element=[_elementStack lastObject]; + + // NSLog(@"foundCharacters=%@",string); + [element setStringValue:[[element stringValue] stringByAppendingString:string]]; +} + +-(void)parser:(NSXMLParser *)parser foundIgnorableWhitespace:(NSString *)whitespace { + + if(_options&NSXMLDocumentTidyXML) + return; + + [self parser:parser foundCharacters:whitespace]; +} + +-initWithData:(NSData *)data options:(NSUInteger)options error:(NSError **)error { + [super initWithKind:NSXMLDocumentKind options:NSXMLNodeOptionsNone]; +// NSLog(@"xml=%@",[[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]); + NSXMLParser *parser=[[NSXMLParser alloc] initWithData:data]; + + [parser setDelegate:self]; + _options=options; + _elementStack=[[NSMutableArray alloc] init]; + + if(![parser parse]){ + [self dealloc]; + + if(error!=NULL) + *error=[[[parser parserError] retain] autorelease]; + + [parser release]; + return nil; +} + + [parser release]; + + return self; +} + +-initWithContentsOfURL:(NSURL *)url options:(NSUInteger)options error:(NSError **)error { + NSData *data=[NSData dataWithContentsOfURL:url options:0 error:error]; + + if(data==nil){ + [self dealloc]; + return nil; +} + + return [self initWithData:data options:options error:error]; +} + +-(void)dealloc { + [_elementStack release]; + [_rootElement release]; + [super dealloc]; +} + +-(NSXMLDocumentContentKind)documentContentKind { + return _contentKind; +} + +-(NSString *)version { + return _version; +} + +-(NSString *)characterEncoding { + return _characterEncoding; +} + +-(NSString *)MIMEType { + return _mimeType; +} + +-(BOOL)isStandalone { + return _isStandalone; +} + +-(NSXMLElement *)rootElement { + return [_children count]?[_children objectAtIndex:0]:nil; +} + +-(NSXMLDTD *)DTD { + return _dtd; +} + +-(NSString *)URI { + return _uri; +} + +-(void)setDocumentContentKind:(NSXMLDocumentContentKind)kind { + _contentKind=kind; +} + +-(void)setCharacterEncoding:(NSString *)encoding { + encoding=[encoding copy]; + [_characterEncoding release]; + _characterEncoding=encoding; +} + +-(void)setVersion:(NSString *)version { + version=[version copy]; + [_version release]; + _version=version; +} + +-(void)setMIMEType:(NSString *)mimeType { + mimeType=[mimeType copy]; + [_mimeType release]; + _mimeType=mimeType; +} + +-(void)setStandalone:(BOOL)flag { + _isStandalone=flag; +} + +-(void)setRootElement:(NSXMLNode *)element { + element=[element retain]; + [_rootElement release]; + _rootElement=(NSXMLElement *)element; +} + +-(void)setDTD:(NSXMLDTD *)dtd { + dtd=[dtd retain]; + [_dtd release]; + _dtd=dtd; +} + +-(void)setURI:(NSString *)uri { + uri=[uri copy]; + [_uri release]; + _uri=uri; +} + +-(void)setChildren:(NSArray *)children { + [_children setArray:children]; +} + +-(void)addChild:(NSXMLNode *)node { + [_children addObject:node]; +} + +-(void)insertChild:(NSXMLNode *)child atIndex:(NSUInteger)index { + [_children insertObject:child atIndex:index]; +} + +-(void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index { + NSInteger i,count=[children count]; + + for(i=0;i"]; + + for(NSXMLNode *node in _children) + [result appendString:[node XMLStringWithOptions:options]]; + + return result; +} + +-(NSData *)XMLData { + return [self XMLDataWithOptions:NSXMLNodeOptionsNone]; +} + +-(NSData *)XMLDataWithOptions:(NSUInteger)options { + NSString *string=[self XMLStringWithOptions:options]; + + return [string dataUsingEncoding:NSUTF8StringEncoding]; +} + +-objectByApplyingXSLT:(NSData *)xslt arguments:(NSDictionary *)arguments error:(NSError *)error { + NSUnimplementedMethod(); + return nil; +} + +-objectByApplyingXSLTAtURL:(NSURL *)url arguments:(NSDictionary *)arguments error:(NSError *)error { + NSUnimplementedMethod(); + return nil; +} + +-objectByApplyingXSLTString:(NSString *)string arguments:(NSDictionary *)arguments error:(NSError *)error { + NSUnimplementedMethod(); + return nil; +} + +@end diff --git a/src/NSXMLElement.m b/src/NSXMLElement.m deleted file mode 120000 index 51932e8e1..000000000 --- a/src/NSXMLElement.m +++ /dev/null @@ -1 +0,0 @@ -../../cocotron/Foundation/xml/NSXMLElement.m \ No newline at end of file diff --git a/src/NSXMLElement.m b/src/NSXMLElement.m new file mode 100644 index 000000000..d83b9ce51 --- /dev/null +++ b/src/NSXMLElement.m @@ -0,0 +1,241 @@ +/* Copyright (c) 2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import +#import +#import +#import +#import +#import + +@implementation NSXMLElement + +-initWithName:(NSString *)name { + [super initWithKind:NSXMLElementKind options:NSXMLNodeOptionsNone]; + _name=[name copy]; + _attributes=[[NSMutableDictionary alloc] init]; + _namespaces=[[NSMutableDictionary alloc] init]; + return self; +} + +-initWithName:(NSString *)name stringValue:(NSString *)string { + [self initWithName:name]; + _value=[string copy]; + return self; +} + +-initWithName:(NSString *)name URI:(NSString *)uri { + NSUnimplementedMethod(); + return 0; +} + +-initWithXMLString:(NSString *)xml error:(NSError **)error { + NSUnimplementedMethod(); + return 0; +} + +-copyWithZone:(NSZone *)zone { + NSUnimplementedMethod(); + return 0; +} + +-(NSArray *)attributes { + return [_attributes allValues]; +} + +-(NSXMLNode *)attributeForLocalName:(NSString *)name URI:(NSString *)uri { + NSUnimplementedMethod(); + return 0; +} + +-(NSXMLNode *)attributeForName:(NSString *)name { + return [_attributes objectForKey:name]; +} + +-(NSArray *)elementsForLocalName:(NSString *)localName URI:(NSString *)uri { + NSUnimplementedMethod(); + return 0; +} + +-(NSArray *)elementsForName:(NSString *)name { + NSMutableArray *result=[NSMutableArray array]; + + for(NSXMLNode *node in _children) + if([[node name] isEqualToString:name]) + [result addObject:node]; + + return result; +} + +-(NSArray *)namespaces { + NSUnimplementedMethod(); + return 0; +} + +-(NSXMLNode *)namespaceForPrefix:(NSString *)prefix { + NSUnimplementedMethod(); + return 0; +} + +-(void)setAttributes:(NSArray *)attributes { + NSInteger i,count=[attributes count]; + + [_attributes removeAllObjects]; + + for(i=0;i_parent=self; + [_children addObject:node]; +} + +-(void)insertChild:(NSXMLNode *)child atIndex:(NSUInteger)index { + [_children insertObject:child atIndex:index]; +} + +-(void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index { + NSInteger i,count=[children count]; + + for(i=0;i') + entity=@">"; + else if(code=='\"') + entity=@"""; + else if(code=='\'') + entity=@"'"; + + if(entity!=nil){ + if(i-location>0){ + NSString *chunk=[[NSString alloc] initWithCharacters:buffer+location length:i-location]; + [result appendString:chunk]; + [chunk release]; + } + + [result appendString:entity]; + location=i+1; + } + + } + + if(location==0) + [result appendString:string]; + else if(i-location>0){ + NSString *chunk=[[NSString alloc] initWithCharacters:buffer+location length:i-location]; + [result appendString:chunk]; + [chunk release]; + } +} + +-(NSString *)XMLStringWithOptions:(NSUInteger)options { + NSMutableString *result=[NSMutableString string]; + + [result appendString:@"<"]; + [result appendString:[self name]]; + + for(NSXMLNode *attribute in [self attributes]){ + [result appendString:@" "]; + [result appendString:[attribute XMLStringWithOptions:options]]; + } + + [result appendString:@">"]; + + for(NSXMLNode *element in [self children]){ + [result appendString:@" "]; + [result appendString:[element XMLStringWithOptions:options]]; + } + + appendStringWithCharacterEntities(result,[self stringValue]); + + [result appendString:@"\n"]; + + return result; +} + +@end diff --git a/src/NSXMLNode.m b/src/NSXMLNode.m deleted file mode 120000 index 733c09886..000000000 --- a/src/NSXMLNode.m +++ /dev/null @@ -1 +0,0 @@ -../../cocotron/Foundation/xml/NSXMLNode.m \ No newline at end of file diff --git a/src/NSXMLNode.m b/src/NSXMLNode.m new file mode 100644 index 000000000..6c1f82c2f --- /dev/null +++ b/src/NSXMLNode.m @@ -0,0 +1,361 @@ +/* Copyright (c) 2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import +#import +#import +#import +#import +#import + +@implementation NSXMLNode + ++document { + return [[[NSXMLDocument alloc] init] autorelease]; +} + ++documentWithRootElement:(NSXMLElement *)element { + return [[[NSXMLDocument alloc] initWithRootElement:element] autorelease]; +} + + ++elementWithName:(NSString *)name { + return [[[NSXMLElement alloc] initWithName:name] autorelease]; +} + ++elementWithName:(NSString *)name children:(NSArray *)children attributes:(NSArray *)attributes { + NSXMLElement *result=[[[NSXMLElement alloc] initWithName:name] autorelease]; + + [result setChildren:children]; + [result setAttributes:attributes]; + + return result; +} + ++elementWithName:(NSString *)name stringValue:(NSString *)string { + return [[[NSXMLElement alloc] initWithName:name stringValue:string] autorelease]; +} + ++attributeWithName:(NSString *)name stringValue:(NSString *)string { + NSXMLNode *result=[[[self alloc] initWithKind:NSXMLAttributeKind] autorelease]; + + [result setName:name]; + [result setStringValue:string]; + + return result; +} + ++commentWithStringValue:(NSString *)string { + NSXMLNode *result=[[[self alloc] initWithKind:NSXMLCommentKind] autorelease]; + + [result setStringValue:string]; + + return result; +} + ++textWithStringValue:(NSString *)string { + NSXMLNode *result=[[[self alloc] initWithKind:NSXMLTextKind] autorelease]; + + [result setStringValue:string]; + + return result; +} + ++processingInstructionWithName:(NSString *)name stringValue:(NSString *)string { + NSXMLNode *result=[[[self alloc] initWithKind:NSXMLProcessingInstructionKind] autorelease]; + + [result setName:name]; + [result setStringValue:string]; + + return result; +} + ++DTDNodeWithXMLString:(NSString *)string { + return [[[NSXMLDTDNode alloc] initWithXMLString:string] autorelease]; +} + ++namespaceWithName:(NSString *)name stringValue:(NSString *)string { + NSXMLNode *result=[[[self alloc] initWithKind:NSXMLNamespaceKind] autorelease]; + + [result setName:name]; + [result setStringValue:string]; + + return result; +} + ++(NSXMLNode *)predefinedNamespaceForPrefix:(NSString *)prefix { + NSUnimplementedMethod(); + return nil; +} + ++(NSString *)prefixForName:(NSString *)name { + NSUnimplementedMethod(); + return nil; +} + ++(NSString *)localNameForName:(NSString *)name { + NSUnimplementedMethod(); + return nil; +} + + +-initWithKind:(NSXMLNodeKind)kind { + return [self initWithKind:kind options:NSXMLNodeOptionsNone]; +} + +-initWithKind:(NSXMLNodeKind)kind options:(NSUInteger)options { + _parent=nil; + _children=[[NSMutableArray alloc] init]; + _index=0; + _kind=kind; + _options=options; + _name=nil; + _value=@""; // Behavior is empty string not null + return self; +} + +-(void)dealloc { + _parent=nil; + [_children release]; + [_name release]; + [_value release]; + [super dealloc]; +} + +-copyWithZone:(NSZone *)zone { + NSXMLNode *copy=NSCopyObject(self,0,zone); + + copy->_name=[_name copy]; + copy->_value=[_value copy]; + + return copy; +} + +-(NSUInteger)index { + return _index; +} + +-(NSXMLNodeKind)kind { + return _kind; +} + +-(NSUInteger)level { + NSUnimplementedMethod(); + return 0; +} + +-(NSString *)localName { + NSUnimplementedMethod(); + return nil; +} + +-(NSString *)name { + return _name; +} + +-(NSXMLNode *)nextNode { + NSUnimplementedMethod(); + return nil; +} + +-(NSXMLNode *)nextSibling { + NSUnimplementedMethod(); + return nil; +} + +-(NSString *)stringValue { + return _value; +} + +-(NSString *)URI { + NSUnimplementedMethod(); + return nil; +} + +-objectValue { + return _value; +} + +-(NSXMLNode *)parent { + return _parent; +} + +-(NSString *)prefix { + NSUnimplementedMethod(); + return nil; +} + +-(NSXMLNode *)previousNode { + NSUnimplementedMethod(); + return nil; +} + +-(NSXMLNode *)previousSibling { + NSUnimplementedMethod(); + return nil; +} + +-(NSXMLDocument *)rootDocument { + NSUnimplementedMethod(); + return nil; +} + +-(NSUInteger)childCount { + return [_children count]; +} + +-(NSArray *)children { + return _children; +} + +-(NSXMLNode *)childAtIndex:(NSUInteger)index { + return [_children objectAtIndex:index]; +} + +-(void)setName:(NSString *)name { + name=[name copy]; + [_name release]; + _name=name; +} + +-(void)setObjectValue:object { + object=[object retain]; + [_value release]; + _value=object; +} + +-(void)setStringValue:(NSString *)string { + string=[string copy]; + [_value release]; + _value=string; +} + +-(void)setStringValue:(NSString *)string resolvingEntities:(BOOL)resolveEntities { + NSUnimplementedMethod(); +} + +-(void)detach { +// [_parent removeChild:self]; + _parent=nil; +} + +-(NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error { + NSMutableArray *result=[NSMutableArray array]; + NSRange range=[xpath rangeOfString:@"/"]; + + if(range.location==NSNotFound){ + + for(NSXMLNode *node in _children){ + + if([xpath isEqualToString:@"*"]) + [result addObject:node]; + + if([xpath isEqualToString:[node name]]) + [result addObject:node]; +} + } + else { + NSString *firstComponent=[xpath substringWithRange:NSMakeRange(0,range.location)]; + NSString *remainder=[xpath substringFromIndex:NSMaxRange(range)]; + + for(NSXMLNode *node in _children){ + + if([firstComponent isEqualToString:@"*"]) + [result addObjectsFromArray:[node nodesForXPath:remainder error:error]]; + + if([firstComponent isEqualToString:[node name]]) + [result addObjectsFromArray:[node nodesForXPath:remainder error:error]]; + } + } + + return result; +} + +-(NSArray *)objectsForXQuery:(NSString *)xquery constants:(NSDictionary *)constants error:(NSError **)error { + NSUnimplementedMethod(); + return nil; +} + +-(NSArray *)objectsForXQuery:(NSString *)xquery error:(NSError **)error { + NSUnimplementedMethod(); + return nil; +} + +-(NSString *)XMLString { + return [self XMLStringWithOptions:0]; +} + +-(NSString *)XMLStringWithOptions:(NSUInteger)options { + NSMutableString *result=[NSMutableString string]; + + switch([self kind]){ + + case NSXMLInvalidKind: + break; + + case NSXMLDocumentKind: + // Handled in subclass + break; + + case NSXMLElementKind: + // Handled in subclass + break; + + case NSXMLAttributeKind: + [result appendString:[self name]]; + [result appendString:@"=\""]; + [result appendString:[self stringValue]]; + [result appendString:@"\""]; + break; + + case NSXMLNamespaceKind: + break; + + case NSXMLProcessingInstructionKind: + break; + + case NSXMLCommentKind: + break; + + case NSXMLTextKind: + break; + + case NSXMLDTDKind: + break; + + case NSXMLEntityDeclarationKind: + break; + + case NSXMLAttributeDeclarationKind: + break; + + case NSXMLElementDeclarationKind: + break; + + case NSXMLNotationDeclarationKind: + break; +} + + return result; +} + +-(NSString *)XPath { + NSUnimplementedMethod(); + return nil; +} + +-(NSString *)canonicalXMLStringPreservingComments:(BOOL)comments { + NSUnimplementedMethod(); + return nil; +} + +-(NSString *)description { + return [self XMLString]; +} + +@end diff --git a/src/NSXMLParser.m b/src/NSXMLParser.m deleted file mode 120000 index 8c36a91f1..000000000 --- a/src/NSXMLParser.m +++ /dev/null @@ -1 +0,0 @@ -../../cocotron/Foundation/xml/NSXMLParser.m \ No newline at end of file diff --git a/src/NSXMLParser.m b/src/NSXMLParser.m new file mode 100644 index 000000000..2e52d8835 --- /dev/null +++ b/src/NSXMLParser.m @@ -0,0 +1,587 @@ +/* Copyright (c) 2007 Christopher J. W. Lloyd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#import +#import +#import +#import +#import +#import +#import + +enum { + STATE_content, + STATE_ignoreable_content, + STATE_Reference, + STATE_CharRef, + STATE_CharRef_hex, + STATE_CharRef_decimal, + STATE_EntityRef_Name, + STATE_Tag, + STATE_ignore_unhandled, + STATE_STag, + STATE_ETag, + STATE_ETag_whitespace, + STATE_Attributes, + STATE_EmptyElementTag, + STATE_Attribute_Name, + STATE_Attribute_Name_whitespace, + STATE_Attribute_Equal, + STATE_Attribute_Value, + STATE_Attribute_Value_DoubleQuote, + STATE_Attribute_Value_SingleQuote, + STATE_CDATA +}; + + +@implementation NSXMLParser + +-initWithData:(NSData *)data { + _data=[data retain]; + + _bytes=[data bytes]; + _length=[data length]; + _range=NSMakeRange(0,0); + + _entityRefContents=[NSMutableDictionary new]; + [_entityRefContents setObject:@"&" forKey:@"amp"]; + [_entityRefContents setObject:@"<" forKey:@"lt"]; + [_entityRefContents setObject:@">" forKey:@"gt"]; + [_entityRefContents setObject:@"\'" forKey:@"apos"]; + [_entityRefContents setObject:@"\"" forKey:@"quot"]; + + _state=STATE_content; + _elementNameStack=[[NSMutableArray alloc] init]; + + return self; +} + +-initWithContentsofURL:(NSURL *)url { + NSData *data=[NSData dataWithContentsOfURL:url]; + + if(data==nil){ + [self dealloc]; + return nil; +} + + return [self initWithData:data]; +} + +-(void)dealloc { + [_data release]; + [_entityRefContents release]; + [_elementNameStack release]; + [_currentAttributes release]; + [super dealloc]; +} + +-delegate { + return _delegate; +} + +-(BOOL)shouldProcessNamespaces { + return _shouldProcessNamespaces; +} + +-(BOOL)shouldReportNamespacePrefixes { + return _shouldReportNamespacePrefixes; +} + +-(BOOL)shouldResolveExternalEntities { + return _shouldResolveExternalEntities; +} + +-(void)setDelegate:delegate { + _delegate=delegate; +} + +-(void)setShouldProcessNamespaces:(BOOL)flag { + _shouldProcessNamespaces=flag; +} + +-(void)setShouldReportNamespacePrefixes:(BOOL)flag { + _shouldReportNamespacePrefixes=flag; +} + +-(void)setShouldResolveExternalEntities:(BOOL)flag { + _shouldResolveExternalEntities=flag; +} + +-(NSString *)createCurrentString { + return [[NSString alloc] initWithBytes:_bytes+_range.location length:_range.length encoding:NSUTF8StringEncoding]; +} + +-(void)content:(NSString *)string { + if([_delegate respondsToSelector:@selector(parser:foundCharacters:)]) + [_delegate parser:self foundCharacters:string]; +} + +-(void)ignoreableWhitespace:(NSString *)string { + if([_delegate respondsToSelector:@selector(parser:foundIgnorableWhitespace:)]) + [_delegate parser:self foundIgnorableWhitespace:string]; +} + +-(void)charRef:(NSString *)charRef { + if([_delegate respondsToSelector:@selector(parser:foundCharacters:)]) + [_delegate parser:self foundCharacters:charRef]; +} + +-(void)entityRef:(NSString *)entityRef { + NSString *key=[self createCurrentString]; + NSString *contents=[_entityRefContents objectForKey:key]; + + if(contents!=nil){ + if([_delegate respondsToSelector:@selector(parser:foundCharacters:)]) + [_delegate parser:self foundCharacters:contents]; + } + else + NSLog(@"unknown entity=%@",key); + + [key release]; +} + +-(void)sTag:(NSString *)sTag { + [_elementNameStack addObject:sTag]; +} + +-(void)didStartElement { + NSString *elementName=[_elementNameStack lastObject]; + + if([_delegate respondsToSelector:@selector(parser:didStartElement:namespaceURI:qualifiedName:attributes:)]) + [_delegate parser:self didStartElement:elementName namespaceURI:nil qualifiedName:nil attributes:_currentAttributes]; + + [_currentAttributes release]; + _currentAttributes=nil; +} + +-(void)didEndElement { + NSString *elementName=[_elementNameStack lastObject]; + [_delegate parser:self didEndElement:elementName namespaceURI:nil qualifiedName:nil]; + [_elementNameStack removeLastObject]; +} + +-(void)eTag:(NSString *)eTag { +// FIX, maybe double check name here + [self didEndElement]; +} + +-(void)attributeName:(NSString *)name { + _currentAttributeName=[name copy]; +} + +-(void)attributeValue:(NSString *)value { + if(_currentAttributes==nil) + _currentAttributes=[[NSMutableDictionary alloc] init]; + + [_currentAttributes setObject:value forKey:_currentAttributeName]; + + [_currentAttributeName release]; + _currentAttributeName=nil; +} + +-(NSString *)currentString { + return [[self createCurrentString] autorelease]; + } + +static inline BOOL codeIsIgnoreableWhitespace(uint8_t code){ + if(code==0x0A || code==0x0D || code==0x09) + return YES; + return NO; +} + +static inline BOOL codeIsWhitespace(uint8_t code){ + if(code==0x20 || codeIsIgnoreableWhitespace(code)) + return YES; + return NO; +} + +static inline BOOL codeIsNameStart(uint8_t code){ + if((code>='A' && code<='Z') || + (code>='a' && code<='z') || + code==':' || code=='_') + return YES; + + return NO; +} + +static inline BOOL codeIsNameContinue(uint8_t code){ + if((code>='A' && code<='Z') || + (code>='a' && code<='z') || + code==':' || code=='_' || + (code>='0' && code<='9') || + code=='.' || code=='-') + return YES; + + return NO; +} + +-(void)unexpectedIn:(NSString *)state { + NSUInteger position=NSMaxRange(_range)-1; + uint8_t code=_bytes[position]; + + [NSException raise:@"" format:@"Unexpected character %c in %@, position=%d",code,state,position]; +} + +-(BOOL)parse { + int createNewPool=0; + NSAutoreleasePool *pool=nil; + + while(NSMaxRange(_range)<_length){ + + if(pool==nil) + pool=[NSAutoreleasePool new]; + + uint8_t code=_bytes[NSMaxRange(_range)]; + enum { + extendLength, + advanceLocationToNext, + advanceLocationToCurrent, + } rangeAction=extendLength; + + switch(_state){ + + case STATE_content: + if(code=='&'){ + if(_range.length>0) + [self content:[self currentString]]; + _state=STATE_Reference; + rangeAction=advanceLocationToNext; + } + else if(code=='<'){ + if(_range.length>0) + [self content:[self currentString]]; + _state=STATE_Tag; + rangeAction=advanceLocationToNext; + } + else if(codeIsIgnoreableWhitespace(code)){ + if(_range.length>0) + [self content:[self currentString]]; + _state=STATE_ignoreable_content; + rangeAction=advanceLocationToCurrent; + } + else { + _state=STATE_content; + } + break; + + case STATE_ignoreable_content: + if(!codeIsIgnoreableWhitespace(code)){ + if(_range.length>0) + [self ignoreableWhitespace:[self currentString]]; + _state=STATE_content; + rangeAction=advanceLocationToCurrent; + } + break; + + case STATE_Reference: + if(code=='#'){ + _charRef=0; + _state=STATE_CharRef; + rangeAction=advanceLocationToNext; + } + else if(codeIsNameStart(code)){ + _state=STATE_EntityRef_Name; + rangeAction=advanceLocationToCurrent; + } + else { + [self unexpectedIn:@"Reference"]; + return NO; +} + break; + + case STATE_CharRef: + if(code=='x'){ + _state=STATE_CharRef_hex; + rangeAction=advanceLocationToCurrent; + } + else if(code>='0' && code<='9'){ + _charRef=code-'0'; + _state=STATE_CharRef_decimal; + rangeAction=advanceLocationToCurrent; + } + else { + [self unexpectedIn:@"CharRef"]; + return NO; + } + break; + + case STATE_CharRef_hex: + if(code>='0' && code<='9'){ + _charRef=_charRef*16+code-'0'; + _state=STATE_CharRef_hex; + } + else if(code>='a' && code<='z'){ + _charRef=_charRef*16+code-'a'+10; + _state=STATE_CharRef_hex; + } + else if(code>='A' && code<='Z'){ + _charRef=_charRef*16+code-'A'+10; + _state=STATE_CharRef_hex; + } + else if(code==';'){ + [self charRef:[NSString stringWithCharacters:&_charRef length:1]]; + _state=STATE_content; + rangeAction=advanceLocationToNext; + } + else{ + [self unexpectedIn:@"hexadecimal CharRef"]; + return NO; + } + break; + + case STATE_CharRef_decimal: + if(code>='0' && code<='9'){ + _charRef=_charRef*10+code-'0'; + _state=STATE_CharRef_decimal; + } + else if(code==';'){ + [self charRef:[NSString stringWithCharacters:&_charRef length:1]]; + _state=STATE_content; + rangeAction=advanceLocationToNext; + } + else { + [self unexpectedIn:@"decimal CharRef"]; + return NO; + } + break; + + case STATE_EntityRef_Name: + if(codeIsNameContinue(code)) + _state=STATE_EntityRef_Name; + else if(code==';'){ + [self entityRef:[self currentString]]; + _state=STATE_content; + rangeAction=advanceLocationToNext; + } + else { + [self unexpectedIn:@"EntityRef Name"]; + return NO; + } + break; + + case STATE_Tag: + if(code=='/'){ + _state=STATE_ETag; + rangeAction=advanceLocationToNext; + } + else if(codeIsNameStart(code)){ + _state=STATE_STag; + rangeAction=advanceLocationToCurrent; + } + else if(code=='?'){ // FIX, to just get through ?xml + _state=STATE_ignore_unhandled; + rangeAction=advanceLocationToNext; + } + else if(code=='!'){ + if (NSMaxRange(_range)+8 < _length) { + if (0 == memcmp(_bytes + NSMaxRange(_range), "![CDATA[", 8)) { + _state = STATE_CDATA; + _range.length += 8; + rangeAction = advanceLocationToCurrent; + } + } + if (_state != STATE_CDATA) { // get through !DOCTYPE + _state=STATE_ignore_unhandled; + rangeAction=advanceLocationToNext; + } + } + else { + [self unexpectedIn:@"Tag"]; + return NO; + } + break; + + case STATE_CDATA: + if (code==']' && NSMaxRange(_range)+3 < _length) { + if (0 == memcmp(_bytes + NSMaxRange(_range), "]]>", 3)) { + if(_range.length>0) + [self content:[self currentString]]; + + _state = STATE_content; + _range.length += 3; + rangeAction = advanceLocationToCurrent; + } + } + break; + + case STATE_ignore_unhandled: + rangeAction=advanceLocationToNext; + if(code=='>') + _state=STATE_content; + break; + + case STATE_STag: + if(codeIsNameContinue(code)) + _state=STATE_STag; + else { + [self sTag:[self currentString]]; + _state=STATE_Attributes; + rangeAction=advanceLocationToCurrent; + } + break; + + case STATE_ETag: + if(codeIsNameContinue(code)) + _state=STATE_ETag; + else { + [self eTag:[self currentString]]; + _state=STATE_ETag_whitespace; + rangeAction=advanceLocationToCurrent; + } + break; + + case STATE_ETag_whitespace: + if(codeIsWhitespace(code)) + _state=STATE_ETag_whitespace; + else if(code=='>'){ + _state=STATE_content; + rangeAction=advanceLocationToNext; + } + else { + [self unexpectedIn:@"ETag"]; + return NO; + } + break; + + case STATE_Attributes: + if(codeIsWhitespace(code)) + _state=STATE_Attributes; + else if(code=='/') + _state=STATE_EmptyElementTag; + else if(code=='>'){ + [self didStartElement]; + _state=STATE_content; + rangeAction=advanceLocationToNext; + } + else if(codeIsNameStart(code)){ + _state=STATE_Attribute_Name; + rangeAction=advanceLocationToCurrent; + } + break; + + case STATE_EmptyElementTag: + if(code=='>'){ + [self didStartElement]; + [self didEndElement]; + _state=STATE_content; + rangeAction=advanceLocationToNext; + } + else { + [self unexpectedIn:@"EmptyElementTag"]; + return NO; + } + break; + + case STATE_Attribute_Name: + if(codeIsNameContinue(code)) + _state=STATE_Attribute_Name; + else { + [self attributeName:[self currentString]]; + _state=STATE_Attribute_Name_whitespace; + rangeAction=advanceLocationToCurrent; + } + break; + + case STATE_Attribute_Name_whitespace: + if(codeIsWhitespace(code)) + _state=STATE_Attribute_Name_whitespace; + else if(code=='=') + _state=STATE_Attribute_Equal; + break; + + case STATE_Attribute_Equal: + if(codeIsWhitespace(code)) + _state=STATE_Attribute_Equal; + else { + rangeAction=advanceLocationToCurrent; + _state=STATE_Attribute_Value; + } + break; + + case STATE_Attribute_Value: + if(code=='\"'){ + _state=STATE_Attribute_Value_DoubleQuote; + rangeAction=advanceLocationToNext; + } + else if(code=='\''){ + _state=STATE_Attribute_Value_SingleQuote; + rangeAction=advanceLocationToNext; + } + else { + [self unexpectedIn:@"Attribute Value"]; + return NO; + } + break; + + case STATE_Attribute_Value_DoubleQuote: + if(code=='\"'){ + [self attributeValue:[self currentString]]; + _state=STATE_Attributes; + rangeAction=advanceLocationToNext; + } + break; + + case STATE_Attribute_Value_SingleQuote: + if(code=='\''){ + [self attributeValue:[self currentString]]; + _state=STATE_Attributes; + rangeAction=advanceLocationToNext; + } + break; + } + + switch(rangeAction){ + case extendLength: + _range.length++; + break; + + case advanceLocationToNext: + _range.location=NSMaxRange(_range)+1; + _range.length=0; + break; + + case advanceLocationToCurrent: + _range.location=NSMaxRange(_range); + _range.length=0; + break; + } + createNewPool++; + + if((createNewPool%1000)==0){ + [pool release]; + pool=nil; + } + } + return YES; +} + +-(void)abortParsing { + NSUnimplementedMethod(); +} + +-(NSError *)parserError { + return _parserError; +} + +-(NSString *)systemID { + return _systemID; +} + +-(NSString *)publicID { + return _publicID; +} + +-(NSInteger)columnNumber { + return _columnNumber; +} + +-(NSInteger)lineNumber { + return _lineNumber; +} + +@end