Add LSTC/OCNT fields and counter field variants.

This commit is contained in:
Uli Kusterer 2003-08-17 23:21:37 +02:00
parent 04e81cb47d
commit a8cd81969e
9 changed files with 451 additions and 5 deletions

View File

@ -122,8 +122,6 @@ RKEditorRegistry* gRKEditorRegistryMainRegistry = nil; // Access through +mainR
NSEnumerator *e = [[[NSFileManager defaultManager] directoryContentsAtPath:path] objectEnumerator];
NSString *name;
NSLog(@"Looking for plugins at %@", path);
while( name = [e nextObject] )
{
name = [path stringByAppendingPathComponent:name];
@ -132,10 +130,8 @@ RKEditorRegistry* gRKEditorRegistryMainRegistry = nil; // Access through +mainR
{
NSBundle *plugin = [NSBundle bundleWithPath: name];
NSLog(@"Identifier %@", [plugin bundleIdentifier]);
if( pluginClass = [plugin principalClass] )
{
NSLog(@"Found plugin: %@", name);
if( [pluginClass instancesRespondToSelector:@selector(initWithResource:)] )
{
NSString *resType;

View File

@ -0,0 +1,33 @@
//
// NuTemplateLSTCElement.h
// ResKnife (PB2)
//
// Implements LSTB and LSTZ fields.
//
// Created by Uli Kusterer on Tue Aug 05 2003.
// Copyright (c) 2003 M. Uli Kusterer. All rights reserved.
//
#import <AppKit/AppKit.h>
#import "NuTemplateGroupElement.h"
@class NuTemplateLSTEElement;
@class NuTemplateOCNTElement;
@interface NuTemplateLSTCElement : NuTemplateGroupElement
{
NuTemplateLSTEElement* endElement; // Template to create our "list end" element from.
NuTemplateOCNTElement* countElement; // Our "list counter" element.
}
-(IBAction) showCreateResourceSheet: (id)sender;
-(void) setEndElement: (NuTemplateLSTEElement*)e;
-(NuTemplateLSTEElement*) endElement;
-(void) setCountElement: (NuTemplateOCNTElement*)e;
-(NuTemplateOCNTElement*) countElement;
@end

View File

@ -0,0 +1,173 @@
//
// NuTemplateLSTCElement.m
// ResKnife (PB2)
//
// Implements LSTB and LSTZ fields.
//
// Created by Uli Kusterer on Tue Aug 05 2003.
// Copyright (c) 2003 M. Uli Kusterer. All rights reserved.
//
#import "NuTemplateLSTCElement.h"
#import "NuTemplateLSTEElement.h"
#import "NuTemplateOCNTElement.h"
@implementation NuTemplateLSTCElement
-(void) dealloc
{
[endElement release];
[super dealloc];
}
-(void) readSubElementsFrom: (NuTemplateStream*)stream
{
countElement = [NuTemplateOCNTElement lastParsedElement];
while( [stream bytesToGo] > 0 )
{
NuTemplateElement* obj = [stream readOneElement];
if( [[obj type] isEqualToString: @"LSTE"] )
{
endElement = [obj retain];
break;
}
[subElements addObject: obj];
}
}
-(void) readDataForElements: (NuTemplateStream*)stream
{
NSEnumerator *enny = [subElements objectEnumerator];
NuTemplateElement *el;
while( el = [enny nextObject] )
{
[el readDataFrom: stream];
}
}
-(void) readDataFrom: (NuTemplateStream*)stream
{
NSEnumerator *enny = [subElements objectEnumerator];
NuTemplateElement *el, *nextItem;
unsigned int itemsToGo = 0,
itemsToGoAtStart = 0;
countElement = [NuTemplateOCNTElement lastParsedElement];
NSLog( @"countElement: %@", countElement );
itemsToGo = [countElement longValue];
itemsToGoAtStart = itemsToGo;
NSLog( @"LSTC: Number of items: %ld", itemsToGo );
// Read a first item:
if( itemsToGo > 0 )
{
[self readDataForElements: stream];
itemsToGo--;
}
/* Read additional elements until we have enough items,
except if we're not the first item in our list. */
if( containing != nil )
{
while( itemsToGo-- )
{
// Actually read the item:
nextItem = [[self copy] autorelease]; // Make another list item just like this one.
[nextItem setContaining: nil]; // Make sure it doesn't get into this "if" clause.
[containing addObject: nextItem]; // Add it below ourselves.
[nextItem readDataFrom:stream]; // Read it the same way we were.
[nextItem setContaining: containing]; // Set "containing" *after* readDataFrom so it doesn't pass the "containing == nil" check above.
}
// Now add a terminating 'LSTE' item:
NuTemplateLSTEElement* tlee;
tlee = [[endElement copy] autorelease];
[containing addObject: tlee];
[tlee setContaining: containing];
[tlee setGroupElemTemplate: self];
[tlee setCountElement: countElement];
[tlee readDataFrom: stream]; // If LSTE has data to read (e.g. if we're an LSTZ, the terminating byte), let it do that!
if( itemsToGoAtStart == 0 ) // It's an empty list. Delete this LSTC again, so we only have the empty LSTE.
{
[tlee setSubElements: subElements]; // Take over the LSTC's sub-elements.
[containing removeObject:self]; // Remove the LSTB.
}
else
[tlee setSubElements: [[subElements copy] autorelease]]; // Make a copy. So each has its own array.
}
}
-(NSString*) stringValue
{
return @"";
}
-(id) copyWithZone: (NSZone*)zone
{
NuTemplateLSTCElement* el = [super copyWithZone: zone];
[el setEndElement: [self endElement]];
[el setCountElement: [self countElement]];
return el;
}
-(void) setEndElement: (NuTemplateLSTEElement*)e
{
[e retain];
[endElement release];
endElement = e;
}
-(NuTemplateLSTEElement*) endElement
{
return endElement;
}
-(void) setCountElement: (NuTemplateOCNTElement*)e
{
countElement = e;
}
-(NuTemplateOCNTElement*) countElement
{
return countElement;
}
-(IBAction) showCreateResourceSheet: (id)sender
{
unsigned idx = [containing indexOfObject:self];
NuTemplateGroupElement* te = [[self copy] autorelease];
[containing insertObject:te atIndex:idx+1];
[te setContaining:containing];
// Update "counter" item:
[countElement setLongValue: ([countElement longValue] +1)];
}
-(IBAction) clear: (id)sender
{
[[self retain] autorelease]; // Make sure we don't go away right now. That may surprise the one who called clear, or otherwise be bad.
[containing removeObject: self]; // Remove us from the array we're in. (this releases us once)
[countElement setLongValue: [countElement longValue] -1];
}
@end

View File

@ -9,10 +9,12 @@
#import <AppKit/AppKit.h>
#import "NuTemplateGroupElement.h"
@class NuTemplateOCNTElement;
@interface NuTemplateLSTEElement : NuTemplateGroupElement
{
NuTemplateGroupElement* groupElemTemplate; // The item of which we're to create a copy.
NuTemplateOCNTElement* countElement; // The "counter" element if we're the end of an LSTC list.
BOOL writesZeroByte; // Write a terminating zero-byte when writing out this item (used by LSTZ).
}
@ -24,4 +26,7 @@
-(void) setGroupElemTemplate: (NuTemplateGroupElement*)e;
-(NuTemplateGroupElement*) groupElemTemplate;
-(void) setCountElement: (NuTemplateOCNTElement*)e;
-(NuTemplateOCNTElement*) countElement;
@end

View File

@ -8,7 +8,7 @@
#import "NuTemplateLSTEElement.h"
#import "NuTemplateLSTBElement.h"
#import "NuTemplateOCNTElement.h"
@implementation NuTemplateLSTEElement
@ -32,6 +32,17 @@
}
-(void) setCountElement: (NuTemplateOCNTElement*)e
{
countElement = e;
}
-(NuTemplateOCNTElement*) countElement
{
return countElement;
}
-(void) readSubElementsFrom: (NuTemplateStream*)stream
{
@ -93,6 +104,7 @@
[el setGroupElemTemplate: [self groupElemTemplate]];
[el setWritesZeroByte: [self writesZeroByte]];
[el setCountElement: [self countElement]];
return el;
}
@ -105,6 +117,7 @@
[containing insertObject:ge atIndex:idx];
[ge setContaining: containing];
[countElement setLongValue: ([countElement longValue] +1)];
}

View File

@ -0,0 +1,26 @@
//
// NuTemplateOCNTElement.h
// ResKnife (PB2)
//
// Created by Uli Kusterer on Tue Aug 05 2003.
// Copyright (c) 2003 M. Uli Kusterer. All rights reserved.
//
#import "NuTemplateElement.h"
@interface NuTemplateOCNTElement : NuTemplateElement
{
long longValue;
}
+(NuTemplateOCNTElement*) lastParsedElement;
+(void) setLastParsedElement: (NuTemplateOCNTElement*)e;
-(void) setLongValue: (long)n;
-(long) longValue;
-(NSString*) stringValue;
-(void) setStringValue: (NSString*)str;
@end

View File

@ -0,0 +1,134 @@
//
// NuTemplateOCNTElement.m
// ResKnife (PB2)
//
// Created by Uli Kusterer on Tue Aug 05 2003.
// Copyright (c) 2003 M. Uli Kusterer. All rights reserved.
//
#import "NuTemplateOCNTElement.h"
static NuTemplateOCNTElement* sLastParsedElement = nil;
@implementation NuTemplateOCNTElement
+(NuTemplateOCNTElement*) lastParsedElement
{
return sLastParsedElement;
}
+(void) setLastParsedElement: (NuTemplateOCNTElement*)e
{
NSLog( @"[NuTemplateOCNTElement setLastParsedElement: %@]", e );
sLastParsedElement = e;
}
-(id) initForType: (NSString*)t withLabel: (NSString*)l
{
if( self = [super initForType:t withLabel:l] )
longValue = 0;
[[self class] setLastParsedElement:self];
return self;
}
-(id) copyWithZone: (NSZone*)zone
{
NuTemplateOCNTElement* el = [super copyWithZone: zone];
if( el )
{
[el setLongValue: longValue];
[[self class] setLastParsedElement:el];
}
return el;
}
-(void) readDataFrom: (NuTemplateStream*)stream
{
if( [type isEqualToString: @"LCNT"] )
[stream readAmount:4 toBuffer: &longValue];
else if( [type isEqualToString: @"LZCT"] )
{
short n = -1;
[stream readAmount:sizeof(n) toBuffer: &n];
longValue = n +1;
}
else if( [type isEqualToString: @"ZCNT"] )
{
short n = -1;
[stream readAmount:sizeof(n) toBuffer: &n];
longValue = n +1;
}
else
{
short n = 0;
[stream readAmount:sizeof(n) toBuffer: &n];
longValue = n;
}
}
-(unsigned int) sizeOnDisk
{
if( [type isEqualToString: @"LCNT"] )
return 4;
else if( [type isEqualToString: @"LZCT"] )
return 4;
else
return 2;
}
-(void) writeDataTo: (NuTemplateStream*)stream
{
if( [type isEqualToString: @"LCNT"] )
[stream writeAmount:4 fromBuffer: &longValue];
else if( [type isEqualToString: @"LZCT"] )
{
long n = longValue -1;
[stream writeAmount:sizeof(n) fromBuffer: &n];
}
else if( [type isEqualToString: @"ZCNT"] )
{
short n = longValue -1;
[stream writeAmount:sizeof(n) fromBuffer: &n];
}
else
{
short n = longValue;
[stream writeAmount:sizeof(n) fromBuffer: &n];
}
}
-(void) setLongValue: (long)d
{
longValue = d;
}
-(long) longValue
{
return longValue;
}
-(NSString*) stringValue
{
return [NSString stringWithFormat: @"%ld", longValue];
}
-(void) setStringValue: (NSString*)str
{
// Dummy out. User can't change counter this way, they have to add items.
}
@end

View File

@ -32,6 +32,8 @@
#import "NuTemplateDWRDElement.h"
#import "NuTemplateDLNGElement.h"
#import "NuTemplateDBYTElement.h"
#import "NuTemplateOCNTElement.h"
#import "NuTemplateLSTCElement.h"
#import "NuTemplateStream.h"
#import "NSOutlineView-SelectedItems.h"
@ -153,6 +155,9 @@
{
currElement = [[currElement copy] autorelease]; // Copy the template object.
if( [[currElement type] isEqualToString: @"OCNT"] )
NSLog( @"Instantiated: %@", currElement );
[resourceStructure addObject: currElement]; // Add it to our parsed resource data list. Do this right away so the element can append other items should it desire to.
[currElement setContaining: resourceStructure];
[currElement readDataFrom: stream]; // Fill it with resource data.
@ -204,6 +209,11 @@
[fieldReg setObject: [NuTemplateDLNGElement class] forKey: @"DLNG"];
[fieldReg setObject: [NuTemplateDBYTElement class] forKey: @"DBYT"];
[fieldReg setObject: [NuTemplateDBYTElement class] forKey: @"CHAR"];
[fieldReg setObject: [NuTemplateOCNTElement class] forKey: @"OCNT"];
[fieldReg setObject: [NuTemplateOCNTElement class] forKey: @"ZCNT"];
[fieldReg setObject: [NuTemplateOCNTElement class] forKey: @"LCNT"];
[fieldReg setObject: [NuTemplateOCNTElement class] forKey: @"LZCT"];
[fieldReg setObject: [NuTemplateLSTCElement class] forKey: @"LSTC"];
}
// Read new fields from the template and add them to our list:

View File

@ -171,6 +171,10 @@
3D4737B304E872DB00AF65FE,
3D4737B804E873F300AF65FE,
3D4737B704E873F300AF65FE,
3D50046F04EF040900F3B64D,
3D50047004EF040900F3B64D,
3D50047404EF122000F3B64D,
3D50047304EF122000F3B64D,
);
isa = PBXGroup;
name = "Field Types";
@ -311,6 +315,8 @@
3D0933F804DFE80500DD74B1,
3D4737B604E872DB00AF65FE,
3D4737BA04E873F300AF65FE,
3D50047104EF040900F3B64D,
3D50047604EF122000F3B64D,
);
isa = PBXHeadersBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@ -340,6 +346,8 @@
3D0933F904DFE80500DD74B1,
3D4737B504E872DB00AF65FE,
3D4737B904E873F300AF65FE,
3D50047204EF040900F3B64D,
3D50047504EF122000F3B64D,
);
isa = PBXSourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@ -783,6 +791,54 @@
settings = {
};
};
3D50046F04EF040900F3B64D = {
fileEncoding = 30;
isa = PBXFileReference;
path = NuTemplateOCNTElement.h;
refType = 4;
};
3D50047004EF040900F3B64D = {
fileEncoding = 30;
isa = PBXFileReference;
path = NuTemplateOCNTElement.m;
refType = 4;
};
3D50047104EF040900F3B64D = {
fileRef = 3D50046F04EF040900F3B64D;
isa = PBXBuildFile;
settings = {
};
};
3D50047204EF040900F3B64D = {
fileRef = 3D50047004EF040900F3B64D;
isa = PBXBuildFile;
settings = {
};
};
3D50047304EF122000F3B64D = {
fileEncoding = 30;
isa = PBXFileReference;
path = NuTemplateLSTCElement.m;
refType = 4;
};
3D50047404EF122000F3B64D = {
fileEncoding = 30;
isa = PBXFileReference;
path = NuTemplateLSTCElement.h;
refType = 4;
};
3D50047504EF122000F3B64D = {
fileRef = 3D50047304EF122000F3B64D;
isa = PBXBuildFile;
settings = {
};
};
3D50047604EF122000F3B64D = {
fileRef = 3D50047404EF122000F3B64D;
isa = PBXBuildFile;
settings = {
};
};
//3D0
//3D1
//3D2