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,17 +287,6 @@ main(int argc, char **argv, char **env)
args = [proc arguments]; args = [proc arguments];
/*
* 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);
for (i = 1; i < [args count]; i++) for (i = 1; i < [args count]; i++)
{ {
NSString *arg = [args objectAtIndex: i]; NSString *arg = [args objectAtIndex: i];
@ -308,7 +300,6 @@ main(int argc, char **argv, char **env)
|| [arg hasSuffix: @".gsdoc"]== YES) || [arg hasSuffix: @".gsdoc"]== YES)
{ {
NSString *gsdocfile; NSString *gsdocfile;
NSString *htmlfile;
NSString *hfile; NSString *hfile;
NSString *sfile; NSString *sfile;
NSString *ddir; NSString *ddir;
@ -318,7 +309,15 @@ main(int argc, char **argv, char **env)
NSString *generated; NSString *generated;
BOOL isSource = [arg hasSuffix: @".m"]; BOOL isSource = [arg hasSuffix: @".m"];
BOOL isDocumentation = [arg hasSuffix: @".gsdoc"]; BOOL isDocumentation = [arg hasSuffix: @".gsdoc"];
NSDictionary *attrs;
NSDate *sDate;
NSDate *gDate;
if (pool != nil)
{
RELEASE(pool);
pool = [NSAutoreleasePool new];
}
file = [[arg lastPathComponent] stringByDeletingPathExtension]; file = [[arg lastPathComponent] stringByDeletingPathExtension];
hdir = [arg stringByDeletingLastPathComponent]; hdir = [arg stringByDeletingLastPathComponent];
if ([hdir length] == 0) if ([hdir length] == 0)
@ -343,14 +342,38 @@ main(int argc, char **argv, char **env)
sfile = [sfile stringByAppendingPathExtension: @"m"]; sfile = [sfile stringByAppendingPathExtension: @"m"];
gsdocfile = [ddir stringByAppendingPathComponent: file]; gsdocfile = [ddir stringByAppendingPathComponent: file];
gsdocfile = [gsdocfile stringByAppendingPathExtension: @"gsdoc"]; gsdocfile = [gsdocfile stringByAppendingPathExtension: @"gsdoc"];
htmlfile = [ddir stringByAppendingPathComponent: file];
htmlfile = [htmlfile stringByAppendingPathExtension: @"html"];
if (pass == 0)
{
/* /*
* We perform parsing of source code in pass 0 only. * When were the files last modified?
*/ */
attrs = [mgr fileAttributesAtPath: hfile traverseLink: YES];
if (attrs == nil)
{
sDate = [NSDate distantPast];
}
else
{
sDate = [attrs objectForKey: NSFileModificationDate];
}
AUTORELEASE(RETAIN(sDate));
attrs = [mgr fileAttributesAtPath: sfile traverseLink: YES];
if (attrs != nil)
{
NSDate *d;
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]; [parser reset];
if (isSource == NO && isDocumentation == NO) if (isSource == NO && isDocumentation == NO)
@ -410,7 +433,7 @@ main(int argc, char **argv, char **env)
[[parser info] setObject: file forKey: @"base"]; [[parser info] setObject: file forKey: @"base"];
if (up == nil) if (up == nil)
{ {
up = file; ASSIGN(up, file);
} }
else else
{ {
@ -420,7 +443,7 @@ main(int argc, char **argv, char **env)
{ {
[[parser info] setObject: prev forKey: @"prev"]; [[parser info] setObject: prev forKey: @"prev"];
} }
prev = file; ASSIGN(prev, file);
if (i < [args count] - 1) if (i < [args count] - 1)
{ {
unsigned j = i + 1; unsigned j = i + 1;
@ -454,11 +477,8 @@ main(int argc, char **argv, char **env)
if ([mgr isReadableFileAtPath: gsdocfile] == YES) if ([mgr isReadableFileAtPath: gsdocfile] == YES)
{ {
CREATE_AUTORELEASE_POOL(pool);
GSXMLParser *parser; GSXMLParser *parser;
AGSIndex *locRefs; AGSIndex *locRefs;
AGSHtml *html;
NSString *result;
parser = [GSXMLParser parserWithContentsOfFile: gsdocfile]; parser = [GSXMLParser parserWithContentsOfFile: gsdocfile];
[parser substituteEntities: YES]; [parser substituteEntities: YES];
@ -477,30 +497,12 @@ 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 only perform final outpu in pass 1 * accumulate index info
*/
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]]; [indexer mergeRefs: [locRefs refs]];
[prjRefs mergeRefs: [locRefs refs]]; [prjRefs mergeRefs: [locRefs refs]];
} }
RELEASE(pool);
}
else if (isDocumentation) else if (isDocumentation)
{ {
NSLog(@"No readable documentation at '%@' ... skipping", NSLog(@"No readable documentation at '%@' ... skipping",
@ -512,21 +514,117 @@ main(int argc, char **argv, char **env)
NSLog(@"Unknown argument '%@' ... ignored", arg); NSLog(@"Unknown argument '%@' ... ignored", arg);
} }
} }
RELEASE(arp);
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 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]];
/*
* 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);
}
}
}
else
{
NSLog(@"No readable documentation at '%@' ... skipping",
gsdocfile);
}
}
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;
} }