4
* Copyright (C) 2000 Richard Guenther
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
#include <sys/types.h>
35
#include "glame_hash.h"
43
/* auto-generated builtin register function */
44
#include "../plugins/builtins.c"
48
static int is_scm(const char *fname)
53
if (!(f = fopen(fname, "r")))
56
if (fscanf(f, " %c", &c) != 1
57
|| (c != '(' && c != ';')) {
66
int glame_load_plugin(const char *fname)
70
/* Shared object plugin type? Just try to load it as such, will
71
* fail if it is not. */
72
if (plugin_load(fname) == 0)
75
/* Scheme macro plugin type? We really can't detect, if
76
* it is or not... hope guile doesnt choke on random garbage...
81
glscript_load_mode = 0;
82
s_res = glame_gh_safe_eval_file(fname);
83
if (gh_boolean_p(s_res) && !gh_scm2bool(s_res))
88
filter_t *glame_load_instance(const char *fname)
95
glscript_load_mode = 1;
96
s_res = glame_gh_safe_eval_file(fname);
97
if (gh_boolean_p(s_res) && !gh_scm2bool(s_res))
99
return last_loaded_filter_instance; /* HACK... */
102
static void add_plugin_path(const char *path)
107
if (!path || !(tmp = p = strdup(path)))
112
if ((p = strchr(p, ':')))
115
/* Try to open the directory and add the path to
116
* the plugin subsystem. */
117
if ((d = opendir(dir))) {
119
plugin_add_path(dir);
128
static void load_plugins_from_directory(const char *dir)
133
/* Try to open the directory. */
134
if (!(d = opendir(dir)))
137
/* Try to load every file as plugin. */
138
while ((e = readdir(d))) {
143
/* Only take .so and .scm, but not glame.scm */
144
if (!(ext = strrchr(e->d_name, '.'))
145
|| !(strcmp(ext, ".scm") == 0
146
|| strcmp(ext, ".la") == 0
147
|| strcmp(ext, ".so") == 0)
148
|| strcmp(e->d_name, "glame.scm") == 0)
151
snprintf(fname, 255, "%s/%s", dir, e->d_name);
152
if (stat(fname, &st) == -1)
154
if (!S_ISREG(st.st_mode) || !(st.st_mode & S_IRUSR))
156
glame_load_plugin(fname);
162
static void load_plugins_from_path(const char *path)
166
if (!path || !(tmp = p = strdup(path)))
171
if ((p = strchr(p, ':')))
173
load_plugins_from_directory(dir);
180
static int plugins_register()
182
/* Add plugin paths. */
183
if (!access("cglame.c", F_OK))
184
add_plugin_path("./plugins/.libs");
185
add_plugin_path(PKGLIBDIR);
187
add_plugin_path(getenv("LADSPA_PATH"));
188
add_plugin_path("/usr/lib/ladspa");
189
add_plugin_path("/usr/local/lib/ladspa");
192
/* First initialize the builtin plugins */
195
/* Plugins from default paths - and "debug path" (first) */
196
if (!access("cglame.c", F_OK))
197
load_plugins_from_path("./plugins/.libs");
198
load_plugins_from_path(PKGLIBDIR);
200
load_plugins_from_path(getenv("LADSPA_PATH"));
201
load_plugins_from_path("/usr/lib/ladspa");
202
load_plugins_from_path("/usr/local/lib/ladspa");
208
static void glame_cleanup()
213
static void (*glame_main)();
214
static void init_after_guile(int argc, char **argv)
217
/* We dont like guiles signal handlers for debugging
219
scm_restore_signals();
224
/* Init lowlevel GLAME subsystems. */
226
if (hash_alloc() == -1)
228
atexit(glame_cleanup);
230
/* Load non-scheme plugins. */
231
if (plugins_register() == -1)
234
/* Init scripting. */
235
if (glscript_init() == -1)
237
add_plugin_path(PKGSCRIPTSDIR);
238
if (!access("cglame.c", F_OK))
239
load_plugins_from_path("./plugins"); /* for .scm */
240
load_plugins_from_path(PKGSCRIPTSDIR);
242
/* Load configuration. */
245
/* Set defaults, where we dont have any reasonable place/time
247
glame_config_get_long_with_default("swapfile/maxundo", 5);
248
_GLAME_WBUFSIZE = glame_config_get_long_with_default(
249
"filter/wbufsize", 1024);
254
int glame_init(void (*main)(void), int argc, char **argv)
257
gh_enter(argc, argv, init_after_guile);
261
plugin_t *glame_create_plugin(filter_t *filter, const char *name)
265
if (!name || !filter)
267
if (!(plugin = plugin_add(name)))
269
if (filter_register(filter, plugin) == -1) {
270
_plugin_delete(plugin);