diff options
Diffstat (limited to 'wrapper/plugin.c')
-rw-r--r-- | wrapper/plugin.c | 78 |
1 files changed, 27 insertions, 51 deletions
diff --git a/wrapper/plugin.c b/wrapper/plugin.c index 1851941..6a38035 100644 --- a/wrapper/plugin.c +++ b/wrapper/plugin.c @@ -20,86 +20,62 @@ #ifndef FILE_plugin_c_SEEN #define FILE_plugin_c_SEEN -#include <stdio.h> #include <stdlib.h> /* EXIT_FAILURE */ #include <unistd.h> /* file acces */ #include <string.h> -#include <errno.h> -#include <error.h> - #include <dirent.h> #include <sys/stat.h> #include "rvs.h" #include "plugin.h" -/* finds a plugin with `name'. Start looking at `plugin' (linked list) */ -struct plugin * -_plugin_find_plugin(struct plugin *plugin, char *name) -{ - if (strcmp(plugin->name,name) == 0) { - return plugin; - } else { - if (plugin->next==NULL) { - error(EXIT_FAILURE,0,"cannot find plugin `%s'",name); - return NULL; - } else { - return _plugin_find_plugin(plugin->next,name); - } - } -} - -/* finds a command with `name'. Start looking at `command' (linked list) */ -struct plugin_command * -_plugin_find_command(struct plugin_command *command, char *name) -{ - if (strcmp(command->name,name) == 0) { - return command; - } else { - if (command->p_next==NULL) { - error(EXIT_FAILURE,0, - "plugin `%s' does not contain command `%s'", - command->plugin->name,name); - return NULL; - } else { - return _plugin_find_command(command->p_next,name); - } - } -} - #include "plugin-parse.c" -#include "plugin-depend.c" +/*#include "plugin-depend.c"*/ -struct plugin * +/* assume we're in rvs's libexecdir, where plugins are + now, load plugin plug_name, + whose configuration file is plugin_conf +*/ +struct tree_list * _plugin_load (const char *plug_name, const char *plugin_conf) { - struct plugin *plugin=(struct plugin *)xmalloc(sizeof(*plugin)); - char *plug_name2 = (char *)xmalloc(strlen(plug_name)+1); - strcpy(plug_name2,plug_name); - plugin->name=plug_name2; + struct tree_list *plugin=xmalloc( sizeof(*plugin) ); + plugin->node=stralloc(plug_name); plugin->next=NULL; + plugin->child=NULL; xchdir(plug_name); FILE *file = xfopen(plugin_conf,"r"); - plugin->child=_plugin_parse(plugin, file); + struct tree_list **last=&plugin->child; + + struct plugin_command *command; + while ( (command=_plugin_parse(file))!=NULL ) { + command->plugin=plugin; + + struct tree_list *com=xmalloc( sizeof(*com) ); + com->node=command; + *last=com;/* this sets the last's `next' */ + last=&com->next; + } fclose( file ); xchdir(".."); return plugin; } -struct plugin_tree * +/* load all the plugins in libexecdir, using the config file plugin_conf */ +struct tree_list * load_plugins (const char *libexecdir, const char *plugin_conf) { - struct plugin_tree *tree=(struct plugin_tree *)xmalloc(sizeof(*tree)); - struct plugin **last=&tree->plugins; - *last=NULL; - struct plugin *plugin; + struct tree_list *first=NULL; + struct tree_list **last=&first; + struct tree_list *plugin; xchdir(libexecdir); + /* Yeah, I know this next bit is pretty ugly. */ DIR *cwd; struct dirent *dirent; int serr; @@ -119,7 +95,7 @@ load_plugins (const char *libexecdir, const char *plugin_conf) closedir (cwd); xchdir(".."); - return tree; + return first; } #endif |