From: <ho...@us...> - 2006-03-20 15:25:11
|
Revision: 5911 Author: hofman Date: 2006-03-20 07:24:57 -0800 (Mon, 20 Mar 2006) ViewCVS: http://svn.sourceforge.net/bibdesk/?rev=5911&view=rev Log Message: ----------- Check for circular macro definitions. Modified Paths: -------------- trunk/bibdesk/BibTeXParser.m Modified: trunk/bibdesk/BibTeXParser.m =================================================================== --- trunk/bibdesk/BibTeXParser.m 2006-03-20 15:11:19 UTC (rev 5910) +++ trunk/bibdesk/BibTeXParser.m 2006-03-20 15:24:57 UTC (rev 5911) @@ -64,6 +64,9 @@ // becomes an autoreleased array of dicts of different types. static NSString *stringFromBTField(AST *field, NSString *fieldName, NSString *filePath, id <BDSKMacroResolver> theDocument, NSStringEncoding parserEncoding); +// private function to check if a macro definition leads to a circular definition. +static BOOL isCircularMacro(NSString *macroKey, NSString *macroString, id <BDSKMacroResolver> document); + @end @implementation BibTeXParser @@ -166,7 +169,10 @@ NSString *macroKey = [NSString stringWithCString: field->text usingEncoding:parserEncoding]; NSString *macroString = stringFromBTField(field, sFieldName, filePath, aDocument, parserEncoding); // handles TeXification id macroResolver = (aDocument) ? aDocument : [BDSKGlobalMacroResolver defaultMacroResolver]; - [macroResolver addMacroDefinitionWithoutUndo:macroString forMacro:macroKey]; + if(isCircularMacro(macroKey, macroString, macroResolver)) + NSLog(@"Macro leads to circular definition, ignored: %@ = %@", macroKey, [macroString stringAsBibTeXString]); + else + [macroResolver addMacroDefinitionWithoutUndo:macroString forMacro:macroKey]; }else if(frontMatter && [entryType isEqualToString:@"comment"]){ NSMutableString *commentStr = [[NSMutableString alloc] init]; @@ -338,7 +344,10 @@ field = bt_next_field(entry, NULL, &fieldName); macroKey = [NSString stringWithCString: field->text usingEncoding:NSUTF8StringEncoding]; macroString = stringFromBTField(field, nil, @"Paste/Drag", aDocument, NSUTF8StringEncoding); // handles TeXification - [retDict setObject:macroString forKey:macroKey]; + if(isCircularMacro(macroKey, macroString, aDocument)) + NSLog(@"Macro leads to circular definition, ignored: %@ = %@", macroKey, [macroString stringAsBibTeXString]); + else + [retDict setObject:macroString forKey:macroKey]; bt_free_ast(entry); entry = NULL; @@ -383,7 +392,7 @@ + (NSDictionary *)macrosFromBibTeXStyle:(NSString *)styleContents document:(BibDocument *)aDocument{ [[BDSKErrorObjectController sharedErrorObjectController] setDocumentForErrors:aDocument]; - id macroResolver = (aDocument) ? aDocument : [BDSKGlobalMacroResolver defaultMacroResolver]; + id macroResolver = (aDocument) ? (id <BDSKMacroResolver>)aDocument : [BDSKGlobalMacroResolver defaultMacroResolver]; NSScanner *scanner = [[NSScanner alloc] initWithString:styleContents]; [scanner setCharactersToBeSkipped:nil]; @@ -444,8 +453,12 @@ [value removeSurroundingWhitespace]; - [bstMacros setObject:[NSString complexStringWithBibTeXString:value macroResolver:macroResolver] - forKey:[key stringByRemovingSurroundingWhitespace]]; + key = [key stringByRemovingSurroundingWhitespace]; + value = [NSString complexStringWithBibTeXString:value macroResolver:macroResolver]; + if(isCircularMacro(key, value, macroResolver)) + NSLog(@"Macro leads to circular definition, ignored: %@ = %@", key, [value stringAsBibTeXString]); + else + [bstMacros setObject:value forKey:key]; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |