summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/s_loader.c
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2009-05-22 21:58:48 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2009-05-22 21:58:48 +0000
commit513389b4c1bc8afe4b2dc9947c534bfeb105e3da (patch)
tree10e673b35651ac567fed2eda0c679c7ade64cbc6 /apps/plugins/pdbox/PDa/src/s_loader.c
parent95fa7f6a2ef466444fbe3fe87efc6d5db6b77b36 (diff)
downloadrockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.zip
rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.gz
rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.bz2
rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.xz
Add FS #10214. Initial commit of the original PDa code for the GSoC Pure Data plugin project of Wincent Balin. Stripped some non-sourcefiles and added a rockbox readme that needs a bit more info from Wincent. Is added to CATEGORIES and viewers, but not yet to SUBDIRS (ie doesn't build yet)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21044 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/s_loader.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/s_loader.c338
1 files changed, 338 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/src/s_loader.c b/apps/plugins/pdbox/PDa/src/s_loader.c
new file mode 100644
index 0000000..83a59f3
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/src/s_loader.c
@@ -0,0 +1,338 @@
+/* Copyright (c) 1997-1999 Miller Puckette.
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+#ifdef DL_OPEN
+#include <dlfcn.h>
+#endif
+#ifdef UNIX
+#include <stdlib.h>
+#include <unistd.h>
+#endif
+#ifdef MSW
+#include <io.h>
+#include <windows.h>
+#endif
+#ifdef MACOSX
+#include <mach-o/dyld.h>
+#endif
+#include <string.h>
+#include "m_pd.h"
+#include "s_stuff.h"
+#include <stdio.h>
+
+typedef void (*t_xxx)(void);
+
+static char sys_dllextent[] =
+#ifdef __FreeBSD__
+ ".pd_freebsd";
+#endif
+#ifdef IRIX
+#ifdef N32
+ ".pd_irix6";
+#else
+ ".pd_irix5";
+#endif
+#endif
+#ifdef __linux__
+ ".pd_linux";
+#endif
+#ifdef MACOSX
+ ".pd_darwin";
+#endif
+#ifdef MSW
+ ".dll";
+#endif
+
+void class_set_extern_dir(t_symbol *s);
+
+#ifdef STATIC
+int sys_load_lib(char *dirname, char *classname)
+{ return 1;}
+#else
+int sys_load_lib(char *dirname, char *classname)
+{
+ char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING],
+ classname2[MAXPDSTRING], *nameptr, *lastdot;
+ void *dlobj;
+ t_xxx makeout = NULL;
+ int fd;
+#ifdef MSW
+ HINSTANCE ntdll;
+#endif
+#if 0
+ fprintf(stderr, "lib %s %s\n", dirname, classname);
+#endif
+ /* try looking in the path for (classname).(sys_dllextent) ... */
+ if ((fd = open_via_path(dirname, classname, sys_dllextent,
+ dirbuf, &nameptr, MAXPDSTRING, 1)) < 0)
+ {
+ /* next try (classname)/(classname).(sys_dllextent) ... */
+ strncpy(classname2, classname, MAXPDSTRING);
+ filename[MAXPDSTRING-2] = 0;
+ strcat(classname2, "/");
+ strncat(classname2, classname, MAXPDSTRING-strlen(classname2));
+ filename[MAXPDSTRING-1] = 0;
+ if ((fd = open_via_path(dirname, classname2, sys_dllextent,
+ dirbuf, &nameptr, MAXPDSTRING, 1)) < 0)
+ {
+ return (0);
+ }
+ }
+
+
+ close(fd);
+ class_set_extern_dir(gensym(dirbuf));
+
+ /* refabricate the pathname */
+ strncpy(filename, dirbuf, MAXPDSTRING);
+ filename[MAXPDSTRING-2] = 0;
+ strcat(filename, "/");
+ strncat(filename, nameptr, MAXPDSTRING-strlen(filename));
+ filename[MAXPDSTRING-1] = 0;
+ /* extract the setup function name */
+ if (lastdot = strrchr(nameptr, '.'))
+ *lastdot = 0;
+
+#ifdef MACOSX
+ strcpy(symname, "_");
+ strcat(symname, nameptr);
+#else
+ strcpy(symname, nameptr);
+#endif
+ /* if the last character is a tilde, replace with "_tilde" */
+ if (symname[strlen(symname) - 1] == '~')
+ strcpy(symname + (strlen(symname) - 1), "_tilde");
+ /* and append _setup to form the C setup function name */
+ strcat(symname, "_setup");
+#ifdef DL_OPEN
+ dlobj = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
+ if (!dlobj)
+ {
+ post("%s: %s", filename, dlerror());
+ class_set_extern_dir(&s_);
+ return (0);
+ }
+ makeout = (t_xxx)dlsym(dlobj, symname);
+#endif
+#ifdef MSW
+ sys_bashfilename(filename, filename);
+ ntdll = LoadLibrary(filename);
+ if (!ntdll)
+ {
+ post("%s: couldn't load", filename);
+ class_set_extern_dir(&s_);
+ return (0);
+ }
+ makeout = (t_xxx)GetProcAddress(ntdll, symname);
+#endif
+#ifdef MACOSX
+ {
+ NSObjectFileImage image;
+ void *ret;
+ NSSymbol s;
+ if ( NSCreateObjectFileImageFromFile( filename, &image) != NSObjectFileImageSuccess )
+ {
+ post("%s: couldn't load", filename);
+ class_set_extern_dir(&s_);
+ return 0;
+ }
+ ret = NSLinkModule( image, filename,
+ NSLINKMODULE_OPTION_BINDNOW + NSLINKMODULE_OPTION_PRIVATE);
+
+ s = NSLookupSymbolInModule(ret, symname);
+
+ if (s)
+ makeout = (t_xxx)NSAddressOfSymbol( s);
+ else makeout = 0;
+ }
+#endif
+
+ if (!makeout)
+ {
+ post("load_object: Symbol \"%s\" not found", symname);
+ class_set_extern_dir(&s_);
+ return 0;
+ }
+ (*makeout)();
+ class_set_extern_dir(&s_);
+ return (1);
+}
+
+#endif
+
+
+
+
+
+
+
+/* Copyright (c) 1997-1999 Miller Puckette.
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+#ifdef DL_OPEN
+#include <dlfcn.h>
+#endif
+#ifdef UNIX
+#include <stdlib.h>
+#include <unistd.h>
+#endif
+#ifdef MSW
+#include <io.h>
+#include <windows.h>
+#endif
+#ifdef MACOSX
+#include <mach-o/dyld.h>
+#endif
+#include <string.h>
+#include "m_pd.h"
+#include "s_stuff.h"
+#include <stdio.h>
+
+typedef void (*t_xxx)(void);
+
+static char sys_dllextent[] =
+#ifdef __FreeBSD__
+ ".pd_freebsd";
+#endif
+#ifdef IRIX
+#ifdef N32
+ ".pd_irix6";
+#else
+ ".pd_irix5";
+#endif
+#endif
+#ifdef __linux__
+ ".pd_linux";
+#endif
+#ifdef MACOSX
+ ".pd_darwin";
+#endif
+#ifdef MSW
+ ".dll";
+#endif
+
+void class_set_extern_dir(t_symbol *s);
+
+#ifdef STATIC
+int sys_load_lib(char *dirname, char *classname)
+{ return 1;}
+#else
+int sys_load_lib(char *dirname, char *classname)
+{
+ char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING],
+ classname2[MAXPDSTRING], *nameptr, *lastdot;
+ void *dlobj;
+ t_xxx makeout = NULL;
+ int fd;
+#ifdef MSW
+ HINSTANCE ntdll;
+#endif
+#if 0
+ fprintf(stderr, "lib %s %s\n", dirname, classname);
+#endif
+ /* try looking in the path for (classname).(sys_dllextent) ... */
+ if ((fd = open_via_path(dirname, classname, sys_dllextent,
+ dirbuf, &nameptr, MAXPDSTRING, 1)) < 0)
+ {
+ /* next try (classname)/(classname).(sys_dllextent) ... */
+ strncpy(classname2, classname, MAXPDSTRING);
+ filename[MAXPDSTRING-2] = 0;
+ strcat(classname2, "/");
+ strncat(classname2, classname, MAXPDSTRING-strlen(classname2));
+ filename[MAXPDSTRING-1] = 0;
+ if ((fd = open_via_path(dirname, classname2, sys_dllextent,
+ dirbuf, &nameptr, MAXPDSTRING, 1)) < 0)
+ {
+ return (0);
+ }
+ }
+
+
+ close(fd);
+ class_set_extern_dir(gensym(dirbuf));
+
+ /* refabricate the pathname */
+ strncpy(filename, dirbuf, MAXPDSTRING);
+ filename[MAXPDSTRING-2] = 0;
+ strcat(filename, "/");
+ strncat(filename, nameptr, MAXPDSTRING-strlen(filename));
+ filename[MAXPDSTRING-1] = 0;
+ /* extract the setup function name */
+ if (lastdot = strrchr(nameptr, '.'))
+ *lastdot = 0;
+
+#ifdef MACOSX
+ strcpy(symname, "_");
+ strcat(symname, nameptr);
+#else
+ strcpy(symname, nameptr);
+#endif
+ /* if the last character is a tilde, replace with "_tilde" */
+ if (symname[strlen(symname) - 1] == '~')
+ strcpy(symname + (strlen(symname) - 1), "_tilde");
+ /* and append _setup to form the C setup function name */
+ strcat(symname, "_setup");
+#ifdef DL_OPEN
+ dlobj = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
+ if (!dlobj)
+ {
+ post("%s: %s", filename, dlerror());
+ class_set_extern_dir(&s_);
+ return (0);
+ }
+ makeout = (t_xxx)dlsym(dlobj, symname);
+#endif
+#ifdef MSW
+ sys_bashfilename(filename, filename);
+ ntdll = LoadLibrary(filename);
+ if (!ntdll)
+ {
+ post("%s: couldn't load", filename);
+ class_set_extern_dir(&s_);
+ return (0);
+ }
+ makeout = (t_xxx)GetProcAddress(ntdll, symname);
+#endif
+#ifdef MACOSX
+ {
+ NSObjectFileImage image;
+ void *ret;
+ NSSymbol s;
+ if ( NSCreateObjectFileImageFromFile( filename, &image) != NSObjectFileImageSuccess )
+ {
+ post("%s: couldn't load", filename);
+ class_set_extern_dir(&s_);
+ return 0;
+ }
+ ret = NSLinkModule( image, filename,
+ NSLINKMODULE_OPTION_BINDNOW + NSLINKMODULE_OPTION_PRIVATE);
+
+ s = NSLookupSymbolInModule(ret, symname);
+
+ if (s)
+ makeout = (t_xxx)NSAddressOfSymbol( s);
+ else makeout = 0;
+ }
+#endif
+
+ if (!makeout)
+ {
+ post("load_object: Symbol \"%s\" not found", symname);
+ class_set_extern_dir(&s_);
+ return 0;
+ }
+ (*makeout)();
+ class_set_extern_dir(&s_);
+ return (1);
+}
+
+#endif
+
+
+
+
+
+
+