[65313] users/toby/objcports
toby at macports.org
toby at macports.org
Wed Mar 24 21:37:55 PDT 2010
Revision: 65313
http://trac.macports.org/changeset/65313
Author: toby at macports.org
Date: 2010-03-24 21:37:54 -0700 (Wed, 24 Mar 2010)
Log Message:
-----------
support reading PortIndex from arbitrary url
Modified Paths:
--------------
users/toby/objcports/MPIndex.h
users/toby/objcports/objcports.xcodeproj/project.pbxproj
users/toby/objcports/port.m
Added Paths:
-----------
users/toby/objcports/MPIndex.m
Removed Paths:
-------------
users/toby/objcports/MPIndex.c
Deleted: users/toby/objcports/MPIndex.c
===================================================================
--- users/toby/objcports/MPIndex.c 2010-03-25 03:47:53 UTC (rev 65312)
+++ users/toby/objcports/MPIndex.c 2010-03-25 04:37:54 UTC (rev 65313)
@@ -1,64 +0,0 @@
-#include <CoreFoundation/CoreFoundation.h>
-#include <tcl.h>
-
-#include "MPIndex.h"
-#include "cftcl.h"
-#include "internal.h"
-
-CFDictionaryRef
-MPCopyPortIndex(CFStringRef filename)
-{
- CFMutableDictionaryRef result = NULL;
- Tcl_Interp *interp;
- char *fn;
- Tcl_Channel chan;
-
- result = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
-
- interp = Tcl_CreateInterp();
- assert(Tcl_SetSystemEncoding(interp, "utf-8") == TCL_OK);
- fn = strdup_cf(filename);
- chan = Tcl_OpenFileChannel(interp, fn, "r", 0);
- free(fn);
- Tcl_RegisterChannel(interp, chan);
-
- for (;;) {
- int objc;
- Tcl_Obj **objv;
- CFStringRef key;
- CFDictionaryRef value;
- Tcl_Obj *line;
- int len;
-
- line = Tcl_NewObj();
- Tcl_IncrRefCount(line);
-
- /* Read info line. */
- if (Tcl_GetsObj(chan, line) < 0) {
- Tcl_DecrRefCount(line);
- break;
- }
- Tcl_ListObjGetElements(interp, line, &objc, &objv);
- assert(objc == 2);
- key = CFStringCreateWithTclObject(NULL, objv[0]);
- Tcl_GetIntFromObj(interp, objv[1], &len);
-
- /* Read dictionary. */
- Tcl_ReadChars(chan, line, len, 0);
- Tcl_ListObjGetElements(interp, line, &objc, &objv);
- value = CFDictionaryCreateWithTclObjects(NULL, objv, objc);
- assert(value);
-
- /* Store data. */
- CFDictionarySetValue(result, key, value);
- CFRelease(key);
- CFRelease(value);
-
- Tcl_DecrRefCount(line);
- }
-
- Tcl_UnregisterChannel(interp, chan);
- Tcl_DeleteInterp(interp);
-
- return result;
-}
Modified: users/toby/objcports/MPIndex.h
===================================================================
--- users/toby/objcports/MPIndex.h 2010-03-25 03:47:53 UTC (rev 65312)
+++ users/toby/objcports/MPIndex.h 2010-03-25 04:37:54 UTC (rev 65313)
@@ -1 +1,8 @@
-CFDictionaryRef MPCopyPortIndex(CFStringRef filename);
+ at interface MPIndex : NSObject {
+ NSURL *_source;
+ NSMutableDictionary *_index;
+}
+
+- (id)initWithSourceURL:(NSURL *)source;
+
+ at end
Copied: users/toby/objcports/MPIndex.m (from rev 65311, users/toby/objcports/MPIndex.c)
===================================================================
--- users/toby/objcports/MPIndex.m (rev 0)
+++ users/toby/objcports/MPIndex.m 2010-03-25 04:37:54 UTC (rev 65313)
@@ -0,0 +1,173 @@
+#include <Foundation/Foundation.h>
+#include <tcl.h>
+
+#include "MPIndex.h"
+#include "cftcl.h"
+
+struct NSData_channel_ctx {
+ NSData *data;
+ off_t offset;
+};
+
+static int
+dataclose(ClientData instanceData, Tcl_Interp *interp)
+{
+ struct NSData_channel_ctx *ctx = (struct NSData_channel_ctx *)instanceData;
+
+ [ctx->data release];
+ free(ctx);
+
+ return 0;
+}
+
+static int
+datainput(ClientData instanceData, char *buf, int bufSize, int *errorCodePtr)
+{
+ struct NSData_channel_ctx *ctx = (struct NSData_channel_ctx *)instanceData;
+ size_t bytes;
+
+ bytes = MIN([ctx->data length] - ctx->offset, bufSize);
+
+ memcpy(buf, [ctx->data bytes] + ctx->offset, bytes);
+ ctx->offset += bytes;
+
+ return (int)bytes;
+}
+
+static void
+datawatch(ClientData instanceData, int mask)
+{
+ //printf("%s (%p %d)\n", __FUNCTION__, instanceData, mask);
+}
+
+static Tcl_ChannelType NSDataChannelType = {
+ "NSData", // typeName
+ TCL_CHANNEL_VERSION_5, // version
+ dataclose, // closeProc
+ datainput, // inputProc
+ NULL, // outputProc (maybe)
+ NULL, // seekProc
+ NULL, // setOptionProc
+ NULL, // getOptionProc
+ datawatch, // watchProc
+ NULL, // getHandleProc (maybe)
+ NULL, // close2Proc
+ NULL, // blockModeProc
+ NULL, // flushProc (2)
+ NULL, // handlerProc (2)
+ NULL, // wideSeekProc (3)
+ NULL, // threadActionProc (4)
+ NULL, // truncateProc (5)
+};
+
+Tcl_Channel
+Tcl_CreateNSDataChannel(NSData *data)
+{
+ char *channel_name;
+ Tcl_Channel channel = NULL;
+ struct NSData_channel_ctx *ctx;
+
+ if (data) {
+ ctx = malloc(sizeof(*ctx));
+ ctx->data = [data retain];
+ ctx->offset = 0;
+
+ asprintf(&channel_name, "%p", data);
+ channel = Tcl_CreateChannel(&NSDataChannelType, channel_name, ctx, TCL_READABLE);
+ free(channel_name);
+ }
+
+ return channel;
+}
+
+static NSMutableDictionary *
+MPCopyPortIndex(NSData *data)
+{
+ NSMutableDictionary *result;
+ Tcl_Interp *interp;
+ Tcl_Channel chan;
+
+ result = [[NSMutableDictionary alloc] initWithCapacity:0];
+
+ interp = Tcl_CreateInterp();
+ assert(Tcl_SetSystemEncoding(interp, "utf-8") == TCL_OK);
+
+ chan = Tcl_CreateNSDataChannel(data);
+ Tcl_RegisterChannel(interp, chan);
+
+ for (;;) {
+ int objc;
+ Tcl_Obj **objv;
+ Tcl_Obj *line;
+ int len;
+ NSString *key;
+ NSDictionary *value;
+
+ line = Tcl_NewObj();
+ Tcl_IncrRefCount(line);
+
+ /* Read info line. */
+ if (Tcl_GetsObj(chan, line) < 0) {
+ Tcl_DecrRefCount(line);
+ break;
+ }
+ Tcl_ListObjGetElements(interp, line, &objc, &objv);
+ assert(objc == 2);
+ key = CFStringCreateWithTclObject(NULL, objv[0]);
+ Tcl_GetIntFromObj(interp, objv[1], &len);
+
+ /* Read dictionary. */
+ Tcl_ReadChars(chan, line, len, 0);
+ Tcl_ListObjGetElements(interp, line, &objc, &objv);
+ value = CFDictionaryCreateWithTclObjects(NULL, objv, objc);
+ assert(value);
+
+ /* Store data. */
+ [result setObject:value forKey:key];
+ CFRelease(key);
+ CFRelease(value);
+
+ Tcl_DecrRefCount(line);
+ }
+
+ Tcl_UnregisterChannel(interp, chan);
+ Tcl_DeleteInterp(interp);
+
+ return result;
+}
+
+ at implementation MPIndex
+
+- (id)initWithSourceURL:(NSURL *)source
+{
+ NSError *error;
+ NSData *data;
+
+ self = [super init];
+
+ _source = [source retain];
+
+ data = [[NSData alloc] initWithContentsOfURL:[_source URLByAppendingPathComponent:@"PortIndex"] options:(NSDataReadingMapped | NSDataReadingUncached) error:&error];
+ if (data) {
+ _index = MPCopyPortIndex(data);
+ [data release];
+ } else {
+ NSLog(@"%@", error);
+ }
+
+ return self;
+}
+
+- (void)dealloc
+{
+ [_source release];
+ [_index release];
+ [super dealloc];
+}
+
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"<%@: %@>", [self class], _source];
+}
+
+ at end
Modified: users/toby/objcports/objcports.xcodeproj/project.pbxproj
===================================================================
--- users/toby/objcports/objcports.xcodeproj/project.pbxproj 2010-03-25 03:47:53 UTC (rev 65312)
+++ users/toby/objcports/objcports.xcodeproj/project.pbxproj 2010-03-25 04:37:54 UTC (rev 65313)
@@ -7,11 +7,12 @@
objects = {
/* Begin PBXBuildFile section */
+ DA03DF48115B11A90036231B /* libcurl.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = DA03DF47115B11A90036231B /* libcurl.dylib */; };
DA13887B101AED7000F73A82 /* MPConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = DA13887A101AED7000F73A82 /* MPConfig.m */; };
DA382DE5105A284E00D9B600 /* cftcl.c in Sources */ = {isa = PBXBuildFile; fileRef = DA382DE4105A284E00D9B600 /* cftcl.c */; };
DA382EF0105A2B4900D9B600 /* Tcl.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA382EEF105A2B4900D9B600 /* Tcl.framework */; };
DA7AF1BC1058D1E200CF2187 /* internal.c in Sources */ = {isa = PBXBuildFile; fileRef = DA7AF1BB1058D1E200CF2187 /* internal.c */; };
- DA96BED00F7C9C2500362779 /* MPIndex.c in Sources */ = {isa = PBXBuildFile; fileRef = DA96BECF0F7C9C2500362779 /* MPIndex.c */; };
+ DA96BED00F7C9C2500362779 /* MPIndex.m in Sources */ = {isa = PBXBuildFile; fileRef = DA96BECF0F7C9C2500362779 /* MPIndex.m */; };
DAB2118E107B33AB002E931E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DAB2118D107B33AB002E931E /* Foundation.framework */; };
DAD371710F0280EF0064AFF4 /* port.m in Sources */ = {isa = PBXBuildFile; fileRef = DAD371680F0280EF0064AFF4 /* port.m */; };
DAD371740F0280EF0064AFF4 /* MPPort.c in Sources */ = {isa = PBXBuildFile; fileRef = DAD3716E0F0280EF0064AFF4 /* MPPort.c */; };
@@ -32,6 +33,7 @@
/* Begin PBXFileReference section */
08FB779EFE84155DC02AAC07 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = "<absolute>"; };
8DD76FA10486AA7600D96B5E /* port */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = port; sourceTree = BUILT_PRODUCTS_DIR; };
+ DA03DF47115B11A90036231B /* libcurl.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcurl.dylib; path = /usr/lib/libcurl.dylib; sourceTree = "<absolute>"; };
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>"; };
DA382DE3105A284E00D9B600 /* cftcl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cftcl.h; sourceTree = "<group>"; };
@@ -40,7 +42,7 @@
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>"; };
- DA96BECF0F7C9C2500362779 /* MPIndex.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = MPIndex.c; sourceTree = "<group>"; };
+ DA96BECF0F7C9C2500362779 /* MPIndex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPIndex.m; sourceTree = "<group>"; };
DAB2118D107B33AB002E931E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
DAD371680F0280EF0064AFF4 /* port.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = port.m; sourceTree = "<group>"; };
DAD3716D0F0280EF0064AFF4 /* MPPort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPPort.h; sourceTree = "<group>"; };
@@ -55,6 +57,7 @@
files = (
DAB2118E107B33AB002E931E /* Foundation.framework in Frameworks */,
DA382EF0105A2B4900D9B600 /* Tcl.framework in Frameworks */,
+ DA03DF48115B11A90036231B /* libcurl.dylib in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -68,6 +71,7 @@
C6859EA2029092E104C91782 /* Documentation */,
08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */,
1AB674ADFE9D54B511CA2CBB /* Products */,
+ DA03DF47115B11A90036231B /* libcurl.dylib */,
);
name = objcports;
sourceTree = "<group>";
@@ -77,7 +81,7 @@
children = (
DAD371680F0280EF0064AFF4 /* port.m */,
DA96BECE0F7C9C2500362779 /* MPIndex.h */,
- DA96BECF0F7C9C2500362779 /* MPIndex.c */,
+ DA96BECF0F7C9C2500362779 /* MPIndex.m */,
DAD3716D0F0280EF0064AFF4 /* MPPort.h */,
DAD3716E0F0280EF0064AFF4 /* MPPort.c */,
DA138879101AED7000F73A82 /* MPConfig.h */,
@@ -160,7 +164,7 @@
buildActionMask = 2147483647;
files = (
DAD371710F0280EF0064AFF4 /* port.m in Sources */,
- DA96BED00F7C9C2500362779 /* MPIndex.c in Sources */,
+ DA96BED00F7C9C2500362779 /* MPIndex.m in Sources */,
DAD371740F0280EF0064AFF4 /* MPPort.c in Sources */,
DA13887B101AED7000F73A82 /* MPConfig.m in Sources */,
DA7AF1BC1058D1E200CF2187 /* internal.c in Sources */,
Modified: users/toby/objcports/port.m
===================================================================
--- users/toby/objcports/port.m 2010-03-25 03:47:53 UTC (rev 65312)
+++ users/toby/objcports/port.m 2010-03-25 04:37:54 UTC (rev 65313)
@@ -19,12 +19,16 @@
static void
do_showindex(char *f)
{
- NSDictionary *dict;
+ NSURL *url;
+ MPIndex *portindex;
- dict = (NSDictionary *)MPCopyPortIndex((CFStringRef)[NSString stringWithUTF8String:f]);
- if (dict) {
- NSLog(@"%@", dict);
- [dict release];
+ url = [NSURL URLWithString:[NSString stringWithUTF8String:f]];
+ if (url) {
+ portindex = [[MPIndex alloc] initWithSourceURL:url];
+ if (portindex) {
+ NSLog(@"%@", portindex);
+ [portindex release];
+ }
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20100324/c963ceae/attachment-0001.html>
More information about the macports-changes
mailing list