Browse Source

Rename auto internal variables to __var

git-svn-id: https://klish.googlecode.com/svn/trunk@154 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
bc0c1e67e6
4 changed files with 32 additions and 9 deletions
  1. 1 1
      clish.xsd
  2. 1 1
      clish/shell/shell_tinyxml_read.cpp
  3. 1 0
      clish/variable.h
  4. 29 7
      clish/variable/variable_expand.c

+ 1 - 1
clish.xsd

@@ -399,7 +399,7 @@
     <xs:complexType name="config_t">
         <xs:attribute name="operation" type="operation_t" use="optional" default="set"/>
         <xs:attribute name="priority" type="xs:string" use="optional" default="0x7f00"/>
-        <xs:attribute name="pattern" type="xs:string" use="optional" default="^${cmd}"/>
+        <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"/>

+ 1 - 1
clish/shell/shell_tinyxml_read.cpp

@@ -543,7 +543,7 @@ process_config(clish_shell_t * shell, TiXmlElement * element, void *parent)
 	if (pattern != NULL)
 		clish_command__set_pattern(cmd, pattern);
 	else
-		clish_command__set_pattern(cmd, "^${cmd}");
+		clish_command__set_pattern(cmd, "^${__cmd}");
 
 	if (file != NULL)
 		clish_command__set_file(cmd, file);

+ 1 - 0
clish/variable.h

@@ -29,6 +29,7 @@ char *clish_variable_expand(const char *string,
  * methods
  *----------------- */
 char *clish_variable__get_line(const clish_command_t * cmd, clish_pargv_t * pargv);
+char *clish_variable__get_params(const clish_command_t * cmd, clish_pargv_t * pargv);
 
 /*-----------------
  * attributes

+ 29 - 7
clish/variable/variable_expand.c

@@ -72,13 +72,16 @@ static char *find_context_var(const context_t * this, const char *name)
 	char *pattern = NULL;
 	regmatch_t pmatches[2];
 
-	if (!lub_string_nocasecmp(name, "cmd")) {
+	if (!lub_string_nocasecmp(name, "__cmd")) {
 		if (this->cmd)
 			result =
 			    lub_string_dup(clish_command__get_name(this->cmd));
-	} else if (!lub_string_nocasecmp(name, "line")) {
+	} else if (!lub_string_nocasecmp(name, "__line")) {
 		if (this->cmd && this->pargv)
 			result = clish_variable__get_line(this->cmd, this->pargv);
+	} else if (!lub_string_nocasecmp(name, "__params")) {
+		if (this->cmd && this->pargv)
+			result = clish_variable__get_params(this->cmd, this->pargv);
 	}
 
 	return result;
@@ -268,17 +271,15 @@ char *clish_variable_expand(const char *string,
 }
 
 /*--------------------------------------------------------- */
-char *clish_variable__get_line(const clish_command_t * cmd, clish_pargv_t * pargv)
+char *clish_variable__get_params(const clish_command_t * cmd, clish_pargv_t * pargv)
 {
 	char *line = NULL;
 	unsigned i, cnt;
 	const clish_param_t *param;
 	const clish_parg_t *parg;
 
-	lub_string_cat(&line, clish_command__get_name(cmd));
-
 	if (!pargv)
-		return line;
+		return NULL;
 
 	cnt = clish_pargv__get_count(pargv);
 	for (i = 0; i < cnt; i++) {
@@ -286,11 +287,32 @@ char *clish_variable__get_line(const clish_command_t * cmd, clish_pargv_t * parg
 		if (CLISH_PARAM_SWITCH == clish_param__get_mode(param))
 			continue;
 		parg = clish_pargv__get_parg(pargv, i);
-		lub_string_cat(&line, " ");
+		if (0 != i)
+			lub_string_cat(&line, " ");
 		lub_string_cat(&line, clish_parg__get_value(parg));
 	}
 
 	return line;
 }
 
+
+/*--------------------------------------------------------- */
+char *clish_variable__get_line(const clish_command_t * cmd, clish_pargv_t * pargv)
+{
+	char *line = NULL;
+	char *params = NULL;
+
+	lub_string_cat(&line, clish_command__get_name(cmd));
+
+	if (!pargv)
+		return line;
+
+	params = clish_variable__get_params(cmd, pargv);
+	if (params)
+		lub_string_cat(&line, params);
+	lub_string_free(params);
+
+	return line;
+}
+
 /*--------------------------------------------------------- */