Browse Source

Implement internal variables __cur_depth, __cur_pwd.

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

+ 11 - 2
clish/clish_config_callback.c

@@ -87,7 +87,7 @@ clish_config_callback(const clish_shell_t * shell,
 				lub_string_cat(&command, tmp);
 			}
 
-			for (i = 0; i < clish_command__get_depth(cmd); i++) {
+			for (i = 0; i < clish_command__get_cfg_depth(cmd, viewid, pargv); i++) {
 				const char *str =
 				    clish_shell__get_pwd_line(shell, i);
 				if (!str)
@@ -131,7 +131,7 @@ clish_config_callback(const clish_shell_t * shell,
 				lub_string_cat(&command, tmp);
 			}
 
-			for (i = 0; i < clish_command__get_depth(cmd); i++) {
+			for (i = 0; i < clish_command__get_cfg_depth(cmd, viewid, pargv); i++) {
 				const char *str =
 				    clish_shell__get_pwd_line(shell, i);
 				if (!str)
@@ -168,6 +168,15 @@ clish_config_callback(const clish_shell_t * shell,
 				lub_string_cat(&command, tmp);
 			}
 
+			for (i = 0; i < clish_command__get_cfg_depth(cmd, viewid, pargv); i++) {
+				const char *str =
+				    clish_shell__get_pwd_line(shell, i);
+				if (!str)
+					return BOOL_FALSE;
+				lub_string_cat(&command, " \"");
+				lub_string_cat(&command, str);
+				lub_string_cat(&command, "\"");
+			}
 			break;
 		}
 

+ 2 - 0
clish/shell/private.h

@@ -77,6 +77,8 @@ struct clish_shell_s {
 	clish_pargv_t *completion_pargv;
 	unsigned completion_index;
 	unsigned completion_pindex;
+	clish_param_t *param_depth;
+	clish_param_t *param_pwd;
 };
 
 /**

+ 4 - 0
clish/shell/shell_delete.c

@@ -59,6 +59,10 @@ static void clish_shell_fini(clish_shell_t * this)
 		clish_pargv_delete(this->completion_pargv);
 		this->completion_pargv = NULL;
 	}
+
+	/* Free internal params */
+	clish_param_delete(this->param_depth);
+	clish_param_delete(this->param_pwd);
 }
 
 /*--------------------------------------------------------- */

+ 18 - 11
clish/shell/shell_new.c

@@ -11,6 +11,8 @@ clish_shell_init(clish_shell_t * this,
 		 const clish_shell_hooks_t * hooks,
 		 void *cookie, FILE * istream, FILE * ostream)
 {
+	clish_ptype_t *tmp_ptype = NULL;
+
 	/* initialise the tree of views */
 	lub_bintree_init(&this->view_tree,
 			 clish_view_bt_offset(),
@@ -40,18 +42,23 @@ clish_shell_init(clish_shell_t * this,
 	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", "[^\\]+",
+	/* Create internal ptypes and params */
+	/* Current depth */
+	tmp_ptype = clish_shell_find_create_ptype(this,
+		"__DEPTH", "Depth", "[0-9]+",
+		CLISH_PTYPE_REGEXP, CLISH_PTYPE_NONE);
+	assert(tmp_ptype);
+	this->param_depth = clish_param_new("__cur_depth",
+		"Current depth", tmp_ptype);
+	clish_param__set_hidden(this->param_depth, BOOL_TRUE);
+	/* Current pwd */
+	tmp_ptype = clish_shell_find_create_ptype(this,
+		"__PWD", "Path", ".+",
 		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);
-*/
+	assert(tmp_ptype);
+	this->param_pwd = clish_param_new("__cur_pwd",
+		"Current path", tmp_ptype);
+	clish_param__set_hidden(this->param_pwd, BOOL_TRUE);
 }
 
 /*-------------------------------------------------------- */

+ 12 - 0
clish/shell/shell_parse.c

@@ -16,6 +16,18 @@ clish_pargv_status_t clish_shell_parse(
 	/* Now construct the parameters for the command */
 	if (NULL != *cmd)
 		*pargv = clish_pargv_new(*cmd, line, 0, &result);
+	if (*pargv) {
+		char str[100];
+		char * tmp;
+		int depth = clish_shell__get_depth(this);
+		snprintf(str, sizeof(str) - 1, "%u", depth);
+		clish_pargv_insert(*pargv, this->param_depth, str);
+		tmp = clish_shell__get_pwd_full(this, depth);
+		if (tmp) {
+			clish_pargv_insert(*pargv, this->param_pwd, tmp);
+			lub_string_free(tmp);
+		}
+	}
 
 	return result;
 }