Skip to content

Commit

Permalink
We now can handle multiple files.
Browse files Browse the repository at this point in the history
The new Leonie already sends us the information now.
  • Loading branch information
uliwitness committed Mar 14, 2013
1 parent 1487739 commit 682545b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ForgeDebuggerAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
NSButton * mRemoveCheckpointButton;
NSTableView * mInstructionsTableView;
NSMutableDictionary * mInstructions;
NSMutableDictionary * mFilesByID;
uint16_t mCurrentFileID;
}

@property (assign) IBOutlet NSWindow * window;
Expand Down
38 changes: 32 additions & 6 deletions ForgeDebuggerAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ @implementation ForgeDebuggerAppDelegate
@synthesize instructionsTableView = mInstructionsTableView;


-(id) init
{
if(( self = [super init] ))
{
mCurrentFileID = 0xffff; // We start at 0, can't use that. Unlikely that first file we execute has max. ID.
}

return self;
}

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
mServerSocket = [[ULINetSocket netsocketListeningOnPort: 13762] retain];
Expand All @@ -36,6 +46,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification
mVariables = [[NSMutableArray alloc] init];
mHandlers = [[NSMutableArray alloc] init];
mInstructions = [[NSMutableDictionary alloc] init];
mFilesByID = [[NSMutableDictionary alloc] init];

[self setDebuggerUIEnabled: NO];
}
Expand All @@ -46,6 +57,7 @@ -(void) dealloc
[mVariables release];
[mHandlers release];
[mInstructions release];
[mFilesByID release];

[super dealloc];
}
Expand Down Expand Up @@ -286,18 +298,20 @@ -(void) handleCURROperation: (NSData*)theData

-(void) handleSOUROperation: (NSData*)theData
{
NSRange theRange = { 0, 0 };
NSRange theRange = { 1, 0 }; // Should be 2, but subdataUntilNextNullByteInData: assumes it has to skip a '\0' byte when called with anything other than 0.
uint16_t fileID = *(uint16_t*)[theData bytes];
NSData * fileNameData = [self subdataUntilNextNullByteInData: theData foundRange: &theRange];
NSData * fileContentData = [self subdataUntilNextNullByteInData: theData foundRange: &theRange];

NSString * fileNameStr = [[NSString alloc] initWithData: fileNameData encoding: NSUTF8StringEncoding];
NSString * fileContentStr = [[NSString alloc] initWithData: fileContentData encoding: NSUTF8StringEncoding];
[[[mTextView textStorage] mutableString] setString: fileContentStr];
[mFileNameField setStringValue: fileNameStr];
// [[[mTextView textStorage] mutableString] setString: fileContentStr];
// [mFileNameField setStringValue: fileNameStr];
[mFilesByID setObject: @{ @"contents": fileContentStr, @"name": fileNameStr } forKey: [NSNumber numberWithInt: fileID]];
[fileNameStr release];
[fileContentStr release];

[[mTextView textStorage] addAttribute: NSFontAttributeName value: [NSFont userFixedPitchFontOfSize: 10.0] range: NSMakeRange(0,[[mTextView textStorage] length])];
// [[mTextView textStorage] addAttribute: NSFontAttributeName value: [NSFont userFixedPitchFontOfSize: 10.0] range: NSMakeRange(0,[[mTextView textStorage] length])];
}


Expand All @@ -306,13 +320,25 @@ -(void) handleLINEOperation: (NSData*)theData
NSRange allRange = NSMakeRange(0,[[mTextView textStorage] length]);
NSRange lineRange = { 0,0 };
uint32_t theLine = 0;
uint16_t theFileID = 0;
NSString * theStr = [mTextView string];
NSInteger textLength = [theStr length];
NSInteger currLine = 1;
BOOL foundLine = NO;
BOOL foundLineEnd = NO;

[theData getBytes: &theLine length: sizeof(theLine)];
[theData getBytes: &theFileID length: sizeof(theFileID)];
theLine = *((uint32_t*)((char*)[theData bytes] +sizeof(theFileID)));

if( theFileID != mCurrentFileID )
{
NSDictionary* fileDict = mFilesByID[ [NSNumber numberWithInt: theFileID] ];

[[[mTextView textStorage] mutableString] setString: fileDict[@"contents"]];
[mFileNameField setStringValue: fileDict[@"name"]];

[[mTextView textStorage] addAttribute: NSFontAttributeName value: [NSFont userFixedPitchFontOfSize: 10.0] range: NSMakeRange(0,[[mTextView textStorage] length])];
}

for( NSInteger currIdx = 0; currIdx < textLength; currIdx++ )
{
Expand All @@ -335,7 +361,7 @@ -(void) handleLINEOperation: (NSData*)theData

if( foundLine && !foundLineEnd )
lineRange.length = textLength -lineRange.location;

[[mTextView textStorage] removeAttribute: NSBackgroundColorAttributeName range: allRange];
[[mTextView textStorage] addAttribute: NSBackgroundColorAttributeName value: [NSColor colorWithCalibratedRed:0.8 green: 1.0 blue: 0.8 alpha: 1.0] range: lineRange];
}
Expand Down

0 comments on commit 682545b

Please sign in to comment.