Explorar o código

Some plugin link functions

Serj Kalichev %!s(int64=12) %!d(string=hai) anos
pai
achega
8efebe601f
Modificáronse 5 ficheiros con 71 adicións e 1 borrados
  1. 4 0
      bin/clish.c
  2. 1 1
      clish/shell.h
  3. 59 0
      clish/shell/shell_plugin.c
  4. 1 0
      clish/view.h
  5. 6 0
      clish/view/view.c

+ 4 - 0
bin/clish.c

@@ -279,6 +279,10 @@ int main(int argc, char **argv)
 		fprintf(stderr, "Error: Can't load plugins.\n");
 		goto end;
 	}
+	if (clish_shell_link_plugins(shell) < 0) {
+		fprintf(stderr, "Error: Undefined reference while plugin linking.\n");
+		goto end;
+	}
 
 	/* Set source of command stream: files or interactive tty */
 	if(optind < argc) {

+ 1 - 1
clish/shell.h

@@ -358,7 +358,7 @@ struct passwd *clish_shell__get_user(clish_shell_t *instance);
 
 /* Plugin functions */
 int clish_shell_load_plugins(clish_shell_t *instance);
-
+int clish_shell_link_plugins(clish_shell_t *instance);
 
 _END_C_DECL
 

+ 59 - 0
clish/shell/shell_plugin.c

@@ -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;

+ 1 - 0
clish/view.h

@@ -74,6 +74,7 @@ void clish_view__set_restore(clish_view_t * instance,
 clish_view_restore_t clish_view__get_restore(const clish_view_t * instance);
 int clish_view_insert_hotkey(const clish_view_t *instance, const char *key, const char *cmd);
 const char *clish_view_find_hotkey(const clish_view_t *instance, int code);
+lub_bintree_t *clish_view__cmd_tree(clish_view_t *instance);
 
 #endif				/* _clish_view_h */
 /** @} clish_view */

+ 6 - 0
clish/view/view.c

@@ -403,3 +403,9 @@ const char *clish_view_find_hotkey(const clish_view_t *this, int code)
 }
 
 /*--------------------------------------------------------- */
+lub_bintree_t *clish_view__cmd_tree(clish_view_t *this)
+{
+	return &this->tree;
+}
+
+/*--------------------------------------------------------- */