Browse Source

Functions to clean namespace proxy commands

git-svn-id: https://klish.googlecode.com/svn/trunk@182 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
e67959be23
4 changed files with 29 additions and 0 deletions
  1. 1 0
      clish/nspace.h
  2. 16 0
      clish/nspace/nspace.c
  3. 1 0
      clish/view.h
  4. 11 0
      clish/view/view.c

+ 1 - 0
clish/nspace.h

@@ -44,6 +44,7 @@ clish_command_t *clish_nspace_find_command(clish_nspace_t * instance, const char
 void clish_nspace_dump(const clish_nspace_t * instance);
 clish_command_t * clish_nspace_create_prefix_cmd(clish_nspace_t * instance,
 	const char * name, const char * help);
+void clish_nspace_clean_proxy(clish_nspace_t * instance);
 /*-----------------
  * attributes
  *----------------- */

+ 16 - 0
clish/nspace/nspace.c

@@ -238,6 +238,22 @@ const clish_command_t *clish_nspace_find_next_completion(clish_nspace_t * this,
 	return retval;
 }
 
+/*--------------------------------------------------------- */
+void clish_nspace_clean_proxy(clish_nspace_t * this)
+{
+	clish_command_t *cmd = NULL;
+
+	/* Recursive proxy clean */
+	clish_view_clean_proxy(this->view);
+	/* Delete each command proxy held by this nspace */
+	while ((cmd = lub_bintree_findfirst(&this->tree))) {
+		/* remove the command from the tree */
+		lub_bintree_remove(&this->tree, cmd);
+		/* release the instance */
+		clish_command_delete(cmd);
+	}
+}
+
 /*---------------------------------------------------------
  * PUBLIC ATTRIBUTES
  *--------------------------------------------------------- */

+ 1 - 0
clish/view.h

@@ -54,6 +54,7 @@ clish_command_t *clish_view_resolve_prefix(clish_view_t * instance,
 	const char *line, bool_t inherit);
 void clish_view_dump(clish_view_t * instance);
 void clish_view_insert_nspace(clish_view_t * instance, clish_nspace_t * nspace);
+void clish_view_clean_proxy(clish_view_t * instance);
 /*-----------------
  * attributes 
  *----------------- */

+ 11 - 0
clish/view/view.c

@@ -312,6 +312,17 @@ void clish_view_insert_nspace(clish_view_t * this, clish_nspace_t * nspace)
 	this->nspacev[this->nspacec++] = nspace;
 }
 
+/*--------------------------------------------------------- */
+void clish_view_clean_proxy(clish_view_t * this)
+{
+	int i;
+
+	/* Iterate namespace instances */
+	for (i = 0; i < this->nspacec; i++) {
+		clish_nspace_clean_proxy(this->nspacev[i]);
+	}
+}
+
 /*---------------------------------------------------------
  * PUBLIC ATTRIBUTES
  *--------------------------------------------------------- */