[54247] users/toby/objcports

toby at macports.org toby at macports.org
Thu Jul 23 13:17:22 PDT 2009


Revision: 54247
          http://trac.macports.org/changeset/54247
Author:   toby at macports.org
Date:     2009-07-23 13:17:22 -0700 (Thu, 23 Jul 2009)
Log Message:
-----------
improve callback implementatin

Modified Paths:
--------------
    users/toby/objcports/MPPort.m
    users/toby/objcports/objcports.xcodeproj/project.pbxproj
    users/toby/objcports/variables.plist

Modified: users/toby/objcports/MPPort.m
===================================================================
--- users/toby/objcports/MPPort.m	2009-07-23 19:46:28 UTC (rev 54246)
+++ users/toby/objcports/MPPort.m	2009-07-23 20:17:22 UTC (rev 54247)
@@ -143,7 +143,11 @@
 		[self release];
 		self = nil;
 	}
-	
+
+	for (NSString *vv in _variableInfo) {
+		NSLog(@"%@ -- %@ -- %@", vv, [_variables objectForKey:vv], [self variable:vv]);
+	}
+
 	return self;
 }
 
@@ -213,16 +217,47 @@
 	return [type isEqualToString:@"Array"];
 }
 
-- (id)variableCallback:(NSString *)name
+- (id)defaultCallback:(NSString *)name
 {
-	return @"callback result";
+	return @"";
 }
 
+- (id)osInfo:(NSString *)name
+{
+	NSString *ret = nil;
+	int rc;
+	struct utsname u;
+
+	rc = uname(&u);
+	assert(rc == 0);
+
+	if ([name isEqualToString:@"os.platform"]) {
+		ret = [[NSString stringWithUTF8String:u.sysname] lowercaseString];
+	} else if ([name isEqualToString:@"os.arch"]) {
+		ret = [NSString stringWithUTF8String:u.machine];
+	} else if ([name isEqualToString:@"os.endian"]) {
+#ifdef __BIG_ENDIAN__
+		ret = @"big";
+#else
+		ret = @"little";
+#endif
+	} else if ([name isEqualToString:@"os.major"]) {
+		ret = [[[NSString stringWithUTF8String:u.release] componentsSeparatedByString:@"."] objectAtIndex:0];
+	} else if ([name isEqualToString:@"os.version"]) {
+		ret = [NSString stringWithUTF8String:u.release];
+	} else {
+		abort();
+	}
+
+	return ret;
+}
+
 - (NSString *)variable:(NSString *)name
 {
 	NSDictionary *info;
 	id setValue;
 	id defValue;
+	id callback;
 	NSString *ret = nil;
 
 	info = [_variableInfo objectForKey:name];
@@ -236,10 +271,11 @@
 				assert([setValue isKindOfClass:[NSString class]]);
 				ret = setValue;
 			}
-		} else if ((defValue = [info objectForKey:kPortVariableDefault]) != nil) {
+		} else if ((defValue = [info objectForKey:kPortVariableDefault])) {
 			ret = defValue;
-		} else if ([[info objectForKey:kPortVariableCallback] boolValue] == YES) {
-			ret = [self variableCallback:name];
+		} else if ((callback = [info objectForKey:kPortVariableCallback])) {
+			assert([callback isKindOfClass:[NSString class]]);
+			ret = [self performSelector:NSSelectorFromString(callback) withObject:name];
 		} else {
 			ret = [NSString stringWithUTF8String:""];
 		}

Modified: users/toby/objcports/objcports.xcodeproj/project.pbxproj
===================================================================
--- users/toby/objcports/objcports.xcodeproj/project.pbxproj	2009-07-23 19:46:28 UTC (rev 54246)
+++ users/toby/objcports/objcports.xcodeproj/project.pbxproj	2009-07-23 20:17:22 UTC (rev 54247)
@@ -44,6 +44,7 @@
 		DAD3716F0F0280EF0064AFF4 /* MPStringAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPStringAdditions.h; sourceTree = "<group>"; };
 		DAD371700F0280EF0064AFF4 /* MPStringAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPStringAdditions.m; sourceTree = "<group>"; };
 		DAD371940F0281940064AFF4 /* libtcl.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libtcl.dylib; path = /usr/lib/libtcl.dylib; sourceTree = "<absolute>"; };
+		FD1CD53B1018F5AD0071534F /* variables.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = variables.plist; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -84,6 +85,7 @@
 				DAD3716E0F0280EF0064AFF4 /* MPPort.m */,
 				DAD3716F0F0280EF0064AFF4 /* MPStringAdditions.h */,
 				DAD371700F0280EF0064AFF4 /* MPStringAdditions.m */,
+				FD1CD53B1018F5AD0071534F /* variables.plist */,
 			);
 			name = Source;
 			sourceTree = "<group>";

Modified: users/toby/objcports/variables.plist
===================================================================
--- users/toby/objcports/variables.plist	2009-07-23 19:46:28 UTC (rev 54246)
+++ users/toby/objcports/variables.plist	2009-07-23 20:17:22 UTC (rev 54247)
@@ -186,7 +186,7 @@
 		<key>Constant</key>
 		<true/>
 		<key>Callback</key>
-		<true/>
+		<string>defaultCallback:</string>
 	</dict>
 	<key>dist_subdir</key>
 	<dict/>
@@ -233,7 +233,7 @@
 		<key>Constant</key>
 		<true/>
 		<key>Callback</key>
-		<true/>
+		<string>defaultCallback:</string>
 	</dict>
 	<key>frameworks_dir</key>
 	<dict>
@@ -270,7 +270,10 @@
 	<key>long_description</key>
 	<dict/>
 	<key>maintainers</key>
-	<dict/>
+	<dict>
+		<key>Type</key>
+		<string>Array</string>
+	</dict>
 	<key>master_sites</key>
 	<dict>
 		<key>Type</key>
@@ -282,26 +285,36 @@
 	<dict/>
 	<key>os.arch</key>
 	<dict>
+		<key>Callback</key>
+		<string>osInfo:</string>
 		<key>Constant</key>
 		<true/>
 	</dict>
 	<key>os.endian</key>
 	<dict>
+		<key>Callback</key>
+		<string>osInfo:</string>
 		<key>Constant</key>
 		<true/>
 	</dict>
 	<key>os.major</key>
 	<dict>
+		<key>Callback</key>
+		<string>osInfo:</string>
 		<key>Constant</key>
 		<true/>
 	</dict>
 	<key>os.platform</key>
 	<dict>
+		<key>Callback</key>
+		<string>osInfo:</string>
 		<key>Constant</key>
 		<true/>
 	</dict>
 	<key>os.version</key>
 	<dict>
+		<key>Callback</key>
+		<string>osInfo:</string>
 		<key>Constant</key>
 		<true/>
 	</dict>
@@ -416,7 +429,7 @@
 		<key>Constant</key>
 		<true/>
 		<key>Callback</key>
-		<true/>
+		<string>defaultCallback:</string>
 	</dict>
 	<key>worksrcdir</key>
 	<dict>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20090723/66a19f2d/attachment.html>


More information about the macports-changes mailing list