diff --git a/ChangeLog b/ChangeLog index c952371fd..4cb647b6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2002-02-12 Richard Frith-Macdonald + + * Tools/AGSHtml.m: support for merging types and functions etc. + * Tools/AGSIndex.m: ditto + * Tools/AGSOutput.h: ditto + * Tools/AGSOutput.m: ditto + * Tools/autogsdoc.m: ditto + Put stuff in place for merging info + revert key-value coding changes. + Mon Feb 11 15:11:31 2002 Nicola Pero * Source/GSString.m (NSImmutableString): Implemented copy, diff --git a/Source/NSClassDescription.m b/Source/NSClassDescription.m index 08264ca40..c1424002c 100644 --- a/Source/NSClassDescription.m +++ b/Source/NSClassDescription.m @@ -150,7 +150,7 @@ static Class NSClassDescriptionClass = 0; /** * Returns the attribute keys supplied by the - * + * * object for the receivers class. */ - (NSArray*) attributeKeys diff --git a/Tools/AGSHtml.m b/Tools/AGSHtml.m index b96c0d3b8..290cf2687 100644 --- a/Tools/AGSHtml.m +++ b/Tools/AGSHtml.m @@ -373,7 +373,7 @@ static NSMutableSet *textNodes = nil; NSArray *catNames; /* - * For a clss, we want to list methods in any associated + * For a class, we want to list methods in any associated * categories as well as those of the class itsself. */ catNames = [[[refs objectForKey: @"categories"] @@ -1324,6 +1324,7 @@ static NSMutableSet *textNodes = nil; { NSString *type = [prop objectForKey: @"type"]; NSString *r = [prop objectForKey: @"id"]; + GSXMLNode *tmp = [node children]; NSString *s; if ([type isEqual: @"method"] || [type isEqual: @"ivariable"]) @@ -1338,13 +1339,27 @@ static NSMutableSet *textNodes = nil; if (s == nil) { NSLog(@"ref '%@' not found for %@", r, type); - [self outputText: [node children] to: buf]; + if (tmp == nil) + { + [buf appendString: r]; + } + else + { + [self outputText: tmp to: buf]; + } [buf appendString: @"\n"]; } else { [buf appendString: s]; - [self outputText: [node children] to: buf]; + if (tmp == nil) + { + [buf appendString: r]; + } + else + { + [self outputText: tmp to: buf]; + } [buf appendString: @"\n"]; } } @@ -1940,7 +1955,7 @@ NSLog(@"Element '%@' not implemented", name); // FIXME [buf appendString: @"
\n"]; while (node != nil) { - if([[node name] isEqual: @"method"] == YES) + if ([[node name] isEqual: @"method"] == YES) { [self outputNode: node to: buf]; } diff --git a/Tools/AGSIndex.m b/Tools/AGSIndex.m index b2dc32e1a..ba0642e91 100644 --- a/Tools/AGSIndex.m +++ b/Tools/AGSIndex.m @@ -516,11 +516,8 @@ setDirectory(NSMutableDictionary *dict, NSString *path) } else { - NSString *tmp = ref; - - ref = u; - u = tmp; - // type ... unit ... ref ... file + u = ref; + ref = unit; } t = [refs objectForKey: type]; diff --git a/Tools/AGSOutput.h b/Tools/AGSOutput.h index 4b497c6f2..f657aa3d1 100644 --- a/Tools/AGSOutput.h +++ b/Tools/AGSOutput.h @@ -39,8 +39,9 @@ to: (unsigned)end maxSize: (unsigned)limit output: (NSMutableString*)buf; -- (NSString*) output: (NSDictionary*)d; -- (BOOL) output: (NSDictionary*)d file: (NSString*)name; +- (BOOL) output: (NSDictionary*)d + file: (NSString*)name + directory: (NSString*)dest; - (void) outputDecl: (NSDictionary*)d kind: (NSString*)kind to: (NSMutableString*)str; diff --git a/Tools/AGSOutput.m b/Tools/AGSOutput.m index 4c2b0a118..fc1f62bd1 100644 --- a/Tools/AGSOutput.m +++ b/Tools/AGSOutput.m @@ -22,6 +22,12 @@ #include "AGSOutput.h" +@interface AGSOutput (Private) +- (BOOL) mergeMarkup: (NSString*)markup + ofKind: (NSString*)kind + directory: (NSString*)dest; +@end + static NSString *escapeType(NSString *str) { str = [str stringByReplacingString: @"<" withString: @"<"]; @@ -69,6 +75,18 @@ static BOOL snuggleStart(NSString *t) */ @implementation AGSOutput ++ (void) initialize +{ + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + + [ud registerDefaults: [NSDictionary dictionaryWithObjectsAndKeys: + @"TypesAndConstants", @"ConstantsTemplate", + @"Functions", @"FunctionsTemplate", + @"TypesAndConstants", @"TypedefsTemplate", + @"TypesAndConstants", @"VariablesTemplate", + nil]]; +} + - (void) dealloc { DESTROY(identifier); @@ -183,7 +201,9 @@ static BOOL snuggleStart(NSString *t) * Return a string containing a gsdoc document generated from d (the * parse tree) */ -- (NSString*) output: (NSDictionary*)d +- (BOOL) output: (NSDictionary*)d + file: (NSString*)name + directory: (NSString*)dest { NSMutableString *str = [NSMutableString stringWithCapacity: 10240]; NSDictionary *classes; @@ -394,14 +414,14 @@ static BOOL snuggleStart(NSString *t) if ([types count] > 0) { - NSArray *names; - unsigned i; - unsigned c = [types count]; + NSMutableString *m = [NSMutableString new]; + NSArray *names; + unsigned i; + unsigned c = [types count]; - [str appendString: @" \n"]; - [str appendString: - @" Types\n"]; - [str appendString: @"

\n"]; + [m appendString: @" \n"]; + [m appendString: @" Types\n"]; + [m appendString: @"

\n"]; chapters++; names = [types allKeys]; @@ -411,22 +431,29 @@ static BOOL snuggleStart(NSString *t) NSString *name = [names objectAtIndex: i]; NSDictionary *d = [types objectForKey: name]; - [self outputDecl: d kind: @"type" to: str]; + [self outputDecl: d kind: @"type" to: m]; } - [str appendString: @"
\n"]; + [m appendString: @"
\n"]; + + if ([self mergeMarkup: m ofKind: @"Typedefs" directory: dest] == NO) + { + [str appendString: m]; + chapters++; + } + RELEASE(m); } if ([constants count] > 0) { - NSArray *names; - unsigned i; - unsigned c = [constants count]; + NSMutableString *m = [NSMutableString new]; + NSArray *names; + unsigned i; + unsigned c = [constants count]; - [str appendString: @" \n"]; - [str appendString: - @" Constants\n"]; - [str appendString: @"

\n"]; + [m appendString: @" \n"]; + [m appendString: @" Constants\n"]; + [m appendString: @"

\n"]; chapters++; names = [constants allKeys]; @@ -436,22 +463,29 @@ static BOOL snuggleStart(NSString *t) NSString *name = [names objectAtIndex: i]; NSDictionary *d = [constants objectForKey: name]; - [self outputDecl: d kind: @"constant" to: str]; + [self outputDecl: d kind: @"constant" to: m]; } - [str appendString: @"
\n"]; + [m appendString: @"
\n"]; + + if ([self mergeMarkup: m ofKind: @"Constants" directory: dest] == NO) + { + [str appendString: m]; + chapters++; + } + RELEASE(m); } if ([variables count] > 0) { - NSArray *names; - unsigned i; - unsigned c = [variables count]; + NSMutableString *m = [NSMutableString new]; + NSArray *names; + unsigned i; + unsigned c = [variables count]; - [str appendString: @" \n"]; - [str appendString: - @" Variables\n"]; - [str appendString: @"

\n"]; + [m appendString: @" \n"]; + [m appendString: @" Variables\n"]; + [m appendString: @"

\n"]; chapters++; names = [variables allKeys]; @@ -461,24 +495,30 @@ static BOOL snuggleStart(NSString *t) NSString *name = [names objectAtIndex: i]; NSDictionary *d = [variables objectForKey: name]; - [self outputDecl: d kind: @"variable" to: str]; + [self outputDecl: d kind: @"variable" to: m]; } - [str appendString: @"
\n"]; + [m appendString: @"
\n"]; + + if ([self mergeMarkup: m ofKind: @"Variables" directory: dest] == NO) + { + [str appendString: m]; + chapters++; + } + RELEASE(m); } if ([functions count] > 0) { - NSArray *names; - unsigned i; - unsigned c = [functions count]; + NSMutableString *m = [NSMutableString new]; + NSArray *names; + unsigned i; + unsigned c = [functions count]; - [str appendString: @" \n"]; - [str appendString: - @" Functions\n"]; - [str appendString: @"

\n"]; + [m appendString: @" \n"]; + [m appendString: @" Functions\n"]; + [m appendString: @"

\n"]; - chapters++; names = [functions allKeys]; names = [names sortedArrayUsingSelector: @selector(compare:)]; for (i = 0; i < c; i++) @@ -486,10 +526,16 @@ static BOOL snuggleStart(NSString *t) NSString *name = [names objectAtIndex: i]; NSDictionary *d = [functions objectForKey: name]; - [self outputFunction: d to: str]; + [self outputFunction: d to: m]; } - [str appendString: @"
\n"]; + [m appendString: @"
\n"]; + if ([self mergeMarkup: m ofKind: @"Functions" directory: dest] == NO) + { + [str appendString: m]; + chapters++; + } + RELEASE(m); } if (chapters == 0) @@ -511,13 +557,6 @@ static BOOL snuggleStart(NSString *t) [str appendString: @" \n"]; [str appendString: @"\n"]; - return str; -} - -- (BOOL) output: (NSDictionary*)d file: (NSString*)name -{ - NSString *str = [self output: d]; - return [str writeToFile: name atomically: YES]; } @@ -1842,3 +1881,139 @@ static BOOL snuggleStart(NSString *t) @end +@implementation AGSOutput (Private) +- (BOOL) mergeMarkup: (NSString*)markup + ofKind: (NSString*)kind + directory: (NSString*)dest +{ + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + NSString *key = [kind stringByAppendingString: @"Template"]; + NSString *name = [ud stringForKey: key]; + NSString *file; + NSFileManager *mgr; + NSString *base; + NSString *tmp; + NSMutableString *str; + NSRange range; + NSRange start; + NSRange end; + + if ([name length] == 0) + { + return NO; // No common document. + } + + file = [name stringByAppendingPathExtension: @"gsdoc"]; + if (dest != nil && [file isAbsolutePath] == NO) + { + file = [dest stringByAppendingPathComponent: file]; + } + mgr = [NSFileManager defaultManager]; + base = [info objectForKey: @"base"]; + + /* + * Load the current file that info should be merged into. + */ + if ([mgr isReadableFileAtPath: file] == YES) + { + str = [NSMutableString stringWithContentsOfFile: file]; + } + else + { + tmp = [name stringByAppendingPathExtension: @"template"]; + + if ([mgr isReadableFileAtPath: tmp] == YES) + { + str = [NSMutableString stringWithContentsOfFile: tmp]; + } + else + { + /* + * No pre-existing file, and no blank template available ... + * Generate a standard template. + */ + str = [[NSMutableString alloc] initWithCapacity: 1024]; + + [str appendString: @"\n"]; + [str appendString: @"\n"]; + [str appendString: @"\n"]; + [str appendString: @" \n"]; + [str appendString: @" "]; + [str appendString: kind]; + [str appendString: @"<\title>\n"]; + tmp = [NSString stringWithFormat: @"Generated by %@", NSUserName()]; + [str appendString: @" <author name=\""]; + [str appendString: tmp]; + [str appendString: @"\"></author>\n"]; + [str appendString: @" </head>\n"]; + [str appendString: @" <body>\n"]; + [str appendString: @" </body>\n"]; + [str appendString: @"</gsdoc>\n"]; + } + } + + /* + * Locate start and end points for all markup of this 'kind'. + */ + tmp = [NSString stringWithFormat: @"<!--Start%@-->", kind]; + start = [str rangeOfString: tmp]; + if (start.length == 0) + { + start = [str rangeOfString: @"</body>"]; + if (start.length == 0) + { + NSLog(@"No </body> markup in %@ document", kind); + return NO; + } + [str insertString: tmp atIndex: start.location]; + start.length = [tmp length]; + } + tmp = [NSString stringWithFormat: @"<!--End%@-->", kind]; + end = [str rangeOfString: tmp]; + if (end.length == 0) + { + end.location = NSMaxRange(start); + end.length = [tmp length]; + [str insertString: tmp atIndex: end.location]; + } + else if (end.location <= start.location) + { + NSLog(@"End marker comes before start marker in %@ document", kind); + return NO; + } + + /* + * Now locate start and end points for markup for this file. + */ + tmp = [NSString stringWithFormat: @"<!--Start%@%@-->", base, kind]; + start = [str rangeOfString: tmp]; + if (start.length == 0) + { + start.location = end.location; // Insert before end of section. + start.length = [tmp length]; + [str insertString: tmp atIndex: end.location]; + } + tmp = [NSString stringWithFormat: @"<!--End%@%@-->", base, kind]; + end = [str rangeOfString: tmp]; + if (end.length == 0) + { + end.location = NSMaxRange(start); + end.length = [tmp length]; + [str insertString: tmp atIndex: end.location]; + } + + range = NSMakeRange(NSMaxRange(start), end.location - NSMaxRange(start)); + [str replaceCharactersInRange: range withString: markup]; + + if ([str writeToFile: file atomically: YES] == NO) + { + NSLog(@"Unable to write %@ markup to %@", kind, file); + } + return YES; +} +@end + diff --git a/Tools/autogsdoc.m b/Tools/autogsdoc.m index a0bd562e1..df0e0b06c 100644 --- a/Tools/autogsdoc.m +++ b/Tools/autogsdoc.m @@ -512,7 +512,6 @@ main(int argc, char **argv, char **env) NSString *gsdocfile; NSString *file; NSArray *a; - NSString *generated; NSDictionary *attrs; NSDate *sDate = nil; NSDate *gDate = nil; @@ -650,10 +649,9 @@ main(int argc, char **argv, char **env) [[parser info] setObject: up forKey: @"up"]; } - generated = [output output: [parser info]]; - - if ([generated writeToFile: gsdocfile - atomically: YES] == NO) + if ([output output: [parser info] + file: gsdocfile + directory: documentationDirectory] == NO) { NSLog(@"Sorry unable to write %@", gsdocfile); }