Browse Source

xml: Remove unneeded NSPACE tag. Use ref=<> attribute

Serj Kalichev 1 year ago
parent
commit
96c9fa3a44
2 changed files with 28 additions and 217 deletions
  1. 24 148
      klish.xsd
  2. 4 69
      klish/xml-helper/load.c

+ 24 - 148
klish.xsd

@@ -25,7 +25,6 @@
 	<xs:element name="ACTION" type="action_t"/>
 	<xs:element name="ENTRY" type="entry_t"/>
 	<xs:element name="VIEW" type="view_t"/> <!-- Wrapper -->
-	<xs:element name="NSPACE" type="nspace_t"/> <!-- Wrapper -->
 	<xs:element name="COMMAND" type="command_t"/> <!-- Wrapper -->
 	<xs:element name="SUBCOMMAND" type="param_t"/> <!-- Wrapper -->
 	<xs:element name="FILTER" type="command_t"/> <!-- Wrapper -->
@@ -276,7 +275,6 @@
 			<xs:element ref="ENTRY" minOccurs="0" maxOccurs="unbounded"/>
 			<xs:element ref="PTYPE" minOccurs="0" maxOccurs="unbounded"/>
 			<xs:element ref="VIEW" minOccurs="0" maxOccurs="unbounded"/>
-			<xs:element ref="NSPACE" minOccurs="0" maxOccurs="unbounded"/>
 			<xs:element ref="COMMAND" minOccurs="0" maxOccurs="unbounded"/>
 			<xs:element ref="FILTER" minOccurs="0" maxOccurs="unbounded"/>
 			<xs:element ref="PARAM" minOccurs="0" maxOccurs="unbounded"/>
@@ -325,7 +323,6 @@
 		<xs:choice>
 			<xs:element ref="ACTION" minOccurs="0" maxOccurs="unbounded"/>
 			<xs:element ref="ENTRY" minOccurs="0" maxOccurs="unbounded"/>
-			<xs:element ref="NSPACE" minOccurs="0" maxOccurs="unbounded"/>
 			<xs:element ref="COND" minOccurs="0" maxOccurs="unbounded"/>
 			<xs:element ref="COMPL" minOccurs="0" maxOccurs="unbounded"/>
 			<xs:element ref="HELP" minOccurs="0" maxOccurs="unbounded"/>
@@ -338,6 +335,8 @@
 		</xs:sequence>
 		<xs:attribute name="name" type="xs:string" use="required"/>
 		<xs:attribute name="help" type="xs:string" use="optional"/>
+		<xs:attribute name="ref" type="xs:string" use="optional"/>
+		<xs:attribute name="value" type="xs:string" use="optional"/>
 	</xs:complexType>
 
 
@@ -357,16 +356,32 @@
 *
 ********************************************************
 -->
-	<xs:complexType name="view_t">
-		<xs:sequence>
-			<xs:element ref="NSPACE" minOccurs="0" maxOccurs="unbounded"/>
-			<xs:element ref="COMMAND" minOccurs="0" maxOccurs="unbounded"/>
+
+	<xs:group name="view_group_t">
+		<xs:choice>
 			<xs:element ref="HOTKEY" minOccurs="0" maxOccurs="unbounded"/>
 			<xs:element ref="ENTRY" minOccurs="0" maxOccurs="unbounded"/>
+			<xs:element ref="PTYPE" minOccurs="0" maxOccurs="unbounded"/>
+			<xs:element ref="VIEW" minOccurs="0" maxOccurs="unbounded"/>
+			<xs:element ref="COMMAND" minOccurs="0" maxOccurs="unbounded"/>
+			<xs:element ref="FILTER" minOccurs="0" maxOccurs="unbounded"/>
+			<xs:element ref="PARAM" minOccurs="0" maxOccurs="unbounded"/>
+			<xs:element ref="COND" minOccurs="0" maxOccurs="unbounded"/>
+			<xs:element ref="COMPL" minOccurs="0" maxOccurs="unbounded"/>
+			<xs:element ref="HELP" minOccurs="0" maxOccurs="unbounded"/>
+			<xs:element ref="SWITCH" minOccurs="0" maxOccurs="unbounded"/>
+			<xs:element ref="SUBCOMMAND" minOccurs="0" maxOccurs="unbounded"/>
+			<xs:element ref="MULTI" minOccurs="0" maxOccurs="unbounded"/>
+		</xs:choice>
+	</xs:group>
+
+	<xs:complexType name="view_t">
+		<xs:sequence>
+			<xs:group ref="view_group_t" minOccurs="0" maxOccurs="unbounded"/>
 		</xs:sequence>
 		<xs:attribute name="name" type="xs:string" use="required"/>
-		<xs:attribute name="prompt" type="xs:string" use="optional"/>
-		<xs:attribute name="access" type="xs:string" use="optional"/>
+		<xs:attribute name="help" type="xs:string" use="optional"/>
+		<xs:attribute name="ref" type="xs:string" use="optional"/>
 	</xs:complexType>
 
 
@@ -502,143 +517,4 @@
 		<xs:attribute name="escape_chars" type="xs:string" use="optional"/>
 	</xs:complexType>
 
-
-<!--
-********************************************************
-* <OVERVIEW> specifies a textual description of the shell.
-*
-* This should provide instructions about key bindings and
-* escape sequences which can be used in the CLI.
-*
-********************************************************
--->
-	<xs:simpleType name="overview_t">
-		<xs:restriction base="xs:string">
-			<xs:whiteSpace value="preserve"/>
-		</xs:restriction>
-	</xs:simpleType>
-
-
-<!--
-********************************************************
-* <DETAIL> specifies a textual description.
-*
-* This may be used within the scope of a <COMMAND> 
-* element, in which case it would typically contain 
-* detailed usage instructions including examples.
-*
-* This may also be used within the scope of a <STARTUP>
-* element, in which case the text is used as the banner
-* details which are displayed on shell startup. This is
-* shown before any specified <ACTION> is executed.
-*
-* This text may also be used in the production of user manuals.
-********************************************************
--->
-	<xs:simpleType name="detail_t">
-		<xs:restriction base="xs:string">
-			<xs:whiteSpace value="preserve"/>
-		</xs:restriction>
-	</xs:simpleType>
-
-
-<!--
-*******************************************************
-* <NSPACE> import commands from specific view to current view.
-*
-* ref - the view to import commands from
-*
-* [prefix] - the prefix for imported commands
-*
-* [prefix_help] - the help for namespace prefix
-*
-* [help] - a boolean flag to use imported
-*	commands while help
-*
-* [completion] - a boolean flag to use imported
-*	commands while completion
-*
-* [context_help] - a boolean flag to use imported
-*	commands while context help
-*
-* [inherit] - a boolean flag to inherit nested
-*	namespace commands recursively
-*
-* [access] - access rights
-*
-********************************************************
--->
-	<xs:complexType name="nspace_t">
-		<xs:attribute name="ref" type="xs:string" use="required"/>
-		<xs:attribute name="prefix" type="xs:string" use="optional"/>
-		<xs:attribute name="prefix_help" type="xs:string" use="optional"/>
-		<xs:attribute name="help" type="xs:boolean" use="optional" default="false"/>
-		<xs:attribute name="completion" type="xs:boolean" use="optional" default="true"/>
-		<xs:attribute name="context_help" type="xs:boolean" use="optional" default="false"/>
-		<xs:attribute name="inherit" type="xs:boolean" use="optional" default="true"/>
-		<xs:attribute name="access" type="xs:string" use="optional"/>
-	</xs:complexType>
-
-
-<!--
-*******************************************************
-* <VAR> Specify the variable.
-*
-*
-*
-********************************************************
--->
-	<xs:complexType name="var_t">
-		<xs:sequence>
-			<xs:element ref="ACTION" minOccurs="0" maxOccurs="unbounded"/>
-		</xs:sequence>
-		<xs:attribute name="name" type="xs:string" use="required"/>
-		<xs:attribute name="help" type="xs:string" use="optional"/>
-		<xs:attribute name="value" type="xs:string" use="optional"/>
-		<xs:attribute name="dynamic" type="xs:boolean" use="optional" default="false"/>
-	</xs:complexType>
-
-
-<!--
-*******************************************************
-* <WATCHDOG> is used to recover system after errors.
-*
-********************************************************
--->
-	<xs:complexType name="wdog_t">
-		<xs:sequence>
-			<xs:element ref="ACTION" minOccurs="1" maxOccurs="unbounded"/>
-		</xs:sequence>
-	</xs:complexType>
-
-
-
-
-
-
-<!--
-*******************************************************
-* <HOOK> is used to redefine internal hooks
-*
-* name - The name of internal hook (init, fini, access, log).
-*
-* [builtin] - specify the name of an internally registered
-*	function.
-*
-********************************************************
--->
-	<xs:simpleType name="hook_list_e">
-		<xs:restriction base="xs:string">
-			<xs:enumeration value="init"/>
-			<xs:enumeration value="fini"/>
-			<xs:enumeration value="access"/>
-			<xs:enumeration value="log"/>
-		</xs:restriction>
-	</xs:simpleType>
-
-	<xs:complexType name="hook_t">
-		<xs:attribute name="name" type="hook_list_e"/>
-		<xs:attribute name="builtin" type="xs:string" use="optional"/>
-	</xs:complexType>
-
 </xs:schema>

+ 4 - 69
klish/xml-helper/load.c

@@ -32,7 +32,6 @@ static kxml_process_fn
 	process_view,
 	process_ptype,
 	process_plugin,
-	process_nspace,
 	process_klish,
 	process_entry;
 
@@ -49,7 +48,6 @@ typedef enum {
 	KTAG_VIEW,
 	KTAG_PTYPE,
 	KTAG_PLUGIN,
-	KTAG_NSPACE,
 	KTAG_KLISH,
 	KTAG_ENTRY,
 	KTAG_COND,
@@ -70,7 +68,6 @@ static const char * const kxml_tags[] = {
 	"VIEW",
 	"PTYPE",
 	"PLUGIN",
-	"NSPACE",
 	"KLISH",
 	"ENTRY",
 	"COND",
@@ -90,7 +87,6 @@ static kxml_process_fn *kxml_handlers[] = {
 	process_view,
 	process_ptype,
 	process_plugin,
-	process_nspace,
 	process_klish,
 	process_entry,
 	process_command,
@@ -578,14 +574,15 @@ static bool_t process_view(const kxml_node_t *element, void *parent,
 	ientry.purpose = "common";
 	ientry.min = "1";
 	ientry.max = "1";
-	ientry.ref = NULL;
+	ientry.ref = kxml_node_attr(element, "ref");
 	ientry.value = NULL;
 	ientry.restore = "false";
 	ientry.order = "false";
 	ientry.filter = "false";
 
-	// Parent must be a KLISH tag
-	if (parent_tag != KTAG_KLISH) {
+	if ((parent_tag == KTAG_ACTION) ||
+//		(parent_tag == KTAG_HOTKEY) ||
+		(parent_tag == KTAG_PLUGIN)) {
 		faux_error_sprintf(error,
 			TAG": Tag \"%s\" can't contain VIEW tag",
 			kxml_tag_name(parent_tag));
@@ -602,69 +599,7 @@ static bool_t process_view(const kxml_node_t *element, void *parent,
 err:
 	kxml_node_attr_free(ientry.name);
 	kxml_node_attr_free(ientry.help);
-
-	return res;
-}
-
-
-// It's a namespace for really different objects but not for VIEWs only.
-static bool_t process_nspace(const kxml_node_t *element, void *parent,
-       faux_error_t *error)
-{
-	ientry_t ientry = {};
-	kentry_t *entry = NULL;
-	bool_t res = BOOL_FALSE;
-	ktags_e parent_tag = kxml_node_tag(kxml_node_parent(element));
-
-	// Mandatory NSPACE name
-	ientry.name = kxml_node_attr(element, "name");
-	if (!ientry.name) {
-		faux_error_sprintf(error, TAG": NSPACE without name");
-		return BOOL_FALSE;
-	}
-	ientry.help = kxml_node_attr(element, "help");
-	ientry.container = kxml_node_attr(element, "container");
-	ientry.mode = "common";
-	ientry.purpose = kxml_node_attr(element, "common");;
-	ientry.min = kxml_node_attr(element, "min");
-	ientry.max = kxml_node_attr(element, "max");
-	ientry.ref = kxml_node_attr(element, "ref");
-	if (!ientry.ref) {
-		faux_error_sprintf(error, TAG": NSPACE without reference");
-		return BOOL_FALSE;
-	}
-	ientry.value = kxml_node_attr(element, "value");
-	ientry.restore = kxml_node_attr(element, "restore");
-	ientry.order = kxml_node_attr(element, "order");
-	ientry.filter = "false";
-
-	if (	(KTAG_PLUGIN == parent_tag) ||
-//		(KTAG_HOTKEY == parent_tag) ||
-		(KTAG_ACTION == parent_tag)
-		) {
-		faux_error_sprintf(error,
-			TAG": Tag \"%s\" can't contain NSPACE tag",
-			kxml_tag_name(parent_tag));
-		kentry_free(entry);
-		goto err;
-	}
-
-	if (!(entry = add_entry_to_hierarchy(parent_tag, parent, &ientry, error)))
-		goto err;
-
-	// Don't process NSPACE child elements
-
-	res = BOOL_TRUE;
-err:
-	kxml_node_attr_free(ientry.name);
-	kxml_node_attr_free(ientry.help);
-	kxml_node_attr_free(ientry.container);
-	kxml_node_attr_free(ientry.min);
-	kxml_node_attr_free(ientry.max);
 	kxml_node_attr_free(ientry.ref);
-	kxml_node_attr_free(ientry.value);
-	kxml_node_attr_free(ientry.restore);
-	kxml_node_attr_free(ientry.order);
 
 	return res;
 }