[darwinbuild-changes] [248] trunk/darwinxref/DBDataStore.c

source_changes at macosforge.org source_changes at macosforge.org
Wed Oct 4 02:01:57 PDT 2006


Revision: 248
          http://trac.macosforge.org/projects/darwinbuild/changeset/248
Author:   kevin
Date:     2006-10-04 02:01:57 -0700 (Wed, 04 Oct 2006)

Log Message:
-----------
- DBCopyProjectNames now copies all project names (including inherited builds).
  To get project names for only one build, use DBCopyOneProjectNames().

Modified Paths:
--------------
    trunk/darwinxref/DBDataStore.c

Modified: trunk/darwinxref/DBDataStore.c
===================================================================
--- trunk/darwinxref/DBDataStore.c	2005-09-15 16:20:22 UTC (rev 247)
+++ trunk/darwinxref/DBDataStore.c	2006-10-04 09:01:57 UTC (rev 248)
@@ -262,13 +262,46 @@
 	return res;
 }
 
-CFArrayRef DBCopyProjectNames(CFStringRef build) {
+CFArrayRef DBCopyOneProjectNames(CFStringRef build) {
 	char* cbuild = strdup_cfstr(build);
 	CFArrayRef res = SQL_CFARRAY("SELECT DISTINCT project FROM properties WHERE build=%Q ORDER BY project", cbuild);
 	free(cbuild);
 	return res;
 }
 
+// appends each element that does not already exist in the array
+static void arrayAppendArrayDistinct(CFMutableArrayRef array, CFArrayRef other) {
+	CFIndex i, count = CFArrayGetCount(other);
+	CFRange range = CFRangeMake(0, CFArrayGetCount(array));
+	for (i = 0; i < count; ++i) {
+		CFTypeRef o = CFArrayGetValueAtIndex(other, i);
+		if (!CFArrayContainsValue(array, range, o)) {
+			CFArrayAppendValue(array, o);
+		}
+	}
+}
+
+static CFStringRef _DBCopyPropString(CFStringRef build, CFStringRef project, CFStringRef property);
+
+CFArrayRef DBCopyProjectNames(CFStringRef build) {
+	CFMutableArrayRef projects = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
+	do {		
+		char* cbuild = strdup_cfstr(build);
+		CFArrayRef res = SQL_CFARRAY("SELECT DISTINCT project FROM properties WHERE build=%Q", cbuild);
+		free(cbuild);
+
+		arrayAppendArrayDistinct(projects, res);
+		CFRelease(res);
+
+		build = _DBCopyPropString(build, NULL, CFSTR("inherits"));
+	} while (build != NULL);
+
+	CFArraySortValues(projects, CFRangeMake(0, CFArrayGetCount(projects)), (CFComparatorFunction)CFStringCompare, 0);
+
+	return projects;
+}
+
+
 CFArrayRef DBCopyChangedProjectNames(CFStringRef oldbuild, CFStringRef newbuild) {
 	char* coldbuild = strdup_cfstr(oldbuild);
 	char* cnewbuild = strdup_cfstr(newbuild);

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20061004/a81bfb59/attachment-0001.html


More information about the darwinbuild-changes mailing list