mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-04-23 14:30:48 +00:00
Correction for index out of range issue.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@19873 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7f5c027157
commit
e3f19322e9
2 changed files with 16 additions and 269 deletions
13
Gorm.m
13
Gorm.m
|
@ -1313,11 +1313,16 @@ NSString *GormResizeCellNotification = @"GormResizeCellNotification";
|
|||
}
|
||||
else if (sel_eq(action, @selector(paste:)))
|
||||
{
|
||||
id o = [s objectAtIndex: 0];
|
||||
NSString *n = [active nameForObject: o];
|
||||
if ([n isEqual: @"NSOwner"] || [n isEqual: @"NSFirst"])
|
||||
if ([s count] == 0)
|
||||
return NO;
|
||||
else
|
||||
{
|
||||
return NO;
|
||||
id o = [s objectAtIndex: 0];
|
||||
NSString *n = [active nameForObject: o];
|
||||
if ([n isEqual: @"NSOwner"] || [n isEqual: @"NSFirst"])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return [selectionOwner respondsToSelector: @selector(pasteInSelection)];
|
||||
|
|
|
@ -1382,273 +1382,15 @@
|
|||
|
||||
- (BOOL) parseHeader: (NSString *)headerPath
|
||||
{
|
||||
BOOL result = NO;
|
||||
/*
|
||||
NSString *headerFile = [NSString stringWithContentsOfFile: headerPath];
|
||||
NSScanner *headerScanner = [NSScanner scannerWithString: headerFile];
|
||||
NSCharacterSet *superClassStopSet = [NSCharacterSet characterSetWithCharactersInString: @" \n"];
|
||||
NSCharacterSet *classStopSet = [NSCharacterSet characterSetWithCharactersInString: @" :"];
|
||||
NSCharacterSet *categoryStopSet = [NSCharacterSet characterSetWithCharactersInString: @" ("];
|
||||
NSCharacterSet *typeStopSet = [NSCharacterSet characterSetWithCharactersInString: @" "];
|
||||
NSCharacterSet *actionStopSet = [NSCharacterSet characterSetWithCharactersInString: @";:"];
|
||||
NSCharacterSet *outletStopSet = [NSCharacterSet characterSetWithCharactersInString: @";,"];
|
||||
NSCharacterSet *illegalOutletSet = [NSCharacterSet characterSetWithCharactersInString: @"~`@#$%^&*()+={}|[]\\:;'<>?,./"];
|
||||
NSCharacterSet *illegalActionSet = [NSCharacterSet characterSetWithCharactersInString: @"~`@#$%^&*()+={}|[]\\;'<>?,./"];
|
||||
NSArray *outletTokens = [NSArray arrayWithObjects: @"id", @"IBOutlet", nil];
|
||||
NSArray *actionTokens = [NSArray arrayWithObjects: @"(void)", @"(IBAction)", @"(id)", nil];
|
||||
NSRange notFoundRange = NSMakeRange(NSNotFound,0);
|
||||
// NSCharacterSet *commentStopSet = [NSCharacterSet characterSetWithCharactersInString: @"\n"];
|
||||
|
||||
while (![headerScanner isAtEnd])
|
||||
{
|
||||
NSString *classString = nil;
|
||||
BOOL classfound = NO, result = NO, category = NO;
|
||||
NSEnumerator *outletEnum = [outletTokens objectEnumerator];
|
||||
NSEnumerator *actionEnum = [actionTokens objectEnumerator];
|
||||
NSString *outletToken = nil;
|
||||
NSString *actionToken = nil;
|
||||
int alert;
|
||||
|
||||
classfound = [headerScanner scanUpToString: @"@interface"
|
||||
intoString: NULL];
|
||||
|
||||
[headerScanner scanUpToString: @"@end"
|
||||
intoString: &classString];
|
||||
|
||||
if (classfound && ![headerScanner isAtEnd])
|
||||
{
|
||||
NSString
|
||||
*className = nil,
|
||||
*superClassName = nil,
|
||||
*ivarString = nil,
|
||||
*methodString = nil;
|
||||
NSScanner
|
||||
*classScanner = [NSScanner scannerWithString: classString],
|
||||
*ivarScanner = nil,
|
||||
*methodScanner = nil;
|
||||
NSMutableArray
|
||||
*actions = [NSMutableArray array],
|
||||
*outlets = [NSMutableArray array];
|
||||
|
||||
[classScanner scanString: @"@interface"
|
||||
intoString: NULL];
|
||||
[classScanner scanUpToCharactersFromSet: classStopSet
|
||||
intoString: &className];
|
||||
[classScanner scanString: @":"
|
||||
intoString: NULL];
|
||||
[classScanner scanUpToCharactersFromSet: superClassStopSet
|
||||
intoString: &superClassName];
|
||||
[classScanner scanUpToString: @"{"
|
||||
intoString: NULL];
|
||||
[classScanner scanUpToString: @"}"
|
||||
intoString: &ivarString];
|
||||
|
||||
category = (ivarString == nil);
|
||||
if(!category)
|
||||
{
|
||||
[classScanner scanUpToString: @"@end"
|
||||
intoString: &methodString];
|
||||
NSDebugLog(@"Found a class \"%@\" with super class \"%@\"", className,
|
||||
superClassName);
|
||||
}
|
||||
else
|
||||
{
|
||||
NSDebugLog(@"A CATEGORY");
|
||||
classScanner = [NSScanner scannerWithString: classString];
|
||||
[classScanner scanString: @"@interface"
|
||||
intoString: NULL];
|
||||
[classScanner scanUpToCharactersFromSet: categoryStopSet
|
||||
intoString: &className];
|
||||
[classScanner scanString: @"("
|
||||
intoString: NULL];
|
||||
[classScanner scanUpToCharactersFromSet: superClassStopSet
|
||||
intoString: &superClassName];
|
||||
[classScanner scanString: @")"
|
||||
intoString: NULL];
|
||||
[classScanner scanUpToString: @"@end"
|
||||
intoString: &methodString];
|
||||
NSDebugLog(@"method String %@",methodString);
|
||||
}
|
||||
|
||||
|
||||
// if its' not a category and it's known, ask before proceeding...
|
||||
if([self isKnownClass: className] && !category)
|
||||
{
|
||||
NSString *message = [NSString stringWithFormat:
|
||||
_(@"The class %@ already exists. Replace it?"),
|
||||
className];
|
||||
alert = NSRunAlertPanel(_(@"Problem adding class from header"),
|
||||
message,
|
||||
_(@"Yes"),
|
||||
_(@"No"),
|
||||
nil);
|
||||
if (alert != NSAlertDefaultReturn)
|
||||
return NO;
|
||||
}
|
||||
|
||||
// if it's not a category go through the ivars...
|
||||
if(!category)
|
||||
{
|
||||
NSDebugLog(@"Ivar string is not nil");
|
||||
// Interate over the possible tokens which can make an
|
||||
// ivar an outlet.
|
||||
while ((outletToken = [outletEnum nextObject]) != nil)
|
||||
{
|
||||
NSString *delimiter = nil;
|
||||
NSDebugLog(@"outlet Token = %@", outletToken);
|
||||
// Scan the variables of the class...
|
||||
ivarScanner = [NSScanner scannerWithString: ivarString];
|
||||
while (![ivarScanner isAtEnd])
|
||||
{
|
||||
NSString *outlet = nil;
|
||||
NSString *type = nil;
|
||||
|
||||
if (delimiter == nil || [delimiter isEqualToString: @";"])
|
||||
{
|
||||
[ivarScanner scanUpToString: outletToken
|
||||
intoString: NULL];
|
||||
[ivarScanner scanString: outletToken
|
||||
intoString: NULL];
|
||||
}
|
||||
|
||||
// if using the IBOutlet token in the header, scan in the outlet type
|
||||
// as well.
|
||||
if([outletToken isEqualToString: @"IBOutlet"])
|
||||
{
|
||||
[ivarScanner scanUpToCharactersFromSet: typeStopSet
|
||||
intoString: NULL];
|
||||
[ivarScanner scanCharactersFromSet: typeStopSet
|
||||
intoString: NULL];
|
||||
[ivarScanner scanUpToCharactersFromSet: typeStopSet
|
||||
intoString: &type];
|
||||
NSDebugLog(@"outlet type = %@",type);
|
||||
}
|
||||
|
||||
[ivarScanner scanUpToCharactersFromSet: outletStopSet
|
||||
intoString: &outlet];
|
||||
[ivarScanner scanCharactersFromSet: outletStopSet
|
||||
intoString: &delimiter];
|
||||
if ([ivarScanner isAtEnd] == NO
|
||||
&& [outlets indexOfObject: outlet] == NSNotFound)
|
||||
{
|
||||
NSDebugLog(@"outlet = %@", outlet);
|
||||
if(NSEqualRanges([outlet rangeOfCharacterFromSet: illegalOutletSet],notFoundRange))
|
||||
{
|
||||
[outlets addObject: outlet];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while ((actionToken = [actionEnum nextObject]) != nil)
|
||||
{
|
||||
NSDebugLog(@"Action token %@", actionToken);
|
||||
methodScanner = [NSScanner scannerWithString: methodString];
|
||||
while (![methodScanner isAtEnd])
|
||||
{
|
||||
NSString *action = nil;
|
||||
BOOL hasArguments = NO;
|
||||
|
||||
// Scan the method name
|
||||
[methodScanner scanUpToString: actionToken
|
||||
intoString: NULL];
|
||||
[methodScanner scanString: actionToken
|
||||
intoString: NULL];
|
||||
[methodScanner scanUpToCharactersFromSet: actionStopSet
|
||||
intoString: &action];
|
||||
|
||||
// This will return true if the method has args.
|
||||
hasArguments = [methodScanner scanString: @":"
|
||||
intoString: NULL];
|
||||
|
||||
if (hasArguments)
|
||||
{
|
||||
BOOL isAction = NO;
|
||||
NSString *argType = nil;
|
||||
|
||||
// If the argument is (id) then the method can
|
||||
// be considered an action and we add it to the list.
|
||||
isAction = [methodScanner scanString: @"(id)"
|
||||
intoString: &argType];
|
||||
|
||||
if (![methodScanner isAtEnd])
|
||||
{
|
||||
if (isAction)
|
||||
{
|
||||
// Add the ':' back /
|
||||
action = [action stringByAppendingString: @":"];
|
||||
NSDebugLog(@"action = %@", action);
|
||||
if(NSEqualRanges([action rangeOfCharacterFromSet: illegalActionSet],notFoundRange))
|
||||
{
|
||||
[actions addObject: action];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NSDebugLog(@"Not an action");
|
||||
}
|
||||
}
|
||||
}
|
||||
} // end while
|
||||
} // end while
|
||||
|
||||
if([self isKnownClass: className] &&
|
||||
[self isCustomClass: className] && category)
|
||||
{
|
||||
[self addActions: actions forClassNamed: className];
|
||||
[self addOutlets: outlets forClassNamed: className];
|
||||
result = YES;
|
||||
}
|
||||
else if(!category)
|
||||
{
|
||||
result = [self addClassNamed: className
|
||||
withSuperClassNamed: superClassName
|
||||
withActions: actions
|
||||
withOutlets: outlets];
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
NSDebugLog(@"Class %@ added", className);
|
||||
}
|
||||
else
|
||||
if (alert == NSAlertDefaultReturn)
|
||||
{
|
||||
[self removeClassNamed: className];
|
||||
result = [self addClassNamed: className
|
||||
withSuperClassNamed: superClassName
|
||||
withActions: actions
|
||||
withOutlets: outlets];
|
||||
if (!result)
|
||||
{
|
||||
NSString *message = [NSString stringWithFormat:
|
||||
_(@"Could not replace class %@."), className];
|
||||
NSRunAlertPanel(_(@"Problem adding class from header"),
|
||||
message,
|
||||
nil,
|
||||
nil,
|
||||
nil);
|
||||
NSDebugLog(@"Class %@ failed to add", className);
|
||||
}
|
||||
else
|
||||
{
|
||||
NSDebugLog(@"Class %@ replaced.", className);
|
||||
}
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName: GormDidAddClassNotification
|
||||
object: self];
|
||||
[document selectClass: className];
|
||||
}
|
||||
} // if we found a class
|
||||
}
|
||||
return YES;
|
||||
OCHeaderParser *ochp = [[OCHeaderParser alloc] initWithContentsOfFile: headerPath];
|
||||
NSArray *classes = [ochp ];
|
||||
NSArray *actions = [ochp actionList];
|
||||
NSString
|
||||
*/
|
||||
|
||||
return NO;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (BOOL) isAction: (NSString *)name ofClass: (NSString *)className
|
||||
|
|
Loading…
Reference in a new issue