Browse Source

The COMMAND's view can contain vars

Serj Kalichev 10 years ago
parent
commit
a9849e74d9
5 changed files with 32 additions and 23 deletions
  1. 3 3
      clish/command.h
  2. 12 7
      clish/command/command.c
  3. 1 1
      clish/command/private.h
  4. 12 1
      clish/shell/shell_execute.c
  5. 4 11
      clish/shell/shell_xml.c

+ 3 - 3
clish/command.h

@@ -53,7 +53,7 @@ const char *clish_command__get_escape_chars(const clish_command_t * instance);
 const char *clish_command__get_regex_chars(const clish_command_t * instance);
 const clish_param_t *clish_command__get_args(const clish_command_t * instance);
 clish_action_t *clish_command__get_action(const clish_command_t *instance);
-clish_view_t *clish_command__get_view(const clish_command_t * instance);
+const char *clish_command__get_view(const clish_command_t *instance);
 char *clish_command__get_viewid(const clish_command_t *instance);
 unsigned int clish_command__get_param_count(const clish_command_t * instance);
 const clish_param_t *clish_command__get_param(const clish_command_t * instance,
@@ -65,8 +65,8 @@ void clish_command__set_regex_chars(clish_command_t * instance,
 	const char *escape_chars);
 void clish_command__set_args(clish_command_t * instance, clish_param_t * args);
 void clish_command__set_detail(clish_command_t * instance, const char *detail);
-void clish_command__set_view(clish_command_t * instance, clish_view_t * view);
-void clish_command__force_view(clish_command_t * instance, clish_view_t * view);
+void clish_command__set_view(clish_command_t *instance, const char *view);
+void clish_command__force_view(clish_command_t *instance, const char *view);
 void clish_command__set_viewid(clish_command_t * instance, const char *viewid);
 void clish_command__force_viewid(clish_command_t * instance, const char *viewid);
 void clish_command__set_pview(clish_command_t * instance, clish_view_t * view);

+ 12 - 7
clish/command/command.c

@@ -59,6 +59,7 @@ static void clish_command_fini(clish_command_t * this)
 	clish_paramv_delete(this->paramv);
 
 	lub_string_free(this->alias);
+	lub_string_free(this->view);
 	lub_string_free(this->viewid);
 	clish_action_delete(this->action);
 	clish_config_delete(this->config);
@@ -250,39 +251,43 @@ clish_config_t *clish_command__get_config(const clish_command_t *this)
 }
 
 /*--------------------------------------------------------- */
-void clish_command__set_view(clish_command_t * this, clish_view_t * view)
+void clish_command__set_view(clish_command_t * this, const char *view)
 {
 	assert(NULL == this->view);
 	clish_command__force_view(this, view);
 }
 
 /*--------------------------------------------------------- */
-void clish_command__force_view(clish_command_t * this, clish_view_t * view)
+void clish_command__force_view(clish_command_t *this, const char *view)
 {
-	this->view = view;
+	if (this->view)
+		lub_string_free(this->view);
+	this->view = lub_string_dup(view);
 }
 
 /*--------------------------------------------------------- */
-clish_view_t *clish_command__get_view(const clish_command_t * this)
+const char *clish_command__get_view(const clish_command_t *this)
 {
 	return this->view;
 }
 
 /*--------------------------------------------------------- */
-void clish_command__set_viewid(clish_command_t * this, const char *viewid)
+void clish_command__set_viewid(clish_command_t *this, const char *viewid)
 {
 	assert(NULL == this->viewid);
 	clish_command__force_viewid(this, viewid);
 }
 
 /*--------------------------------------------------------- */
-void clish_command__force_viewid(clish_command_t * this, const char *viewid)
+void clish_command__force_viewid(clish_command_t *this, const char *viewid)
 {
+	if (this->viewid)
+		lub_string_free(this->viewid);
 	this->viewid = lub_string_dup(viewid);
 }
 
 /*--------------------------------------------------------- */
-char *clish_command__get_viewid(const clish_command_t * this)
+char *clish_command__get_viewid(const clish_command_t *this)
 {
 	return this->viewid;
 }

+ 1 - 1
clish/command/private.h

@@ -14,7 +14,7 @@ struct clish_command_s {
 	clish_paramv_t *paramv;
 	clish_action_t *action;
 	clish_config_t *config;
-	clish_view_t *view;
+	char *view;
 	char *viewid;
 	char *detail;
 	char *escape_chars;

+ 12 - 1
clish/shell/shell_execute.c

@@ -335,7 +335,18 @@ int clish_shell_execute(clish_context_t *context, char **out)
 
 	/* Move into the new view */
 	if (!result) {
-		clish_view_t *view = clish_command__get_view(cmd);
+		clish_view_t *view = NULL;
+		const char *view_str = clish_command__get_view(cmd);
+		if (view_str) {
+			char *view_exp = NULL;
+			view_exp = clish_shell_expand(view_str,
+				SHELL_VAR_NONE, context);
+			view = clish_shell_find_view(this, view_exp);
+			if (!view)
+				fprintf(stderr, "System error: Can't "
+					"change view to %s\n", view_exp);
+			lub_string_free(view_exp);
+		}
 		/* Save the PWD */
 		if (view) {
 			char *line = clish_shell__get_line(context);

+ 4 - 11
clish/shell/shell_xml.c

@@ -396,14 +396,9 @@ process_command(clish_shell_t * shell, clish_xmlnode_t * element, void *parent)
 		clish_command__set_args(cmd, param);
 	}
 
-	/* define the view which this command changes to */
-	if (view) {
-		clish_view_t *next = clish_shell_find_create_view(shell, view,
-			NULL);
-
-		/* reference the next view */
-		clish_command__set_view(cmd, next);
-	}
+	/* Define the view which this command changes to */
+	if (view)
+		clish_command__set_view(cmd, view);
 
 	/* define the view id which this command changes to */
 	if (viewid)
@@ -470,9 +465,7 @@ process_startup(clish_shell_t * shell, clish_xmlnode_t * element, void *parent)
 	clish_command__set_lock(cmd, BOOL_FALSE);
 
 	/* define the view which this command changes to */
-	clish_view_t *next = clish_shell_find_create_view(shell, view, NULL);
-	/* reference the next view */
-	clish_command__set_view(cmd, next);
+	clish_command__set_view(cmd, view);
 
 	/* define the view id which this command changes to */
 	if (viewid)