=================================================================== RCS file: /cvs/docbook2mdoc/node.c,v retrieving revision 1.10 retrieving revision 1.24 diff -u -p -r1.10 -r1.24 --- docbook2mdoc/node.c 2019/04/12 16:40:53 1.10 +++ docbook2mdoc/node.c 2019/04/28 15:03:29 1.24 @@ -1,4 +1,4 @@ -/* $Id: node.c,v 1.10 2019/04/12 16:40:53 schwarze Exp $ */ +/* $Id: node.c,v 1.24 2019/04/28 15:03:29 schwarze Exp $ */ /* * Copyright (c) 2014 Kristaps Dzonsons * Copyright (c) 2019 Ingo Schwarze @@ -19,6 +19,7 @@ #include #include +#include "xmalloc.h" #include "node.h" /* @@ -31,9 +32,7 @@ struct nodeprop { }; static const struct nodeprop properties[] = { - { "affiliation", CLASS_TRANS }, { "appendix", CLASS_BLOCK }, - { "application", CLASS_LINE }, { "arg", CLASS_ENCL }, { "author", CLASS_LINE }, { "authorgroup", CLASS_BLOCK }, @@ -47,7 +46,7 @@ static const struct nodeprop properties[] = { { "command", CLASS_LINE }, { "constant", CLASS_LINE }, { "contrib", CLASS_TRANS }, - { "copyright", CLASS_TRANS }, + { "copyright", CLASS_LINE }, { "date", CLASS_TRANS }, { "!DOCTYPE", CLASS_VOID }, { "editor", CLASS_LINE }, @@ -60,7 +59,7 @@ static const struct nodeprop properties[] = { { "fieldsynopsis", CLASS_TRANS }, { "filename", CLASS_LINE }, { "firstterm", CLASS_LINE }, - { "footnote", CLASS_TRANS }, + { "footnote", CLASS_BLOCK }, { "funcdef", CLASS_BLOCK }, { "funcprototype", CLASS_BLOCK }, { "funcsynopsis", CLASS_TRANS }, @@ -68,7 +67,7 @@ static const struct nodeprop properties[] = { { "function", CLASS_LINE }, { "glossterm", CLASS_LINE }, { "group", CLASS_ENCL }, - { "holder", CLASS_TRANS }, + { "imagedata", CLASS_TEXT }, { "xi:include", CLASS_VOID }, { "index", CLASS_TRANS }, { "info", CLASS_TRANS }, @@ -80,7 +79,7 @@ static const struct nodeprop properties[] = { { "link", CLASS_ENCL }, { "listitem", CLASS_TRANS }, { "literal", CLASS_ENCL }, - { "literallayout", CLASS_BLOCK }, + { "literallayout", CLASS_NOFILL }, { "manvolnum", CLASS_TRANS }, { "markup", CLASS_LINE }, { "member", CLASS_LINE }, @@ -95,16 +94,18 @@ static const struct nodeprop properties[] = { { "mml:msup", CLASS_LINE }, { "modifier", CLASS_LINE }, { "note", CLASS_BLOCK }, + { "olink", CLASS_ENCL }, { "option", CLASS_LINE }, { "orderedlist", CLASS_BLOCK }, - { "orgname", CLASS_TRANS }, { "para", CLASS_BLOCK }, { "paramdef", CLASS_LINE }, { "parameter", CLASS_LINE }, { "personname", CLASS_TRANS }, { "preface", CLASS_BLOCK }, - { "programlisting", CLASS_BLOCK }, + { "productname", CLASS_LINE }, + { "programlisting", CLASS_NOFILL }, { "prompt", CLASS_TRANS }, + { "pubdate", CLASS_TRANS }, { "quote", CLASS_ENCL }, { "refclass", CLASS_TRANS }, { "refdescriptor", CLASS_TRANS }, @@ -118,16 +119,19 @@ static const struct nodeprop properties[] = { { "refnamediv", CLASS_BLOCK }, { "refpurpose", CLASS_LINE }, { "refsynopsisdiv", CLASS_BLOCK }, - { "releaseinfo", CLASS_TRANS }, { "replaceable", CLASS_LINE }, { "row", CLASS_BLOCK }, { "sbr", CLASS_BLOCK }, - { "screen", CLASS_BLOCK }, + { "screen", CLASS_NOFILL }, { "section", CLASS_BLOCK }, { "simplelist", CLASS_TRANS }, + { "simplesect", CLASS_BLOCK }, { "spanspec", CLASS_TRANS }, - { "subtitle", CLASS_TRANS }, - { "synopsis", CLASS_BLOCK }, + { "subscript", CLASS_TEXT }, + { "subtitle", CLASS_BLOCK }, + { "superscript", CLASS_TEXT }, + { "synopsis", CLASS_NOFILL }, + { "systemitem", CLASS_LINE }, { "table", CLASS_TRANS }, { "tbody", CLASS_TRANS }, { "term", CLASS_LINE }, @@ -140,12 +144,13 @@ static const struct nodeprop properties[] = { { "variablelist", CLASS_BLOCK }, { "varlistentry", CLASS_BLOCK }, { "varname", CLASS_LINE }, + { "void", CLASS_TEXT }, { "warning", CLASS_BLOCK }, { "wordasword", CLASS_TRANS }, - { "year", CLASS_TRANS }, + { "xref", CLASS_LINE }, { "[UNKNOWN]", CLASS_VOID }, - { "[TEXT]", CLASS_TEXT }, - { "[ESCAPE]", CLASS_TEXT } + { "(t)", CLASS_TEXT }, + { "(e)", CLASS_TEXT } }; static const char *const attrkeys[ATTRKEY__MAX] = { @@ -155,25 +160,33 @@ static const char *const attrkeys[ATTRKEY__MAX] = { "cols", "DEFINITION", "endterm", + "entityref", + "fileref", "href", "id", "linkend", + "localinfo", "NAME", "open", "PUBLIC", "rep", "SYSTEM", + "targetdoc", + "targetptr", "url", "xlink:href" }; static const char *const attrvals[ATTRVAL__MAX] = { + "event", + "ipaddress", "monospaced", "norepeat", "opt", "plain", "repeat", - "req" + "req", + "systemname" }; enum attrkey @@ -187,6 +200,12 @@ attrkey_parse(const char *name) return key; } +const char * +attrkey_name(enum attrkey key) +{ + return attrkeys[key]; +} + enum attrval attrval_parse(const char *name) { @@ -198,6 +217,12 @@ attrval_parse(const char *name) return val; } +const char * +attr_getval(const struct pattr *a) +{ + return a->val == ATTRVAL__MAX ? a->rawval : attrvals[a->val]; +} + enum nodeid pnode_parse(const char *name) { @@ -228,12 +253,11 @@ pnode_alloc(struct pnode *np) { struct pnode *n; - if ((n = calloc(1, sizeof(*n))) != NULL) { - TAILQ_INIT(&n->childq); - TAILQ_INIT(&n->attrq); - if ((n->parent = np) != NULL) - TAILQ_INSERT_TAIL(&np->childq, n, child); - } + n = xcalloc(1, sizeof(*n)); + TAILQ_INIT(&n->childq); + TAILQ_INIT(&n->attrq); + if ((n->parent = np) != NULL) + TAILQ_INSERT_TAIL(&np->childq, n, child); return n; } @@ -328,10 +352,25 @@ pnode_findfirst(struct pnode *n, enum nodeid node) { struct pnode *nc, *res; + if (n == NULL) + return NULL; if (n->node == node) return n; TAILQ_FOREACH(nc, &n->childq, child) if ((res = pnode_findfirst(nc, node)) != NULL) return res; return NULL; +} + +/* + * Like pnode_findfirst(), but also take the node out of the tree. + */ +struct pnode * +pnode_takefirst(struct pnode *n, enum nodeid node) +{ + struct pnode *nc; + + if ((nc = pnode_findfirst(n, node)) != NULL && nc->parent != NULL) + TAILQ_REMOVE(&nc->parent->childq, nc, child); + return nc; }