Some restructuring and minor fixes to autogsdoc

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@11552 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2001-11-27 20:55:12 +00:00
parent 000f954c4f
commit 7ce99f4e24
4 changed files with 287 additions and 185 deletions

View file

@ -4,6 +4,9 @@
the delay between polling for incoming packets can grow to ... the delay between polling for incoming packets can grow to ...
improve response on heavily loaded systems. improve response on heavily loaded systems.
* Source/GSHTTPURLHandle.m: ditto * Source/GSHTTPURLHandle.m: ditto
* Tools/autogsdoc.m: Tidied structure a little and added file
modification date checks to see whether files should be regenerated
or not.
2001-11-24 Fred Kiefer <FredKiefer@gmx.de> 2001-11-24 Fred Kiefer <FredKiefer@gmx.de>

View file

@ -713,7 +713,7 @@ NSLog(@"Element '%@' not implemented", name); // FIXME
} }
if (f == nil) if (f == nil)
{ {
NSLog(@"ref '%@' not found for %@", name, type); NSLog(@"ref '%@' not found for %@", r, type);
} }
else else
{ {

View file

@ -1174,6 +1174,7 @@ static BOOL snuggleStart(NSString *t)
{ {
unsigned sPos = NSMaxRange(r); unsigned sPos = NSMaxRange(r);
pos = sPos;
r = NSMakeRange(pos, [tmp length] - pos); r = NSMakeRange(pos, [tmp length] - pos);
r = [tmp rangeOfString: @"]" options: NSLiteralSearch range: r]; r = [tmp rangeOfString: @"]" options: NSLiteralSearch range: r];
if (r.length > 0) if (r.length > 0)

View file

@ -222,6 +222,7 @@ main(int argc, char **argv, char **env)
unsigned i; unsigned i;
NSUserDefaults *defs; NSUserDefaults *defs;
NSFileManager *mgr; NSFileManager *mgr;
NSDictionary *projects;
NSString *documentationDirectory; NSString *documentationDirectory;
NSString *declared; NSString *declared;
NSString *headerDirectory; NSString *headerDirectory;
@ -234,7 +235,7 @@ main(int argc, char **argv, char **env)
AGSOutput *output; AGSOutput *output;
NSString *up = nil; NSString *up = nil;
NSString *prev = nil; NSString *prev = nil;
unsigned pass; CREATE_AUTORELEASE_POOL(outer);
CREATE_AUTORELEASE_POOL(pool); CREATE_AUTORELEASE_POOL(pool);
#ifdef GS_PASS_ARGUMENTS #ifdef GS_PASS_ARGUMENTS
@ -250,6 +251,8 @@ main(int argc, char **argv, char **env)
declared = [defs stringForKey: @"Declared"]; declared = [defs stringForKey: @"Declared"];
projects = [defs dictionaryForKey: @"Projects"];
headerDirectory = [defs stringForKey: @"HeaderDirectory"]; headerDirectory = [defs stringForKey: @"HeaderDirectory"];
if (headerDirectory == nil) if (headerDirectory == nil)
{ {
@ -284,181 +287,285 @@ main(int argc, char **argv, char **env)
args = [proc arguments]; args = [proc arguments];
/* for (i = 1; i < [args count]; i++)
* On the initial pass (pass0), we parse all files, produce indexes,
* and write gsdoc output, but not html output.
*
* On the next pass, we have all the indexing info, so we can use it
* to produce html output.
*/
for (pass = 0; pass < 2; pass++)
{ {
CREATE_AUTORELEASE_POOL(arp); NSString *arg = [args objectAtIndex: i];
for (i = 1; i < [args count]; i++) if ([arg hasPrefix: @"-"])
{ {
NSString *arg = [args objectAtIndex: i]; i++; // Skip next value ... it is a default.
}
else if ([arg hasSuffix: @".h"] == YES
|| [arg hasSuffix: @".m"] == YES
|| [arg hasSuffix: @".gsdoc"]== YES)
{
NSString *gsdocfile;
NSString *hfile;
NSString *sfile;
NSString *ddir;
NSString *hdir;
NSString *sdir;
NSString *file;
NSString *generated;
BOOL isSource = [arg hasSuffix: @".m"];
BOOL isDocumentation = [arg hasSuffix: @".gsdoc"];
NSDictionary *attrs;
NSDate *sDate;
NSDate *gDate;
if ([arg hasPrefix: @"-"]) if (pool != nil)
{ {
i++; // Skip next value ... it is a default. RELEASE(pool);
pool = [NSAutoreleasePool new];
} }
else if ([arg hasSuffix: @".h"] == YES file = [[arg lastPathComponent] stringByDeletingPathExtension];
|| [arg hasSuffix: @".m"] == YES hdir = [arg stringByDeletingLastPathComponent];
|| [arg hasSuffix: @".gsdoc"]== YES) if ([hdir length] == 0)
{ {
NSString *gsdocfile; hdir = headerDirectory;
NSString *htmlfile; sdir = sourceDirectory;
NSString *hfile; }
NSString *sfile; else if ([hdir isAbsolutePath] == YES)
NSString *ddir; {
NSString *hdir; sdir = hdir;
NSString *sdir; }
NSString *file; else
NSString *generated; {
BOOL isSource = [arg hasSuffix: @".m"]; hdir = [headerDirectory stringByAppendingPathComponent: hdir];
BOOL isDocumentation = [arg hasSuffix: @".gsdoc"]; sdir = [sourceDirectory stringByAppendingPathComponent: sdir];
}
ddir = documentationDirectory;
file = [[arg lastPathComponent] stringByDeletingPathExtension]; hfile = [hdir stringByAppendingPathComponent: file];
hdir = [arg stringByDeletingLastPathComponent]; hfile = [hfile stringByAppendingPathExtension: @"h"];
if ([hdir length] == 0) sfile = [sdir stringByAppendingPathComponent: file];
{ sfile = [sfile stringByAppendingPathExtension: @"m"];
hdir = headerDirectory; gsdocfile = [ddir stringByAppendingPathComponent: file];
sdir = sourceDirectory; gsdocfile = [gsdocfile stringByAppendingPathExtension: @"gsdoc"];
}
else if ([hdir isAbsolutePath] == YES)
{
sdir = hdir;
}
else
{
hdir = [headerDirectory stringByAppendingPathComponent: hdir];
sdir = [sourceDirectory stringByAppendingPathComponent: sdir];
}
ddir = documentationDirectory;
hfile = [hdir stringByAppendingPathComponent: file]; /*
hfile = [hfile stringByAppendingPathExtension: @"h"]; * When were the files last modified?
sfile = [sdir stringByAppendingPathComponent: file]; */
sfile = [sfile stringByAppendingPathExtension: @"m"]; attrs = [mgr fileAttributesAtPath: hfile traverseLink: YES];
gsdocfile = [ddir stringByAppendingPathComponent: file]; if (attrs == nil)
gsdocfile = [gsdocfile stringByAppendingPathExtension: @"gsdoc"]; {
htmlfile = [ddir stringByAppendingPathComponent: file]; sDate = [NSDate distantPast];
htmlfile = [htmlfile stringByAppendingPathExtension: @"html"]; }
else
{
sDate = [attrs objectForKey: NSFileModificationDate];
}
AUTORELEASE(RETAIN(sDate));
attrs = [mgr fileAttributesAtPath: sfile traverseLink: YES];
if (attrs != nil)
{
NSDate *d;
if (pass == 0) d = [attrs objectForKey: NSFileModificationDate];
if ([d earlierDate: sDate] == d)
{
sDate = d;
AUTORELEASE(RETAIN(sDate));
}
}
attrs = [mgr fileAttributesAtPath: gsdocfile traverseLink: YES];
gDate = [attrs objectForKey: NSFileModificationDate];
AUTORELEASE(RETAIN(gDate));
if (gDate == nil || [sDate earlierDate: gDate] == gDate)
{
[parser reset];
if (isSource == NO && isDocumentation == NO)
{ {
/* /*
* We perform parsing of source code in pass 0 only. * Try to parse header to see what needs documenting.
*/ */
[parser reset]; if ([mgr isReadableFileAtPath: hfile] == NO)
if (isSource == NO && isDocumentation == NO)
{ {
/* NSLog(@"No readable header at '%@' ... skipping",
* Try to parse header to see what needs documenting. hfile);
*/ continue;
if ([mgr isReadableFileAtPath: hfile] == NO)
{
NSLog(@"No readable header at '%@' ... skipping",
hfile);
continue;
}
if (declared != nil)
{
[parser setDeclared:
[declared stringByAppendingPathComponent:
[hfile lastPathComponent]]];
}
[parser parseFile: hfile isSource: NO];
} }
else if (isSource == YES) if (declared != nil)
{ {
/* [parser setDeclared:
* Try to parse source *as-if-it-was-a-header* [declared stringByAppendingPathComponent:
* to see what needs documenting. [hfile lastPathComponent]]];
*/
if ([mgr isReadableFileAtPath: sfile] == NO)
{
NSLog(@"No readable source at '%@' ... skipping",
sfile);
continue;
}
if (declared != nil)
{
[parser setDeclared:
[declared stringByAppendingPathComponent:
[sfile lastPathComponent]]];
}
[parser parseFile: sfile isSource: NO];
} }
[parser parseFile: hfile isSource: NO];
if (isDocumentation == NO) }
else if (isSource == YES)
{
/*
* Try to parse source *as-if-it-was-a-header*
* to see what needs documenting.
*/
if ([mgr isReadableFileAtPath: sfile] == NO)
{ {
/* NSLog(@"No readable source at '%@' ... skipping",
* If we can read a source file, parse it for any sfile);
* additional information on items found in the header. continue;
*/
if ([mgr isReadableFileAtPath: sfile] == YES)
{
[parser parseFile: sfile isSource: YES];
}
/*
* Set up linkage for this file.
*/
[[parser info] setObject: file forKey: @"base"];
if (up == nil)
{
up = file;
}
else
{
[[parser info] setObject: up forKey: @"up"];
}
if (prev != nil)
{
[[parser info] setObject: prev forKey: @"prev"];
}
prev = file;
if (i < [args count] - 1)
{
unsigned j = i + 1;
while (j < [args count])
{
NSString *name = [args objectAtIndex: j++];
if ([name hasSuffix: @".h"]
|| [name hasSuffix: @".m"]
|| [name hasSuffix: @".gsdoc"])
{
name = [[name lastPathComponent]
stringByDeletingPathExtension];
[[parser info] setObject: name
forKey: @"next"];
break;
}
}
}
generated = [output output: [parser info]];
if ([generated writeToFile: gsdocfile
atomically: YES] == NO)
{
NSLog(@"Sorry unable to write %@", gsdocfile);
}
} }
if (declared != nil)
{
[parser setDeclared:
[declared stringByAppendingPathComponent:
[sfile lastPathComponent]]];
}
[parser parseFile: sfile isSource: NO];
} }
if ([mgr isReadableFileAtPath: gsdocfile] == YES) if (isDocumentation == NO)
{ {
CREATE_AUTORELEASE_POOL(pool); /*
GSXMLParser *parser; * If we can read a source file, parse it for any
AGSIndex *locRefs; * additional information on items found in the header.
AGSHtml *html; */
NSString *result; if ([mgr isReadableFileAtPath: sfile] == YES)
{
[parser parseFile: sfile isSource: YES];
}
/*
* Set up linkage for this file.
*/
[[parser info] setObject: file forKey: @"base"];
if (up == nil)
{
ASSIGN(up, file);
}
else
{
[[parser info] setObject: up forKey: @"up"];
}
if (prev != nil)
{
[[parser info] setObject: prev forKey: @"prev"];
}
ASSIGN(prev, file);
if (i < [args count] - 1)
{
unsigned j = i + 1;
while (j < [args count])
{
NSString *name = [args objectAtIndex: j++];
if ([name hasSuffix: @".h"]
|| [name hasSuffix: @".m"]
|| [name hasSuffix: @".gsdoc"])
{
name = [[name lastPathComponent]
stringByDeletingPathExtension];
[[parser info] setObject: name
forKey: @"next"];
break;
}
}
}
generated = [output output: [parser info]];
if ([generated writeToFile: gsdocfile
atomically: YES] == NO)
{
NSLog(@"Sorry unable to write %@", gsdocfile);
}
}
}
if ([mgr isReadableFileAtPath: gsdocfile] == YES)
{
GSXMLParser *parser;
AGSIndex *locRefs;
parser = [GSXMLParser parserWithContentsOfFile: gsdocfile];
[parser substituteEntities: YES];
[parser doValidityChecking: YES];
if ([parser parse] == NO)
{
NSLog(@"WARNING %@ is not a valid document", gsdocfile);
}
if (![[[[parser doc] root] name] isEqualToString: @"gsdoc"])
{
NSLog(@"not a gsdoc document - because name node is %@",
[[[parser doc] root] name]);
return 1;
}
locRefs = AUTORELEASE([AGSIndex new]);
[locRefs makeRefs: [[parser doc] root]];
/*
* accumulate index info
*/
[indexer mergeRefs: [locRefs refs]];
[prjRefs mergeRefs: [locRefs refs]];
}
else if (isDocumentation)
{
NSLog(@"No readable documentation at '%@' ... skipping",
gsdocfile);
}
}
else
{
NSLog(@"Unknown argument '%@' ... ignored", arg);
}
}
for (i = 1; i < [args count]; i++)
{
NSString *arg = [args objectAtIndex: i];
if ([arg hasPrefix: @"-"])
{
i++; // Skip next value ... it is a default.
}
else if ([arg hasSuffix: @".h"] == YES
|| [arg hasSuffix: @".m"] == YES
|| [arg hasSuffix: @".gsdoc"]== YES)
{
NSString *gsdocfile;
NSString *htmlfile;
NSString *ddir;
NSString *file;
NSString *generated;
NSDictionary *attrs;
NSDate *gDate;
NSDate *hDate;
if (pool != nil)
{
RELEASE(pool);
pool = [NSAutoreleasePool new];
}
file = [[arg lastPathComponent] stringByDeletingPathExtension];
ddir = documentationDirectory;
gsdocfile = [ddir stringByAppendingPathComponent: file];
gsdocfile = [gsdocfile stringByAppendingPathExtension: @"gsdoc"];
htmlfile = [ddir stringByAppendingPathComponent: file];
htmlfile = [htmlfile stringByAppendingPathExtension: @"html"];
/*
* When were the files last modified?
*/
attrs = [mgr fileAttributesAtPath: gsdocfile traverseLink: YES];
gDate = [attrs objectForKey: NSFileModificationDate];
AUTORELEASE(RETAIN(gDate));
attrs = [mgr fileAttributesAtPath: htmlfile traverseLink: YES];
hDate = [attrs objectForKey: NSFileModificationDate];
AUTORELEASE(RETAIN(hDate));
if ([mgr isReadableFileAtPath: gsdocfile] == YES)
{
if (hDate == nil || [gDate earlierDate: hDate] == hDate)
{
GSXMLParser *parser;
AGSIndex *locRefs;
AGSHtml *html;
parser = [GSXMLParser parserWithContentsOfFile: gsdocfile]; parser = [GSXMLParser parserWithContentsOfFile: gsdocfile];
[parser substituteEntities: YES]; [parser substituteEntities: YES];
@ -477,56 +584,47 @@ main(int argc, char **argv, char **env)
locRefs = AUTORELEASE([AGSIndex new]); locRefs = AUTORELEASE([AGSIndex new]);
[locRefs makeRefs: [[parser doc] root]]; [locRefs makeRefs: [[parser doc] root]];
if (pass == 1) /*
* We perform final output
*/
html = AUTORELEASE([AGSHtml new]);
[html setGlobalRefs: prjRefs];
[html setLocalRefs: locRefs];
generated = [html outputDocument: [[parser doc] root]];
if ([generated writeToFile: htmlfile atomically: YES] == NO)
{ {
/* NSLog(@"Sorry unable to write %@", htmlfile);
* We only perform final outpu in pass 1
*/
html = AUTORELEASE([AGSHtml new]);
[html setGlobalRefs: prjRefs];
[html setLocalRefs: locRefs];
result = [html outputDocument: [[parser doc] root]];
if ([result writeToFile: htmlfile atomically: YES] == NO)
{
NSLog(@"Sorry unable to write %@", htmlfile);
}
} }
else
{
/*
* We only accumulate index info in pass 0
*/
[indexer mergeRefs: [locRefs refs]];
[prjRefs mergeRefs: [locRefs refs]];
}
RELEASE(pool);
}
else if (isDocumentation)
{
NSLog(@"No readable documentation at '%@' ... skipping",
gsdocfile);
} }
} }
else else
{ {
NSLog(@"Unknown argument '%@' ... ignored", arg); NSLog(@"No readable documentation at '%@' ... skipping",
gsdocfile);
} }
} }
RELEASE(arp); else
{
NSLog(@"Unknown argument '%@' ... ignored", arg);
}
} }
RELEASE(pool);
DESTROY(up);
DESTROY(prev);
/* /*
* Save references. * Save references.
*/ */
refsFile = [documentationDirectory stringByAppendingPathComponent: refsFile = [documentationDirectory stringByAppendingPathComponent:
projectName]; projectName];
refsFile = [refsFile stringByAppendingPathExtension: @"gsdocidx"]; refsFile = [refsFile stringByAppendingPathExtension: @"igsdoc"];
if ([[prjRefs refs] writeToFile: refsFile atomically: YES] == NO) if ([[prjRefs refs] writeToFile: refsFile atomically: YES] == NO)
{ {
NSLog(@"Sorry unable to write %@", refsFile); NSLog(@"Sorry unable to write %@", refsFile);
} }
RELEASE(pool); RELEASE(outer);
return 0; return 0;
} }