3 Free software by Richard W.E. Furse. Do with as you will. No
6 /*****************************************************************************/
17 #include <sys/types.h>
21 /*****************************************************************************/
26 /*****************************************************************************/
28 /* Search just the one directory. */
30 LADSPADirectoryPluginSearch
31 (const char * pcDirectory,
32 LADSPAPluginSearchCallbackFunction fCallbackFunction) {
36 LADSPA_Descriptor_Function fDescriptorFunction;
39 struct dirent * psDirectoryEntry;
40 void * pvPluginHandle;
42 lDirLength = strlen(pcDirectory);
45 if (pcDirectory[lDirLength - 1] == '/')
50 psDirectory = opendir(pcDirectory);
56 psDirectoryEntry = readdir(psDirectory);
57 if (!psDirectoryEntry) {
58 closedir(psDirectory);
62 pcFilename = malloc(lDirLength
63 + strlen(psDirectoryEntry->d_name)
65 strcpy(pcFilename, pcDirectory);
67 strcat(pcFilename, "/");
68 strcat(pcFilename, psDirectoryEntry->d_name);
70 pvPluginHandle = dlopen(pcFilename, RTLD_LAZY);
72 /* This is a file and the file is a shared library! */
76 = (LADSPA_Descriptor_Function)dlsym(pvPluginHandle,
78 if (dlerror() == NULL && fDescriptorFunction) {
79 /* We've successfully found a ladspa_descriptor function. Pass
80 it to the callback function. */
81 fCallbackFunction(pcFilename,
86 /* It was a library, but not a LADSPA one. Unload it. */
94 /*****************************************************************************/
97 LADSPAPluginSearch(LADSPAPluginSearchCallbackFunction fCallbackFunction) {
101 const char * pcLADSPAPath;
102 const char * pcStart;
104 /* thomasvs: I'm sorry, but I'm going to add glib stuff here.
105 * I'm appending logical values for LADSPA_PATH here
108 pcLADSPAPath = g_strdup_printf ("%s:/usr/lib/ladspa:/usr/local/lib/ladspa",
109 getenv("LADSPA_PATH"));
112 /* fprintf(stderr, */
113 /* "Warning: You do not have a LADSPA_PATH " */
114 /* "environment variable set.\n"); */
118 pcStart = pcLADSPAPath;
119 while (*pcStart != '\0') {
121 while (*pcEnd != ':' && *pcEnd != '\0')
124 pcBuffer = malloc(1 + pcEnd - pcStart);
126 strncpy(pcBuffer, pcStart, pcEnd - pcStart);
127 pcBuffer[pcEnd - pcStart] = '\0';
129 LADSPADirectoryPluginSearch(pcBuffer, fCallbackFunction);
138 /*****************************************************************************/