Browse Source

Technological revision. Don't use

git-svn-id: https://klish.googlecode.com/svn/trunk@179 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
50d6aa5e80

+ 6 - 2
clish.xsd

@@ -349,6 +349,8 @@
 *
 * [prefix]       - the prefix for imported commands
 *
+* [prefix_help]  - the help for namespace prefix
+*
 * [help]         - a boolean flag to use imported
 *                commands while help
 *
@@ -375,14 +377,16 @@
 
     <xs:complexType name="namespace_t">
         <xs:attribute name="ref" type="xs:string" use="required"/>
-        <xs:attribute name="prefix" type="xs:string" use="required"/>
+        <xs:attribute name="prefix" type="xs:string" use="optional"/>
+        <xs:attribute name="prefix_help" type="xs:string" use="optional"/>
         <xs:attribute name="help" type="bool_t" use="optional" default="false"/>
         <xs:attribute name="completion" type="bool_t" use="optional" default="true"/>
         <xs:attribute name="context_help" type="bool_t" use="optional" default="false"/>
         <xs:attribute name="inherit" type="bool_t" use="optional" default="true"/>
         <xs:attribute name="restore" type="restore_t" use="optional" default="none"/>
     </xs:complexType>
-    <!--
+
+<!--
 *******************************************************
 * <CONFIG> Specify the config operation.
 *

+ 2 - 0
clish/nspace.h

@@ -42,6 +42,8 @@ const clish_command_t *clish_nspace_find_next_completion(clish_nspace_t *
 	clish_nspace_visibility_t field);
 clish_command_t *clish_nspace_find_command(clish_nspace_t * instance, const char *name);
 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);
 /*-----------------
  * attributes
  *----------------- */

+ 37 - 36
clish/nspace/nspace.c

@@ -27,63 +27,66 @@ static void clish_nspace_init(clish_nspace_t * this, clish_view_t * view)
 	this->completion = BOOL_TRUE;
 	this->context_help = BOOL_FALSE;
 	this->inherit = BOOL_TRUE;
-
-	/* initialise the tree of commands links for this nspace */
-	lub_bintree_init(&this->tree,
-		 clish_command_bt_offset(),
-		 clish_command_bt_compare, clish_command_bt_getkey);
+	this->prefix_cmd = NULL;
+	this->proxy_cmd = NULL;
 }
 
 /*--------------------------------------------------------- */
 static void clish_nspace_fini(clish_nspace_t * this)
 {
-	clish_command_t *cmd;
-
 	/* deallocate the memory for this instance */
 	lub_string_free(this->prefix);
 	this->prefix = NULL;
-	/* delete each command link 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);
+	if (this->proxy_cmd) {
+		clish_command_delete(this->proxy_cmd);
+		this->proxy_cmd = NULL;
+	}
+	if (this->prefix_cmd) {
+		clish_command_delete(this->prefix_cmd);
+		this->prefix_cmd = NULL;
+	}
+}
+
+/*--------------------------------------------------------- */
+clish_command_t * clish_nspace_create_prefix_cmd(clish_nspace_t * this,
+	const char * name, const char * help)
+{
+	if (this->prefix_cmd) {
+		clish_command_delete(this->prefix_cmd);
+		this->prefix_cmd = NULL;
 	}
+
+	return (this->prefix_cmd = clish_command_new(name, help));
 }
 
 /*--------------------------------------------------------- */
 static clish_command_t *clish_nspace_find_create_command(clish_nspace_t * this,
-							 const char *prefix,
-							 const clish_command_t *
-							 ref)
+	const char *prefix, const clish_command_t * ref)
 {
-	clish_command_t *cmd;
 	char *name = NULL;
 
+	if (this->proxy_cmd) {
+		clish_command_delete(this->proxy_cmd);
+		this->proxy_cmd = NULL;
+	}
+
 	assert(prefix);
+	if (!ref) {
+		assert(this->prefix_cmd);
+		this->proxy_cmd = clish_command_new_link(prefix, this->prefix_cmd);
+		return this->proxy_cmd;
+	}
+
 	lub_string_catn(&name, prefix, strlen(prefix));
 	lub_string_catn(&name, " ", 1);
 	lub_string_catn(&name, clish_command__get_name(ref),
 			strlen(clish_command__get_name(ref)));
 
-	/* The command is cached already */
-	if (cmd = lub_bintree_find(&this->tree, name)) {
-		free(name);
-		return cmd;
-	}
-
-	cmd = clish_command_new_link(name, ref);
+	this->proxy_cmd = clish_command_new_link(name, ref);
 	free(name);
-	assert(cmd);
 
-	/* Insert command link into the tree */
-	if (-1 == lub_bintree_insert(&this->tree, cmd)) {
-		clish_command_delete(cmd);
-		cmd = NULL;
-	}
-
-	return cmd;
+	return this->proxy_cmd;
 }
 
 /*---------------------------------------------------------
@@ -110,7 +113,7 @@ void clish_nspace_delete(clish_nspace_t * this)
 
 /*--------------------------------------------------------- */
 static const char *clish_nspace_after_prefix(const char *prefix,
-					     const char *line)
+	const char *line)
 {
 	const char *in_line = NULL;
 	regex_t regexp;
@@ -154,8 +157,6 @@ clish_command_t *clish_nspace_find_command(clish_nspace_t * this, const char *na
 		return NULL;
 
 	cmd = clish_view_find_command(view, in_line, this->inherit);
-	if (!cmd)
-		return NULL;
 
 	return clish_nspace_find_create_command(this, prefix, cmd);
 }
@@ -259,7 +260,7 @@ bool_t clish_nspace__get_inherit(const clish_nspace_t * this)
 /*--------------------------------------------------------- */
 bool_t
 clish_nspace__get_visibility(const clish_nspace_t * instance,
-			     clish_nspace_visibility_t field)
+	clish_nspace_visibility_t field)
 {
 	bool_t result = BOOL_FALSE;
 

+ 2 - 1
clish/nspace/private.h

@@ -7,9 +7,10 @@
  * PRIVATE TYPES
  *--------------------------------------------------------- */
 struct clish_nspace_s {
-	lub_bintree_t tree;	/* Tree of command links */
 	clish_view_t *view;	/* The view to import commands from */
 	char *prefix;		/* if non NULL the prefix for imported commands */
+	clish_command_t * prefix_cmd;
+	clish_command_t * proxy_cmd;
 	bool_t help;
 	bool_t completion;
 	bool_t context_help;

+ 5 - 4
clish/shell/private.h

@@ -39,7 +39,7 @@ typedef enum {
  * iterate around commands
  */
 typedef struct {
-	const char *last_cmd;
+	char *last_cmd;
 	clish_nspace_visibility_t field;
 } clish_shell_iterator_t;
 
@@ -82,9 +82,10 @@ struct clish_shell_s {
 /**
  * Initialise a command iterator structure
  */
-void
-clish_shell_iterator_init(clish_shell_iterator_t * iter,
-			  clish_nspace_visibility_t field);
+void clish_shell_iterator_init(clish_shell_iterator_t * iter,
+	clish_nspace_visibility_t field);
+void clish_shell_iterator_fini(clish_shell_iterator_t * iter);
+
 
 /**
  * get the next command which is an extension of the specified line 

+ 13 - 2
clish/shell/shell_command_generator.c

@@ -9,12 +9,20 @@
 /*-------------------------------------------------------- */
 void
 clish_shell_iterator_init(clish_shell_iterator_t * iter,
-			  clish_nspace_visibility_t field)
+	clish_nspace_visibility_t field)
 {
 	iter->last_cmd = NULL;
 	iter->field = field;
 }
 
+/*-------------------------------------------------------- */
+void
+clish_shell_iterator_fini(clish_shell_iterator_t * iter)
+{
+	lub_string_free(iter->last_cmd);
+	iter->last_cmd = NULL;
+}
+
 /*-------------------------------------------------------- */
 const clish_command_t *clish_shell_find_next_completion(const clish_shell_t *
 							this, const char *line,
@@ -38,10 +46,12 @@ const clish_command_t *clish_shell_find_next_completion(const clish_shell_t *
 	if (clish_command_diff(result, cmd) > 0)
 		result = cmd;
 
+	lub_string_free(iter->last_cmd);
 	if (!result)
 		iter->last_cmd = NULL;
 	else
-		iter->last_cmd = clish_command__get_name(result);
+		iter->last_cmd = lub_string_dup(
+			clish_command__get_name(result));
 
 	return result;
 }
@@ -177,6 +187,7 @@ char *clish_shell_word_generator(clish_shell_t * this,
 		/* see whether there is an extended extension */
 		clish_shell_iterator_init(&iter, CLISH_NSPACE_COMPLETION);
 		next = clish_shell_find_next_completion(this, line, &iter);
+		clish_shell_iterator_fini(&iter);
 	}
 	if ((NULL != cmd) && (NULL == next)) {
 		/* this needs to be completed as a parameter */

+ 3 - 0
clish/shell/shell_delete.c

@@ -59,6 +59,9 @@ static void clish_shell_fini(clish_shell_t * this)
 		clish_pargv_delete(this->completion_pargv);
 		this->completion_pargv = NULL;
 	}
+
+	/* free iterator */
+	clish_shell_iterator_fini(&this->iter);
 }
 
 /*--------------------------------------------------------- */

+ 1 - 0
clish/shell/shell_help.c

@@ -92,6 +92,7 @@ void clish_shell_help(clish_shell_t * this, const char *line)
 
 		first_cmd = clish_shell_find_next_completion(this, line, &iter);
 		next_cmd = clish_shell_find_next_completion(this, line, &iter);
+		clish_shell_iterator_fini(&iter);
 	} else {
 		first_cmd = next_cmd = NULL;
 	}

+ 9 - 0
clish/shell/shell_tinyxml_read.cpp

@@ -465,6 +465,7 @@ process_namespace(clish_shell_t * shell, TiXmlElement * element, void *parent)
 
 	const char *view = element->Attribute("ref");
 	const char *prefix = element->Attribute("prefix");
+	const char *prefix_help = element->Attribute("prefix_help");
 	const char *help = element->Attribute("help");
 	const char *completion = element->Attribute("completion");
 	const char *context_help = element->Attribute("context_help");
@@ -480,6 +481,14 @@ process_namespace(clish_shell_t * shell, TiXmlElement * element, void *parent)
 
 	if (NULL != prefix) {
 		clish_nspace__set_prefix(nspace, prefix);
+		if (prefix_help)
+			clish_nspace_create_prefix_cmd(nspace,
+				"prefix",
+				prefix_help);
+		else
+			clish_nspace_create_prefix_cmd(nspace,
+				"prefix",
+				"Prefix for the imported commands.");
 	}
 
 	if (help && (lub_string_nocasecmp(help, "true") == 0))