From ed30436305ed7a7fe6170d90a453a9d04faecf52 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 7 Sep 2009 22:37:12 -0400 Subject: I think I have it back to where it was last week (although, a lot cleaner, and elagant) --- wrapper/plugin.h | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 4 deletions(-) (limited to 'wrapper/plugin.h') diff --git a/wrapper/plugin.h b/wrapper/plugin.h index 825c8d2..4672895 100644 --- a/wrapper/plugin.h +++ b/wrapper/plugin.h @@ -21,15 +21,27 @@ #define FILE_plugin_h_SEEN #include "rvs.h" -#include "structures.h" -/* a single plugin command, for use as *node in binary trees */ +/* a plugin */ +/* a generic binary tree emulating a n-ary tree via linked list */ +struct plugin +{ + char *name; + struct plugin_command *commands;/* left leaf */ + struct plugin *next; /* right leaf */ +}; + +/* a single plugin command */ struct plugin_command { + /* node */ char *name; - struct tree_list *plugin; /* which plugin does it belong to? */ + struct plugin *plugin; /* which plugin does it belong to? */ struct plugin_command *depend; /* what does this depend on? */ - char *depends;/* what does this depend on? */ + char *depends;/* what does this depend on? (string) */ + + /* linked list */ + struct plugin_command *next; }; /* create a blank plugin_command */ @@ -39,13 +51,86 @@ mkcommand() struct plugin_command *command; command=(struct plugin_command *)xmalloc(sizeof(*command)); + /* node */ command->name=NULL; command->plugin=NULL; command->depend=NULL; command->depends=NULL; + /* linked list */ + command->next=NULL; + return command; } + +struct plugin * +plugin_find_plugin(struct plugin *node, char *name) +{ + + if (node==NULL) + return node; + else { + if (strcmp(node->name,name) == 0) + return node; + else + return plugin_find_plugin(node->next,name); + } +} + +struct plugin_command * +plugin_find_plugin_command(struct plugin_command *node, char *name) +{ + if (node==NULL) + return node; + else { + if (strcmp(node->name,name) == 0) + return node; + else + return plugin_find_plugin_command(node->next,name); + } +} + +/* returns the first command with `name' it finds + Perhaps it should return a linked list of all commands with `name'? + This would require a dedicated struct for the function. + That makes me kind of want to move it to another file. */ +struct plugin_command * +plugin_find_command(struct plugin *plugin, char *name) +{ + struct plugin_command *ret; + ret=plugin_find_plugin_command(plugin->commands,name); + if (ret == NULL) + ret=plugin_find_command(plugin->next,name); + return ret; +} + +void +plugin_free_command(struct plugin_command *command) +{ + if (command!=NULL) { + #ifdef DEBUG + printf(" + %s\n",command->name); + #endif + xfree(command->name); + xfree(command->depends); + xfree(command); + plugin_free_command(command->next); + } +} + +void +plugin_free_plugin(struct plugin *plugin) +{ + if (plugin!=NULL) { + #ifdef DEBUG + printf(" - %s\n",plugin->name); + #endif + xfree(plugin->name); + plugin_free_command(plugin->commands); + plugin_free_plugin(plugin->next); + } +} + #endif -- cgit v1.2.3-2-g168b