Browse Source

Change visibility field to hidden flag.

git-svn-id: https://klish.googlecode.com/svn/trunk@167 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
87a6e403ce
6 changed files with 25 additions and 44 deletions
  1. 1 8
      clish.xsd
  2. 2 10
      clish/param.h
  3. 5 7
      clish/param/param.c
  4. 1 1
      clish/param/private.h
  5. 15 15
      clish/shell/shell_tinyxml_read.cpp
  6. 1 3
      clish/variable/variable_expand.c

+ 1 - 8
clish.xsd

@@ -264,13 +264,6 @@
         </xs:restriction>
     </xs:simpleType>
 
-    <xs:simpleType name="param_visibility_t">
-        <xs:restriction base="xs:string">
-            <xs:enumeration value="normal"/>
-            <xs:enumeration value="hidden"/>
-        </xs:restriction>
-    </xs:simpleType>
-
     <xs:complexType name="param_t">
         <xs:sequence>
             <xs:element ref="PARAM" minOccurs="0" maxOccurs="unbounded"/>
@@ -282,7 +275,7 @@
         <xs:attribute name="mode" type="param_mode_t" use="optional" default="common"/>
         <xs:attribute name="optional" type="bool_t" use="optional" default="false"/>
         <xs:attribute name="value" type="xs:string" use="optional"/>
-        <xs:attribute name="visibility" type="param_visibility_t" use="optional" default="normal"/>
+        <xs:attribute name="hidden" type="bool_t" use="optional" default="false"/>
     </xs:complexType>
     <!--
 ********************************************************

+ 2 - 10
clish/param.h

@@ -18,12 +18,6 @@ the arguments which a user is inputing for a command.
 typedef struct clish_paramv_s clish_paramv_t;
 typedef struct clish_param_s clish_param_t;
 
-typedef enum {
-	CLISH_PARAM_NORMAL,
-	CLISH_PARAM_HIDDEN,
-	CLISH_PARAM_INTERNAL
-} clish_param_visibility_t;
-
 #include "clish/ptype.h"
 
 /**
@@ -83,10 +77,8 @@ void clish_param__set_optional(clish_param_t * instance, bool_t optional);
 bool_t clish_param__get_optional(const clish_param_t * instance);
 void clish_param__set_value(clish_param_t * instance, const char * value);
 char *clish_param__get_value(const clish_param_t * instance);
-void clish_param__set_visibility(clish_param_t * instance,
-	clish_param_visibility_t visibility);
-clish_param_visibility_t clish_param__get_visibility(
-	const clish_param_t * instance);
+void clish_param__set_hidden(clish_param_t * instance, bool_t hidden);
+bool_t clish_param__get_hidden(const clish_param_t * instance);
 
 /* paramv methods */
 clish_paramv_t *clish_paramv_new(void);

+ 5 - 7
clish/param/param.c

@@ -29,7 +29,7 @@ clish_param_init(clish_param_t * this,
 	this->mode = CLISH_PARAM_COMMON;
 	this->optional = BOOL_FALSE;
 	this->value = NULL;
-	this->visibility = CLISH_PARAM_NORMAL;
+	this->hidden = BOOL_FALSE;
 
 	this->paramv = clish_paramv_new();
 }
@@ -307,15 +307,13 @@ char *clish_param__get_value(const clish_param_t * this)
 }
 
 /*--------------------------------------------------------- */
-void clish_param__set_visibility(clish_param_t * this,
-	clish_param_visibility_t visibility)
+void clish_param__set_hidden(clish_param_t * this, bool_t hidden)
 {
-	this->visibility = visibility;
+	this->hidden = hidden;
 }
 
 /*--------------------------------------------------------- */
-clish_param_visibility_t clish_param__get_visibility(
-	const clish_param_t * this)
+bool_t clish_param__get_hidden(const clish_param_t * this)
 {
-	return this->visibility;
+	return this->hidden;
 }

+ 1 - 1
clish/param/private.h

@@ -21,5 +21,5 @@ struct clish_param_s {
 	clish_paramv_t *paramv;
 	clish_param_mode_e mode;
 	bool_t optional;
-	clish_param_visibility_t visibility;
+	bool_t hidden;
 };

+ 15 - 15
clish/shell/shell_tinyxml_read.cpp

@@ -317,7 +317,7 @@ process_param(clish_shell_t * shell, TiXmlElement * element, void *parent)
 		const char *mode = element->Attribute("mode");
 		const char *optional = element->Attribute("optional");
 		const char *value = element->Attribute("value");
-		const char *visibility = element->Attribute("visibility");
+		const char *hidden = element->Attribute("hidden");
 		clish_param_t *param;
 		clish_ptype_t *tmp = NULL;
 
@@ -373,17 +373,26 @@ process_param(clish_shell_t * shell, TiXmlElement * element, void *parent)
 		if (NULL != defval) {
 			clish_param__set_default(param, defval);
 		}
+
+		if (hidden && (lub_string_nocasecmp(hidden, "true") == 0))
+			clish_param__set_hidden(param, BOOL_TRUE);
+		else
+			clish_param__set_hidden(param, BOOL_FALSE);
+
 		if (NULL != mode) {
-			if (!lub_string_nocasecmp(mode, "switch"))
+			if (!lub_string_nocasecmp(mode, "switch")) {
 				clish_param__set_mode(param,
-						      CLISH_PARAM_SWITCH);
-			else if (!lub_string_nocasecmp(mode, "subcommand"))
+					CLISH_PARAM_SWITCH);
+				/* Force hidden attribute */
+				clish_param__set_hidden(param, BOOL_TRUE);
+			} else if (!lub_string_nocasecmp(mode, "subcommand"))
 				clish_param__set_mode(param,
-						      CLISH_PARAM_SUBCOMMAND);
+					CLISH_PARAM_SUBCOMMAND);
 			else
 				clish_param__set_mode(param,
-						      CLISH_PARAM_COMMON);
+					CLISH_PARAM_COMMON);
 		}
+
 		if (optional && (lub_string_nocasecmp(optional, "true") == 0))
 			clish_param__set_optional(param, BOOL_TRUE);
 		else
@@ -396,15 +405,6 @@ process_param(clish_shell_t * shell, TiXmlElement * element, void *parent)
 				CLISH_PARAM_SUBCOMMAND);
 		}
 
-		if (NULL != visibility) {
-			if (!lub_string_nocasecmp(visibility, "hidden"))
-				clish_param__set_visibility(param,
-					CLISH_PARAM_HIDDEN);
-			else
-				clish_param__set_visibility(param,
-					CLISH_PARAM_NORMAL);
-		}
-
 		if (cmd)
 			// add the parameter to the command
 			clish_command_insert_param(cmd, param);

+ 1 - 3
clish/variable/variable_expand.c

@@ -283,9 +283,7 @@ char *clish_variable__get_params(const clish_command_t * cmd, clish_pargv_t * pa
 	cnt = clish_pargv__get_count(pargv);
 	for (i = 0; i < cnt; i++) {
 		param = clish_pargv__get_param(pargv, i);
-		if (CLISH_PARAM_SWITCH == clish_param__get_mode(param))
-			continue;
-		if (CLISH_PARAM_NORMAL != clish_param__get_visibility(param))
+		if (clish_param__get_hidden(param))
 			continue;
 		parg = clish_pargv__get_parg(pargv, i);
 		if (NULL != line)