Browse Source

Implement -w and -i clish options to set startup view and viewid.

git-svn-id: https://klish.googlecode.com/svn/trunk@258 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
4274b34a44
6 changed files with 48 additions and 11 deletions
  1. 12 3
      bin/clish.cpp
  2. 2 0
      clish/command.h
  3. 12 0
      clish/command/command.c
  4. 2 0
      clish/shell.h
  5. 20 0
      clish/shell/shell_startup.c
  6. 0 8
      clish/shell/shell_tinyxml_read.cpp

+ 12 - 3
bin/clish.cpp

@@ -48,8 +48,8 @@ int main(int argc, char **argv)
 	bool_t lockless = BOOL_FALSE;
 	bool_t stop_on_error = BOOL_FALSE;
 	const char *xml_path = getenv("CLISH_PATH");
-	const char *view = NULL;
-	const char *viewid = NULL;
+	const char *view = getenv("CLISH_VIEW");
+	const char *viewid = getenv("CLISH_VIEWID");
 
 	static const char *shortopts = "hvs:ledx:w:i:";
 /*	static const struct option longopts[] = {
@@ -110,12 +110,12 @@ int main(int argc, char **argv)
 		}
 	}
 
+	/* Create shell instance */
 	shell = clish_shell_new(&my_hooks, NULL, NULL, stdout, stop_on_error);
 	if (!shell) {
 		fprintf(stderr, "Cannot run clish.\n");
 		return -1;
 	}
-
 	/* Load the XML files */
 	clish_shell_load_scheme(shell, xml_path);
 	/* Set communication to the konfd */
@@ -123,6 +123,12 @@ int main(int argc, char **argv)
 	/* Set lockless mode */
 	if (lockless)
 		clish_shell__set_lockfile(shell, NULL);
+	/* Set startup view */
+	if (view)
+		clish_shell__set_startup_view(shell, view);
+	/* Set startup viewid */
+	if (viewid)
+		clish_shell__set_startup_viewid(shell, viewid);
 	/* Execute startup */
 	running = clish_shell_startup(shell);
 	if (!running) {
@@ -179,6 +185,9 @@ static void help(int status, const char *argv0)
 		printf("\t-l, --lockless\tDon't use locking mechanism.\n");
 		printf("\t-e, --stop-on-error\tStop programm execution on error.\n");
 		printf("\t-d, --dry-run\tDon't actually execute ACTION scripts.\n");
+		printf("\t-x, --xml-path\tPath to XML scheme files.\n");
+		printf("\t-w, --view\tSet the startup view.\n");
+		printf("\t-i, --viewid\tSet the startup viewid.\n");
 	}
 }
 

+ 2 - 0
clish/command.h

@@ -73,7 +73,9 @@ clish_command__set_escape_chars(clish_command_t * instance,
 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_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);
 clish_view_t *clish_command__get_pview(const clish_command_t * instance);
 unsigned clish_command__get_depth(const clish_command_t * instance);

+ 12 - 0
clish/command/command.c

@@ -308,6 +308,12 @@ char *clish_command__get_action(const clish_command_t * this,
 void clish_command__set_view(clish_command_t * this, clish_view_t * view)
 {
 	assert(NULL == this->view);
+	clish_command__force_view(this, view);
+}
+
+/*--------------------------------------------------------- */
+void clish_command__force_view(clish_command_t * this, clish_view_t * view)
+{
 	this->view = view;
 }
 
@@ -321,6 +327,12 @@ clish_view_t *clish_command__get_view(const clish_command_t * this)
 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)
+{
 	this->viewid = lub_string_dup(viewid);
 }
 

+ 2 - 0
clish/shell.h

@@ -372,6 +372,8 @@ bool_t clish_shell_loop(clish_shell_t * instance);
 clish_shell_state_t clish_shell__get_state(const clish_shell_t * instance);
 void clish_shell__set_state(clish_shell_t * instance,
 	clish_shell_state_t state);
+void clish_shell__set_startup_view(clish_shell_t * instance, const char * viewname);
+void clish_shell__set_startup_viewid(clish_shell_t * instance, const char * viewid);
 
 _END_C_DECL
 

+ 20 - 0
clish/shell/shell_startup.c

@@ -20,3 +20,23 @@ bool_t clish_shell_startup(clish_shell_t * this)
 }
 
 /*----------------------------------------------------------- */
+void clish_shell__set_startup_view(clish_shell_t * this, const char * viewname)
+{
+	clish_view_t *view;
+
+	assert(this);
+	assert(this->startup);
+	/* Search for the view */
+	view = clish_shell_find_create_view(this, viewname, NULL);
+	clish_command__force_view(this->startup, view);
+}
+
+/*----------------------------------------------------------- */
+void clish_shell__set_startup_viewid(clish_shell_t * this, const char * viewid)
+{
+	assert(this);
+	assert(this->startup);
+	clish_command__force_viewid(this->startup, viewid);
+}
+
+/*----------------------------------------------------------- */

+ 0 - 8
clish/shell/shell_tinyxml_read.cpp

@@ -273,14 +273,6 @@ process_startup(clish_shell_t * shell, TiXmlElement * element, void *parent)
 	clish_command_t *cmd = NULL;
 	const char *view = element->Attribute("view");
 	const char *viewid = element->Attribute("viewid");
-	const char *env_view = getenv("CLISH_VIEW");
-	const char *env_viewid = getenv("CLISH_VIEWID");
-
-	/* Redefine startup view if environment is set. */
-	if (env_view)
-		view = env_view;
-	if (env_viewid)
-		viewid = env_viewid;
 
 	assert(NULL == shell->startup);
 	assert(view);