Browse Source

The symbols know about their parent plugin

Serj Kalichev 11 years ago
parent
commit
29e813378c
4 changed files with 23 additions and 2 deletions
  1. 2 0
      clish/plugin.h
  2. 13 0
      clish/plugin/plugin.c
  3. 7 2
      clish/plugin/plugin_dump.c
  4. 1 0
      clish/plugin/private.h

+ 2 - 0
clish/plugin.h

@@ -37,6 +37,8 @@ void clish_sym__set_name(clish_sym_t *instance, const char *name);
 char *clish_sym__get_name(clish_sym_t *instance);
 void clish_sym__set_permanent(clish_sym_t *instance, bool_t permanent);
 bool_t clish_sym__get_permanent(clish_sym_t *instance);
+void clish_sym__set_plugin(clish_sym_t *instance, clish_plugin_t *plugin);
+clish_plugin_t *clish_sym__get_plugin(clish_sym_t *instance);
 
 /* Plugin */
 

+ 13 - 0
clish/plugin/plugin.c

@@ -83,6 +83,18 @@ char *clish_sym__get_name(clish_sym_t *this)
 	return this->name;
 }
 
+/*--------------------------------------------------------- */
+void clish_sym__set_plugin(clish_sym_t *this, clish_plugin_t *plugin)
+{
+	this->plugin = plugin;
+}
+
+/*--------------------------------------------------------- */
+clish_plugin_t *clish_sym__get_plugin(clish_sym_t *this)
+{
+	return this->plugin;
+}
+
 /**********************************************************
  * PLUGIN functions                                       *
  **********************************************************/
@@ -146,6 +158,7 @@ clish_sym_t *clish_plugin_add_sym(clish_plugin_t *this,
 
 	if (!(sym = clish_sym_new(name, func)))
 		return NULL;
+	clish_sym__set_plugin(sym, this);
 	lub_list_add(this->syms, sym);
 
 	return sym;

+ 7 - 2
clish/plugin/plugin_dump.c

@@ -12,8 +12,11 @@ void clish_sym_dump(const clish_sym_t *this)
 	lub_dump_printf("sym(%p)\n", this);
 
 	lub_dump_indent();
-	lub_dump_printf("name : %s\n", this->name);
-	lub_dump_printf("func : %p\n", this->func);
+	lub_dump_printf("name      : %s\n", this->name);
+	lub_dump_printf("func      : %p\n", this->func);
+	lub_dump_printf("permanent : %s\n",
+		this->permanent ? "true" : "false");
+	lub_dump_printf("plugin    : %p\n", this->plugin);
 	lub_dump_undent();
 }
 
@@ -24,6 +27,7 @@ void clish_plugin_dump(const clish_plugin_t *this)
 	clish_sym_t *sym;
 
 	lub_dump_printf("plugin(%p)\n", this);
+	lub_dump_indent();
 	lub_dump_printf("name  : %s\n", this->name);
 	lub_dump_printf("file  : %s\n", this->file);
 	lub_dump_printf("dlhan : %p\n", this->dlhan);
@@ -35,6 +39,7 @@ void clish_plugin_dump(const clish_plugin_t *this)
 		clish_sym_dump(sym);
 	}
 	lub_dump_undent();
+	lub_dump_undent();
 }
 
 /*--------------------------------------------------------- */

+ 1 - 0
clish/plugin/private.h

@@ -13,6 +13,7 @@ struct clish_sym_s {
 	char *name; /* Symbol name */
 	clish_plugin_fn_t *func; /* Function address */
 	bool_t permanent; /* If permanent the dry-run can't switch off it */
+	clish_plugin_t *plugin; /* Parent plugin */
 };
 
 struct clish_plugin_s {