Browse Source

Working on process_ptype() and xsd

Serj Kalichev 1 year ago
parent
commit
f7ed842d2c
2 changed files with 70 additions and 67 deletions
  1. 58 62
      klish.xsd
  2. 12 5
      klish/xml-helper/load.c

+ 58 - 62
klish.xsd

@@ -20,6 +20,9 @@
 
 
 	<xs:element name="KLISH" type="klish_t"/>
+	<xs:element name="PLUGIN" type="plugin_t"/>
+	<xs:element name="HOTKEY" type="hotkey_t"/>
+	<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="COMMAND" type="command_t"/> <!-- Wrapper -->
@@ -27,73 +30,68 @@
 	<xs:element name="COMPL" type="command_t"/> <!-- Wrapper -->
 	<xs:element name="HELP" type="command_t"/> <!-- Wrapper -->
 	<xs:element name="FILTER" type="command_t"/> <!-- Wrapper -->
-	<xs:element name="STARTUP" type="startup_t"/>
-	<xs:element name="ACTION" type="action_t"/>
-	<xs:element name="OVERVIEW" type="overview_t"/>
-	<xs:element name="DETAIL" type="detail_t"/>
 	<xs:element name="PTYPE" type="ptype_t"/> <!-- Wrapper -->
 	<xs:element name="PARAM" type="param_t"/> <!-- Wrapper -->
 	<xs:element name="SWITCH" type="param_t"/> <!-- Wrapper -->
 	<xs:element name="SUBCOMMAND" type="param_t"/> <!-- Wrapper -->
 	<xs:element name="MULTI" type="param_t"/> <!-- Wrapper -->
 	<xs:element name="NSPACE" type="nspace_t"/> <!-- Wrapper -->
-	<xs:element name="VAR" type="var_t"/>
-	<xs:element name="WATCHDOG" type="wdog_t"/>
-	<xs:element name="HOTKEY" type="hotkey_t"/>
-	<xs:element name="PLUGIN" type="plugin_t"/>
-	<xs:element name="HOOK" type="hook_t"/>
 
 
+<!--
+*******************************************************
+* <KLISH>
+********************************************************
+-->
+	<xs:group name="klish_group_t">
+		<xs:choice>
+			<xs:element ref="PLUGIN" minOccurs="0" maxOccurs="unbounded"/>
+			<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:choice>
+	</xs:group>
+
 	<xs:complexType name="klish_t">
 		<xs:annotation>
 			<xs:documentation xml:lang="en">
-			'KLISH' is the top level container. Any object (command,
-			type, var) which are defined within this tag are global
-			in scope i.e. it is visible from all 'VIEW's.
+			'KLISH' is the top level container.
 			</xs:documentation>
 			<xs:documentation xml:lang="ru">
 			Тег 'KLISH' - контейнер верхнего уровня. Все остальные
-			теги должны быть вложенными. Любой объект (команда,
-			тип, переменная т.д.), заданный внутри этого тега,
-			считается глобальным, т.е. видимым их любых 'VIEW".
+			теги должны быть вложенными.
 			</xs:documentation>
 		</xs:annotation>
+		<!--  Any order of tags and any number -->
 		<xs:sequence>
-			<xs:element ref="PLUGIN" minOccurs="0" maxOccurs="unbounded"/>
-			<xs:element ref="HOOK" minOccurs="0" maxOccurs="unbounded"/>
-			<xs:element ref="HOTKEY" minOccurs="0" maxOccurs="unbounded"/>
-			<xs:element ref="WATCHDOG" minOccurs="0" maxOccurs="1"/>
-			<xs:element ref="PTYPE" minOccurs="0" maxOccurs="unbounded"/>
-			<xs:element ref="OVERVIEW" minOccurs="0"/>
-			<xs:element ref="STARTUP" minOccurs="0"/>
-			<xs:element ref="VAR" minOccurs="0" maxOccurs="unbounded"/>
-			<xs:element ref="VIEW" minOccurs="0" maxOccurs="unbounded"/>
-			<xs:element ref="ENTRY" minOccurs="0" maxOccurs="unbounded"/>
+			<xs:group ref="klish_group_t" minOccurs="0" maxOccurs="unbounded"/>
 		</xs:sequence>
 	</xs:complexType>
 
 
 <!--
 *******************************************************
-* <PTYPE> is used to define the syntax for a parameter type.
-*
-* name="<string>" - A textual name for this type. This name can be used to
-*	reference this type within a PARAM's ptype attribute.
-*
-* help="<string>" - Help string.
+* <PLUGIN> is used to dynamically load plugins.
+* Plugin contains symbols that can be used for ACTIONs.
 *
+* name - Plugin name. If "file" attribute is not specified then plugin's
+*	filename is autogenerated as "klish-plugin-<name>.so".
+* [id] - Internal plugin name. Can be the same as "name".
+* [file] - File name if standard autogenerated filename (using "name" field)
+*	is not appropriate.
 ********************************************************
 -->
-	<xs:complexType name="ptype_t">
-		<xs:sequence>
-			<xs:element ref="ACTION" minOccurs="0" maxOccurs="unbounded"/>
-			<xs:element ref="ENTRY" minOccurs="0" maxOccurs="unbounded"/>
-		</xs:sequence>
-		<xs:attribute name="name" type="xs:string" use="required"/>
-		<xs:attribute name="help" type="xs:string" use="required"/>
+	<xs:complexType name="plugin_t">
+		<xs:simpleContent>
+			<xs:extension base="xs:string">
+				<xs:attribute name="name" type="xs:string" use="required"/>
+				<xs:attribute name="id" type="xs:string" use="optional"/>
+				<xs:attribute name="file" type="xs:string" use="optional"/>
+			</xs:extension>
+		</xs:simpleContent>
 	</xs:complexType>
 
-
 <!--
 *******************************************************
 * <ENTRY> This tag is used to define wide class of elements.
@@ -203,6 +201,27 @@
 		<xs:attribute name="filter" type="xs:boolean" use="optional" default="false"/>
 	</xs:complexType>
 
+<!--
+*******************************************************
+* <PTYPE> is used to define the syntax for a parameter type.
+*
+* name="<string>" - A textual name for this type. This name can be used to
+*	reference this type within a PARAM's ptype attribute.
+*
+* help="<string>" - Help string.
+*
+********************************************************
+-->
+	<xs:complexType name="ptype_t">
+		<xs:sequence>
+			<xs:element ref="ACTION" minOccurs="0" maxOccurs="unbounded"/>
+			<xs:element ref="ENTRY" minOccurs="0" maxOccurs="unbounded"/>
+		</xs:sequence>
+		<xs:attribute name="name" type="xs:string" use="required"/>
+		<xs:attribute name="help" type="xs:string" use="required"/>
+	</xs:complexType>
+
+
 
 <!--
 *******************************************************
@@ -262,7 +281,6 @@
 -->
 	<xs:complexType name="startup_t">
 		<xs:sequence>
-			<xs:element ref="DETAIL" minOccurs="0"/>
 			<xs:element ref="ACTION" minOccurs="0" maxOccurs="unbounded"/>
 		</xs:sequence>
 		<xs:attribute name="view" type="xs:string" use="required"/>
@@ -458,7 +476,6 @@
 -->
 	<xs:complexType name="command_t">
 		<xs:sequence>
-			<xs:element ref="DETAIL" minOccurs="0"/>
 			<!--  Any order of PARAM tags and any number -->
 			<xs:group ref="param_group_t" minOccurs="0" maxOccurs="unbounded"/>
 			<xs:element ref="ACTION" minOccurs="0" maxOccurs="unbounded"/>
@@ -597,27 +614,6 @@
 	</xs:complexType>
 
 
-<!--
-*******************************************************
-* <PLUGIN> is used to dynamically load plugins.
-* Plugin contains symbols that can be used for ACTIONs.
-*
-* name - Plugin name. If "file" attribute is not specified then plugin's
-*	filename is autogenerated as "klish-plugin-<name>.so".
-* [id] - Internal plugin name. Can be the same as "name".
-* [file] - File name if standard autogenerated filename (using "name" field)
-*	is not appropriate.
-********************************************************
--->
-	<xs:complexType name="plugin_t">
-		<xs:simpleContent>
-			<xs:extension base="xs:string">
-				<xs:attribute name="name" type="xs:string" use="required"/>
-				<xs:attribute name="id" type="xs:string" use="optional"/>
-				<xs:attribute name="file" type="xs:string" use="optional"/>
-			</xs:extension>
-		</xs:simpleContent>
-	</xs:complexType>
 
 
 <!--

+ 12 - 5
klish/xml-helper/load.c

@@ -394,7 +394,7 @@ static bool_t process_ptype(const kxml_node_t *element, void *parent,
 	kentry_t *entry = NULL;
 	bool_t res = BOOL_FALSE;
 	ktags_e parent_tag = kxml_node_tag(kxml_node_parent(element));
-	kscheme_t *scheme = (kscheme_t *)parent;
+	bool_t rc = BOOL_FALSE;
 
 	// Mandatory PTYPE name
 	ientry.name = kxml_node_attr(element, "name");
@@ -414,8 +414,7 @@ static bool_t process_ptype(const kxml_node_t *element, void *parent,
 	ientry.order = "true";
 	ientry.filter = "false";
 
-	// Parent must be a KLISH tag
-	// TODO: Add to scheme or to entry
+	// Parent must be a KLISH tag or VIEW
 	if ((parent_tag != KTAG_KLISH) &&
 		(KTAG_VIEW != parent_tag)) {
 		faux_error_sprintf(error,
@@ -423,7 +422,7 @@ static bool_t process_ptype(const kxml_node_t *element, void *parent,
 			kxml_tag_name(parent_tag));
 		goto err;
 	}
-	if (!scheme) {
+	if (!parent) {
 		faux_error_sprintf(error,
 			TAG": Broken parent object for PTYPE \"%s\"",
 			ientry.name);
@@ -434,7 +433,14 @@ static bool_t process_ptype(const kxml_node_t *element, void *parent,
 	entry = ientry_load(&ientry, error);
 	if (!entry)
 		goto err;
-	if (!kscheme_add_entrys(scheme, entry)) {
+	if (KTAG_KLISH == parent_tag) {
+		kscheme_t *scheme = (kscheme_t *)parent;
+		rc = kscheme_add_entrys(scheme, entry);
+	} else {
+		kentry_t *pentry = (kentry_t *)parent;
+		rc = kentry_add_entrys(pentry, entry);
+	}
+	if (!rc) {
 		faux_error_sprintf(error, TAG": Can't add PTYPE \"%s\". "
 			"Probably duplication",
 			kentry_name(entry));
@@ -449,6 +455,7 @@ static bool_t process_ptype(const kxml_node_t *element, void *parent,
 err:
 	kxml_node_attr_free(ientry.name);
 	kxml_node_attr_free(ientry.help);
+	kxml_node_attr_free(ientry.ref);
 	kxml_node_attr_free(ientry.value);
 
 	return res;