Browse Source

Save pargv within pwd

Serj Kalichev 8 years ago
parent
commit
cb406797bd
6 changed files with 35 additions and 2 deletions
  1. 1 0
      clish/pargv.h
  2. 18 1
      clish/pargv/pargv.c
  3. 2 0
      clish/shell.h
  4. 1 0
      clish/shell/private.h
  5. 12 0
      clish/shell/shell_pwd.c
  6. 1 1
      plugins/clish/sym_misc.c

+ 1 - 0
clish/pargv.h

@@ -43,6 +43,7 @@ const clish_parg_t *clish_pargv_find_arg(clish_pargv_t * instance,
 	const char *name);
 int clish_pargv_insert(clish_pargv_t * instance,
 	const clish_param_t * param, const char *value);
+clish_pargv_t *clish_pargv_clone(const clish_pargv_t *src);
 void clish_pargv_dump(const clish_pargv_t * instance);
 /*-----------------
  * attributes

+ 18 - 1
clish/pargv/pargv.c

@@ -79,10 +79,27 @@ clish_pargv_t *clish_pargv_new(void)
 	return this;
 }
 
+/*--------------------------------------------------------- */
+clish_pargv_t *clish_pargv_clone(const clish_pargv_t *src)
+{
+	clish_pargv_t *dst;
+	unsigned int i;
+
+	if (!src)
+		return NULL;
+
+	dst = clish_pargv_new();
+	for (i = 0; i < src->pargc; i++) {
+		clish_pargv_insert(dst, src->pargv[i]->param, src->pargv[i]->value);
+	}
+
+	return dst;
+}
+
 /*--------------------------------------------------------- */
 static void clish_pargv_fini(clish_pargv_t * this)
 {
-	unsigned i;
+	unsigned int i;
 
 	/* cleanup time */
 	for (i = 0; i < this->pargc; i++) {

+ 2 - 0
clish/shell.h

@@ -146,6 +146,8 @@ void clish_shell__set_pwd(clish_shell_t *instance, const char * line,
 	clish_view_t * view, char * viewid, clish_context_t *context);
 char *clish_shell__get_pwd_line(const clish_shell_t * instance,
 	 unsigned int index);
+clish_pargv_t *clish_shell__get_pwd_pargv(const clish_shell_t *instance,
+	unsigned int index);
 char *clish_shell__get_pwd_full(const clish_shell_t * instance,
 	unsigned int depth);
 clish_view_t *clish_shell__get_pwd_view(const clish_shell_t * instance,

+ 1 - 0
clish/shell/private.h

@@ -39,6 +39,7 @@ typedef struct {
 	char *line;
 	clish_view_t *view;
 	lub_bintree_t viewid;
+	clish_pargv_t *pargv;
 } clish_shell_pwd_t;
 
 /* Context structure */

+ 12 - 0
clish/shell/shell_pwd.c

@@ -13,6 +13,7 @@ void clish_shell__init_pwd(clish_shell_pwd_t *pwd)
 {
 	pwd->line = NULL;
 	pwd->view = NULL;
+	pwd->pargv = NULL;
 	/* initialise the tree of vars */
 	lub_bintree_init(&pwd->viewid,
 		clish_var_bt_offset(),
@@ -26,6 +27,7 @@ void clish_shell__fini_pwd(clish_shell_pwd_t *pwd)
 
 	lub_string_free(pwd->line);
 	pwd->view = NULL;
+	clish_pargv_delete(pwd->pargv);
 	/* delete each VAR held  */
 	while ((var = lub_bintree_findfirst(&pwd->viewid))) {
 		lub_bintree_remove(&pwd->viewid, var);
@@ -67,6 +69,7 @@ void clish_shell__set_pwd(clish_shell_t *this,
 	/* Fill the new pwd entry */
 	newpwd->line = line ? lub_string_dup(line) : NULL;
 	newpwd->view = view;
+	newpwd->pargv = clish_pargv_clone(clish_context__get_pargv(context));
 	clish_shell__expand_viewid(viewid, &newpwd->viewid, context);
 	clish_shell__fini_pwd(this->pwdv[index]);
 	free(this->pwdv[index]);
@@ -83,6 +86,15 @@ char *clish_shell__get_pwd_line(const clish_shell_t *this, unsigned int index)
 	return this->pwdv[index]->line;
 }
 
+/*--------------------------------------------------------- */
+clish_pargv_t *clish_shell__get_pwd_pargv(const clish_shell_t *this, unsigned int index)
+{
+	if (index >= this->pwdc)
+		return NULL;
+
+	return this->pwdv[index]->pargv;
+}
+
 /*--------------------------------------------------------- */
 char *clish_shell__get_pwd_full(const clish_shell_t * this, unsigned int depth)
 {

+ 1 - 1
plugins/clish/sym_misc.c

@@ -155,7 +155,7 @@ CLISH_PLUGIN_SYM(clish_nested_up)
 
 	if (!this)
 		return -1;
-	/* If depth=0 than exit */
+	/* If depth=0 then exit */
 	if ((depth = clish_shell__get_depth(this)) == 0) {
 		clish_shell__set_state(this, SHELL_STATE_CLOSING);
 		return 0;