From 2bd2ab5457ebb6d9b29c263de4d7367f6ace1064 Mon Sep 17 00:00:00 2001 From: CaS Date: Sun, 13 Oct 2002 17:34:45 +0000 Subject: [PATCH] Final tweak for cleaning ... clean up template files. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14766 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 4 +- Tools/autogsdoc.m | 99 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 80 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2bd1b32a3..5eedae120 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,7 +14,9 @@ type specifications of the form (id) * Tools/autogsdoc.m: Add -Files option to read names of files to process as a property list rather than using command line args. - Add -Clean flag to remove generated output files. + Add -Clean flag to remove generated output files and purge + generated data from templates. Add -CleanTemplates to completely + temove template files. * Tools/AGSParser.m: Warn about private methods and ivars. 2002-10-12 Richard Frith-Macdonald diff --git a/Tools/autogsdoc.m b/Tools/autogsdoc.m index 73d8d5951..64daccb96 100644 --- a/Tools/autogsdoc.m +++ b/Tools/autogsdoc.m @@ -678,40 +678,92 @@ main(int argc, char **argv, char **env) NSEnumerator *enumerator; NSArray *outputNames; NSMutableSet *allPaths; + NSMutableSet *templates = nil; NSSet *preserve = nil; NSString *path; + NSArray *keys = [NSArray arrayWithObjects: + @"Constants", + @"Functions", + @"Macros", + @"Typedefs", + @"Variables", + nil]; + + /* + * Build a set of all template files. + */ + templates = AUTORELEASE([NSMutableSet new]); + enumerator = [keys objectEnumerator]; + while ((path = [enumerator nextObject]) != nil) + { + path = [path stringByAppendingString: @"Template"]; + path = [defs stringForKey: path]; + if (path != nil) + { + path = [path stringByAppendingPathExtension: @"gsdoc"]; + if ([path isAbsolutePath] == NO) + { + path = [documentationDirectory + stringByAppendingPathComponent: path]; + } + [templates addObject: path]; + } + } /* * Unless we are supposed to clean templates, we preserve any - * template gsdoc files. + * template gsdoc files, but remove any generated content. */ if ([defs boolForKey: @"CleanTemplates"] == NO) { - NSArray *keys = [NSArray arrayWithObjects: - @"ConstantsTemplate", - @"FunctionsTemplate", - @"MacrosTemplate", - @"TypesTemplate", - @"VariablesTemplate", - nil]; - NSMutableSet *s = [NSMutableSet new]; - - enumerator = [keys objectEnumerator]; + preserve = templates; + enumerator = [templates objectEnumerator]; while ((path = [enumerator nextObject]) != nil) { - path = [defs stringForKey: path]; - if (path != nil) + if ([mgr isReadableFileAtPath: path] == YES) { - path = [path stringByAppendingPathExtension: @"gsdoc"]; - if ([path isAbsolutePath] == NO) + NSMutableString *ms; + NSEnumerator *e = [keys objectEnumerator]; + NSString *k; + unsigned length; + + ms = [[NSMutableString alloc] initWithContentsOfFile: path]; + if (ms == nil) { - path = [documentationDirectory - stringByAppendingPathComponent: path]; + NSLog(@"Cleaning ... failed to read '%@'", path); + continue; + } + length = [ms length]; + while ((k = [e nextObject]) != nil) + { + NSString *ss; + NSString *es; + NSRange sr; + NSRange er; + + ss = [NSString stringWithFormat: @"", k]; + sr = [ms rangeOfString: ss]; + es = [NSString stringWithFormat: @"", k]; + er = [ms rangeOfString: es]; + if (sr.length > 0 && er.length > 0 + && er.location > sr.location) + { + NSRange r; + + r.location = sr.location; + r.length = NSMaxRange(er) - r.location; + [ms replaceCharactersInRange: r withString: @""]; + } + } + if ([ms length] != length) + { + if ([ms writeToFile: path atomically: YES] == NO) + { + NSLog(@"Cleaning ... failed to write '%@'", path); + } } - [s addObject: path]; } } - preserve = AUTORELEASE(s); } /* @@ -720,7 +772,7 @@ main(int argc, char **argv, char **env) */ output = [[projectRefs refs] objectForKey: @"output"]; enumerator = [output objectEnumerator]; - allPaths = [NSMutableSet new]; + allPaths = [[NSMutableSet alloc] initWithSet: templates]; while ((outputNames = [enumerator nextObject]) != nil) { [allPaths addObjectsFromArray: outputNames]; @@ -756,9 +808,12 @@ main(int argc, char **argv, char **env) /* * Remove the project index file. */ - if ([mgr removeFileAtPath: refsFile handler: nil] == NO) + if ([mgr fileExistsAtPath: refsFile] == YES) { - NSLog(@"Cleaning ... failed to remove %@", refsFile); + if ([mgr removeFileAtPath: refsFile handler: nil] == NO) + { + NSLog(@"Cleaning ... failed to remove %@", refsFile); + } } /*