=================================================================== RCS file: /cvs/docbook2mdoc/parse.c,v retrieving revision 1.1 retrieving revision 1.3 diff -u -p -r1.1 -r1.3 --- docbook2mdoc/parse.c 2019/03/26 18:32:07 1.1 +++ docbook2mdoc/parse.c 2019/03/26 21:52:09 1.3 @@ -1,4 +1,4 @@ -/* $Id: parse.c,v 1.1 2019/03/26 18:32:07 schwarze Exp $ */ +/* $Id: parse.c,v 1.3 2019/03/26 21:52:09 schwarze Exp $ */ /* * Copyright (c) 2014 Kristaps Dzonsons * Copyright (c) 2019 Ingo Schwarze @@ -47,9 +47,9 @@ struct element { }; static const struct element elements[] = { - { "acronym", NODE_ACRONYM }, + { "acronym", NODE_IGNORE }, { "affiliation", NODE_AFFILIATION }, - { "anchor", NODE_ANCHOR }, + { "anchor", NODE_IGNORE }, { "application", NODE_APPLICATION }, { "arg", NODE_ARG }, { "author", NODE_AUTHOR }, @@ -75,7 +75,7 @@ static const struct element elements[] = { { "envar", NODE_ENVAR }, { "fieldsynopsis", NODE_FIELDSYNOPSIS }, { "filename", NODE_FILENAME }, - { "firstname", NODE_FIRSTNAME }, + { "firstname", NODE_IGNORE }, { "firstterm", NODE_FIRSTTERM }, { "footnote", NODE_FOOTNOTE }, { "funcdef", NODE_FUNCDEF }, @@ -115,13 +115,13 @@ static const struct element elements[] = { { "option", NODE_OPTION }, { "orderedlist", NODE_ORDEREDLIST }, { "orgname", NODE_ORGNAME }, - { "othername", NODE_OTHERNAME }, + { "othername", NODE_IGNORE }, { "para", NODE_PARA }, { "paramdef", NODE_PARAMDEF }, { "parameter", NODE_PARAMETER }, { "part", NODE_SECTION }, { "personname", NODE_PERSONNAME }, - { "phrase", NODE_PHRASE }, + { "phrase", NODE_IGNORE }, { "preface", NODE_PREFACE }, { "primary", NODE_PRIMARY }, { "programlisting", NODE_PROGRAMLISTING }, @@ -157,7 +157,7 @@ static const struct element elements[] = { { "spanspec", NODE_SPANSPEC }, { "structname", NODE_STRUCTNAME }, { "subtitle", NODE_SUBTITLE }, - { "surname", NODE_SURNAME }, + { "surname", NODE_IGNORE }, { "synopsis", NODE_SYNOPSIS }, { "table", NODE_TABLE }, { "tbody", NODE_TBODY }, @@ -167,7 +167,7 @@ static const struct element elements[] = { { "thead", NODE_THEAD }, { "tip", NODE_TIP }, { "title", NODE_TITLE }, - { "trademark", NODE_TRADEMARK }, + { "trademark", NODE_IGNORE }, { "type", NODE_TYPE }, { "ulink", NODE_ULINK }, { "userinput", NODE_USERINPUT }, @@ -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 *name, const 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 *name, const 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 *