Browse Source

Working on seq_num

git-svn-id: https://klish.googlecode.com/svn/trunk@159 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 14 years ago
parent
commit
52d8a47dda

+ 16 - 6
clish/clish_config_callback.c

@@ -33,6 +33,10 @@ clish_config_callback(const clish_shell_t * shell,
 	char *command = NULL;
 	konf_client_t *client;
 	konf_buf_t *buf = NULL;
+	const char *viewid = NULL;
+
+	if (shell)
+		viewid = clish_shell__get_viewid(shell);
 
 	switch (clish_command__get_cfg_op(cmd)) {
 
@@ -72,9 +76,11 @@ clish_config_callback(const clish_shell_t * shell,
 
 			if (clish_command__get_seq(cmd) == BOOL_TRUE) {
 				lub_string_cat(&command, " -q");
-				if (clish_command__get_seq_num(cmd) != 0) {
+				if (clish_command__get_seq_num(cmd,
+					viewid, pargv) != 0) {
 					snprintf(tmp, sizeof(tmp) - 1, " -n %u",
-						clish_command__get_seq_num(cmd));
+						clish_command__get_seq_num(cmd,
+							viewid, pargv));
 					tmp[sizeof(tmp) - 1] = '\0';
 					lub_string_cat(&command, tmp);
 				}
@@ -111,9 +117,11 @@ clish_config_callback(const clish_shell_t * shell,
 
 			if (clish_command__get_seq(cmd) == BOOL_TRUE) {
 				lub_string_cat(&command, " -q");
-				if (clish_command__get_seq_num(cmd) != 0) {
+				if (clish_command__get_seq_num(cmd,
+					viewid, pargv) != 0) {
 					snprintf(tmp, sizeof(tmp) - 1, " -n %u",
-						clish_command__get_seq_num(cmd));
+						clish_command__get_seq_num(cmd,
+							viewid, pargv));
 					tmp[sizeof(tmp) - 1] = '\0';
 					lub_string_cat(&command, tmp);
 				}
@@ -150,9 +158,11 @@ clish_config_callback(const clish_shell_t * shell,
 
 			if (clish_command__get_seq(cmd) == BOOL_TRUE) {
 				lub_string_cat(&command, " -q");
-				if (clish_command__get_seq_num(cmd) != 0) {
+				if (clish_command__get_seq_num(cmd,
+					viewid, pargv) != 0) {
 					snprintf(tmp, sizeof(tmp) - 1, " -n %u",
-						clish_command__get_seq_num(cmd));
+						clish_command__get_seq_num(cmd,
+							viewid, pargv));
 					tmp[sizeof(tmp) - 1] = '\0';
 					lub_string_cat(&command, tmp);
 				}

+ 3 - 2
clish/command.h

@@ -95,8 +95,9 @@ void clish_command__set_splitter(clish_command_t * instance, bool_t splitter);
 bool_t clish_command__get_splitter(const clish_command_t * instance);
 bool_t clish_command__get_seq(const clish_command_t * instance);
 void clish_command__set_seq(clish_command_t * instance, bool_t seq);
-void clish_command__set_seq_num(clish_command_t * instance, unsigned short seq_num);
-unsigned short clish_command__get_seq_num(const clish_command_t * instance);
+void clish_command__set_seq_num(clish_command_t * instance, const char * seq_num);
+unsigned short clish_command__get_seq_num(const clish_command_t * instance,
+	const char *viewid, clish_pargv_t * pargv);
 clish_view_restore_t clish_command__get_restore(const clish_command_t * instance);
 
 #endif				/* _clish_command_h */

+ 32 - 5
clish/command/command.c

@@ -45,7 +45,7 @@ clish_command_init(clish_command_t * this, const char *name, const char *text)
 	this->file = NULL;
 	this->splitter = BOOL_TRUE;
 	this->seq = BOOL_FALSE;
-	this->seq_num = 0;
+	this->seq_num = NULL;
 }
 
 /*--------------------------------------------------------- */
@@ -86,6 +86,8 @@ static void clish_command_fini(clish_command_t * this)
 	this->pattern = NULL;
 	lub_string_free(this->file);
 	this->file = NULL;
+	lub_string_free(this->seq_num);
+	this->seq_num = NULL;
 }
 
 /*---------------------------------------------------------
@@ -489,15 +491,40 @@ void clish_command__set_seq(clish_command_t * this, bool_t seq)
 }
 
 /*--------------------------------------------------------- */
-void clish_command__set_seq_num(clish_command_t * this, unsigned short seq_num)
+void clish_command__set_seq_num(clish_command_t * this, const char * seq_num)
 {
-	this->seq_num = seq_num;
+	assert(NULL == this->file);
+	this->seq_num = lub_string_dup(seq_num);
 }
 
 /*--------------------------------------------------------- */
-unsigned short clish_command__get_seq_num(const clish_command_t * this)
+unsigned short clish_command__get_seq_num(const clish_command_t * this,
+	const char *viewid, clish_pargv_t * pargv)
 {
-	return this->seq_num;
+	unsigned short num = 0;
+	char *str;
+
+	if (!this->seq_num)
+		return 0;
+
+	str = clish_variable_expand(this->seq_num, viewid, this, pargv);
+	if ((str != NULL) && (*str != '\0')) {
+		long val = 0;
+		char *endptr;
+
+		val = strtol(str, &endptr, 0);
+		if (endptr == str)
+			num = 0;
+		else if (val > 0xffff)
+			num = 0xffff;
+		else if (val < 0)
+			num = 0;
+		else
+			num = (unsigned short)val;
+	}
+	lub_string_free(str);
+
+	return num;
 }
 
 /*--------------------------------------------------------- */

+ 1 - 1
clish/command/private.h

@@ -30,5 +30,5 @@ struct clish_command_s {
 	char *file;
 	bool_t splitter;
 	bool_t seq;
-	unsigned short seq_num;
+	char *seq_num;
 };

+ 3 - 18
clish/shell/shell_tinyxml_read.cpp

@@ -558,24 +558,9 @@ process_config(clish_shell_t * shell, TiXmlElement * element, void *parent)
 	else
 		clish_command__set_seq(cmd, BOOL_FALSE);
 
-	if ((seq_num != NULL) && (*seq_num != '\0')) {
-		long val = 0;
-		char *endptr;
-		unsigned short pri;
-
-		val = strtol(seq_num, &endptr, 0);
-		if (endptr == seq_num)
-			pri = 0;
-		else if (val > 0xffff)
-			pri = 0xffff;
-		else if (val < 0)
-			pri = 0;
-		else
-			pri = (unsigned short)val;
-		if (0 != pri) {
-			clish_command__set_seq(cmd, BOOL_TRUE);
-			clish_command__set_seq_num(cmd, pri);
-		}
+	if (seq_num && (*seq_num != '\0')) {
+		clish_command__set_seq(cmd, BOOL_TRUE);
+		clish_command__set_seq_num(cmd, seq_num);
 	}
 
 }