Browse Source

We don't need both sequence and sequence_num. The sequence_num was removed. The sequence field can get the line number.

git-svn-id: https://klish.googlecode.com/svn/trunk@170 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
1b21c3bc9a

+ 1 - 2
clish.xsd

@@ -406,8 +406,7 @@
         <xs:attribute name="pattern" type="xs:string" use="optional" default="^${__cmd}"/>
         <xs:attribute name="file" type="xs:string" use="optional" default="startup-config"/>
         <xs:attribute name="splitter" type="bool_t" use="optional" default="true"/>
-        <xs:attribute name="sequence" type="bool_t" use="optional" default="false"/>
-        <xs:attribute name="sequence_num" type="xs:string" use="optional" default="0"/>
+        <xs:attribute name="sequence" type="xs:string" use="optional" default="0"/>
     </xs:complexType>
 
 

+ 18 - 30
clish/clish_config_callback.c

@@ -76,16 +76,12 @@ clish_config_callback(const clish_shell_t * shell,
 				lub_string_cat(&command, tmp);
 			}
 
-			if (clish_command__get_seq(cmd) == BOOL_TRUE) {
-				lub_string_cat(&command, " -q");
-				if (clish_command__get_seq_num(cmd,
-					viewid, pargv) != 0) {
-					snprintf(tmp, sizeof(tmp) - 1, " -n %u",
-						clish_command__get_seq_num(cmd,
-							viewid, pargv));
-					tmp[sizeof(tmp) - 1] = '\0';
-					lub_string_cat(&command, tmp);
-				}
+			if (clish_command__is_seq(cmd)) {
+				snprintf(tmp, sizeof(tmp) - 1, " -q %u",
+					clish_command__get_seq(cmd,
+						viewid, pargv));
+				tmp[sizeof(tmp) - 1] = '\0';
+				lub_string_cat(&command, tmp);
 			}
 
 			for (i = 0; i < clish_command__get_depth(cmd); i++) {
@@ -124,16 +120,12 @@ clish_config_callback(const clish_shell_t * shell,
 				lub_string_cat(&command, tmp);
 			}
 
-			if (clish_command__get_seq(cmd) == BOOL_TRUE) {
-				lub_string_cat(&command, " -q");
-				if (clish_command__get_seq_num(cmd,
-					viewid, pargv) != 0) {
-					snprintf(tmp, sizeof(tmp) - 1, " -n %u",
-						clish_command__get_seq_num(cmd,
-							viewid, pargv));
-					tmp[sizeof(tmp) - 1] = '\0';
-					lub_string_cat(&command, tmp);
-				}
+			if (clish_command__is_seq(cmd)) {
+				snprintf(tmp, sizeof(tmp) - 1, " -q %u",
+					clish_command__get_seq(cmd,
+						viewid, pargv));
+				tmp[sizeof(tmp) - 1] = '\0';
+				lub_string_cat(&command, tmp);
 			}
 
 			for (i = 0; i < clish_command__get_depth(cmd); i++) {
@@ -165,16 +157,12 @@ clish_config_callback(const clish_shell_t * shell,
 				lub_string_cat(&command, "\"");
 			}
 
-			if (clish_command__get_seq(cmd) == BOOL_TRUE) {
-				lub_string_cat(&command, " -q");
-				if (clish_command__get_seq_num(cmd,
-					viewid, pargv) != 0) {
-					snprintf(tmp, sizeof(tmp) - 1, " -n %u",
-						clish_command__get_seq_num(cmd,
-							viewid, pargv));
-					tmp[sizeof(tmp) - 1] = '\0';
-					lub_string_cat(&command, tmp);
-				}
+			if (clish_command__is_seq(cmd)) {
+				snprintf(tmp, sizeof(tmp) - 1, " -q %u",
+					clish_command__get_seq(cmd,
+						viewid, pargv));
+				tmp[sizeof(tmp) - 1] = '\0';
+				lub_string_cat(&command, tmp);
 			}
 
 			break;

+ 3 - 4
clish/command.h

@@ -93,10 +93,9 @@ char *clish_command__get_file(const clish_command_t * instance,
 	const char * viewid, clish_pargv_t * pargv);
 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, const char * seq_num);
-unsigned short clish_command__get_seq_num(const clish_command_t * instance,
+const char * clish_command__is_seq(const clish_command_t * instance);
+void clish_command__set_seq(clish_command_t * instance, const char * seq_num);
+unsigned short clish_command__get_seq(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);
 

+ 14 - 21
clish/command/command.c

@@ -44,8 +44,7 @@ clish_command_init(clish_command_t * this, const char *name, const char *text)
 	this->pattern = NULL;
 	this->file = NULL;
 	this->splitter = BOOL_TRUE;
-	this->seq = BOOL_FALSE;
-	this->seq_num = NULL;
+	this->seq = NULL;
 }
 
 /*--------------------------------------------------------- */
@@ -86,8 +85,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;
+	lub_string_free(this->seq);
+	this->seq = NULL;
 }
 
 /*---------------------------------------------------------
@@ -479,35 +478,23 @@ void clish_command__set_splitter(clish_command_t * this, bool_t splitter)
 }
 
 /*--------------------------------------------------------- */
-bool_t clish_command__get_seq(const clish_command_t * this)
-{
-	return this->seq;
-}
-
-/*--------------------------------------------------------- */
-void clish_command__set_seq(clish_command_t * this, bool_t seq)
-{
-	this->seq = seq;
-}
-
-/*--------------------------------------------------------- */
-void clish_command__set_seq_num(clish_command_t * this, const char * seq_num)
+void clish_command__set_seq(clish_command_t * this, const char * seq)
 {
 	assert(NULL == this->file);
-	this->seq_num = lub_string_dup(seq_num);
+	this->seq = lub_string_dup(seq);
 }
 
 /*--------------------------------------------------------- */
-unsigned short clish_command__get_seq_num(const clish_command_t * this,
+unsigned short clish_command__get_seq(const clish_command_t * this,
 	const char *viewid, clish_pargv_t * pargv)
 {
 	unsigned short num = 0;
 	char *str;
 
-	if (!this->seq_num)
+	if (!this->seq)
 		return 0;
 
-	str = clish_variable_expand(this->seq_num, viewid, this, pargv);
+	str = clish_variable_expand(this->seq, viewid, this, pargv);
 	if ((str != NULL) && (*str != '\0')) {
 		long val = 0;
 		char *endptr;
@@ -527,6 +514,12 @@ unsigned short clish_command__get_seq_num(const clish_command_t * this,
 	return num;
 }
 
+/*--------------------------------------------------------- */
+const char * clish_command__is_seq(const clish_command_t * this)
+{
+	return this->seq;
+}
+
 /*--------------------------------------------------------- */
 clish_view_restore_t clish_command__get_restore(const clish_command_t * this)
 {

+ 1 - 2
clish/command/private.h

@@ -29,6 +29,5 @@ struct clish_command_s {
 	char *pattern;
 	char *file;
 	bool_t splitter;
-	bool_t seq;
-	char *seq_num;
+	char *seq;
 };

+ 2 - 10
clish/shell/shell_tinyxml_read.cpp

@@ -520,7 +520,6 @@ process_config(clish_shell_t * shell, TiXmlElement * element, void *parent)
 	const char *file = element->Attribute("file");
 	const char *splitter = element->Attribute("splitter");
 	const char *seq = element->Attribute("sequence");
-	const char *seq_num = element->Attribute("sequence_num");
 
 	if (operation && !lub_string_nocasecmp(operation, "unset"))
 		clish_command__set_cfg_op(cmd, CLISH_CONFIG_UNSET);
@@ -566,15 +565,8 @@ process_config(clish_shell_t * shell, TiXmlElement * element, void *parent)
 	else
 		clish_command__set_splitter(cmd, BOOL_TRUE);
 
-	if (seq && (lub_string_nocasecmp(seq, "true") == 0))
-		clish_command__set_seq(cmd, BOOL_TRUE);
-	else
-		clish_command__set_seq(cmd, BOOL_FALSE);
-
-	if (seq_num && (*seq_num != '\0')) {
-		clish_command__set_seq(cmd, BOOL_TRUE);
-		clish_command__set_seq_num(cmd, seq_num);
-	}
+	if (seq != NULL)
+		clish_command__set_seq(cmd, seq);
 }
 
 ///////////////////////////////////////

+ 3 - 6
konf/query/query.c

@@ -108,7 +108,7 @@ int konf_query_parse(konf_query_t *query, int argc, char **argv)
 	unsigned i = 0;
 	int pwdc = 0;
 
-	static const char *shortopts = "suoedtp:qn:r:l:f:i";
+	static const char *shortopts = "suoedtp:q:r:l:f:i";
 /*	static const struct option longopts[] = {
 		{"set",		0, NULL, 's'},
 		{"unset",	0, NULL, 'u'},
@@ -117,8 +117,7 @@ int konf_query_parse(konf_query_t *query, int argc, char **argv)
 		{"dump",	0, NULL, 'd'},
 		{"stream",	0, NULL, 't'},
 		{"priority",	1, NULL, 'p'},
-		{"seq",		0, NULL, 'q'},
-		{"seq_num",	1, NULL, 'n'},
+		{"seq",		1, NULL, 'q'},
 		{"pattern",	1, NULL, 'r'},
 		{"line",	1, NULL, 'l'},
 		{"file",	1, NULL, 'f'},
@@ -167,13 +166,11 @@ int konf_query_parse(konf_query_t *query, int argc, char **argv)
 			break;
 			}
 		case 'q':
-			query->seq = BOOL_TRUE;
-			break;
-		case 'n':
 			{
 			long val = 0;
 			char *endptr;
 
+			query->seq = BOOL_TRUE;
 			val = strtol(optarg, &endptr, 0);
 			if (endptr == optarg)
 				break;

+ 2 - 0
konf/tree/tree.c

@@ -311,6 +311,8 @@ int konf_tree_del_pattern(konf_tree_t *this,
 		if (seq && (seq_num != 0) &&
 			(seq_num != conf->seq_num))
 			continue;
+		if (seq && (seq_num == 0))
+			continue;
 		lub_bintree_remove(&this->tree, conf);
 		konf_tree_delete(conf);
 		del_cnt++;