[57363] users/toby/objcports

toby at macports.org toby at macports.org
Thu Sep 10 00:06:34 PDT 2009


Revision: 57363
          http://trac.macports.org/changeset/57363
Author:   toby at macports.org
Date:     2009-09-10 00:06:29 -0700 (Thu, 10 Sep 2009)
Log Message:
-----------
more C

Modified Paths:
--------------
    users/toby/objcports/MPConfig.h
    users/toby/objcports/objcports.xcodeproj/project.pbxproj
    users/toby/objcports/port.m

Added Paths:
-----------
    users/toby/objcports/MPConfig.c

Removed Paths:
-------------
    users/toby/objcports/MPConfig.m

Copied: users/toby/objcports/MPConfig.c (from rev 57175, users/toby/objcports/MPConfig.m)
===================================================================
--- users/toby/objcports/MPConfig.c	                        (rev 0)
+++ users/toby/objcports/MPConfig.c	2009-09-10 07:06:29 UTC (rev 57363)
@@ -0,0 +1,103 @@
+#include <CoreFoundation/CoreFoundation.h>
+#include <tcl.h>
+#include <regex.h>
+
+#include "MPConfig.h"
+#include "internal.h"
+
+static void
+load_autoconf(CFMutableDictionaryRef config)
+{
+	Tcl_Interp *interp;
+	int rc;
+	CFStringRef tmp;
+	
+	interp = Tcl_CreateInterp(); 
+	rc = Tcl_EvalFile(interp, "/Library/Tcl/macports1.0/macports_autoconf.tcl");
+	if (rc == 0) {
+		tmp = CFStringCreateWithCString(NULL, Tcl_GetVar(interp, "macports::autoconf::macports_conf_path", 0), kCFStringEncodingUTF8);
+		if (tmp) {
+			CFDictionarySetValue(config, CFSTR("macports_conf_path"), tmp);
+			CFRelease(tmp);
+		}
+
+		tmp = CFStringCreateWithCString(NULL, Tcl_GetVar(interp, "macports::autoconf::macports_user_dir", 0), kCFStringEncodingUTF8);
+		if (tmp) {
+			CFDictionarySetValue(config, CFSTR("macports_user_dir"), tmp);
+			CFRelease(tmp);
+		}
+	}
+	Tcl_DeleteInterp(interp);
+}
+
+CFDictionaryRef
+MPCopyConfig()
+{
+	CFMutableDictionaryRef config = NULL;
+	CFMutableArrayRef configFiles;
+	CFStringRef tmp;
+	CFIndex i, count;
+	char *s;
+	int rc;
+
+	config = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+	
+	load_autoconf(config);
+
+	configFiles = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
+
+	// XXX: should probably construct path intelligently
+	tmp = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/macports.conf"), CFDictionaryGetValue(config, CFSTR("macports_conf_path")));
+	CFArrayAppendValue(configFiles, tmp);
+	CFRelease(tmp);
+
+#if 0
+	// XXX: need to expand macports_user_dir
+	tmp = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/macports.conf"), CFDictionaryGetValue(config, CFSTR("macports_user_dir")));
+	CFArrayAppendValue(configFiles, tmp);
+	CFRelease(tmp);
+#endif
+
+	if ((s = getenv("PORTSRC"))) {
+		tmp = CFStringCreateWithCString(NULL, s, kCFStringEncodingUTF8);
+		CFArrayAppendValue(configFiles, tmp);
+		CFRelease(tmp);
+	}
+
+	regex_t re;
+	rc = regcomp(&re, "^([A-Za-z_]+)([\\\t ]+(.*))?$", REG_EXTENDED);
+	assert(rc == 0);
+	assert(re.re_nsub == 3);
+	count = CFArrayGetCount(configFiles);
+	for (i = 0; i < count; i++) {
+		char *f;
+		size_t len;
+		char *line;
+		FILE *fp;
+		f = strdup_cf(CFArrayGetValueAtIndex(configFiles, i));
+		fp = fopen(f, "r");
+		free(f);
+		if (fp == NULL) continue;
+		while ((line = fgetln(fp, &len))) {
+			regmatch_t match[4];
+			line[len - 1] = '\0';
+			rc = regexec(&re, line, 4, match, 0);
+			if (rc == 0) {
+				const void *key, *value;
+				key = CFStringCreateWithBytes(NULL, (UInt8 *)&line[match[1].rm_so], match[1].rm_eo - match[1].rm_so, kCFStringEncodingUTF8, FALSE);
+				if (match[3].rm_so >= 0) {
+					value = CFStringCreateWithBytes(NULL, (UInt8 *)&line[match[3].rm_so], match[3].rm_eo - match[3].rm_so, kCFStringEncodingUTF8, FALSE);
+				} else {
+					value = CFSTR("");
+				}
+				CFDictionarySetValue(config, key, value);
+				CFRelease(key);
+				CFRelease(value);
+			}
+		}
+		fclose(fp);
+	}
+	regfree(&re);
+
+	return config;
+}

Modified: users/toby/objcports/MPConfig.h
===================================================================
--- users/toby/objcports/MPConfig.h	2009-09-10 06:53:47 UTC (rev 57362)
+++ users/toby/objcports/MPConfig.h	2009-09-10 07:06:29 UTC (rev 57363)
@@ -1,8 +1 @@
- at interface MPConfig : NSObject
-{
-	NSMutableDictionary *_config;
-}
-
-+ (MPConfig *)sharedConfig;
-
- at end
+CFDictionaryRef MPCopyConfig(void);

Deleted: users/toby/objcports/MPConfig.m
===================================================================
--- users/toby/objcports/MPConfig.m	2009-09-10 06:53:47 UTC (rev 57362)
+++ users/toby/objcports/MPConfig.m	2009-09-10 07:06:29 UTC (rev 57363)
@@ -1,116 +0,0 @@
-#include <Foundation/Foundation.h>
-#include <tcl.h>
-#include <regex.h>
-
-#include "MPConfig.h"
-
-static MPConfig *sharedConfigInstance = nil;
-
- at interface MPConfig (priv)
-- (void)loadAutoconf;
- at end
-
- at implementation MPConfig
-
-+ (MPConfig *)sharedConfig
-{
-	@synchronized (self) {
-		if (sharedConfigInstance == nil) {
-			[[self alloc] init];
-		}
-	}
-
-	return sharedConfigInstance;
-}
-
-+ (id)allocWithZone:(NSZone *)zone
-{
-	@synchronized (self) {
-		if (sharedConfigInstance == nil) {
-			sharedConfigInstance = [super allocWithZone:zone];
-			return sharedConfigInstance;
-		}
-	}
-	return nil;
-}
-
-- (id)init
-{
-	NSMutableArray *configFiles;
-	char *s;
-	int rc;
-
-	self = [super init];
-
-	_config = [[NSMutableDictionary alloc] initWithCapacity:0];
-	
-	[self loadAutoconf];
-
-	configFiles = [NSMutableArray arrayWithCapacity:0];
-	[configFiles addObject:[[_config objectForKey:@"macports_conf_path"] stringByAppendingPathComponent:@"macports.conf"]];
-	[configFiles addObject:[[_config objectForKey:@"macports_user_dir"] stringByAppendingPathComponent:@"macports.conf"]];
-	if ((s = getenv("PORTSRC"))) {
-		[configFiles addObject:[NSString stringWithUTF8String:s]];
-	}
-
-	regex_t re;
-	rc = regcomp(&re, "^([A-Za-z_]+)([\\\t ]+(.*))?$", REG_EXTENDED);
-	assert(rc == 0);
-	assert(re.re_nsub == 3);
-	for (NSString *f in configFiles) {
-		size_t len;
-		char *line;
-		FILE *fp = fopen([f UTF8String], "r");
-		if (fp == NULL) continue;
-		while ((line = fgetln(fp, &len))) {
-			regmatch_t match[4];
-			line[len - 1] = '\0';
-			rc = regexec(&re, line, 4, match, 0);
-			if (rc == 0) {
-				NSString *k, *v;
-				k = [[NSString alloc] initWithBytes:&line[match[1].rm_so] length:(match[1].rm_eo - match[1].rm_so) encoding:NSUTF8StringEncoding];
-				if (match[3].rm_so >= 0) {
-					v = [[NSString alloc] initWithBytes:&line[match[3].rm_so] length:(match[3].rm_eo - match[3].rm_so) encoding:NSUTF8StringEncoding];
-				} else {
-					v = @"";
-				}
-				[_config setObject:v forKey:k];
-				[k release];
-				[v release];
-			}
-		}
-		fclose(fp);
-	}
-	regfree(&re);
-
-	NSLog(@"%@", _config);
-
-	return self;
-}
-
-- (void)dealloc
-{
-	[_config release];
-	[super dealloc];
-}
-
-- (void)loadAutoconf
-{
-	Tcl_Interp *interp;
-	int rc;
-	NSString *tmp;
-
-	interp = Tcl_CreateInterp(); 
-	rc = Tcl_EvalFile(interp, "/Library/Tcl/macports1.0/macports_autoconf.tcl");
-	if (rc == 0) {
-		[_config setObject:[NSString stringWithUTF8String:Tcl_GetVar(interp, "macports::autoconf::macports_conf_path", 0)] forKey:@"macports_conf_path"];
-		tmp = [NSString stringWithUTF8String:Tcl_GetVar(interp, "macports::autoconf::macports_user_dir", 0)];
-		tmp = [tmp stringByExpandingTildeInPath];
-		if (tmp) {
-			[_config setObject:tmp forKey:@"macports_user_dir"];
-		}
-	}
-	Tcl_DeleteInterp(interp);
-}
-
- at end

Modified: users/toby/objcports/objcports.xcodeproj/project.pbxproj
===================================================================
--- users/toby/objcports/objcports.xcodeproj/project.pbxproj	2009-09-10 06:53:47 UTC (rev 57362)
+++ users/toby/objcports/objcports.xcodeproj/project.pbxproj	2009-09-10 07:06:29 UTC (rev 57363)
@@ -8,7 +8,7 @@
 
 /* Begin PBXBuildFile section */
 		8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08FB779EFE84155DC02AAC07 /* Foundation.framework */; };
-		DA13887B101AED7000F73A82 /* MPConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = DA13887A101AED7000F73A82 /* MPConfig.m */; };
+		DA13887B101AED7000F73A82 /* MPConfig.c in Sources */ = {isa = PBXBuildFile; fileRef = DA13887A101AED7000F73A82 /* MPConfig.c */; };
 		DA7AF1BC1058D1E200CF2187 /* internal.c in Sources */ = {isa = PBXBuildFile; fileRef = DA7AF1BB1058D1E200CF2187 /* internal.c */; };
 		DA96BED00F7C9C2500362779 /* MPIndex.c in Sources */ = {isa = PBXBuildFile; fileRef = DA96BECF0F7C9C2500362779 /* MPIndex.c */; };
 		DA96BF4C0F7CA1A700362779 /* MPDictionaryAdditions.c in Sources */ = {isa = PBXBuildFile; fileRef = DA96BF4B0F7CA1A700362779 /* MPDictionaryAdditions.c */; };
@@ -35,7 +35,7 @@
 		08FB779EFE84155DC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
 		8DD76FA10486AA7600D96B5E /* port */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = port; sourceTree = BUILT_PRODUCTS_DIR; };
 		DA138879101AED7000F73A82 /* MPConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPConfig.h; sourceTree = "<group>"; };
-		DA13887A101AED7000F73A82 /* MPConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPConfig.m; sourceTree = "<group>"; };
+		DA13887A101AED7000F73A82 /* MPConfig.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = MPConfig.c; sourceTree = "<group>"; };
 		DA7AF1BA1058D1E200CF2187 /* internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = internal.h; sourceTree = "<group>"; };
 		DA7AF1BB1058D1E200CF2187 /* internal.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = internal.c; sourceTree = "<group>"; };
 		DA96BECE0F7C9C2500362779 /* MPIndex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPIndex.h; sourceTree = "<group>"; };
@@ -92,7 +92,7 @@
 				DAD3716F0F0280EF0064AFF4 /* MPStringAdditions.h */,
 				DAD371700F0280EF0064AFF4 /* MPStringAdditions.c */,
 				DA138879101AED7000F73A82 /* MPConfig.h */,
-				DA13887A101AED7000F73A82 /* MPConfig.m */,
+				DA13887A101AED7000F73A82 /* MPConfig.c */,
 				DA7AF1BA1058D1E200CF2187 /* internal.h */,
 				DA7AF1BB1058D1E200CF2187 /* internal.c */,
 				FD1CD53B1018F5AD0071534F /* variables.plist */,
@@ -173,7 +173,7 @@
 				DA96BED00F7C9C2500362779 /* MPIndex.c in Sources */,
 				DAD371740F0280EF0064AFF4 /* MPPort.m in Sources */,
 				DA96BF4C0F7CA1A700362779 /* MPDictionaryAdditions.c in Sources */,
-				DA13887B101AED7000F73A82 /* MPConfig.m in Sources */,
+				DA13887B101AED7000F73A82 /* MPConfig.c in Sources */,
 				DA7AF1BC1058D1E200CF2187 /* internal.c in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

Modified: users/toby/objcports/port.m
===================================================================
--- users/toby/objcports/port.m	2009-09-10 06:53:47 UTC (rev 57362)
+++ users/toby/objcports/port.m	2009-09-10 07:06:29 UTC (rev 57363)
@@ -8,13 +8,16 @@
 int
 main(int argc, char *argv[])
 {
-	NSAutoreleasePool *pool = [NSAutoreleasePool new];
+#if 0
+	CFDictionaryRef config = MPCopyConfig();
+	CFShow(config);
+	CFRelease(config);
+	return 0;
+#endif
 
 	if (argc < 2)
 		exit(1);
 
-	NSLog(@"%@", [MPConfig sharedConfig]);
-
 #if 0
 	CFStringRef filename = CFStringCreateWithCString(NULL, argv[1], kCFStringEncodingUTF8);
 	CFDictionaryRef index = MPCopyPortIndex(filename);
@@ -24,6 +27,8 @@
 	return 0;
 #endif
 
+	NSAutoreleasePool *pool = [NSAutoreleasePool new];
+	
 	while (--argc) {
 		MPPort *port = [[MPPort alloc] initWithPath:[NSString stringWithUTF8String:*++argv] options:nil];
 		NSLog(@"%@ @%@ (%@)", [port variable:@"name"], [port variable:@"version"], [port variable:@"categories"]);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20090910/4cb9a332/attachment-0001.html>


More information about the macports-changes mailing list