[darwinbuild-changes] [30] trunk/darwinxref

source_changes at macosforge.org source_changes at macosforge.org
Wed Oct 4 01:38:45 PDT 2006


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

Log Message:
-----------
- renamed load_plugins() to DBPluginLoadPlugins() and added
  support for multiple plugin directories

Modified Paths:
--------------
    trunk/darwinxref/DBPlugin.c
    trunk/darwinxref/DBPluginPriv.h
    trunk/darwinxref/main.c

Modified: trunk/darwinxref/DBPlugin.c
===================================================================
--- trunk/darwinxref/DBPlugin.c	2005-07-06 18:27:13 UTC (rev 29)
+++ trunk/darwinxref/DBPlugin.c	2006-10-04 08:38:45 UTC (rev 30)
@@ -111,16 +111,33 @@
 	return plugin;
 }
 
-int load_plugins(const char* plugin_path) {
+int DBPluginLoadPlugins(const char* plugin_path) {
 	if (plugins == NULL) {
 		plugins = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &cfDictionaryPluginValueCallBacks);
 	}
 	if (plugins == NULL) return -1;
 	
-	char fullpath[PATH_MAX];
-	realpath(plugin_path, fullpath);
+	//
+	// If the path contains colons, split the path and
+	// search each path component.  If there are no
+	// colons, CFStringCreateArrayBySeparatingStrings()
+	// will return an array with one element being the
+	// entire path.
+	//
+	CFStringRef str = cfstr(plugin_path);
+	CFArrayRef array = CFStringCreateArrayBySeparatingStrings(NULL, str, CFSTR(":"));
+	CFRelease(str);
+	CFIndex i, path_argc = CFArrayGetCount(array);
+	char** path_argv = malloc(sizeof(char*)*(path_argc+1));
+	for (i = 0; i < path_argc; ++i) {
+		path_argv[i] = strdup_cfstr(CFArrayGetValueAtIndex(array, i));
+	}
+	path_argv[i] = NULL;
+	CFRelease(array);
 	
-	const char* path_argv[] = {plugin_path, NULL};
+	//
+	// Search the directories for plugins
+	//
 	FTS* dir = fts_open((char * const *)path_argv, FTS_LOGICAL, NULL);
 	(void)fts_read(dir);
 	FTSENT* ent = fts_children (dir, FTS_NAMEONLY);
@@ -128,9 +145,10 @@
 		DBPlugin* plugin = NULL;
 		if (strstr(ent->fts_name, ".so")) {
 			char* filename;
-			asprintf(&filename, "%s/%s", fullpath, ent->fts_name);
+			asprintf(&filename, "%s/%s", ent->fts_accpath, ent->fts_name);
 //			fprintf(stderr, "plugin: loading %s\n", ent->fts_name);
 			void* handle = dlopen(filename, RTLD_LAZY | RTLD_LOCAL);
+			free(filename);
 			if (handle) {
 				DBPluginInitializeFunc func = dlsym(handle, "initialize");
 				plugin = _DBPluginInitialize();
@@ -143,10 +161,11 @@
 #if HAVE_TCL_PLUGINS
 		} else if (strstr(ent->fts_name, ".tcl")) {
 			char* filename;
-			asprintf(&filename, "%s/%s", fullpath, ent->fts_name);
+			asprintf(&filename, "%s/%s", ent->fts_accpath, ent->fts_name);
 			plugin = _DBPluginInitialize();
 			_DBPluginSetCurrentPlugin(plugin);
 			load_tcl_plugin(plugin, filename);	// Calls out to Tcl plugin
+			free(filename);
 #endif
 		}
 		if (plugin) {
@@ -161,6 +180,14 @@
 		ent = ent->fts_link;
 	}
 	fts_close(dir);
+	
+	//
+	// Release the path array
+	//
+	for (i = 0; i < path_argc; ++i) {
+		free(path_argv[i]);
+	}
+	free(path_argv);
 }
 
 void print_usage(char* progname, int argc, char* argv[]) {

Modified: trunk/darwinxref/DBPluginPriv.h
===================================================================
--- trunk/darwinxref/DBPluginPriv.h	2005-07-06 18:27:13 UTC (rev 29)
+++ trunk/darwinxref/DBPluginPriv.h	2006-10-04 08:38:45 UTC (rev 30)
@@ -79,7 +79,7 @@
 int call_tcl_run(DBPlugin* plugin, CFArrayRef args);
 #endif
 
-int load_plugins(const char* plugin_path);
+int DBPluginLoadPlugins(const char* path);
 int run_plugin(int argc, char* argv[]);
 int DBDataStoreInitialize(const char* datafile);
 void DBSetCurrentBuild(char* build);

Modified: trunk/darwinxref/main.c
===================================================================
--- trunk/darwinxref/main.c	2005-07-06 18:27:13 UTC (rev 29)
+++ trunk/darwinxref/main.c	2006-10-04 08:38:45 UTC (rev 30)
@@ -50,6 +50,11 @@
 	char* progname = argv[0];
 	char* dbfile = "/var/tmp/darwinxref.db";
 	char* build = getenv("DARWINBUILD_BUILD");
+	const char* plugins = getenv("DARWINXREF_PLUGIN_PATH");
+	
+	if (plugins == NULL) {
+		plugins = DEFAULT_PLUGIN_PATH;
+	}
 
 	int ch;
 	while ((ch = getopt(argc, argv, "f:b:")) != -1) {
@@ -71,7 +76,7 @@
 
 	DBDataStoreInitialize(dbfile);
 	DBSetCurrentBuild(build);
-	load_plugins("plugins");
+	DBPluginLoadPlugins(plugins);
 	if (run_plugin(argc, argv) == -1) {
 		print_usage(progname, argc, argv);
 		exit(1);

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


More information about the darwinbuild-changes mailing list