From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from scc-mailout-kit-02.scc.kit.edu (scc-mailout-kit-02.scc.kit.edu [129.13.231.82]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTP id a95b0d70 for ; Sun, 21 Apr 2019 09:55:40 -0500 (EST) Received: from asta-nat.asta.uni-karlsruhe.de ([172.22.63.82] helo=hekate.usta.de) by scc-mailout-kit-02.scc.kit.edu with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (envelope-from ) id 1hIDsY-00062R-PC; Sun, 21 Apr 2019 16:55:39 +0200 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.77) (envelope-from ) id 1hIDsX-00033m-5g; Sun, 21 Apr 2019 16:55:37 +0200 Received: from athene.usta.de ([172.24.96.10]) by donnerwolke.usta.de with esmtp (Exim 4.84_2) (envelope-from ) id 1hIDsX-0002w0-0U; Sun, 21 Apr 2019 16:55:37 +0200 Received: from localhost (athene.usta.de [local]) by athene.usta.de (OpenSMTPD) with ESMTPA id 5080e122; Sun, 21 Apr 2019 16:55:37 +0200 (CEST) Date: Sun, 21 Apr 2019 16:55:36 +0200 From: Ingo Schwarze To: Stephen Gregoratto Cc: tech@mandoc.bsd.lv Subject: Re: [PATCH docbook2mdoc] Add void, tag Message-ID: <20190421145536.GB31325@athene.usta.de> References: <20190420154845.2hm5fx4mqqzq36st@BlackBox> X-Mailinglist: mandoc-tech Reply-To: tech@mandoc.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190420154845.2hm5fx4mqqzq36st@BlackBox> User-Agent: Mutt/1.8.0 (2017-02-23) Hi Stephen, Stephen Gregoratto wrote on Sun, Apr 21, 2019 at 01:48:45AM +1000: > This patch adds the and nodes. > First off, . From the docs: >> The void element produces generated text that indicates the function >> has no arguments (or returns nothing). The exact generated text may >> vary. One common result is void. Sigh. DocBook is so inconsistent. Yes, it says "(or returns nothing)". But apparently, that only applies to and similar elements. The element does not appear to allow a child, and indeed, there is none in Xenocara - even though allowing and using it would be quite logical. > Found this in the xenocara tree. Output as .Ft void in an .Fo block Xenocara only uses as a child of , not , which agrees with the DocBook specification. So i decided to change pnode_printfuncprototype() instead, see the commit below. Also, i marked as CLASS_TEXT rather than CLASS_LINE, i marked it as self-closing in xml_elem_start()/xml_elem_end(), and i added a simple stand-alone handler to pnode_print(), in case it ever occurs outside . > morphed into in DocBook 5.*, and so it should be > formatted the same. Found this when using the official db4-upgrade > stylesheet on some files. Yeah, that seems right. Thanks, Ingo Log Message: ----------- Implement child of . Also treat just like and . Some small parts of this patch were sent in by Stephen Gregoratto . Modified Files: -------------- docbook2mdoc: docbook2mdoc.c node.c node.h parse.c tree.c Revision Data ------------- Index: docbook2mdoc.c =================================================================== RCS file: /home/cvs/mdocml/docbook2mdoc/docbook2mdoc.c,v retrieving revision 1.131 retrieving revision 1.132 diff -Ldocbook2mdoc.c -Ldocbook2mdoc.c -u -p -r1.131 -r1.132 --- docbook2mdoc.c +++ docbook2mdoc.c @@ -315,20 +315,6 @@ pnode_printciterefentry(struct format *f pnode_unlinksub(n); } -static void -pnode_printfuncdef(struct format *f, struct pnode *n) -{ - struct pnode *nc; - - nc = TAILQ_FIRST(&n->childq); - if (nc != NULL && nc->node == NODE_TEXT) { - macro_argline(f, "Ft", nc->b); - pnode_unlink(nc); - } - macro_nodeline(f, "Fo", n, ARG_SINGLE); - pnode_unlinksub(n); -} - /* * The node is a little peculiar. * First, it can have arbitrary open and closing tokens, which default @@ -389,23 +375,65 @@ pnode_printmath(struct format *f, struct static void pnode_printfuncprototype(struct format *f, struct pnode *n) { - struct pnode *nc, *fdef; + struct pnode *fdef, *ftype, *nc, *nn; - TAILQ_FOREACH(fdef, &n->childq, child) - if (fdef->node == NODE_FUNCDEF) + /* + * Extract child and ignore child. + * Leave other children in place, to be treated as parameters. + */ + + fdef = NULL; + TAILQ_FOREACH_SAFE(nc, &n->childq, child, nn) { + switch (nc->node) { + case NODE_FUNCDEF: + if (fdef == NULL) { + fdef = nc; + TAILQ_REMOVE(&n->childq, nc, child); + nc->parent = NULL; + } + break; + case NODE_VOID: + pnode_unlink(nc); break; + default: + break; + } + } + /* + * If no children are left, the function is void; use .Fn. + * Otherwise, use .Fo. + */ + + nc = TAILQ_FIRST(&n->childq); if (fdef != NULL) { - pnode_printfuncdef(f, fdef); + ftype = TAILQ_FIRST(&fdef->childq); + if (ftype != NULL && ftype->node == NODE_TEXT) { + macro_argline(f, "Ft", ftype->b); + pnode_unlink(ftype); + } + if (nc == NULL) { + macro_open(f, "Fn"); + macro_addnode(f, fdef, ARG_SPACE | ARG_SINGLE); + macro_addarg(f, "void", ARG_SPACE); + macro_close(f); + } else + macro_nodeline(f, "Fo", fdef, ARG_SINGLE); pnode_unlink(fdef); - } else + } else if (nc == NULL) + macro_line(f, "Fn UNKNOWN void"); + else macro_line(f, "Fo UNKNOWN"); - TAILQ_FOREACH(nc, &n->childq, child) - macro_nodeline(f, "Fa", nc, ARG_SINGLE); + if (nc == NULL) + return; + while (nc != NULL) { + macro_nodeline(f, "Fa", nc, ARG_SINGLE); + pnode_unlink(nc); + nc = TAILQ_FIRST(&n->childq); + } macro_line(f, "Fc"); - pnode_unlinksub(n); } /* @@ -1340,6 +1368,9 @@ pnode_print(struct format *f, struct pno break; case NODE_VARNAME: macro_open(f, "Va"); + break; + case NODE_VOID: + print_text(f, "void", ARG_SPACE); break; case NODE_XREF: pnode_printxref(f, n); Index: node.c =================================================================== RCS file: /home/cvs/mdocml/docbook2mdoc/node.c,v retrieving revision 1.22 retrieving revision 1.23 diff -Lnode.c -Lnode.c -u -p -r1.22 -r1.23 --- node.c +++ node.c @@ -143,6 +143,7 @@ static const struct nodeprop properties[ { "variablelist", CLASS_BLOCK }, { "varlistentry", CLASS_BLOCK }, { "varname", CLASS_LINE }, + { "void", CLASS_TEXT }, { "warning", CLASS_BLOCK }, { "wordasword", CLASS_TRANS }, { "xref", CLASS_LINE }, Index: node.h =================================================================== RCS file: /home/cvs/mdocml/docbook2mdoc/node.h,v retrieving revision 1.31 retrieving revision 1.32 diff -Lnode.h -Lnode.h -u -p -r1.31 -r1.32 --- node.h +++ node.h @@ -152,6 +152,7 @@ enum nodeid { NODE_VARIABLELIST, NODE_VARLISTENTRY, NODE_VARNAME, + NODE_VOID, NODE_WARNING, NODE_WORDASWORD, NODE_XREF, Index: parse.c =================================================================== RCS file: /home/cvs/mdocml/docbook2mdoc/parse.c,v retrieving revision 1.47 retrieving revision 1.48 diff -Lparse.c -Lparse.c -u -p -r1.47 -r1.48 --- parse.c +++ parse.c @@ -120,6 +120,7 @@ static const struct alias aliases[] = { { "structname", NODE_TYPE }, { "surname", NODE_PERSONNAME }, { "symbol", NODE_CONSTANT }, + { "tag", NODE_MARKUP }, { "trademark", NODE_IGNORE }, { "ulink", NODE_LINK }, { "userinput", NODE_LITERAL }, @@ -519,6 +520,7 @@ xml_elem_start(struct parse *p, const ch case NODE_DOCTYPE: case NODE_ENTITY: case NODE_SBR: + case NODE_VOID: p->flags |= PFLAG_EEND; break; default: @@ -649,6 +651,7 @@ xml_elem_end(struct parse *p, const char break; case NODE_DOCTYPE: case NODE_SBR: + case NODE_VOID: p->flags &= ~PFLAG_EEND; /* FALLTHROUGH */ default: Index: tree.c =================================================================== RCS file: /home/cvs/mdocml/docbook2mdoc/tree.c,v retrieving revision 1.1 retrieving revision 1.2 diff -Ltree.c -Ltree.c -u -p -r1.1 -r1.2 --- tree.c +++ tree.c @@ -31,7 +31,7 @@ print_node(struct pnode *n, int indent) printf("%*s%c%s", indent, "", n->spc ? ' ' : '-', pnode_name(n->node)); - if (pnode_class(n->node) == CLASS_TEXT) { + if (n->b != NULL) { putchar(' '); fputs(n->b, stdout); } -- To unsubscribe send an email to tech+unsubscribe@mandoc.bsd.lv