=================================================================== RCS file: /cvs/docbook2mdoc/docbook2mdoc.c,v retrieving revision 1.116 retrieving revision 1.117 diff -u -p -r1.116 -r1.117 --- docbook2mdoc/docbook2mdoc.c 2019/04/13 13:06:35 1.116 +++ docbook2mdoc/docbook2mdoc.c 2019/04/13 15:13:31 1.117 @@ -1,4 +1,4 @@ -/* $Id: docbook2mdoc.c,v 1.116 2019/04/13 13:06:35 schwarze Exp $ */ +/* $Id: docbook2mdoc.c,v 1.117 2019/04/13 15:13:31 schwarze Exp $ */ /* * Copyright (c) 2014 Kristaps Dzonsons * Copyright (c) 2019 Ingo Schwarze @@ -442,14 +442,13 @@ pnode_printarg(struct format *f, struct pnode *n) f->flags |= FMT_IMPL; } } - TAILQ_FOREACH(nc, &n->childq, child) { if (nc->node == NODE_TEXT) macro_open(f, "Ar"); pnode_print(f, nc); - if (isrep && nc->node == NODE_TEXT) - macro_addarg(f, "...", ARG_SPACE); } + if (isrep && f->linestate == LINE_MACRO) + macro_addarg(f, "...", ARG_SPACE); if (isop) { if (was_impl) macro_open(f, "Oc"); @@ -462,53 +461,56 @@ pnode_printarg(struct format *f, struct pnode *n) static void pnode_printgroup(struct format *f, struct pnode *n) { - struct pnode *nc, *nn; + struct pnode *nc; struct pattr *a; - int isop, sv; + int bar, isop, isrep, was_impl; isop = 1; - TAILQ_FOREACH(a, &n->attrq, child) + isrep = was_impl = 0; + TAILQ_FOREACH(a, &n->attrq, child) { if (a->key == ATTRKEY_CHOICE && - (a->val == ATTRVAL_PLAIN || a->val == ATTRVAL_REQ)) { + (a->val == ATTRVAL_PLAIN || a->val == ATTRVAL_REQ)) isop = 0; - break; + else if (a->key == ATTRKEY_REP && a->val == ATTRVAL_REPEAT) + isrep = 1; + } + if (isop) { + if (f->flags & FMT_IMPL) { + was_impl = 1; + macro_open(f, "Oo"); + } else { + macro_open(f, "Op"); + f->flags |= FMT_IMPL; } - - /* - * Make sure we're on a macro line. - * This will prevent pnode_print() for putting us on a - * subsequent line. - */ - sv = f->linestate == LINE_NEW; - if (isop) - macro_open(f, "Op"); - else if (sv) - macro_open(f, "No"); - f->flags |= FMT_IMPL; - - /* - * Keep on printing text separated by the vertical bar as long - * as we're within the same origin node as the group. - * This is kind of a nightmare. - * Eh, DocBook... - * FIXME: if there's a "Fl", we don't cut off the leading "-" - * like we do in pnode_print(). - */ + } else if (isrep) { + if (f->flags & FMT_IMPL) { + was_impl = 1; + macro_open(f, "Bro"); + } else { + macro_open(f, "Brq"); + f->flags |= FMT_IMPL; + } + } + bar = 0; TAILQ_FOREACH(nc, &n->childq, child) { - pnode_print(f, nc); - nn = TAILQ_NEXT(nc, child); - while (nn != NULL) { - if (nc->node != nn->node) - break; + if (bar && f->linestate == LINE_MACRO) macro_addarg(f, "|", ARG_SPACE); - macro_addnode(f, nn, ARG_SPACE); - nc = nn; - nn = TAILQ_NEXT(nn, child); - } + pnode_print(f, nc); + bar = 1; } - if (sv) - macro_close(f); - f->flags &= ~FMT_IMPL; + if (isop) { + if (was_impl) + macro_open(f, "Oc"); + else + f->flags &= ~FMT_IMPL; + } else if (isrep) { + if (was_impl) + macro_open(f, "Brc"); + else + f->flags &= ~FMT_IMPL; + } + if (isrep && f->linestate == LINE_MACRO) + macro_addarg(f, "...", ARG_SPACE); pnode_unlinksub(n); }