Various tidyups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@9623 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2001-04-19 12:02:13 +00:00
parent d6be9f040d
commit 5c7e2204fc
3 changed files with 492 additions and 341 deletions

View file

@ -2,6 +2,10 @@
* Source/NSTask.m: Tidied code a little, added safety checks for * Source/NSTask.m: Tidied code a little, added safety checks for
usePseudoTerminal method. usePseudoTerminal method.
* Source/NSData.m: ([writeToFile:atomically:]) create new files
with permission 0644 modified by umask.
* Tools/gsdoc.m: Use memory management macros and attempt to get
back to something like conformance with coding standards.
* Documentation/gsdoc/NSTask.gsdoc: documentation fleshed out. * Documentation/gsdoc/NSTask.gsdoc: documentation fleshed out.
2001-04-16 Adam Fedor <fedor@gnu.org> 2001-04-16 Adam Fedor <fedor@gnu.org>

View file

@ -707,6 +707,7 @@ failure:
if (useAuxiliaryFile) if (useAuxiliaryFile)
{ {
int desc; int desc;
int mask;
strcpy(thePath, theRealPath); strcpy(thePath, theRealPath);
strcat(thePath, "XXXXXX"); strcat(thePath, "XXXXXX");
@ -715,6 +716,9 @@ failure:
NSLog(@"mkstemp (%s) failed - %s", thePath, strerror(errno)); NSLog(@"mkstemp (%s) failed - %s", thePath, strerror(errno));
goto failure; goto failure;
} }
mask = umask(0);
umask(mask);
fchmod(desc, 0644 & ~mask);
if ((theFile = fdopen(desc, "w")) == 0) if ((theFile = fdopen(desc, "w")) == 0)
{ {
close(desc); close(desc);

View file

@ -448,7 +448,8 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
{ {
writeFlag = YES; writeFlag = YES;
processFileReferencesFlag = YES; processFileReferencesFlag = YES;
typesTypes = [NSArray arrayWithObjects: @"type", @"class", @"define", nil]; typesTypes
= [NSArray arrayWithObjects: @"type", @"class", @"define", nil];
RETAIN(typesTypes); RETAIN(typesTypes);
classesTypes = [NSArray arrayWithObjects: @"class", @"define", nil]; classesTypes = [NSArray arrayWithObjects: @"class", @"define", nil];
RETAIN(classesTypes); RETAIN(classesTypes);
@ -525,7 +526,8 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
NSString *ref = [NSString stringWithFormat: @"foot-%u", i]; NSString *ref = [NSString stringWithFormat: @"foot-%u", i];
[text appendFormat: @"<a name =\"%@\">footnote %u </a> -\r\n", ref, i]; [text appendFormat:
@"<a name =\"%@\">footnote %u </a> -\r\n", ref, i];
[text appendString: note]; [text appendString: note];
[text appendString: @"<hr>\r\n"]; [text appendString: @"<hr>\r\n"];
} }
@ -1849,7 +1851,8 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
{ {
if ([[prevName pathExtension] isEqual: pathExtension_HTML] == YES) if ([[prevName pathExtension] isEqual: pathExtension_HTML] == YES)
{ {
[text appendFormat: @"<a href =\"%@\">[Previous]</a>\n", prevName]; [text appendFormat: @"<a href =\"%@\">[Previous] </a>\n",
prevName];
} }
else else
{ {
@ -1889,7 +1892,8 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
} }
else else
{ {
[text appendFormat: @"<a href =\"%@.html\">[Next]</a>\n", nextName]; [text appendFormat: @"<a href =\"%@.html\">[Next] </a>\n",
nextName];
} }
} }
} }
@ -2210,7 +2214,8 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
else else
{ {
[text appendFormat: @"%@ <b>%@</b>%@ = %@<br>\r\n", [text appendFormat: @"%@ <b>%@</b>%@ = %@<br>\r\n",
linkedType ? linkedType : @"", name, (posttype ? posttype : @""), value]; linkedType ? linkedType : @"", name, (posttype ? posttype : @""),
value];
} }
if (desc != nil) if (desc != nil)
@ -2579,7 +2584,8 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
NSString *s = [@"+" stringByAppendingString: sText]; NSString *s = [@"+" stringByAppendingString: sText];
NSString *eref; NSString *eref;
eref = [NSString stringWithFormat: @"+%@::%@", methodBlockName, sText]; eref
= [NSString stringWithFormat: @"+%@::%@", methodBlockName, sText];
[self setEntry: s [self setEntry: s
withExternalCompleteRef: eref withExternalCompleteRef: eref
withExternalRef: eref withExternalRef: eref
@ -2591,7 +2597,8 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
NSString *s = [@"-" stringByAppendingString: sText]; NSString *s = [@"-" stringByAppendingString: sText];
NSString *eref; NSString *eref;
eref = [NSString stringWithFormat: @"-%@::%@", methodBlockName, sText]; eref
= [NSString stringWithFormat: @"-%@::%@", methodBlockName, sText];
[self setEntry: s [self setEntry: s
withExternalCompleteRef: eref withExternalCompleteRef: eref
@ -2603,7 +2610,8 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
[text appendFormat: @"<h3><a name =\"%@\">%@</a></h3>\r\n", ref, sText]; [text appendFormat: @"<h3><a name =\"%@\">%@</a></h3>\r\n", ref, sText];
if (desInit) if (desInit)
{ {
[text appendString: @"<b>This is the designated initialiser </b><br>\r\n"]; [text
appendString: @"<b>This is the designated initialiser </b><br>\r\n"];
} }
[text appendFormat: @"%@;<br>\r\n", lText]; [text appendFormat: @"%@;<br>\r\n", lText];
if ([over isEqual: @"subclass"]) if ([over isEqual: @"subclass"])
@ -2713,8 +2721,10 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
} }
[self setEntry: elem [self setEntry: elem
withExternalCompleteRef: [NSString stringWithFormat: @"%@::%@", @"***unknown", elem] withExternalCompleteRef:
withExternalRef: [NSString stringWithFormat: @"%@::%@", @"***unknown", elem] [NSString stringWithFormat: @"%@::%@", @"***unknown", elem]
withExternalRef:
[NSString stringWithFormat: @"%@::%@", @"***unknown", elem]
withRef: ref withRef: ref
inIndexOfType: @"label"]; inIndexOfType: @"label"];
@ -2737,8 +2747,10 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
[footnotes count]]; [footnotes count]];
[self setEntry: elem [self setEntry: elem
withExternalCompleteRef: [NSString stringWithFormat: @"%@::%@", @"***unknown", elem] withExternalCompleteRef:
withExternalRef: [NSString stringWithFormat: @"%@::%@", @"***unknown", elem] [NSString stringWithFormat: @"%@::%@", @"***unknown", elem]
withExternalRef:
[NSString stringWithFormat: @"%@::%@", @"***unknown", elem]
withRef: ref withRef: ref
inIndexOfType: @"footnote"]; inIndexOfType: @"footnote"];
@ -2863,7 +2875,8 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
NSString *modelName = [self getProp: "name" fromNode: node]; NSString *modelName = [self getProp: "name" fromNode: node];
NSString *version = [self getProp: "version" fromNode: node]; NSString *version = [self getProp: "version" fromNode: node];
NSString *adaptorName = [self getProp: "adaptorName" fromNode: node]; NSString *adaptorName = [self getProp: "adaptorName" fromNode: node];
NSString *adaptorClassName = [self getProp: "adaptorClassName" fromNode: node]; NSString *adaptorClassName
= [self getProp: "adaptorClassName" fromNode: node];
NSString *desc = nil; NSString *desc = nil;
NSString *connectionDictionary = nil; NSString *connectionDictionary = nil;
@ -2984,7 +2997,8 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
} }
if (userDictionary != nil) if (userDictionary != nil)
{ {
[text appendFormat: @"<hr><h2>UserDictionary </h2>\r\n%@", userDictionary]; [text appendFormat: @"<hr><h2>UserDictionary </h2>\r\n%@",
userDictionary];
} }
// Stop working on EOModel // Stop working on EOModel
ASSIGN(currentEOModel, nil); ASSIGN(currentEOModel, nil);
@ -3209,7 +3223,8 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
@"Description </TH></TR>\r\n"]; @"Description </TH></TR>\r\n"];
for (i = 0; i < [attributes count]; i++) for (i = 0; i < [attributes count]; i++)
{ {
[text appendFormat: @"<TR>%@</TR>\r\n", [attributes objectAtIndex: i]]; [text appendFormat: @"<TR>%@</TR>\r\n",
[attributes objectAtIndex: i]];
} }
[text appendString: @"</TABLE>\r\n"]; [text appendString: @"</TABLE>\r\n"];
} }
@ -3240,7 +3255,8 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
unsigned i = 0; unsigned i = 0;
[text appendFormat: [text appendFormat:
@"<hr><H3><A NAME=\"%@__ClassProperties\">Class Properties </A></h3>\r\n", @"<hr><H3><A NAME=\"%@__ClassProperties\">"
@"Class Properties </A></h3>\r\n",
entityName]; entityName];
[text appendString: @"<TABLE BORDER=\"1\">\r\n"]; [text appendString: @"<TABLE BORDER=\"1\">\r\n"];
for (i = 0; i < [classProperties count]; i++) for (i = 0; i < [classProperties count]; i++)
@ -3475,7 +3491,8 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
NSMutableString *text = [NSMutableString string]; NSMutableString *text = [NSMutableString string];
NSString *ref = [self getProp: "id" fromNode: node]; NSString *ref = [self getProp: "id" fromNode: node];
NSString *entityName = [self getProp: "entityName" fromNode: node]; NSString *entityName = [self getProp: "entityName" fromNode: node];
NSString *destinationEntityName = [self getProp: "destinationEntityName" fromNode: node]; NSString *destinationEntityName
= [self getProp: "destinationEntityName" fromNode: node];
NSString *relationshipName = [self getProp: "name" fromNode: node]; NSString *relationshipName = [self getProp: "name" fromNode: node];
NSString *isToMany = [self getProp: "isToMany" fromNode: node]; NSString *isToMany = [self getProp: "isToMany" fromNode: node];
@ -3593,12 +3610,13 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
[text appendString: @"</TABLE>\r\n </TD>\r\n"]; [text appendString: @"</TABLE>\r\n </TD>\r\n"];
} }
else else
{
[text appendString: @"<TD></TD>"]; [text appendString: @"<TD></TD>"];
}
if (userDictionary) if (userDictionary)
{ {
[text appendFormat: @"<TD>%@</TD>", [text appendFormat: @"<TD>%@</TD>", userDictionary];
userDictionary];
} }
else else
[text appendString: @"<TD></TD>"]; [text appendString: @"<TD></TD>"];
@ -3642,11 +3660,13 @@ loader(const char *url, const char *eid, xmlParserCtxtPtr *ctxt)
{ {
NSMutableString *text = [NSMutableString string]; NSMutableString *text = [NSMutableString string];
NSString *ref = [self getProp: "id" fromNode: node]; NSString *ref = [self getProp: "id" fromNode: node];
NSString *relationshipName = [self getProp: "relationshipName" fromNode: node]; NSString *relationshipName
= [self getProp: "relationshipName" fromNode: node];
NSString *joinOperator = [self getProp: "joinOperator" fromNode: node]; NSString *joinOperator = [self getProp: "joinOperator" fromNode: node];
NSString *joinSemantic = [self getProp: "joinSemantic" fromNode: node]; NSString *joinSemantic = [self getProp: "joinSemantic" fromNode: node];
NSString *sourceAttribute = [self getProp: "sourceAttribute" fromNode: node]; NSString *sourceAttribute = [self getProp: "sourceAttribute" fromNode: node];
NSString *destinationAttribute = [self getProp: "destinationAttribute" fromNode: node]; NSString *destinationAttribute
= [self getProp: "destinationAttribute" fromNode: node];
NSString *desc = nil; NSString *desc = nil;
NSString *userDictionary = nil; NSString *userDictionary = nil;
@ -3833,7 +3853,8 @@ withExternalCompleteRef: (NSString *)externalCompleteRef
if (goodRange.location+goodRange.length < [item length]) if (goodRange.location+goodRange.length < [item length])
{ {
linked = [NSString stringWithFormat: @"%@%@", linked, linked = [NSString stringWithFormat: @"%@%@", linked,
[item substringWithRange: NSMakeRange(goodRange.location+goodRange.length, [item substringWithRange:
NSMakeRange(goodRange.location+goodRange.length,
[item length]-(goodRange.location+goodRange.length))]]; [item length]-(goodRange.location+goodRange.length))]];
} }
} }
@ -3895,22 +3916,37 @@ withExternalCompleteRef: (NSString *)externalCompleteRef
if ([common length] > 0) if ([common length] > 0)
{ {
int i = 0; int i = 0;
NSMutableArray *locationParts = [[[locationTmp componentsSeparatedByString: @"/"] mutableCopy] autorelease]; NSMutableArray *locationParts;
NSMutableArray *symbolLocationParts = [[[symbolLocation componentsSeparatedByString: @"/"] mutableCopy] autorelease]; NSMutableArray *symbolLocationParts;
locationParts
= [[locationTmp componentsSeparatedByString: @"/"]
mutableCopy];
AUTORELEASE(locationParts);
symbolLocationParts
= [[symbolLocation componentsSeparatedByString: @"/"]
mutableCopy];
AUTORELEASE(symbolLocationParts);
[locationParts removeLastObject]; [locationParts removeLastObject];
[symbolLocationParts removeLastObject]; [symbolLocationParts removeLastObject];
while ([locationParts count] > 0 while ([locationParts count] > 0
&& [symbolLocationParts count] > 0 && [symbolLocationParts count] > 0
&& [[locationParts objectAtIndex: 0] isEqual: [symbolLocationParts objectAtIndex: 0]]) && [[locationParts objectAtIndex: 0] isEqual:
[symbolLocationParts objectAtIndex: 0]])
{ {
[locationParts removeObjectAtIndex: 0]; [locationParts removeObjectAtIndex: 0];
[symbolLocationParts removeObjectAtIndex: 0]; [symbolLocationParts removeObjectAtIndex: 0];
} }
prefix = [NSString string]; prefix = [NSString string];
for (i = 0; i < [locationParts count]; i++) for (i = 0; i < [locationParts count]; i++)
{
prefix = [@".." stringByAppendingPathComponent: prefix]; prefix = [@".." stringByAppendingPathComponent: prefix];
}
for (i = 0; i < [symbolLocationParts count]; i++) for (i = 0; i < [symbolLocationParts count]; i++)
prefix = [prefix stringByAppendingPathComponent: [symbolLocationParts objectAtIndex: i]]; {
prefix = [prefix stringByAppendingPathComponent:
[symbolLocationParts objectAtIndex: i]];
}
} }
else else
prefix = ([symbolLocation length] > 0 ? symbolLocation : @""); prefix = ([symbolLocation length] > 0 ? symbolLocation : @"");
@ -3968,7 +4004,7 @@ NSArray *
FilesFromSymbols(NSDictionary *symbols) FilesFromSymbols(NSDictionary *symbols)
{ {
NSArray *sortedFiles = nil; NSArray *sortedFiles = nil;
NSMutableArray *files = [[NSMutableArray new] autorelease]; NSMutableArray *files = [NSMutableArray arrayWithCapacity: 2];
NSEnumerator *typesEnumerator = [symbols keyEnumerator]; NSEnumerator *typesEnumerator = [symbols keyEnumerator];
id typeKey = nil; id typeKey = nil;
@ -3991,8 +4027,10 @@ FilesFromSymbols(NSDictionary *symbols)
return sortedFiles; return sortedFiles;
} }
//-------------------------------------------------------------------- /*
// Return list of files found in dir (deep search) which have extension extension * Return list of files found in dir (deep search) which have
* extension extension
*/
NSArray * NSArray *
FilesInPathWithExtension(NSString *dir, NSString *extension) FilesInPathWithExtension(NSString *dir, NSString *extension)
{ {
@ -4033,8 +4071,7 @@ AddSymbolsToReferencesWithProjectInfo(NSDictionary *symbols,
id typeKey = nil; id typeKey = nil;
NSCAssert1([symbols isKindOfClass: [NSDictionary class]], NSCAssert1([symbols isKindOfClass: [NSDictionary class]],
@"%@ is not a dictionary", @"%@ is not a dictionary", symbols);
symbols);
typesEnumerator = [symbols keyEnumerator]; typesEnumerator = [symbols keyEnumerator];
while ((typeKey = [typesEnumerator nextObject]) != nil) while ((typeKey = [typesEnumerator nextObject]) != nil)
{ {
@ -4095,20 +4132,28 @@ AddSymbolsToReferencesWithProjectInfo(NSDictionary *symbols,
} }
if (projectName) if (projectName)
{ {
NSString *symbolType = [symbolNew objectForKey: @"type"]; NSString *symbolType
= [symbolNew objectForKey: @"type"];
if ([symbolType isEqual: @"file"]) if ([symbolType isEqual: @"file"])
{ {
NSString *fileName = [symbolNew objectForKey: @"fileName"]; NSString *fileName
= [symbolNew objectForKey: @"fileName"];
if (fileName) if (fileName)
{ {
NSString *fileRef = nil; NSString *fileRef = nil;
fileName = [fileName stringByDeletingPathExtension];
fileRef = [NSString stringWithFormat: @"%@##%@", fileName
projectName, = [fileName stringByDeletingPathExtension];
fileName]; fileRef
= [NSString stringWithFormat: @"%@##%@",
projectName, fileName];
[symbolNew setObject: fileRef [symbolNew setObject: fileRef
forKey: @"completeRef"]; forKey: @"completeRef"];
if (override || ![referencesType objectForKey: fileRef]) if (override
|| ![referencesType objectForKey: fileRef])
{
[referencesType setObject: symbolNew [referencesType setObject: symbolNew
forKey: fileRef]; forKey: fileRef];
} }
@ -4119,11 +4164,15 @@ AddSymbolsToReferencesWithProjectInfo(NSDictionary *symbols,
} }
} }
} }
}
if (projectName) if (projectName)
{ {
NSString *fileName = [[projectInfo objectForKey: @"indexfileName"]stringByDeletingPathExtension]; NSString *fileName
= [[projectInfo objectForKey: @"indexfileName"]
stringByDeletingPathExtension];
NSString *fileRef = nil; NSString *fileRef = nil;
NSMutableDictionary *referencesType = [references objectForKey: @"file"]; NSMutableDictionary *referencesType = [references objectForKey: @"file"];
if (!referencesType) if (!referencesType)
{ {
referencesType = [NSMutableDictionary dictionary]; referencesType = [NSMutableDictionary dictionary];
@ -4131,58 +4180,60 @@ AddSymbolsToReferencesWithProjectInfo(NSDictionary *symbols,
forKey: @"file"]; forKey: @"file"];
} }
if (!fileName) if (!fileName)
{
fileName = @"index"; fileName = @"index";
fileRef = [NSString stringWithFormat: @"%@##%@", }
projectName, fileRef = [NSString stringWithFormat: @"%@##%@", projectName, fileName];
fileName];
if (override || ![referencesType objectForKey: fileRef]) if (override || ![referencesType objectForKey: fileRef])
{ {
NSMutableDictionary *symbol = [NSMutableDictionary dictionaryWithObjectsAndKeys: NSMutableDictionary *symbol
= [NSMutableDictionary dictionaryWithObjectsAndKeys:
fileRef, @"completeRef", fileRef, @"completeRef",
fileName, @"fileName", fileName, @"fileName",
fileName, @"ref", fileName, @"ref",
@"file", @"type", @"file", @"type",
nil]; nil];
if (projectInfo) if (projectInfo)
{
[symbol setObject: projectInfo [symbol setObject: projectInfo
forKey: @"project"]; forKey: @"project"];
}
[referencesType setObject: symbol [referencesType setObject: symbol
forKey: fileRef]; forKey: fileRef];
} }
} }
} }
//-------------------------------------------------------------------- int
int main(int argc, char **argv, char **env) main(int argc, char **argv, char **env)
{ {
NSAutoreleasePool *pool;
NSProcessInfo *proc; NSProcessInfo *proc;
NSArray *args; NSArray *args;
unsigned i; unsigned i;
NSUserDefaults *defs; NSUserDefaults *defs;
NSString *makeRefsFileName = nil; // makeRefs file name NSString *makeRefsFileName = nil;
NSString *projectName = nil; // project Name NSString *projectName = nil;
NSMutableArray *files = nil; // Files to parse NSMutableArray *files = nil;
NSMutableArray *references = nil; // Array of References files/directories NSMutableArray *references = nil;
NSMutableDictionary *generalReferences = nil; // References (information coming from references files/directories) NSMutableDictionary *generalReferences = nil;
NSMutableDictionary *projectReferences = nil; // Project References (references founds by parsing files) NSMutableDictionary *projectReferences = nil;
NSString *makeIndexBaseFileName = nil; // makeIndex file name NSString *makeIndexBaseFileName = nil;
NSString *makeIndexFileNameGSDoc = nil; // makeIndex file name with gsdoc extension NSString *makeIndexFileNameGSDoc = nil;
NSString *makeIndexTemplateFileName = nil; // makeIndex template file name NSString *makeIndexTemplateFileName = nil;
NSMutableDictionary *infoDictionary = nil; // user info NSMutableDictionary *infoDictionary = nil;
NSDictionary *variablesDictionary = nil; // variables dictionary NSDictionary *variablesDictionary = nil;
NSMutableDictionary *projectInfo = nil; // Information On Project NSMutableDictionary *projectInfo = nil;
BOOL goOn = YES; BOOL goOn = YES;
NSFileManager *fileManager = nil; NSFileManager *fileManager = nil;
CREATE_AUTORELEASE_POOL(pool);
#ifdef GS_PASS_ARGUMENTS #ifdef GS_PASS_ARGUMENTS
[NSProcessInfo initializeWithArguments: argv count: argc environment: env]; [NSProcessInfo initializeWithArguments: argv count: argc environment: env];
#endif #endif
pool = [NSAutoreleasePool new];
defs = [NSUserDefaults standardUserDefaults]; defs = [NSUserDefaults standardUserDefaults];
[defs registerDefaults: [NSDictionary dictionaryWithObjectsAndKeys: [defs registerDefaults: [NSDictionary dictionaryWithObjectsAndKeys:
@"Yes", @"Monolithic", @"Yes", @"Monolithic", nil]];
nil]];
proc = [NSProcessInfo processInfo]; proc = [NSProcessInfo processInfo];
if (proc == nil) if (proc == nil)
@ -4192,7 +4243,7 @@ int main(int argc, char **argv, char **env)
} }
fileManager = [NSFileManager defaultManager]; fileManager = [NSFileManager defaultManager];
if (goOn) if (goOn == YES)
{ {
args = [proc arguments]; args = [proc arguments];
@ -4203,56 +4254,80 @@ int main(int argc, char **argv, char **env)
// is this an option ? // is this an option ?
if ([arg hasPrefix: @"--"]) if ([arg hasPrefix: @"--"])
{ {
NSString *argWithoutPrefix = [arg stringWithoutPrefix: @"--"]; NSString *argWithoutPrefix;
NSString *key = nil; NSString *value;
NSString *value = nil; NSString *key;
NSArray *parts = [argWithoutPrefix componentsSeparatedByString: @"="]; NSArray *parts;
argWithoutPrefix = [arg stringWithoutPrefix: @"--"];
parts = [argWithoutPrefix componentsSeparatedByString: @"="];
key = [parts objectAtIndex: 0]; key = [parts objectAtIndex: 0];
if ([parts count] > 1) if ([parts count] > 1)
value = [[parts subarrayWithRange: NSMakeRange(1, [parts count]-1)] componentsJoinedByString: @"="]; {
NSRange r = NSMakeRange(1, [parts count]-1);
NSArray *sub = [parts subarrayWithRange: r];
value = [sub componentsJoinedByString: @"="];
}
else
{
value = nil;
}
// makeRefs option // makeRefs option
if ([key isEqualToString: @"makeRefs"]) if ([key isEqualToString: @"makeRefs"])
{ {
makeRefsFileName = value; makeRefsFileName = value;
if (makeRefsFileName) if (makeRefsFileName != nil)
{ {
if (![[makeRefsFileName pathExtension] isEqual: pathExtension_GSDocRefs]) NSString *ext = [makeRefsFileName pathExtension];
makeRefsFileName = [makeRefsFileName stringByAppendingPathExtension: pathExtension_GSDocRefs];
if ([ext isEqual: pathExtension_GSDocRefs] == NO)
{
makeRefsFileName = [makeRefsFileName
stringByAppendingPathExtension:
pathExtension_GSDocRefs];
}
} }
else else
{
makeRefsFileName = @""; makeRefsFileName = @"";
} }
// projectName option }
else if ([key isEqualToString: @"projectName"]) else if ([key isEqualToString: @"projectName"])
{ {
projectName = value; projectName = value;
NSCAssert([projectName length], @"No project name"); NSCAssert([projectName length], @"No project name");
} }
// refs option
else if ([key isEqualToString: @"refs"]) else if ([key isEqualToString: @"refs"])
{ {
if (!references) if (references == nil)
references = [[NSMutableArray new] autorelease]; {
references = [NSMutableArray arrayWithCapacity: 4];
}
NSCAssert([value length], @"No index"); NSCAssert([value length], @"No index");
[references addObject: value]; [references addObject: value];
} }
// makeIndex option
else if ([key isEqualToString: @"makeIndex"]) else if ([key isEqualToString: @"makeIndex"])
{ {
makeIndexBaseFileName = value; makeIndexBaseFileName = value;
if (makeIndexBaseFileName) if (makeIndexBaseFileName != nil)
makeIndexBaseFileName = [makeIndexBaseFileName stringByDeletingPathExtension]; {
makeIndexBaseFileName
= [makeIndexBaseFileName stringByDeletingPathExtension];
}
else else
{
makeIndexBaseFileName = @"index"; makeIndexBaseFileName = @"index";
} }
// makeIndexTemplate option }
else if ([key isEqualToString: @"makeIndexTemplate"]) else if ([key isEqualToString: @"makeIndexTemplate"])
{ {
makeIndexTemplateFileName = value; makeIndexTemplateFileName = value;
NSCAssert([makeIndexTemplateFileName length], @"No makeIndexTemplate filename"); NSCAssert([makeIndexTemplateFileName length],
@"No makeIndexTemplate filename");
} }
// Verbose
else if ([key hasPrefix: @"verbose"]) else if ([key hasPrefix: @"verbose"])
{ {
NSCAssert1(value, @"No value for %@", key); NSCAssert1(value, @"No value for %@", key);
@ -4263,48 +4338,54 @@ int main(int argc, char **argv, char **env)
[debugSet addObject: @"dflt"]; [debugSet addObject: @"dflt"];
} }
} }
// Location
else if ([key hasPrefix: @"location"]) else if ([key hasPrefix: @"location"])
{ {
NSCAssert1(value, @"No value for %@", key); NSCAssert1(value, @"No value for %@", key);
location = value; location = value;
} }
// define option
else if ([key hasPrefix: @"define-"]) else if ([key hasPrefix: @"define-"])
{ {
if (!infoDictionary) if (infoDictionary == nil)
{
infoDictionary = [NSMutableDictionary dictionary]; infoDictionary = [NSMutableDictionary dictionary];
}
NSCAssert1(value, @"No value for %@", key); NSCAssert1(value, @"No value for %@", key);
[infoDictionary setObject: value [infoDictionary setObject: value
forKey: [key stringWithoutPrefix: @"define-"]]; forKey: [key stringWithoutPrefix: @"define-"]];
} }
// unknown option
else else
{ {
NSLog(@"Unknown option %@", arg); NSLog(@"Unknown option %@", arg);
goOn = NO; goOn = NO;
} }
} }
// file to parse
else else
{ {
if (!files) if (files == nil)
files = [NSMutableArray array]; files = [NSMutableArray array];
//FIXME /*
//Dirty Hack to handle *.gsdoc and * * FIXME
//We need this because sometimes, there is too much files for commande line * Dirty Hack to handle *.gsdoc and *
if ([[arg lastPathComponent] hasSuffix: [NSString stringWithFormat: @"*.%@", pathExtension_GSDoc]] * We need this because sometimes, there are too many files
* for commande line
*/
if ([[arg lastPathComponent] hasSuffix:
[NSString stringWithFormat: @"*.%@", pathExtension_GSDoc]]
|| [[arg lastPathComponent]hasSuffix: @"*"]) || [[arg lastPathComponent]hasSuffix: @"*"])
{ {
NSArray *dirContent = nil; NSArray *dirContent = nil;
int ifile = 0; int ifile = 0;
arg = [arg stringByDeletingLastPathComponent]; arg = [arg stringByDeletingLastPathComponent];
if ([arg length] == 0) if ([arg length] == 0)
{
arg = [fileManager currentDirectoryPath]; arg = [fileManager currentDirectoryPath];
}
dirContent = [fileManager directoryContentsAtPath: arg]; dirContent = [fileManager directoryContentsAtPath: arg];
for (ifile = 0; ifile < [dirContent count]; ifile++) for (ifile = 0; ifile < [dirContent count]; ifile++)
{ {
NSString *file = [dirContent objectAtIndex: ifile]; NSString *file = [dirContent objectAtIndex: ifile];
if ([[file pathExtension] isEqual: pathExtension_GSDoc]) if ([[file pathExtension] isEqual: pathExtension_GSDoc])
{ {
[files addObject: file]; [files addObject: file];
@ -4312,20 +4393,30 @@ int main(int argc, char **argv, char **env)
} }
} }
else else
{
[files addObject: arg]; [files addObject: arg];
} }
} }
} }
}
//Default Values //Default Values
if (goOn) if (goOn)
{ {
if (!projectName) if (projectName == nil)
{
projectName = @"unknown"; projectName = @"unknown";
}
if ([makeRefsFileName length]== 0) if ([makeRefsFileName length]== 0)
makeRefsFileName = [projectName stringByAppendingPathExtension: pathExtension_GSDocRefs]; {
if (makeIndexBaseFileName) makeRefsFileName = [projectName
makeIndexFileNameGSDoc = [makeIndexBaseFileName stringByAppendingPathExtension: pathExtension_GSDoc]; stringByAppendingPathExtension: pathExtension_GSDocRefs];
}
if (makeIndexBaseFileName != nil)
{
makeIndexFileNameGSDoc = [makeIndexBaseFileName
stringByAppendingPathExtension: pathExtension_GSDoc];
}
} }
// Verify option compatibilities // Verify option compatibilities
@ -4338,46 +4429,51 @@ int main(int argc, char **argv, char **env)
{ {
BOOL addedSymbols = NO; BOOL addedSymbols = NO;
NSDictionary *previousProjectReferences = nil; NSDictionary *previousProjectReferences = nil;
NSDebugFLLog(@"debug", @"Construct project references"); NSDebugFLLog(@"debug", @"Construct project references");
projectReferences = [[NSMutableDictionary new] autorelease]; projectReferences = [NSMutableDictionary dictionaryWithCapacity: 2];
[projectReferences setObject: [[NSMutableDictionary new] autorelease] [projectReferences
setObject: [NSMutableDictionary dictionaryWithCapacity: 2]
forKey: @"symbols"]; forKey: @"symbols"];
projectInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: projectInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
projectName, @"projectName", projectName, @"projectName", nil];
nil]; if (location != nil)
if (location) {
[projectInfo setObject: location forKey: @"location"]; [projectInfo setObject: location forKey: @"location"];
if (makeIndexBaseFileName) }
[projectInfo setObject: makeIndexBaseFileName forKey: @"indexfileName"]; if (makeIndexBaseFileName != nil)
{
[projectInfo setObject: makeIndexBaseFileName
forKey: @"indexfileName"];
}
//Read project existing references //Read project existing references
if (makeRefsFileName) if (makeRefsFileName != nil)
{ {
BOOL isDirectory = NO; BOOL isDirectory = NO;
if ([fileManager fileExistsAtPath: makeRefsFileName if ([fileManager fileExistsAtPath: makeRefsFileName
isDirectory: &isDirectory]) isDirectory: &isDirectory])
{ {
if (!isDirectory) if (isDirectory == NO)
{ {
previousProjectReferences = [NSDictionary dictionaryWithContentsOfFile: makeRefsFileName]; previousProjectReferences = [NSDictionary
if (previousProjectReferences && [previousProjectReferences objectForKey: @"symbols"]) dictionaryWithContentsOfFile: makeRefsFileName];
if ([previousProjectReferences objectForKey: @"symbols"])
{ {
AddSymbolsToReferencesWithProjectInfo([previousProjectReferences objectForKey: @"symbols"], AddSymbolsToReferencesWithProjectInfo(
[previousProjectReferences objectForKey: @"symbols"],
[projectReferences objectForKey: @"symbols"], [projectReferences objectForKey: @"symbols"],
projectInfo, projectInfo, NO);
NO);
addedSymbols = YES; addedSymbols = YES;
} }
} }
} }
} }
if (!addedSymbols) if (addedSymbols == NO)
{ {
AddSymbolsToReferencesWithProjectInfo(nil, AddSymbolsToReferencesWithProjectInfo(nil,
[projectReferences objectForKey: @"symbols"], [projectReferences objectForKey: @"symbols"], projectInfo, NO);
projectInfo,
NO);
} }
} }
@ -4385,15 +4481,20 @@ int main(int argc, char **argv, char **env)
if (goOn) if (goOn)
{ {
NSDebugFLLog(@"debug", @"Process references"); NSDebugFLLog(@"debug", @"Process references");
generalReferences = [[NSMutableDictionary new] autorelease]; generalReferences = [NSMutableDictionary dictionaryWithCapacity: 2];
if ([references count] > 0) if ([references count] > 0)
{ {
// From last to first so references are taken in first to last priority /*
while(goOn && [references count]) * From last to first so references are taken in
* first to last priority
*/
while (goOn && [references count] > 0)
{ {
NSString *file = [references lastObject]; NSString *file = [references lastObject];
BOOL isDirectory = NO; BOOL isDirectory = NO;
if (![fileManager fileExistsAtPath: file isDirectory: &isDirectory])
if (![fileManager fileExistsAtPath: file
isDirectory: &isDirectory])
{ {
NSLog(@"Index File %@ doesn't exist", file); NSLog(@"Index File %@ doesn't exist", file);
[references removeLastObject]; [references removeLastObject];
@ -4402,7 +4503,11 @@ int main(int argc, char **argv, char **env)
{ {
if (isDirectory) if (isDirectory)
{ {
NSArray *tmpReferences = FilesInPathWithExtension(file, pathExtension_GSDocRefs); NSArray *tmpReferences;
tmpReferences = FilesInPathWithExtension(file,
pathExtension_GSDocRefs);
if (verbose >= 3) if (verbose >= 3)
{ {
NSLog(@"Processing references directory %@", file); NSLog(@"Processing references directory %@", file);
@ -4413,11 +4518,13 @@ int main(int argc, char **argv, char **env)
else else
{ {
NSDictionary *generalIndexTmp = nil; NSDictionary *generalIndexTmp = nil;
if (verbose >= 2) if (verbose >= 2)
{ {
NSLog(@"Processing references file %@", file); NSLog(@"Processing references file %@", file);
} }
generalIndexTmp = [NSDictionary dictionaryWithContentsOfFile: file]; generalIndexTmp = [NSDictionary
dictionaryWithContentsOfFile: file];
if (!generalIndexTmp) if (!generalIndexTmp)
{ {
NSLog(@"File %@ isn't a dictionary", file); NSLog(@"File %@ isn't a dictionary", file);
@ -4425,14 +4532,18 @@ int main(int argc, char **argv, char **env)
} }
else else
{ {
NSDictionary *fileProjectInfo = [generalIndexTmp objectForKey: @"project"]; NSDictionary *fileProjectInfo;
NSDictionary *symbols = [generalIndexTmp objectForKey: @"symbols"]; NSDictionary *symbols;
NSCAssert1(fileProjectInfo, @"No Project Info in %@", file);
fileProjectInfo
= [generalIndexTmp objectForKey: @"project"];
symbols = [generalIndexTmp objectForKey: @"symbols"];
NSCAssert1(fileProjectInfo,
@"No Project Info in %@", file);
NSCAssert1(symbols, @"No symbols %@", file); NSCAssert1(symbols, @"No symbols %@", file);
AddSymbolsToReferencesWithProjectInfo(symbols, AddSymbolsToReferencesWithProjectInfo(symbols,
generalReferences, generalReferences, fileProjectInfo, YES);
fileProjectInfo,
YES);
} }
[references removeLastObject]; [references removeLastObject];
} }
@ -4443,15 +4554,21 @@ int main(int argc, char **argv, char **env)
//Variables //Variables
if (goOn) if (goOn)
{ {
NSMutableDictionary *variablesMutableDictionary = [NSMutableDictionary dictionary]; NSMutableDictionary *variablesMutableDictionary;
NSEnumerator *enumer = [infoDictionary keyEnumerator]; NSEnumerator *enumer;
id key = nil; id key = nil;
variablesMutableDictionary = [NSMutableDictionary dictionary];
enumer = [infoDictionary keyEnumerator];
NSDebugFLLog(@"debug", @"Variables"); NSDebugFLLog(@"debug", @"Variables");
while ((key = [enumer nextObject])) while ((key = [enumer nextObject]))
{ {
id value = [infoDictionary objectForKey: key]; id v;
[variablesMutableDictionary setObject: value NSString *k;
forKey: [NSString stringWithFormat: @"[[infoDictionary.%@]]", key]];
v = [infoDictionary objectForKey: key];
k = [NSString stringWithFormat: @"[[infoDictionary.%@]]", key];
[variablesMutableDictionary setObject: v forKey: k];
} }
[variablesMutableDictionary setObject: [NSCalendarDate calendarDate] [variablesMutableDictionary setObject: [NSCalendarDate calendarDate]
forKey: @"[[timestampString]]"]; forKey: @"[[timestampString]]"];
@ -4462,20 +4579,23 @@ int main(int argc, char **argv, char **env)
[variablesMutableDictionary setObject: makeIndexBaseFileName [variablesMutableDictionary setObject: makeIndexBaseFileName
forKey: @"[[indexBaseFileName]]"]; forKey: @"[[indexBaseFileName]]"];
} }
if (projectName) if (projectName != nil)
{
[variablesMutableDictionary setObject: projectName [variablesMutableDictionary setObject: projectName
forKey: @"[[projectName]]"]; forKey: @"[[projectName]]"];
variablesDictionary = [[variablesMutableDictionary copy] autorelease]; }
variablesDictionary = [variablesMutableDictionary copy];
AUTORELEASE(variablesDictionary);
if (verbose >= 3) if (verbose >= 3)
{ {
NSEnumerator *enumer = [variablesDictionary keyEnumerator]; NSEnumerator *enumer = [variablesDictionary keyEnumerator];
id key = nil; id key = nil;
while ((key = [enumer nextObject])) while ((key = [enumer nextObject]))
{ {
NSLog(@"Variables: %@=%@", NSLog(@"Variables: %@=%@",
key, key, [variablesDictionary objectForKey: key]);
[variablesDictionary objectForKey: key]);
} }
} }
} }
@ -4492,11 +4612,14 @@ int main(int argc, char **argv, char **env)
else else
{ {
NSMutableArray *tmpNewFiles = [NSMutableArray array]; NSMutableArray *tmpNewFiles = [NSMutableArray array];
for (i = 0; goOn && i < [files count]; i++) for (i = 0; goOn && i < [files count]; i++)
{ {
NSString *file = [files objectAtIndex: i]; NSString *file = [files objectAtIndex: i];
BOOL isDirectory = NO; BOOL isDirectory = NO;
if (![fileManager fileExistsAtPath: file isDirectory: &isDirectory])
if (![fileManager fileExistsAtPath: file
isDirectory: &isDirectory])
{ {
NSLog(@"File %@ doesn't exist", file); NSLog(@"File %@ doesn't exist", file);
goOn = NO; goOn = NO;
@ -4505,7 +4628,10 @@ int main(int argc, char **argv, char **env)
{ {
if (isDirectory) if (isDirectory)
{ {
NSArray *tmpFiles = FilesInPathWithExtension(file, pathExtension_GSDoc); NSArray *tmpFiles;
tmpFiles
= FilesInPathWithExtension(file, pathExtension_GSDoc);
[tmpNewFiles addObjectsFromArray: tmpFiles]; [tmpNewFiles addObjectsFromArray: tmpFiles];
} }
else else
@ -4514,32 +4640,38 @@ int main(int argc, char **argv, char **env)
} }
} }
} }
files = tmpNewFiles; files = [[tmpNewFiles sortedArrayUsingSelector: @selector(compare:)]
files =(NSMutableArray *)[files sortedArrayUsingSelector: @selector(compare:)]; mutableCopy];
AUTORELEASE(files);
} }
} }
if (goOn) if (goOn)
{ {
int pass = 0; int pass = 0;
NSDebugFLLog(@"debug", @"Parse Files"); NSDebugFLLog(@"debug", @"Parse Files");
//1st pass: don't write file, just parse them and construct project references /*
//2nd pass: parse and write files * 1st pass: don't write file, just parse them and
* construct project references
* 2nd pass: parse and write files
*/
for (pass = 0; goOn && pass < 2; pass++) for (pass = 0; goOn && pass < 2; pass++)
{ {
for (i = 0; goOn && i < [files count]; i++) for (i = 0; goOn && i < [files count]; i++)
{ {
NSString *file = [files objectAtIndex: i]; NSString *file = [files objectAtIndex: i];
NSAutoreleasePool *arp = [NSAutoreleasePool new]; NSString *base = [file stringByDeletingPathExtension];
if ([[file stringByDeletingPathExtension] isEqual: makeIndexBaseFileName])//Don't process generated index file CREATE_AUTORELEASE_POOL(arp);
// Don't process generated index file
if ([base isEqual: makeIndexBaseFileName])
{ {
if (verbose >= 1) if (verbose >= 1)
{ {
NSLog(@"Pass %d/2 File %d/%d - Ignoring Index File %@ (Process it later)", NSLog(@"Pass %d/2 File %d/%d - Ignoring Index File "
(pass+1), @"%@ (Process it later)",
(i+1), (pass+1), (i+1), [files count], file);
[files count],
file);
} }
} }
else else
@ -4547,68 +4679,79 @@ int main(int argc, char **argv, char **env)
if (verbose >= 1) if (verbose >= 1)
{ {
NSLog(@"Pass %d/2 File %d/%d - Processing %@", NSLog(@"Pass %d/2 File %d/%d - Processing %@",
(pass+1), (pass+1), (i+1), [files count], file);
(i+1),
[files count],
file);
} }
NS_DURING NS_DURING
{ {
GSDocHtml *p = nil; GSDocHtml *p = nil;
p = [GSDocHtml alloc]; p = [GSDocHtml alloc];
p = [p initWithFileName: file]; p = [p initWithFileName: file];
if (p != nil) if (p != nil)
{ {
NSString *previousFile =((i> 0) ? [files objectAtIndex: i-1] : @""); NSString *previousFile;
NSString *nextFile =(((i+1)< [files count]) ? [files objectAtIndex: i+1] : @""); NSString *nextFile;
NSMutableDictionary *variablesMutableDictionary = nil; NSMutableDictionary *vmDictionary;
NSString *result = nil; NSString *result;
previousFile = ((i > 0) ? [files objectAtIndex: i-1]
: @"");
nextFile = (((i+1) < [files count])
? [files objectAtIndex: i+1] : @"");
vmDictionary = nil;
result = nil;
[p setProjectName: projectName]; [p setProjectName: projectName];
[p setGeneralReferences: generalReferences]; [p setGeneralReferences: generalReferences];
variablesMutableDictionary = [variablesDictionary mutableCopy]; vmDictionary = [variablesDictionary mutableCopy];
[variablesMutableDictionary setObject: [previousFile stringByDeletingPathExtension] [vmDictionary setObject:
[previousFile stringByDeletingPathExtension]
forKey: @"[[prev]]"]; forKey: @"[[prev]]"];
[variablesMutableDictionary setObject: [nextFile stringByDeletingPathExtension] [vmDictionary setObject:
[nextFile stringByDeletingPathExtension]
forKey: @"[[next]]"]; forKey: @"[[next]]"];
if (makeIndexBaseFileName) if (makeIndexBaseFileName)
[variablesMutableDictionary setObject: makeIndexBaseFileName {
forKey: @"[[up]]"]; [vmDictionary setObject:
[p setVariablesDictionary: variablesMutableDictionary]; makeIndexBaseFileName forKey: @"[[up]]"];
}
[p setVariablesDictionary: vmDictionary];
[p setWriteFlag: (pass == 1)]; [p setWriteFlag: (pass == 1)];
[p setProcessFileReferencesFlag: (pass == 0)]; [p setProcessFileReferencesFlag: (pass == 0)];
result = [p parseDocument]; result = [p parseDocument];
if (result == nil) if (result == nil)
{ {
NSLog(@"Pass %d/2 File %d/%d - Error parsing %@", NSLog(@"Pass %d/2 File %d/%d - Error parsing %@",
(pass+1), (pass+1), (i+1), [files count], file);
(i+1),
[files count],
file);
goOn = NO; goOn = NO;
} }
else else
{ {
if (verbose >= 1) if (verbose >= 1)
{ {
NSLog(@"Pass %d/2 File %d/%d - Parsed %@ - OK", NSLog(@"Pass %d/2 File %d/%d"
(pass+1), @" - Parsed %@ - OK",
(i+1), (pass+1), (i+1), [files count], file);
[files count],
file);
} }
if (pass == 0) if (pass == 0)
{ {
NSDebugFLLog(@"debug", @"AddSymbolsToReferencesWithProjectInfo -> projectRefernce"); NSDebugFLLog(@"debug",
AddSymbolsToReferencesWithProjectInfo([p fileReferences], @"AddSymbolsToReferencesWithProjectInfo ->"
[projectReferences objectForKey: @"symbols"], @" projectRefernce");
nil, AddSymbolsToReferencesWithProjectInfo(
NO); [p fileReferences],
NSDebugFLLog(@"debug", @"AddSymbolsToReferencesWithProjectInfo -> generalReference"); [projectReferences
AddSymbolsToReferencesWithProjectInfo([p fileReferences], objectForKey: @"symbols"],
generalReferences, nil, NO);
projectInfo, NSDebugFLLog(@"debug",
YES); @"AddSymbolsToReferencesWithProjectInfo ->"
NSDebugFLLog(@"debug", @"AddSymbolsToReferencesWithProjectInfo finished"); @" generalReference");
AddSymbolsToReferencesWithProjectInfo(
[p fileReferences], generalReferences,
projectInfo, YES);
NSDebugFLLog(@"debug",
@"AddSymbolsToReferencesWithProjectInfo "
@"finished");
} }
} }
RELEASE(p); RELEASE(p);
@ -4865,7 +5008,7 @@ int main(int argc, char **argv, char **env)
NS_ENDHANDLER; NS_ENDHANDLER;
} }
} }
[pool release]; RELEASE(pool);
return (goOn ? 0 : 1); return (goOn ? 0 : 1);
} }