<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[58673] users/toby/objcports/misc/depstree2.c</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.macports.org/changeset/58673">58673</a></dd>
<dt>Author</dt> <dd>toby@macports.org</dd>
<dt>Date</dt> <dd>2009-10-02 10:46:47 -0700 (Fri, 02 Oct 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>obsolete</pre>
<h3>Removed Paths</h3>
<ul>
<li><a href="#userstobyobjcportsmiscdepstree2c">users/toby/objcports/misc/depstree2.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="userstobyobjcportsmiscdepstree2c"></a>
<div class="delfile"><h4>Deleted: users/toby/objcports/misc/depstree2.c (58672 => 58673)</h4>
<pre class="diff"><span>
<span class="info">--- users/toby/objcports/misc/depstree2.c        2009-10-02 17:46:36 UTC (rev 58672)
+++ users/toby/objcports/misc/depstree2.c        2009-10-02 17:46:47 UTC (rev 58673)
</span><span class="lines">@@ -1,306 +0,0 @@
</span><del>-/*
- * Copyright (c) 2009 Toby Peterson <toby@macports.org>. All rights reserved.
- */
-
-#include <CoreFoundation/CoreFoundation.h>
-#include <tcl.h>
-#include <unistd.h>
-
-CFStringRef
-CFStringCreateWithTclObject(CFAllocatorRef allocator, Tcl_Obj *obj)
-{
-        return CFStringCreateWithCString(allocator, Tcl_GetString(obj), kCFStringEncodingUTF8);
-}
-
-CFArrayRef
-CFArrayCreateTcl(CFAllocatorRef allocator, Tcl_Obj **objects, CFIndex count)
-{
-        CFIndex i;
-        CFStringRef array[count];
-        CFArrayRef result;
-
-        for (i = 0; i < count; i++) {
-                array[i] = CFStringCreateWithTclObject(allocator, objects[i]);
-        }
-        result = CFArrayCreate(allocator, (const void **)array, count, &kCFTypeArrayCallBacks);
-        for (i = 0; i < count; i++) {
-                CFRelease(array[i]);
-        }
-        return result;
-}
-
-char *
-strdup_cf(CFStringRef str)
-{
-        CFIndex length, size;
-        char *result = NULL;
-
-        length = CFStringGetLength(str);
-        size = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
-        result = malloc(size);
-        CFStringGetCString(str, result, size, kCFStringEncodingUTF8);
-
-        return result;
-}
-
-int
-fprintf_cf(FILE *stream, CFStringRef format, ...)
-{
-        va_list ap;
-        CFStringRef str;
-        char *output;
-        __block int rc = -1;
-
-        static dispatch_once_t once;
-        static dispatch_queue_t pqueue;
-
-        dispatch_once(&once, ^{
-                pqueue = dispatch_queue_create(NULL, NULL);
-        });
-
-        va_start(ap, format);
-        str = CFStringCreateWithFormatAndArguments(NULL, NULL, format, ap);
-        va_end(ap);
-
-        output = strdup_cf(str);
-        CFRelease(str);
-        dispatch_sync(pqueue, ^{
-                rc = fprintf(stream, "%s", output);
-        });
-        free(output);
-
-        return rc;
-}
-
-CFDictionaryRef
-copy_indexentry(Tcl_Interp *interp, Tcl_Obj **objects, CFIndex count)
-{
-        CFDictionaryRef result = NULL;
-        CFIndex i;
-        CFIndex count2 = count / 2;
-        CFStringRef keys[count2];
-        CFTypeRef values[count2];
-
-        for (i = 0; i < count2; i++) {
-                keys[i] = CFStringCreateWithTclObject(NULL, objects[i * 2]);
-                if (CFStringHasPrefix(keys[i], CFSTR("depends_"))) {
-                        int objc;
-                        Tcl_Obj **objv;
-                        Tcl_ListObjGetElements(interp, objects[i * 2 + 1], &objc, &objv);
-                        values[i] = CFArrayCreateTcl(NULL, objv, objc);
-                } else {
-                        values[i] = CFStringCreateWithTclObject(NULL, objects[i * 2 + 1]);
-                }
-        }
-        result = CFDictionaryCreate(NULL, (const void **)keys, values, count2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
-        for (i = 0; i < count2; i++) {
-                CFRelease(keys[i]);
-                CFRelease(values[i]);
-        }
-
-        return result;
-}
-
-CFDictionaryRef
-get_portindex()
-{
-        static CFMutableDictionaryRef dict;
-        Tcl_Interp *interp;
-        Tcl_Channel chan;
-
-        if (dict) {
-                return dict;
-        }
-
-        dict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
-
-        interp = Tcl_CreateInterp();
-        assert(Tcl_SetSystemEncoding(interp, "utf-8") == TCL_OK);
-        chan = Tcl_OpenFileChannel(interp, "/Volumes/data/source/macports/dports/PortIndex", "r", 0);
-        Tcl_RegisterChannel(interp, chan);
-
-        while (1) {
-                int objc;
-                Tcl_Obj **objv;
-                CFTypeRef key, value;
-                CFArrayRef info;
-                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);
-                info = CFArrayCreateTcl(NULL, objv, objc);
-                assert(CFArrayGetCount(info) == 2);
-                key = CFRetain(CFArrayGetValueAtIndex(info, 0));
-                len = CFStringGetIntValue(CFArrayGetValueAtIndex(info, 1));
-                CFRelease(info);
-
-                /* Read dictionary. */
-                Tcl_ReadChars(chan, line, len, 0);
-                Tcl_ListObjGetElements(interp, line, &objc, &objv);
-                value = copy_indexentry(interp, objv, objc);
-                assert(value != nil);
-
-                /* Store data. */
-                CFDictionarySetValue(dict, key, value);
-
-                CFRelease(key);
-                CFRelease(value);
-
-                Tcl_DecrRefCount(line);
-        }
-
-        Tcl_UnregisterChannel(interp, chan);
-        Tcl_DeleteInterp(interp);
-
-        return dict;
-}
-
-static CFStringRef deptypes[] = {
-        CFSTR("depends_build"),
-        CFSTR("depends_lib"),
-        CFSTR("depends_run"),
-};
-
-CFArrayRef
-copy_deps(CFStringRef port)
-{
-        CFDictionaryRef info;
-        CFMutableArrayRef deps;
-        CFArrayRef tmp, split;
-        CFIndex i, j, count;
-
-        deps = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
-
-        info = CFDictionaryGetValue(get_portindex(), port);
-
-        for (i = 0; i < 3; i++) {
-                tmp = CFDictionaryGetValue(info, deptypes[i]);
-                if (!tmp) continue;
-                count = CFArrayGetCount(tmp);
-                for (j = 0; j < count; j++) {
-                        split = CFStringCreateArrayBySeparatingStrings(NULL, CFArrayGetValueAtIndex(tmp, j), CFSTR(":"));
-                        CFArrayAppendValue(deps, CFArrayGetValueAtIndex(split, CFArrayGetCount(split) - 1));
-                        CFRelease(split);
-                }
-        }
-
-        return deps;
-}
-
-static Boolean
-skip_port(CFStringRef port, dispatch_group_t *group)
-{
-        static CFMutableDictionaryRef built;
-        static dispatch_queue_t built_queue;
-        static dispatch_once_t once;
-        __block Boolean skip = TRUE;
-
-        dispatch_once(&once, ^{
-                built_queue = dispatch_queue_create(NULL, NULL);
-                dispatch_sync(built_queue, ^{
-                        built = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, NULL);
-                });
-        });
-
-        dispatch_sync(built_queue, ^{
-                if (!CFDictionaryContainsKey(built, port)) {
-                        skip = FALSE;
-                        *group = dispatch_group_create();
-                        CFDictionarySetValue(built, port, *group);
-                } else {
-                        skip = TRUE;
-                        *group = (dispatch_group_t)CFDictionaryGetValue(built, port);
-                }
-        });
-
-        return skip;
-}
-
-static void
-build_port(CFStringRef port, CFIndex indent)
-{
-        CFMutableStringRef output;
-        CFIndex j;
-        dispatch_group_t group;
-
-        if (skip_port(port, &group)) {
-                dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
-                return;
-        }
-
-        dispatch_group_enter(group);
-
-        output = CFStringCreateMutable(NULL, 0);
-        for (j = 0; j < indent; j++) {
-                CFStringAppend(output, CFSTR(" "));
-        }
-        CFStringAppend(output, port);
-        fprintf_cf(stdout, CFSTR("building %@\n"), output);
-
-        // fake it
-        usleep(random() / 700);
-
-        fprintf_cf(stdout, CFSTR(" done %@\n"), output);
-
-        CFRelease(output);
-
-        dispatch_group_leave(group);
-        // TODO: leaking this, not sure where to release it
-        //dispatch_release(group);
-}
-
-static void
-build_port_tree(CFStringRef port, CFIndex indent)
-{
-        dispatch_group_t group;
-        CFArrayRef deps;
-        CFIndex count;
-
-        deps = copy_deps(port);
-        count = CFArrayGetCount(deps);
-
-        group = dispatch_group_create();
-
-        if (count) {
-                dispatch_apply(count, dispatch_get_global_queue(0, 0), ^(size_t i) {
-                        dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{
-                                build_port_tree(CFArrayGetValueAtIndex(deps, i), indent + 1);
-                        });
-                });
-                dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
-                CFRelease(deps);
-
-                build_port(port, indent);
-        } else {
-                build_port(port, indent);
-        }
-}
-
-int
-main(int argc, char *argv[])
-{
-        CFStringRef port;
-
-        if (argc != 2) {
-                fprintf(stderr, "usage: depstree port\n");
-                exit(1);
-        }
-
-        srandom(time(NULL));
-
-        port = CFStringCreateWithCString(NULL, argv[1], kCFStringEncodingUTF8);
-        build_port_tree(port, 0);
-        CFRelease(port);
-
-        dispatch_main();
-
-        return 0;
-}
</del></span></pre>
</div>
</div>
</body>
</html>