Browse Source

Function to get full pwd string and current depth. CONFIG's depth in config file. Don't used yet.

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

+ 1 - 0
clish.xsd

@@ -412,6 +412,7 @@
         <xs:attribute name="splitter" type="bool_t" use="optional" default="true"/>
         <xs:attribute name="sequence" type="xs:string" use="optional" default="0"/>
         <xs:attribute name="unique" type="bool_t" use="optional" default="true"/>
+        <xs:attribute name="depth" type="xs:string" use="optional"/>
     </xs:complexType>
 
 

+ 3 - 0
clish/command.h

@@ -101,5 +101,8 @@ clish_view_restore_t clish_command__get_restore(const clish_command_t * instance
 bool_t clish_command__get_unique(const clish_command_t * instance);
 void clish_command__set_unique(clish_command_t * instance, bool_t unique);
 const clish_command_t * clish_command__get_orig(const clish_command_t * instance);
+void clish_command__set_cfg_depth(clish_command_t * instance, const char * cfg_depth);
+unsigned clish_command__get_cfg_depth(const clish_command_t * instance,
+	const char *viewid, clish_pargv_t * pargv);
 
 #endif				/* _clish_command_h */

+ 41 - 1
clish/command/command.c

@@ -46,6 +46,7 @@ clish_command_init(clish_command_t * this, const char *name, const char *text)
 	this->splitter = BOOL_TRUE;
 	this->seq = NULL;
 	this->unique = BOOL_TRUE;
+	this->cfg_depth = NULL;
 }
 
 /*--------------------------------------------------------- */
@@ -88,6 +89,8 @@ static void clish_command_fini(clish_command_t * this)
 	this->file = NULL;
 	lub_string_free(this->seq);
 	this->seq = NULL;
+	lub_string_free(this->cfg_depth);
+	this->cfg_depth = NULL;
 }
 
 /*---------------------------------------------------------
@@ -481,7 +484,7 @@ void clish_command__set_splitter(clish_command_t * this, bool_t splitter)
 /*--------------------------------------------------------- */
 void clish_command__set_seq(clish_command_t * this, const char * seq)
 {
-	assert(NULL == this->file);
+	assert(NULL == this->seq);
 	this->seq = lub_string_dup(seq);
 }
 
@@ -548,3 +551,40 @@ const clish_command_t * clish_command__get_orig(const clish_command_t * this)
 		return clish_command__get_orig(this->link);
 	return this;
 }
+
+/*--------------------------------------------------------- */
+void clish_command__set_cfg_depth(clish_command_t * this, const char * cfg_depth)
+{
+	assert(NULL == this->cfg_depth);
+	this->cfg_depth = lub_string_dup(cfg_depth);
+}
+
+/*--------------------------------------------------------- */
+unsigned clish_command__get_cfg_depth(const clish_command_t * this,
+	const char *viewid, clish_pargv_t * pargv)
+{
+	unsigned num = 0;
+	char *str;
+
+	if (!this->cfg_depth)
+		return clish_command__get_depth(this);
+
+	str = clish_variable_expand(this->cfg_depth, viewid, this, pargv);
+	if ((str != NULL) && (*str != '\0')) {
+		long val = 0;
+		char *endptr;
+
+		val = strtol(str, &endptr, 0);
+		if (endptr == str)
+			num = 0;
+		else if (val > 0xffff)
+			num = 0xffff;
+		else if (val < 0)
+			num = 0;
+		else
+			num = (unsigned)val;
+	}
+	lub_string_free(str);
+
+	return num;
+}

+ 1 - 0
clish/command/private.h

@@ -31,4 +31,5 @@ struct clish_command_s {
 	bool_t splitter;
 	char *seq;
 	bool_t unique;
+	char *cfg_depth;
 };

+ 2 - 0
clish/shell.h

@@ -311,6 +311,7 @@ void clish_shell_close(clish_shell_t * instance);
  * attributes 
  *----------------- */
 const clish_view_t *clish_shell__get_view(const clish_shell_t * instance);
+unsigned clish_shell__get_depth(const clish_shell_t * instance);
 const char *clish_shell__get_viewid(const clish_shell_t * instance);
 const char *clish_shell__get_overview(const clish_shell_t * instance);
 tinyrl_t *clish_shell__get_tinyrl(const clish_shell_t * instance);
@@ -320,6 +321,7 @@ clish_shell__set_pwd(clish_shell_t * instance, unsigned index,
 	const char * line, clish_view_t * view, char * viewid);
 char *clish_shell__get_pwd_line(const clish_shell_t * instance,
 				 unsigned index);
+char *clish_shell__get_pwd_full(const clish_shell_t * instance, unsigned depth);
 clish_view_t *clish_shell__get_pwd_view(const clish_shell_t * instance,
 				 unsigned index);
 char *clish_shell__get_pwd_viewid(const clish_shell_t * instance,

+ 6 - 0
clish/shell/shell__get_view.c

@@ -10,3 +10,9 @@ const clish_view_t *clish_shell__get_view(const clish_shell_t * this)
 }
 
 /*--------------------------------------------------------- */
+unsigned clish_shell__get_depth(const clish_shell_t * this)
+{
+	return clish_view__get_depth(this->view);
+}
+
+/*--------------------------------------------------------- */

+ 13 - 0
clish/shell/shell_new.c

@@ -39,6 +39,19 @@ clish_shell_init(clish_shell_t * this,
 	this->cfg_pwdc = 0;
 	this->client = konf_client_new(KONFD_SOCKET_PATH);
 	this->completion_pargv = NULL;
+
+	/* Create internal ptypes */
+/*	const char *ptype_name = "__SUBCOMMAND";
+			clish_param_t *opt_param = NULL;
+	tmp = clish_shell_find_create_ptype(this,
+		ptype_name, "Depth", "[^\\]+",
+		CLISH_PTYPE_REGEXP, CLISH_PTYPE_NONE);
+			assert(tmp);
+			opt_param = clish_param_new(prefix, help, tmp);
+			clish_param__set_mode(opt_param,
+					      CLISH_PARAM_SUBCOMMAND);
+			clish_param__set_optional(opt_param, BOOL_TRUE);
+*/
 }
 
 /*-------------------------------------------------------- */

+ 3 - 4
clish/shell/shell_parse.c

@@ -6,10 +6,9 @@
 
 #include <string.h>
 /*----------------------------------------------------------- */
-clish_pargv_status_t
-clish_shell_parse(const clish_shell_t * this,
-		  const char *line,
-		  const clish_command_t ** cmd, clish_pargv_t ** pargv)
+clish_pargv_status_t clish_shell_parse(
+	const clish_shell_t * this, const char *line,
+	const clish_command_t ** cmd, clish_pargv_t ** pargv)
 {
  	clish_pargv_status_t result = CLISH_BAD_CMD;
 

+ 24 - 0
clish/shell/shell_pwd.c

@@ -52,6 +52,30 @@ char *clish_shell__get_pwd_line(const clish_shell_t * this, unsigned index)
 	return this->cfg_pwdv[index]->line;
 }
 
+char *clish_shell__get_pwd_full(const clish_shell_t * this, unsigned depth)
+{
+	char *pwd = NULL;
+	unsigned i;
+
+	for (i = 0; i < depth; i++) {
+		const char *str =
+			clish_shell__get_pwd_line(this, i);
+		/* Cannot get full path */
+		if (!str) {
+			lub_string_free(pwd);
+			return NULL;
+		}
+		if (pwd)
+			lub_string_cat(&pwd, " ");
+		lub_string_cat(&pwd, "\"");
+		lub_string_cat(&pwd, str);
+		lub_string_cat(&pwd, "\"");
+	}
+
+	return pwd;
+}
+
+
 clish_view_t *clish_shell__get_pwd_view(const clish_shell_t * this, unsigned index)
 {
 	if (index >= this->cfg_pwdc)

+ 5 - 1
clish/shell/shell_tinyxml_read.cpp

@@ -339,7 +339,7 @@ process_param(clish_shell_t * shell, TiXmlElement * element, void *parent)
 		 * It will create nested PARAM.
 		 */
 		if (NULL != prefix) {
-			const char *ptype_name = "internal_SUBCOMMAND";
+			const char *ptype_name = "__SUBCOMMAND";
 			clish_param_t *opt_param = NULL;
 
 			/* Create a ptype for prefix-named subcommand that
@@ -530,6 +530,7 @@ process_config(clish_shell_t * shell, TiXmlElement * element, void *parent)
 	const char *splitter = element->Attribute("splitter");
 	const char *seq = element->Attribute("sequence");
 	const char *unique = element->Attribute("unique");
+	const char *cfg_depth = element->Attribute("depth");
 
 	if (operation && !lub_string_nocasecmp(operation, "unset"))
 		clish_command__set_cfg_op(cmd, CLISH_CONFIG_UNSET);
@@ -586,6 +587,9 @@ process_config(clish_shell_t * shell, TiXmlElement * element, void *parent)
 		/* The entries without sequence cannot be non-unique */
 		clish_command__set_unique(cmd, BOOL_TRUE);
 
+	if (cfg_depth != NULL)
+		clish_command__set_cfg_depth(cmd, cfg_depth);
+
 }
 
 ///////////////////////////////////////