|
@@ -5,7 +5,9 @@
|
|
|
#include <assert.h>
|
|
|
|
|
|
#include "lub/list.h"
|
|
|
+#include "lub/bintree.h"
|
|
|
#include "clish/plugin.h"
|
|
|
+#include "clish/view.h"
|
|
|
|
|
|
/*----------------------------------------------------------------------- */
|
|
|
int clish_shell_load_plugins(clish_shell_t *this)
|
|
@@ -21,7 +23,64 @@ int clish_shell_load_plugins(clish_shell_t *this)
|
|
|
plugin = (clish_plugin_t *)lub_list_node__get_data(iter);
|
|
|
if (!clish_plugin_load(plugin))
|
|
|
return -1;
|
|
|
+#ifdef DEBUG
|
|
|
clish_plugin_dump(plugin);
|
|
|
+#endif
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+/*----------------------------------------------------------------------- */
|
|
|
+static clish_plugin_fn_t *plugins_find_sym(clish_shell_t *this, const char *name)
|
|
|
+{
|
|
|
+ lub_list_node_t *iter;
|
|
|
+ clish_plugin_t *plugin;
|
|
|
+ clish_plugin_fn_t *func = NULL;
|
|
|
+ assert(this);
|
|
|
+
|
|
|
+ /* Iterate elements */
|
|
|
+ for(iter = lub_list__get_head(this->plugins);
|
|
|
+ iter; iter = lub_list_node__get_next(iter)) {
|
|
|
+ plugin = (clish_plugin_t *)lub_list_node__get_data(iter);
|
|
|
+ if ((func = clish_plugin_get_sym(plugin, name)))
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return func;
|
|
|
+}
|
|
|
+
|
|
|
+/*----------------------------------------------------------------------- */
|
|
|
+static int plugins_link_view(clish_shell_t *this, clish_view_t *view)
|
|
|
+{
|
|
|
+ clish_command_t *c;
|
|
|
+ lub_bintree_iterator_t iter;
|
|
|
+ lub_bintree_t *tree;
|
|
|
+
|
|
|
+ tree = clish_view__cmd_tree(view);
|
|
|
+ /* Iterate the tree of commands */
|
|
|
+ c = lub_bintree_findfirst(tree);
|
|
|
+ for (lub_bintree_iterator_init(&iter, tree, c);
|
|
|
+ c; c = lub_bintree_iterator_next(&iter)) {
|
|
|
+ plugins_find_sym(this, "jjj");
|
|
|
+ printf("command: %s\n", clish_command__get_name(c));
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+/*----------------------------------------------------------------------- */
|
|
|
+int clish_shell_link_plugins(clish_shell_t *this)
|
|
|
+{
|
|
|
+ clish_view_t *v;
|
|
|
+ lub_bintree_iterator_t iter;
|
|
|
+
|
|
|
+ v = lub_bintree_findfirst(&this->view_tree);
|
|
|
+ /* Iterate the tree of views */
|
|
|
+ for (lub_bintree_iterator_init(&iter, &this->view_tree, v);
|
|
|
+ v; v = lub_bintree_iterator_next(&iter)) {
|
|
|
+ if (plugins_link_view(this, v))
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
return 0;
|