2001-12-23 15:26:43 +00:00
|
|
|
/* search.c
|
|
|
|
|
|
|
|
Free software by Richard W.E. Furse. Do with as you will. No
|
|
|
|
warranty. */
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2003-11-07 12:47:02 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2001-12-23 15:26:43 +00:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2002-06-04 19:32:16 +00:00
|
|
|
#include <glib.h>
|
2001-12-23 15:26:43 +00:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
#include "ladspa.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
/* Search just the one directory. */
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
LADSPADirectoryPluginSearch
|
|
|
|
(const char *pcDirectory,
|
|
|
|
LADSPAPluginSearchCallbackFunction fCallbackFunction)
|
|
|
|
{
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
char *pcFilename;
|
|
|
|
DIR *psDirectory;
|
2001-12-23 15:26:43 +00:00
|
|
|
LADSPA_Descriptor_Function fDescriptorFunction;
|
|
|
|
long lDirLength;
|
|
|
|
long iNeedSlash;
|
2004-03-14 22:34:33 +00:00
|
|
|
struct dirent *psDirectoryEntry;
|
|
|
|
void *pvPluginHandle;
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
lDirLength = strlen (pcDirectory);
|
2001-12-23 15:26:43 +00:00
|
|
|
if (!lDirLength)
|
|
|
|
return;
|
|
|
|
if (pcDirectory[lDirLength - 1] == '/')
|
|
|
|
iNeedSlash = 0;
|
|
|
|
else
|
|
|
|
iNeedSlash = 1;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
psDirectory = opendir (pcDirectory);
|
2001-12-23 15:26:43 +00:00
|
|
|
if (!psDirectory)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
psDirectoryEntry = readdir (psDirectory);
|
2001-12-23 15:26:43 +00:00
|
|
|
if (!psDirectoryEntry) {
|
2004-03-14 22:34:33 +00:00
|
|
|
closedir (psDirectory);
|
2001-12-23 15:26:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
pcFilename = malloc (lDirLength + strlen (psDirectoryEntry->d_name)
|
2004-03-15 19:32:27 +00:00
|
|
|
+ 1 + iNeedSlash);
|
2004-03-14 22:34:33 +00:00
|
|
|
strcpy (pcFilename, pcDirectory);
|
2001-12-23 15:26:43 +00:00
|
|
|
if (iNeedSlash)
|
2004-03-14 22:34:33 +00:00
|
|
|
strcat (pcFilename, "/");
|
|
|
|
strcat (pcFilename, psDirectoryEntry->d_name);
|
|
|
|
|
|
|
|
pvPluginHandle = dlopen (pcFilename, RTLD_LAZY);
|
2001-12-23 15:26:43 +00:00
|
|
|
if (pvPluginHandle) {
|
|
|
|
/* This is a file and the file is a shared library! */
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
dlerror ();
|
2001-12-23 15:26:43 +00:00
|
|
|
fDescriptorFunction
|
2004-03-15 19:32:27 +00:00
|
|
|
= (LADSPA_Descriptor_Function) dlsym (pvPluginHandle,
|
|
|
|
"ladspa_descriptor");
|
2004-03-14 22:34:33 +00:00
|
|
|
if (dlerror () == NULL && fDescriptorFunction) {
|
2004-03-15 19:32:27 +00:00
|
|
|
/* We've successfully found a ladspa_descriptor function. Pass
|
|
|
|
it to the callback function. */
|
|
|
|
fCallbackFunction (pcFilename, pvPluginHandle, fDescriptorFunction);
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
2004-03-15 19:32:27 +00:00
|
|
|
/* It was a library, but not a LADSPA one. Unload it. */
|
2004-08-31 14:41:37 +00:00
|
|
|
dlclose (pvPluginHandle);
|
2001-12-23 15:26:43 +00:00
|
|
|
}
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
free (pcFilename);
|
2001-12-23 15:26:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
void
|
|
|
|
LADSPAPluginSearch (LADSPAPluginSearchCallbackFunction fCallbackFunction)
|
|
|
|
{
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
char *pcBuffer;
|
|
|
|
const char *pcEnd;
|
|
|
|
const char *pcLADSPAPath;
|
|
|
|
const char *pcStart;
|
2009-01-08 17:57:19 +00:00
|
|
|
char *search_path;
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2002-06-04 19:32:16 +00:00
|
|
|
/* thomasvs: I'm sorry, but I'm going to add glib stuff here.
|
2004-03-14 22:34:33 +00:00
|
|
|
* I'm appending logical values for LADSPA_PATH here
|
|
|
|
*/
|
2002-06-04 19:32:16 +00:00
|
|
|
|
2009-01-08 17:57:19 +00:00
|
|
|
search_path = getenv ("LADSPA_PATH");
|
|
|
|
if (search_path) {
|
|
|
|
pcLADSPAPath = g_strdup_printf ("%s:/usr/lib/ladspa:/usr/local/lib/ladspa",
|
|
|
|
search_path);
|
|
|
|
} else {
|
|
|
|
pcLADSPAPath = g_strdup ("/usr/lib/ladspa:/usr/local/lib/ladspa");
|
|
|
|
}
|
2002-06-04 19:32:16 +00:00
|
|
|
|
2001-12-23 15:26:43 +00:00
|
|
|
if (!pcLADSPAPath) {
|
2002-03-19 04:10:06 +00:00
|
|
|
/* fprintf(stderr, */
|
2005-12-06 19:44:48 +00:00
|
|
|
/* "Warning: You do not have a LADSPA_PATH " */
|
|
|
|
/* "environment variable set.\n"); */
|
2001-12-23 15:26:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2001-12-23 15:26:43 +00:00
|
|
|
pcStart = pcLADSPAPath;
|
|
|
|
while (*pcStart != '\0') {
|
|
|
|
pcEnd = pcStart;
|
|
|
|
while (*pcEnd != ':' && *pcEnd != '\0')
|
|
|
|
pcEnd++;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
pcBuffer = malloc (1 + pcEnd - pcStart);
|
2001-12-23 15:26:43 +00:00
|
|
|
if (pcEnd > pcStart)
|
2004-03-14 22:34:33 +00:00
|
|
|
strncpy (pcBuffer, pcStart, pcEnd - pcStart);
|
2001-12-23 15:26:43 +00:00
|
|
|
pcBuffer[pcEnd - pcStart] = '\0';
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
LADSPADirectoryPluginSearch (pcBuffer, fCallbackFunction);
|
|
|
|
free (pcBuffer);
|
2001-12-23 15:26:43 +00:00
|
|
|
|
|
|
|
pcStart = pcEnd;
|
|
|
|
if (*pcStart == ':')
|
|
|
|
pcStart++;
|
|
|
|
}
|
2004-08-31 16:07:08 +00:00
|
|
|
g_free ((gpointer) pcLADSPAPath);
|
2001-12-23 15:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
/* EOF */
|