Browse Source

Clean namespace proxy commands when prefix is changed.

git-svn-id: https://klish.googlecode.com/svn/trunk@183 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
24b0f5a3ae
1 changed files with 13 additions and 1 deletions
  1. 13 1
      clish/nspace/nspace.c

+ 13 - 1
clish/nspace/nspace.c

@@ -47,7 +47,6 @@ static void clish_nspace_fini(clish_nspace_t * this)
 	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);
 	}
@@ -76,6 +75,8 @@ static clish_command_t *clish_nspace_find_create_command(clish_nspace_t * this,
 {
 	clish_command_t *cmd;
 	char *name = NULL;
+	clish_command_t *tmp = NULL;
+	lub_bintree_iterator_t iter;
 
 	assert(prefix);
 	if (!ref) {
@@ -98,6 +99,17 @@ static clish_command_t *clish_nspace_find_create_command(clish_nspace_t * this,
 	free(name);
 	assert(cmd);
 
+	/* Delete proxy commands with another prefixes */
+	tmp = lub_bintree_findfirst(&this->tree);
+	for(lub_bintree_iterator_init(&iter, &this->tree, tmp);
+		tmp; tmp = lub_bintree_iterator_next(&iter)) {
+		const char *str = clish_command__get_name(tmp);
+		if (lub_string_nocasestr(str, prefix) == str)
+			continue;
+		lub_bintree_remove(&this->tree, tmp);
+		clish_command_delete(tmp);
+	}
+
 	/* Insert command link into the tree */
 	if (-1 == lub_bintree_insert(&this->tree, cmd)) {
 		clish_command_delete(cmd);