Przeglądaj źródła

Fix nested up function when start depth is not 0

Serj Kalichev 7 lat temu
rodzic
commit
5c3c9fe2b0
3 zmienionych plików z 11 dodań i 5 usunięć
  1. 1 1
      clish/shell.h
  2. 8 1
      clish/shell/shell_view.c
  3. 2 3
      plugins/clish/sym_misc.c

+ 1 - 1
clish/shell.h

@@ -141,7 +141,7 @@ int clish_shell_rmfifo(clish_shell_t * instance, const char *name);
  *----------------- */
 clish_view_t *clish_shell__get_view(const clish_shell_t * instance);
 unsigned int clish_shell__get_depth(const clish_shell_t * instance);
-void clish_shell__set_depth(clish_shell_t *instance, unsigned int depth);
+clish_view_t *clish_shell__set_depth(clish_shell_t *instance, unsigned int depth);
 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);

+ 8 - 1
clish/shell/shell_view.c

@@ -54,10 +54,17 @@ unsigned int clish_shell__get_depth(const clish_shell_t *this)
 }
 
 /*--------------------------------------------------------- */
-void clish_shell__set_depth(clish_shell_t *this, unsigned int depth)
+clish_view_t *clish_shell__set_depth(clish_shell_t *this, unsigned int depth)
 {
+	clish_view_t *tmp;
+
 	assert(this);
+	/* Check if target view is valid = is not NULL */
+	tmp = this->pwdv[depth]->view;
+	if (!tmp)
+		return NULL;
 	this->depth = depth;
+	return tmp;
 }
 
 /*--------------------------------------------------------- */

+ 2 - 3
plugins/clish/sym_misc.c

@@ -157,12 +157,11 @@ CLISH_PLUGIN_SYM(clish_nested_up)
 	if (!this)
 		return -1;
 	/* If depth=0 then exit */
-	if ((depth = clish_shell__get_depth(this)) == 0) {
+	if (((depth = clish_shell__get_depth(this)) == 0) ||
+		!clish_shell__set_depth(this, --depth)) {
 		clish_shell__set_state(this, SHELL_STATE_CLOSING);
 		return 0;
 	}
-	depth--;
-	clish_shell__set_depth(this, depth);
 
 	script = script; /* Happy compiler */
 	out = out; /* Happy compiler */