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)
37 LADSPA_Descriptor_Function fDescriptorFunction;
40 struct dirent *psDirectoryEntry;
43 lDirLength = strlen (pcDirectory);
46 if (pcDirectory[lDirLength - 1] == '/')
51 psDirectory = opendir (pcDirectory);
57 psDirectoryEntry = readdir (psDirectory);
58 if (!psDirectoryEntry) {
59 closedir (psDirectory);
63 pcFilename = malloc (lDirLength + 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, pvPluginHandle, fDescriptorFunction);
83 /* It was a library, but not a LADSPA one. Unload it. */
91 /*****************************************************************************/
94 LADSPAPluginSearch (LADSPAPluginSearchCallbackFunction fCallbackFunction)
99 const char *pcLADSPAPath;
102 /* thomasvs: I'm sorry, but I'm going to add glib stuff here.
103 * I'm appending logical values for LADSPA_PATH here
106 pcLADSPAPath = g_strdup_printf ("%s:/usr/lib/ladspa:/usr/local/lib/ladspa",
107 getenv ("LADSPA_PATH"));
110 /* fprintf(stderr, */
111 /* "Warning: You do not have a LADSPA_PATH " */
112 /* "environment variable set.\n"); */
116 pcStart = pcLADSPAPath;
117 while (*pcStart != '\0') {
119 while (*pcEnd != ':' && *pcEnd != '\0')
122 pcBuffer = malloc (1 + pcEnd - pcStart);
124 strncpy (pcBuffer, pcStart, pcEnd - pcStart);
125 pcBuffer[pcEnd - pcStart] = '\0';
127 LADSPADirectoryPluginSearch (pcBuffer, fCallbackFunction);
136 /*****************************************************************************/