Browse Source

Fix shebang for nested VARs

Serj Kalichev 7 years ago
parent
commit
8c2381eece
3 changed files with 12 additions and 2 deletions
  1. 1 0
      clish/shell.h
  2. 7 0
      clish/shell/context.c
  3. 4 2
      clish/shell/shell_var.c

+ 1 - 0
clish/shell.h

@@ -43,6 +43,7 @@ _BEGIN_C_DECL
 clish_context_t *clish_context_new(clish_shell_t *shell);
 int clish_context_init(clish_context_t *instance, clish_shell_t *shell);
 void clish_context_free(clish_context_t *instance);
+int clish_context_dup(clish_context_t *dst, const clish_context_t *src);
 clish_shell_t *clish_context__get_shell(const void *instance);
 void clish_context__set_cmd(void *instance, const clish_command_t *cmd);
 const clish_command_t *clish_context__get_cmd(const void *instance);

+ 7 - 0
clish/shell/context.c

@@ -44,6 +44,13 @@ void clish_context_free(clish_context_t *this)
 	free(this);
 }
 
+/*--------------------------------------------------------- */
+int clish_context_dup(clish_context_t *dst, const clish_context_t *src)
+{
+	*dst = *src;
+	return 0;
+}
+
 /*--------------------------------------------------------- */
 clish_shell_t *clish_context__get_shell(const void *this)
 {

+ 4 - 2
clish/shell/shell_var.c

@@ -173,8 +173,10 @@ static char *find_var(const char *name, lub_bintree_t *tree, clish_context_t *co
 	/* Try to execute ACTION */
 	if (!res) {
 		char *out = NULL;
-		clish_context__set_action(context, clish_var__get_action(var));
-		if (clish_shell_exec_action(context, &out, BOOL_FALSE)) {
+		clish_context_t ctx;
+		clish_context_dup(&ctx, context);
+		clish_context__set_action(&ctx, clish_var__get_action(var));
+		if (clish_shell_exec_action(&ctx, &out, BOOL_FALSE)) {
 			lub_string_free(out);
 			return NULL;
 		}