From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: docbook2mdoc: Provide a way to exclude elements including their children
Date: Tue, 26 Mar 2019 17:40:03 -0500 (EST) [thread overview]
Message-ID: <e3fcc2d6d15689a5@fantadrom.bsd.lv> (raw)
Log Message:
-----------
Provide a way to exclude elements including their children from the tree
and use that for <anchor>, <indexterm>, <primary>, and <secondary>.
Modified Files:
--------------
docbook2mdoc:
docbook2mdoc.c
node.h
parse.c
Revision Data
-------------
Index: parse.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/parse.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lparse.c -Lparse.c -u -p -r1.3 -r1.4
--- parse.c
+++ parse.c
@@ -38,6 +38,7 @@ struct parse {
const char *fname; /* Name of the input file. */
struct ptree *tree; /* Complete parse result. */
struct pnode *cur; /* Current node in the tree. */
+ int del; /* Levels of nested nodes being deleted. */
int warn;
};
@@ -49,7 +50,7 @@ struct element {
static const struct element elements[] = {
{ "acronym", NODE_IGNORE },
{ "affiliation", NODE_AFFILIATION },
- { "anchor", NODE_IGNORE },
+ { "anchor", NODE_DELETE },
{ "application", NODE_APPLICATION },
{ "arg", NODE_ARG },
{ "author", NODE_AUTHOR },
@@ -87,7 +88,7 @@ static const struct element elements[] =
{ "group", NODE_GROUP },
{ "holder", NODE_HOLDER },
{ "index", NODE_INDEX },
- { "indexterm", NODE_INDEXTERM },
+ { "indexterm", NODE_DELETE },
{ "info", NODE_INFO },
{ "informalequation", NODE_INFORMALEQUATION },
{ "informaltable", NODE_INFORMALTABLE },
@@ -123,7 +124,7 @@ static const struct element elements[] =
{ "personname", NODE_PERSONNAME },
{ "phrase", NODE_IGNORE },
{ "preface", NODE_PREFACE },
- { "primary", NODE_PRIMARY },
+ { "primary", NODE_DELETE },
{ "programlisting", NODE_PROGRAMLISTING },
{ "prompt", NODE_PROMPT },
{ "quote", NODE_QUOTE },
@@ -148,7 +149,7 @@ static const struct element elements[] =
{ "row", NODE_ROW },
{ "sbr", NODE_SBR },
{ "screen", NODE_SCREEN },
- { "secondary", NODE_SECONDARY },
+ { "secondary", NODE_DELETE },
{ "sect1", NODE_SECTION },
{ "sect2", NODE_SECTION },
{ "section", NODE_SECTION },
@@ -176,7 +177,7 @@ static const struct element elements[] =
{ "varname", NODE_VARNAME },
{ "warning", NODE_WARNING },
{ "wordasword", NODE_WORDASWORD },
- { "xi:include", NODE_WARN },
+ { "xi:include", NODE_DELETE_WARN },
{ "year", NODE_YEAR },
{ NULL, NODE__MAX }
};
@@ -194,7 +195,7 @@ xml_char(void *arg, const XML_Char *p, i
int i;
ps = arg;
- if (ps->tree->flags && TREE_FAIL)
+ if (ps->del > 0 || ps->tree->flags & TREE_FAIL)
return;
/*
@@ -260,9 +261,18 @@ xml_elem_start(void *arg, const XML_Char
const XML_Char **att;
ps = arg;
- if (ps->tree->flags && TREE_FAIL)
+ if (ps->tree->flags & TREE_FAIL)
return;
+ /*
+ * An ancestor is excluded from the tree;
+ * keep track of the number of levels excluded.
+ */
+ if (ps->del > 0) {
+ ps->del++;
+ return;
+ }
+
/* Close out the text node, if there is one. */
if (ps->cur != NULL && ps->cur->node == NODE_TEXT) {
pnode_trim(ps->cur);
@@ -282,13 +292,16 @@ xml_elem_start(void *arg, const XML_Char
}
switch (elem->node) {
- case NODE_WARN:
+ case NODE_DELETE_WARN:
if (ps->warn)
fprintf(stderr, "%s:%zu:%zu: warning: "
- "ignoring element <%s>\n", ps->fname,
+ "skipping element <%s>\n", ps->fname,
XML_GetCurrentLineNumber(ps->xml),
XML_GetCurrentColumnNumber(ps->xml), name);
/* FALLTHROUGH */
+ case NODE_DELETE:
+ ps->del = 1;
+ /* FALLTHROUGH */
case NODE_IGNORE:
return;
case NODE_INLINEEQUATION:
@@ -347,11 +360,20 @@ xml_elem_end(void *arg, const XML_Char *
const struct element *elem;
ps = arg;
- if (ps->tree->flags && TREE_FAIL)
+ if (ps->tree->flags & TREE_FAIL)
return;
+ /*
+ * An ancestor is excluded from the tree;
+ * keep track of the number of levels excluded.
+ */
+ if (ps->del > 1) {
+ ps->del--;
+ return;
+ }
+
/* Close out the text node, if there is one. */
- if (ps->cur->node == NODE_TEXT) {
+ if (ps->del == 0 && ps->cur->node == NODE_TEXT) {
pnode_trim(ps->cur);
ps->cur = ps->cur->parent;
}
@@ -361,13 +383,18 @@ xml_elem_end(void *arg, const XML_Char *
break;
switch (elem->node) {
+ case NODE_DELETE_WARN:
+ case NODE_DELETE:
+ ps->del--;
+ break;
case NODE_IGNORE:
- case NODE_WARN:
break;
default:
assert(elem->node == ps->cur->node);
ps->cur = ps->cur->parent;
+ break;
}
+ assert(ps->del == 0);
}
struct parse *
Index: docbook2mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/docbook2mdoc.c,v
retrieving revision 1.76
retrieving revision 1.77
diff -Ldocbook2mdoc.c -Ldocbook2mdoc.c -u -p -r1.76 -r1.77
--- docbook2mdoc.c
+++ docbook2mdoc.c
@@ -612,8 +612,6 @@ pnode_print(struct format *p, struct pno
case NODE_FUNCSYNOPSISINFO:
macro_open(p, "Fd");
break;
- case NODE_INDEXTERM:
- return;
case NODE_INFORMALEQUATION:
macro_line(p, "EQ");
break;
Index: node.h
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/node.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lnode.h -Lnode.h -u -p -r1.3 -r1.4
--- node.h
+++ node.h
@@ -26,8 +26,9 @@
* More DocBook XML elements are recognized, but remapped or discarded.
*/
enum nodeid {
- NODE_IGNORE = 0, /* Must come first. */
- NODE_WARN,
+ NODE_DELETE_WARN,
+ NODE_DELETE,
+ NODE_IGNORE,
/* Alpha-ordered hereafter. */
NODE_AFFILIATION,
NODE_APPLICATION,
@@ -65,7 +66,6 @@ enum nodeid {
NODE_GROUP,
NODE_HOLDER,
NODE_INDEX,
- NODE_INDEXTERM,
NODE_INFO,
NODE_INFORMALEQUATION,
NODE_INFORMALTABLE,
@@ -98,7 +98,6 @@ enum nodeid {
NODE_PARAMETER,
NODE_PERSONNAME,
NODE_PREFACE,
- NODE_PRIMARY,
NODE_PROGRAMLISTING,
NODE_PROMPT,
NODE_QUOTE,
@@ -119,7 +118,6 @@ enum nodeid {
NODE_ROW,
NODE_SBR,
NODE_SCREEN,
- NODE_SECONDARY,
NODE_SECTION,
NODE_SGMLTAG,
NODE_SIMPLELIST,
--
To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv
reply other threads:[~2019-03-26 22:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e3fcc2d6d15689a5@fantadrom.bsd.lv \
--to=schwarze@mandoc.bsd.lv \
--cc=source@mandoc.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).