[38534] branches/gsoc08-framework/MacPorts_Framework

armahg at macports.org armahg at macports.org
Thu Jul 24 14:11:18 PDT 2008


Revision: 38534
          http://trac.macosforge.org/projects/macports/changeset/38534
Author:   armahg at macports.org
Date:     2008-07-24 14:11:18 -0700 (Thu, 24 Jul 2008)
Log Message:
-----------
Changed return value of evaluateArrayAsString and evaluateStringAsString methods in MPInterpreter to return an NSDictionary instead of an NSString. Made changes to rest of code accordingly

Modified Paths:
--------------
    branches/gsoc08-framework/MacPorts_Framework/MPInterpreter.h
    branches/gsoc08-framework/MacPorts_Framework/MPInterpreter.m
    branches/gsoc08-framework/MacPorts_Framework/MPMacPorts.m
    branches/gsoc08-framework/MacPorts_Framework/MPPort.m
    branches/gsoc08-framework/MacPorts_Framework/MPRegistry.m

Modified: branches/gsoc08-framework/MacPorts_Framework/MPInterpreter.h
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework/MPInterpreter.h	2008-07-24 21:07:36 UTC (rev 38533)
+++ branches/gsoc08-framework/MacPorts_Framework/MPInterpreter.h	2008-07-24 21:11:18 UTC (rev 38534)
@@ -46,6 +46,8 @@
 #define	MPPackage			@"macports"
 #define MPPackageVersion	@"1.0"
 #define MP_DEFAULT_PKG_PATH @"/Users/Armahg/macportsbuild/build1/Library/Tcl"
+#define TCL_RETURN_CODE @"return code"
+#define TCL_RETURN_STRING @"return string"
 
 /*!
  @class MPInterpreter
@@ -66,6 +68,9 @@
  */
 + (MPInterpreter *)sharedInterpreter;
 
+- (Tcl_Interp *) sharedTclInterpreter;
+
+
 + (MPInterpreter *)sharedInterpreterWithPkgPath:(NSString *)path;
 - (id) initWithPkgPath:(NSString *)path;
 
@@ -93,7 +98,7 @@
  Each element in the array is an NSString. Note the "return" in the first element of the statement
  NSArray.
  */
-- (NSString *)evaluateArrayAsString:(NSArray *)statement;
+//- (NSString *)evaluateArrayAsString:(NSArray *)statement;
 /*!
  @brief Returns the NSString result of evaluating a Tcl expression
  @param  statement An NSString containing the Tcl expression
@@ -104,11 +109,21 @@
  [SomeMPInterpreterObject evaluateStringAsString:
 							[NSString stringWithString:@"return [macports::getindex SomeValidMacPortsSourcePath]"]];
  */
-- (NSString *)evaluateStringAsString:(NSString *)statement;
+//- (NSString *)evaluateStringAsString:(NSString *)statement;
 
 
+//Redoing evaluateStringAsString and evaluateArrayAsString to return a two element NSDictionary.
+//First element will have key TCL_RETURN_CODE and be an NSNumber with int value of TCL_OK,
+//TCL_RETURN , TCL_ERROR etc. The second key will be TCL_RETURN_STRING and have the same NSString
+//value as is being currently returned. This is going to require a lot of refactoring and changing
+//stuff so i'm only going to document and remove old code after new code is working and i've done
+//a commit. Obtaining the return code will make error handling in the framework much less
+//cumbersome
+- (NSDictionary *)evaluateArrayAsString:(NSArray *)statement;
+- (NSDictionary *)evaluateStringAsString:(NSString *)statement;
 
 
+
 /*!
  @brief Returns an NSArray whose elements are the the elements of a Tcl list in the form of an NSString
  @param list A Tcl list in the form of an NSString

Modified: branches/gsoc08-framework/MacPorts_Framework/MPInterpreter.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework/MPInterpreter.m	2008-07-24 21:07:36 UTC (rev 38533)
+++ branches/gsoc08-framework/MacPorts_Framework/MPInterpreter.m	2008-07-24 21:11:18 UTC (rev 38534)
@@ -181,6 +181,9 @@
 	return self;
 }
 
+- (Tcl_Interp *) sharedTclInterpreter {
+	return _interpreter;
+}
 
 + (MPInterpreter*)sharedInterpreter {
 	return [self sharedInterpreterWithPkgPath:MP_DEFAULT_PKG_PATH];
@@ -232,15 +235,26 @@
 
 #pragma Utilities
 
-- (NSString *)evaluateArrayAsString:(NSArray *)statement {
+- (NSDictionary *)evaluateArrayAsString:(NSArray *)statement {
 	return [self evaluateStringAsString:[statement componentsJoinedByString:@" "]];
 }
 
+/*
 - (NSString *)evaluateStringAsString:(NSString *)statement {
 	Tcl_Eval(_interpreter, [statement UTF8String]);
 	return [NSString stringWithUTF8String:Tcl_GetStringResult(_interpreter)];
 }
+*/
 
+
+- (NSDictionary *)evaluateStringAsString:(NSString *)statement {
+	int return_code = Tcl_Eval(_interpreter, [statement UTF8String]);
+	return [NSDictionary dictionaryWithObjectsAndKeys:
+			[NSNumber numberWithInt:return_code], TCL_RETURN_CODE, 
+			[NSString stringWithUTF8String:Tcl_GetStringResult(_interpreter)], TCL_RETURN_STRING, nil];
+}
+
+
 - (NSArray *)arrayFromTclListAsString:(NSString *)list {
 	NSMutableArray *array;
 	int tclCount;

Modified: branches/gsoc08-framework/MacPorts_Framework/MPMacPorts.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework/MPMacPorts.m	2008-07-24 21:07:36 UTC (rev 38533)
+++ branches/gsoc08-framework/MacPorts_Framework/MPMacPorts.m	2008-07-24 21:11:18 UTC (rev 38534)
@@ -106,8 +106,18 @@
 	[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"MacPortsSyncStarted" object:nil];
 	[[MPNotifications sharedListener] setPerformingTclCommand:@"YES_sync"];
 	
-	[interpreter evaluateStringAsString:@"mportsync"];
+	NSDictionary * returnDict = [interpreter evaluateStringAsString:@"mportsync"];
 	
+	Tcl_Interp * interp = [interpreter sharedTclInterpreter];
+	Tcl_Obj * interpObj = Tcl_GetObjResult(interp);
+	int length, errCode;
+	NSLog(@"TclObj string is %@ with length %d", 
+		  [NSString stringWithUTF8String:Tcl_GetStringFromObj(interpObj, &length)] , \
+		  length);
+	errCode = Tcl_GetErrno();
+	NSLog(@"Errno Id is %@ with value %d", [NSString stringWithUTF8String:Tcl_ErrnoId()], errCode);
+	NSLog(@"Errno Msg is %@", [NSString stringWithUTF8String:Tcl_ErrnoMsg(errCode)]);
+	
 	[[MPNotifications sharedListener] setPerformingTclCommand:@""];
 	[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"MacPortsSyncFinished" object:nil];
 }
@@ -117,7 +127,7 @@
 	[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"MacPortsSelfupdateStarted" object:nil];
 	[[MPNotifications sharedListener] setPerformingTclCommand:@"YES_selfUpdate"];
 	
-	[interpreter evaluateStringAsString:@"macports::selfupdate"];
+	NSDictionary * returnDict = [interpreter evaluateStringAsString:@"macports::selfupdate"];
 	
 	[[MPNotifications sharedListener] setPerformingTclCommand:@""];
 	[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"MacPortsSelfupdateFinished" object:nil];
@@ -151,7 +161,7 @@
 	}
 	result = [NSMutableDictionary dictionaryWithDictionary:
 			  [interpreter dictionaryFromTclListAsString:
-			   [interpreter evaluateArrayAsString:
+			   [[interpreter evaluateArrayAsString:
 				[NSArray arrayWithObjects:
 										  @"return [mportsearch",
 										  query,
@@ -159,7 +169,7 @@
 										  style,
 										  fieldName,
 										  @"]",
-										  nil]]]];
+				 nil]] objectForKey:TCL_RETURN_STRING] ]];
 	
 	newResult = [NSMutableDictionary dictionaryWithCapacity:[result count]];
 	enumerator = [result keyEnumerator];
@@ -192,6 +202,7 @@
 - (NSArray *)sources:(BOOL)refresh {
 	if (refresh) {
 		[sources release];
+		sources = nil;
 	}
 	return [self sources];
 }
@@ -206,14 +217,14 @@
 
 - (NSURL *)pathToPortIndex:(NSString *)source {
 	return [NSURL fileURLWithPath:
-			[interpreter evaluateStringAsString:
-			 [NSString stringWithFormat:@"return [macports::getindex %@ ]", source]]];
+			[[interpreter evaluateStringAsString:
+			 [NSString stringWithFormat:@"return [macports::getindex %@ ]", source]] objectForKey:TCL_RETURN_STRING]];
 }
 
 
 - (NSString *)version {
 	if (version == nil) {
-		version = [interpreter evaluateStringAsString:@"return [macports::version]"];
+		version = [[interpreter evaluateStringAsString:@"return [macports::version]"] objectForKey:TCL_RETURN_STRING];
 	}
 	return version;
 }

Modified: branches/gsoc08-framework/MacPorts_Framework/MPPort.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework/MPPort.m	2008-07-24 21:07:36 UTC (rev 38533)
+++ branches/gsoc08-framework/MacPorts_Framework/MPPort.m	2008-07-24 21:11:18 UTC (rev 38534)
@@ -179,8 +179,8 @@
 		}
 	}
 	
-	[interpreter evaluateStringAsString:
-	 [NSString stringWithFormat:@"[%@ %@]" , procedure, sparams]];
+	NSDictionary * returnDict = [interpreter evaluateStringAsString:
+								 [NSString stringWithFormat:@"[%@ %@]" , procedure, sparams]];
 }
 
 
@@ -205,10 +205,10 @@
 	NSString * tclCmd = [@"YES_" stringByAppendingString:procedure];
 	[[MPNotifications sharedListener] setPerformingTclCommand:tclCmd];
 	
-	[interpreter evaluateStringAsString:
-	 [NSString stringWithFormat:
-	  @"[%@ %@ %@ %@]" ,
-	  procedure, [self name], v, opts]];
+	NSDictionary * returnDict = [interpreter evaluateStringAsString:
+								 [NSString stringWithFormat:
+								  @"[%@ %@ %@ %@]" ,
+								  procedure, [self name], v, opts]];
 	
 	[[MPNotifications sharedListener] setPerformingTclCommand:@""];
 	[self sendGlobalExecNotification:procedure withStatus:@"Finished"];
@@ -235,12 +235,12 @@
 	NSString * tclCmd = [@"YES_" stringByAppendingString:target];
 	[[MPNotifications sharedListener] setPerformingTclCommand:tclCmd];
 	
-	[interpreter evaluateStringAsString:
-	 [NSString stringWithFormat:
-	  @"set portHandle [mportopen  %@  %@  %@]; \
-	  mportexec portHandle %@; \
-	  mportclose portHandle", 
-	  [self valueForKey:@"portURL"], opts, vrnts, target]];
+	NSDictionary * returnDict = [interpreter evaluateStringAsString:
+								 [NSString stringWithFormat:
+								  @"set portHandle [mportopen  %@  %@  %@]; \
+								  mportexec portHandle %@; \
+								  mportclose portHandle", 
+								  [self valueForKey:@"portURL"], opts, vrnts, target]];
 	
 	[[MPNotifications sharedListener] setPerformingTclCommand:@""];
 	[self sendGlobalExecNotification:target withStatus:@"Finished"];

Modified: branches/gsoc08-framework/MacPorts_Framework/MPRegistry.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework/MPRegistry.m	2008-07-24 21:07:36 UTC (rev 38533)
+++ branches/gsoc08-framework/MacPorts_Framework/MPRegistry.m	2008-07-24 21:11:18 UTC (rev 38534)
@@ -1,5 +1,5 @@
 /*
- *	$Id:$
+ *	$Id$
  *	MacPorts.Framework
  *
  *	Authors:
@@ -117,22 +117,23 @@
 }
 
 - (NSArray *)installedAsArray:(NSString *)name withVersion:(NSString *)version {
-	return [interpreter arrayFromTclListAsString:[interpreter evaluateArrayAsString:[NSArray arrayWithObjects:
+	return [interpreter arrayFromTclListAsString:[[interpreter evaluateArrayAsString:[NSArray arrayWithObjects:
 		@"return [registry::installed",
 		name,
 		version,
 		@"]",
 		nil
-		]]];
+		]] objectForKey:TCL_RETURN_STRING]];
 }
 
 - (NSArray *)filesForPort:(NSString *)name {
-	return [interpreter arrayFromTclListAsString:[interpreter evaluateArrayAsString:[NSArray arrayWithObjects:
-		@"return [registry::port_registered",
-		name,
-		@"]",
-		nil
-		]]];
+	return [interpreter arrayFromTclListAsString:
+			[[interpreter evaluateArrayAsString:[NSArray arrayWithObjects:
+												 @"return [registry::port_registered",
+												 name,
+												 @"]",
+												 nil]] 
+			 objectForKey:TCL_RETURN_STRING] ];
 }
 
 @end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080724/14e21cb4/attachment.html 


More information about the macports-changes mailing list