source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* docbook2mdoc: Provide an easy way to parse an XML element without
@ 2019-03-26 20:55 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2019-03-26 20:55 UTC (permalink / raw)
  To: source

Log Message:
-----------
Provide an easy way to parse an XML element without generating a node,
either ignoring it outright or emitting a warning if -W was specified.
Use this to handle <xi:include> more cleanly, fixing two FIXMEs.

Modified Files:
--------------
    docbook2mdoc:
        node.h
        parse.c

Revision Data
-------------
Index: node.h
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/node.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lnode.h -Lnode.h -u -p -r1.1 -r1.2
--- node.h
+++ node.h
@@ -26,7 +26,8 @@
  * More DocBook XML elements are recognized, but remapped or discarded.
  */
 enum	nodeid {
-	NODE_NONE = 0,  /* Must come first. */
+	NODE_IGNORE = 0,  /* Must come first. */
+	NODE_WARN,
 	/* Alpha-ordered hereafter. */
 	NODE_ACRONYM,
 	NODE_AFFILIATION,
Index: parse.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/parse.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lparse.c -Lparse.c -u -p -r1.1 -r1.2
--- parse.c
+++ parse.c
@@ -176,6 +176,7 @@ static	const struct element elements[] =
 	{ "varname",		NODE_VARNAME },
 	{ "warning",		NODE_WARNING },
 	{ "wordasword",		NODE_WORDASWORD },
+	{ "xi:include",		NODE_WARN },
 	{ "year",		NODE_YEAR },
 	{ NULL,			NODE__MAX }
 };
@@ -262,10 +263,6 @@ xml_elem_start(void *arg, const XML_Char
 	if (ps->tree->flags && TREE_FAIL)
 		return;
 
-	/* FIXME: find a better way to ditch other namespaces. */
-	if (strcmp(name, "xi:include") == 0)
-		return;
-
 	/* Close out the text node, if there is one. */
 	if (ps->cur != NULL && ps->cur->node == NODE_TEXT) {
 		pnode_trim(ps->cur);
@@ -284,8 +281,22 @@ xml_elem_start(void *arg, const XML_Char
 		return;
 	}
 
-	if (elem->node == NODE_INLINEEQUATION)
+	switch (elem->node) {
+	case NODE_WARN:
+		if (ps->warn)
+			fprintf(stderr, "%s:%zu:%zu: warning: "
+			    "ignoring element <%s>\n", ps->fname,
+			    XML_GetCurrentLineNumber(ps->xml),
+			    XML_GetCurrentColumnNumber(ps->xml), name);
+		/* FALLTHROUGH */
+	case NODE_IGNORE:
+		return;
+	case NODE_INLINEEQUATION:
 		ps->tree->flags |= TREE_EQN;
+		break;
+	default:
+		break;
+	}
 
 	if ((dat = calloc(1, sizeof(*dat))) == NULL) {
 		perror(NULL);
@@ -333,21 +344,30 @@ static void
 xml_elem_end(void *arg, const XML_Char *name)
 {
 	struct parse	*ps;
+	const struct element *elem;
 
 	ps = arg;
 	if (ps->tree->flags && TREE_FAIL)
 		return;
 
-	/* FIXME: find a better way to ditch other namespaces. */
-	if (strcmp(name, "xi:include") == 0)
-		return;
-
 	/* Close out the text node, if there is one. */
 	if (ps->cur->node == NODE_TEXT) {
 		pnode_trim(ps->cur);
 		ps->cur = ps->cur->parent;
 	}
-	ps->cur = ps->cur->parent;
+
+	for (elem = elements; elem->name != NULL; elem++)
+		if (strcmp(elem->name, name) == 0)
+			break;
+
+	switch (elem->node) {
+	case NODE_IGNORE:
+	case NODE_WARN:
+		break;
+	default:
+		assert(elem->node == ps->cur->node);
+		ps->cur = ps->cur->parent;
+	}
 }
 
 struct parse *
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-03-26 20:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-26 20:55 docbook2mdoc: Provide an easy way to parse an XML element without schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).