Browse Source

Working on aliases. Don't use this revision

git-svn-id: https://klish.googlecode.com/svn/trunk@318 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
b697233267
4 changed files with 48 additions and 33 deletions
  1. 2 0
      clish/command.h
  2. 27 0
      clish/command/command.c
  3. 15 13
      clish/nspace/nspace.c
  4. 4 20
      clish/view/view.c

+ 2 - 0
clish/command.h

@@ -29,6 +29,8 @@ clish_command_t *clish_command_new(const char *name, const char *help);
 clish_command_t *clish_command_new_link(const char *name,
 	const char *help, const clish_command_t * ref);
 clish_command_t *clish_command_new_link_from_alias(const clish_command_t * alias);
+clish_command_t * clish_command_alias_to_link(clish_command_t * instance);
+
 int clish_command_bt_compare(const void *clientnode, const void *clientkey);
 void clish_command_bt_getkey(const void *clientnode, lub_bintree_key_t * key);
 size_t clish_command_bt_offset(void);

+ 27 - 0
clish/command/command.c

@@ -177,6 +177,33 @@ clish_command_t *clish_command_new_link_from_alias(const clish_command_t * alias
 	return clish_command_new_link(alias->name, alias->text, ref);
 }
 
+/*--------------------------------------------------------- */
+clish_command_t * clish_command_alias_to_link(clish_command_t * this)
+{
+	clish_command_t * ref;
+	clish_command_t tmp;
+
+	if (!this || !this->alias)
+		return this;
+	assert(this->alias_view);
+	ref = clish_view_find_command(this->alias_view, this->alias, BOOL_FALSE);
+	if (!ref)
+		return this;
+printf("!!!!!!!! alias=%s\n", this->name);
+clish_command_dump(this);
+	memcpy(&tmp, this, sizeof(tmp));
+	*this = *ref;
+	memcpy(&this->bt_node, &tmp.bt_node, sizeof(tmp.bt_node));
+	this->name = lub_string_dup(tmp.name);
+	this->text = lub_string_dup(tmp.text);
+	this->link = ref;
+	clish_command_fini(&tmp);
+
+printf("!!!!!!!! link=%s\n", this->name);
+clish_command_dump(this);
+	return this;
+}
+
 /*---------------------------------------------------------
  * PUBLIC METHODS
  *--------------------------------------------------------- */

+ 15 - 13
clish/nspace/nspace.c

@@ -91,9 +91,15 @@ static clish_command_t *clish_nspace_find_create_command(clish_nspace_t * this,
 				strlen(clish_command__get_name(ref)));
 		help = clish_command__get_text(ref);
 	}
-
+printf("!!!!!! name=%s\n", name);
 	/* The command is cached already */
 	if ((cmd = lub_bintree_find(&this->tree, name))) {
+
+printf("!!!!!!!!! Already\n");
+if (cmd) {
+	printf("Pre cmd:\n");
+	clish_command_dump(cmd);
+}
 		free(name);
 		return cmd;
 	}
@@ -199,19 +205,15 @@ clish_command_t *clish_nspace_find_command(clish_nspace_t * this, const char *na
 	}
 
 printf("real_prefix=%s cmd=%s\n", real_prefix, cmd ? clish_command__get_name(cmd): NULL);
-if (cmd) {
-	printf("Pre cmd:\n");
-	clish_command_dump(cmd);
-}
 	retval = clish_nspace_find_create_command(this, real_prefix, cmd);
-if (retval) {
-	printf("Retval\n");
-	clish_command_dump(retval);
-if (cmd) {
-	printf("Post cmd:\n");
-	clish_command_dump(cmd);
-}
-}
+//if (retval) {
+//	printf("Retval\n");
+//	clish_command_dump(retval);
+//if (cmd) {
+//	printf("Post cmd:\n");
+//	clish_command_dump(cmd);
+//}
+//}
 	lub_string_free(real_prefix);
 
 	return retval;

+ 4 - 20
clish/view/view.c

@@ -209,28 +209,15 @@ clish_command_t *clish_view_resolve_command(clish_view_t * this,
 /*--------------------------------------------------------- */
 clish_command_t *clish_view_find_command(clish_view_t * this, const char *name, bool_t inherit)
 {
-	clish_command_t *cmd, *link, *result = NULL;
+	clish_command_t *cmd, *result = NULL;
 	clish_nspace_t *nspace;
 	unsigned cnt = clish_view__get_nspace_count(this);
 	int i;
 
 	/* Search the current view */
 	result = lub_bintree_find(&this->tree, name);
-
 	/* Make command link from command alias */
-	if (result && clish_command__get_alias(result)) {
-		link = clish_command_new_link_from_alias(result);
-		/* remove the alias command from the tree */
-		lub_bintree_remove(&this->tree, result);
-		clish_command_delete(result);
-		if (-1 == lub_bintree_insert(&this->tree, link)) {
-			/* inserting a duplicate command is bad */
-			clish_command_delete(link);
-			link = NULL;
-		}
-		result = link;
-printf("!!!!!!!!!!! transform %s\n", clish_command__get_name(result));
-	}
+	result = clish_command_alias_to_link(result);
 
 	if (inherit) {
 		for (i = cnt - 1; i >= 0; i--) {
@@ -241,11 +228,6 @@ printf("!!!!!!!!!!! transform %s\n", clish_command__get_name(result));
 		}
 	}
 
-//	if (result && clish_command__get_alias(result)) {
-//		printf("Sam link\n");
-//		clish_command_dump(result);
-//	}
-
 	return result;
 }
 
@@ -271,6 +253,8 @@ static const clish_command_t *find_next_completion(clish_view_t * this,
 		name = iter_cmd;
 	}
 	while ((cmd = lub_bintree_findnext(&this->tree, name))) {
+		/* Make command link from command alias */
+		cmd = clish_command_alias_to_link(cmd);
 		name = clish_command__get_name(cmd);
 		if (words == lub_argv_wordcount(name)) {
 			/* only bother with commands of which this line is a prefix */