diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
commit | 513389b4c1bc8afe4b2dc9947c534bfeb105e3da (patch) | |
tree | 10e673b35651ac567fed2eda0c679c7ade64cbc6 /apps/plugins/pdbox/PDa/src/s_loader.c | |
parent | 95fa7f6a2ef466444fbe3fe87efc6d5db6b77b36 (diff) | |
download | rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.gz rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.zip |
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.c | 338 |
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 0000000000..83a59f3556 --- /dev/null +++ b/apps/plugins/pdbox/PDa/src/s_loader.c | |||
@@ -0,0 +1,338 @@ | |||
1 | /* Copyright (c) 1997-1999 Miller Puckette. | ||
2 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL | ||
3 | * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | ||
4 | |||
5 | #ifdef DL_OPEN | ||
6 | #include <dlfcn.h> | ||
7 | #endif | ||
8 | #ifdef UNIX | ||
9 | #include <stdlib.h> | ||
10 | #include <unistd.h> | ||
11 | #endif | ||
12 | #ifdef MSW | ||
13 | #include <io.h> | ||
14 | #include <windows.h> | ||
15 | #endif | ||
16 | #ifdef MACOSX | ||
17 | #include <mach-o/dyld.h> | ||
18 | #endif | ||
19 | #include <string.h> | ||
20 | #include "m_pd.h" | ||
21 | #include "s_stuff.h" | ||
22 | #include <stdio.h> | ||
23 | |||
24 | typedef void (*t_xxx)(void); | ||
25 | |||
26 | static char sys_dllextent[] = | ||
27 | #ifdef __FreeBSD__ | ||
28 | ".pd_freebsd"; | ||
29 | #endif | ||
30 | #ifdef IRIX | ||
31 | #ifdef N32 | ||
32 | ".pd_irix6"; | ||
33 | #else | ||
34 | ".pd_irix5"; | ||
35 | #endif | ||
36 | #endif | ||
37 | #ifdef __linux__ | ||
38 | ".pd_linux"; | ||
39 | #endif | ||
40 | #ifdef MACOSX | ||
41 | ".pd_darwin"; | ||
42 | #endif | ||
43 | #ifdef MSW | ||
44 | ".dll"; | ||
45 | #endif | ||
46 | |||
47 | void class_set_extern_dir(t_symbol *s); | ||
48 | |||
49 | #ifdef STATIC | ||
50 | int sys_load_lib(char *dirname, char *classname) | ||
51 | { return 1;} | ||
52 | #else | ||
53 | int sys_load_lib(char *dirname, char *classname) | ||
54 | { | ||
55 | char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING], | ||
56 | classname2[MAXPDSTRING], *nameptr, *lastdot; | ||
57 | void *dlobj; | ||
58 | t_xxx makeout = NULL; | ||
59 | int fd; | ||
60 | #ifdef MSW | ||
61 | HINSTANCE ntdll; | ||
62 | #endif | ||
63 | #if 0 | ||
64 | fprintf(stderr, "lib %s %s\n", dirname, classname); | ||
65 | #endif | ||
66 | /* try looking in the path for (classname).(sys_dllextent) ... */ | ||
67 | if ((fd = open_via_path(dirname, classname, sys_dllextent, | ||
68 | dirbuf, &nameptr, MAXPDSTRING, 1)) < 0) | ||
69 | { | ||
70 | /* next try (classname)/(classname).(sys_dllextent) ... */ | ||
71 | strncpy(classname2, classname, MAXPDSTRING); | ||
72 | filename[MAXPDSTRING-2] = 0; | ||
73 | strcat(classname2, "/"); | ||
74 | strncat(classname2, classname, MAXPDSTRING-strlen(classname2)); | ||
75 | filename[MAXPDSTRING-1] = 0; | ||
76 | if ((fd = open_via_path(dirname, classname2, sys_dllextent, | ||
77 | dirbuf, &nameptr, MAXPDSTRING, 1)) < 0) | ||
78 | { | ||
79 | return (0); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | |||
84 | close(fd); | ||
85 | class_set_extern_dir(gensym(dirbuf)); | ||
86 | |||
87 | /* refabricate the pathname */ | ||
88 | strncpy(filename, dirbuf, MAXPDSTRING); | ||
89 | filename[MAXPDSTRING-2] = 0; | ||
90 | strcat(filename, "/"); | ||
91 | strncat(filename, nameptr, MAXPDSTRING-strlen(filename)); | ||
92 | filename[MAXPDSTRING-1] = 0; | ||
93 | /* extract the setup function name */ | ||
94 | if (lastdot = strrchr(nameptr, '.')) | ||
95 | *lastdot = 0; | ||
96 | |||
97 | #ifdef MACOSX | ||
98 | strcpy(symname, "_"); | ||
99 | strcat(symname, nameptr); | ||
100 | #else | ||
101 | strcpy(symname, nameptr); | ||
102 | #endif | ||
103 | /* if the last character is a tilde, replace with "_tilde" */ | ||
104 | if (symname[strlen(symname) - 1] == '~') | ||
105 | strcpy(symname + (strlen(symname) - 1), "_tilde"); | ||
106 | /* and append _setup to form the C setup function name */ | ||
107 | strcat(symname, "_setup"); | ||
108 | #ifdef DL_OPEN | ||
109 | dlobj = dlopen(filename, RTLD_NOW | RTLD_GLOBAL); | ||
110 | if (!dlobj) | ||
111 | { | ||
112 | post("%s: %s", filename, dlerror()); | ||
113 | class_set_extern_dir(&s_); | ||
114 | return (0); | ||
115 | } | ||
116 | makeout = (t_xxx)dlsym(dlobj, symname); | ||
117 | #endif | ||
118 | #ifdef MSW | ||
119 | sys_bashfilename(filename, filename); | ||
120 | ntdll = LoadLibrary(filename); | ||
121 | if (!ntdll) | ||
122 | { | ||
123 | post("%s: couldn't load", filename); | ||
124 | class_set_extern_dir(&s_); | ||
125 | return (0); | ||
126 | } | ||
127 | makeout = (t_xxx)GetProcAddress(ntdll, symname); | ||
128 | #endif | ||
129 | #ifdef MACOSX | ||
130 | { | ||
131 | NSObjectFileImage image; | ||
132 | void *ret; | ||
133 | NSSymbol s; | ||
134 | if ( NSCreateObjectFileImageFromFile( filename, &image) != NSObjectFileImageSuccess ) | ||
135 | { | ||
136 | post("%s: couldn't load", filename); | ||
137 | class_set_extern_dir(&s_); | ||
138 | return 0; | ||
139 | } | ||
140 | ret = NSLinkModule( image, filename, | ||
141 | NSLINKMODULE_OPTION_BINDNOW + NSLINKMODULE_OPTION_PRIVATE); | ||
142 | |||
143 | s = NSLookupSymbolInModule(ret, symname); | ||
144 | |||
145 | if (s) | ||
146 | makeout = (t_xxx)NSAddressOfSymbol( s); | ||
147 | else makeout = 0; | ||
148 | } | ||
149 | #endif | ||
150 | |||
151 | if (!makeout) | ||
152 | { | ||
153 | post("load_object: Symbol \"%s\" not found", symname); | ||
154 | class_set_extern_dir(&s_); | ||
155 | return 0; | ||
156 | } | ||
157 | (*makeout)(); | ||
158 | class_set_extern_dir(&s_); | ||
159 | return (1); | ||
160 | } | ||
161 | |||
162 | #endif | ||
163 | |||
164 | |||
165 | |||
166 | |||
167 | |||
168 | |||
169 | |||
170 | /* Copyright (c) 1997-1999 Miller Puckette. | ||
171 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL | ||
172 | * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | ||
173 | |||
174 | #ifdef DL_OPEN | ||
175 | #include <dlfcn.h> | ||
176 | #endif | ||
177 | #ifdef UNIX | ||
178 | #include <stdlib.h> | ||
179 | #include <unistd.h> | ||
180 | #endif | ||
181 | #ifdef MSW | ||
182 | #include <io.h> | ||
183 | #include <windows.h> | ||
184 | #endif | ||
185 | #ifdef MACOSX | ||
186 | #include <mach-o/dyld.h> | ||
187 | #endif | ||
188 | #include <string.h> | ||
189 | #include "m_pd.h" | ||
190 | #include "s_stuff.h" | ||
191 | #include <stdio.h> | ||
192 | |||
193 | typedef void (*t_xxx)(void); | ||
194 | |||
195 | static char sys_dllextent[] = | ||
196 | #ifdef __FreeBSD__ | ||
197 | ".pd_freebsd"; | ||
198 | #endif | ||
199 | #ifdef IRIX | ||
200 | #ifdef N32 | ||
201 | ".pd_irix6"; | ||
202 | #else | ||
203 | ".pd_irix5"; | ||
204 | #endif | ||
205 | #endif | ||
206 | #ifdef __linux__ | ||
207 | ".pd_linux"; | ||
208 | #endif | ||
209 | #ifdef MACOSX | ||
210 | ".pd_darwin"; | ||
211 | #endif | ||
212 | #ifdef MSW | ||
213 | ".dll"; | ||
214 | #endif | ||
215 | |||
216 | void class_set_extern_dir(t_symbol *s); | ||
217 | |||
218 | #ifdef STATIC | ||
219 | int sys_load_lib(char *dirname, char *classname) | ||
220 | { return 1;} | ||
221 | #else | ||
222 | int sys_load_lib(char *dirname, char *classname) | ||
223 | { | ||
224 | char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING], | ||
225 | classname2[MAXPDSTRING], *nameptr, *lastdot; | ||
226 | void *dlobj; | ||
227 | t_xxx makeout = NULL; | ||
228 | int fd; | ||
229 | #ifdef MSW | ||
230 | HINSTANCE ntdll; | ||
231 | #endif | ||
232 | #if 0 | ||
233 | fprintf(stderr, "lib %s %s\n", dirname, classname); | ||
234 | #endif | ||
235 | /* try looking in the path for (classname).(sys_dllextent) ... */ | ||
236 | if ((fd = open_via_path(dirname, classname, sys_dllextent, | ||
237 | dirbuf, &nameptr, MAXPDSTRING, 1)) < 0) | ||
238 | { | ||
239 | /* next try (classname)/(classname).(sys_dllextent) ... */ | ||
240 | strncpy(classname2, classname, MAXPDSTRING); | ||
241 | filename[MAXPDSTRING-2] = 0; | ||
242 | strcat(classname2, "/"); | ||
243 | strncat(classname2, classname, MAXPDSTRING-strlen(classname2)); | ||
244 | filename[MAXPDSTRING-1] = 0; | ||
245 | if ((fd = open_via_path(dirname, classname2, sys_dllextent, | ||
246 | dirbuf, &nameptr, MAXPDSTRING, 1)) < 0) | ||
247 | { | ||
248 | return (0); | ||
249 | } | ||
250 | } | ||
251 | |||
252 | |||
253 | close(fd); | ||
254 | class_set_extern_dir(gensym(dirbuf)); | ||
255 | |||
256 | /* refabricate the pathname */ | ||
257 | strncpy(filename, dirbuf, MAXPDSTRING); | ||
258 | filename[MAXPDSTRING-2] = 0; | ||
259 | strcat(filename, "/"); | ||
260 | strncat(filename, nameptr, MAXPDSTRING-strlen(filename)); | ||
261 | filename[MAXPDSTRING-1] = 0; | ||
262 | /* extract the setup function name */ | ||
263 | if (lastdot = strrchr(nameptr, '.')) | ||
264 | *lastdot = 0; | ||
265 | |||
266 | #ifdef MACOSX | ||
267 | strcpy(symname, "_"); | ||
268 | strcat(symname, nameptr); | ||
269 | #else | ||
270 | strcpy(symname, nameptr); | ||
271 | #endif | ||
272 | /* if the last character is a tilde, replace with "_tilde" */ | ||
273 | if (symname[strlen(symname) - 1] == '~') | ||
274 | strcpy(symname + (strlen(symname) - 1), "_tilde"); | ||
275 | /* and append _setup to form the C setup function name */ | ||
276 | strcat(symname, "_setup"); | ||
277 | #ifdef DL_OPEN | ||
278 | dlobj = dlopen(filename, RTLD_NOW | RTLD_GLOBAL); | ||
279 | if (!dlobj) | ||
280 | { | ||
281 | post("%s: %s", filename, dlerror()); | ||
282 | class_set_extern_dir(&s_); | ||
283 | return (0); | ||
284 | } | ||
285 | makeout = (t_xxx)dlsym(dlobj, symname); | ||
286 | #endif | ||
287 | #ifdef MSW | ||
288 | sys_bashfilename(filename, filename); | ||
289 | ntdll = LoadLibrary(filename); | ||
290 | if (!ntdll) | ||
291 | { | ||
292 | post("%s: couldn't load", filename); | ||
293 | class_set_extern_dir(&s_); | ||
294 | return (0); | ||
295 | } | ||
296 | makeout = (t_xxx)GetProcAddress(ntdll, symname); | ||
297 | #endif | ||
298 | #ifdef MACOSX | ||
299 | { | ||
300 | NSObjectFileImage image; | ||
301 | void *ret; | ||
302 | NSSymbol s; | ||
303 | if ( NSCreateObjectFileImageFromFile( filename, &image) != NSObjectFileImageSuccess ) | ||
304 | { | ||
305 | post("%s: couldn't load", filename); | ||
306 | class_set_extern_dir(&s_); | ||
307 | return 0; | ||
308 | } | ||
309 | ret = NSLinkModule( image, filename, | ||
310 | NSLINKMODULE_OPTION_BINDNOW + NSLINKMODULE_OPTION_PRIVATE); | ||
311 | |||
312 | s = NSLookupSymbolInModule(ret, symname); | ||
313 | |||
314 | if (s) | ||
315 | makeout = (t_xxx)NSAddressOfSymbol( s); | ||
316 | else makeout = 0; | ||
317 | } | ||
318 | #endif | ||
319 | |||
320 | if (!makeout) | ||
321 | { | ||
322 | post("load_object: Symbol \"%s\" not found", symname); | ||
323 | class_set_extern_dir(&s_); | ||
324 | return 0; | ||
325 | } | ||
326 | (*makeout)(); | ||
327 | class_set_extern_dir(&s_); | ||
328 | return (1); | ||
329 | } | ||
330 | |||
331 | #endif | ||
332 | |||
333 | |||
334 | |||
335 | |||
336 | |||
337 | |||
338 | |||