=================================================================== RCS file: /cvs/docbook2mdoc/macro.c,v retrieving revision 1.2 retrieving revision 1.5 diff -u -p -r1.2 -r1.5 --- docbook2mdoc/macro.c 2019/03/28 20:41:33 1.2 +++ docbook2mdoc/macro.c 2019/04/03 15:04:03 1.5 @@ -1,4 +1,4 @@ -/* $Id: macro.c,v 1.2 2019/03/28 20:41:33 schwarze Exp $ */ +/* $Id: macro.c,v 1.5 2019/04/03 15:04:03 schwarze Exp $ */ /* * Copyright (c) 2019 Ingo Schwarze * @@ -47,7 +47,8 @@ macro_open(struct format *f, const char *name) void macro_close(struct format *f) { - assert(f->linestate == LINE_MACRO); + if (f->linestate == LINE_NEW) + return; putchar('\n'); f->linestate = LINE_NEW; } @@ -152,6 +153,7 @@ macro_argline(struct format *f, const char *name, cons void macro_addnode(struct format *f, struct pnode *pn, int flags) { + struct pnode *nc; int quote_now; assert(f->linestate == LINE_MACRO); @@ -161,9 +163,11 @@ macro_addnode(struct format *f, struct pnode *pn, int * that text, letting macro_addarg() decide about quoting. */ - if (pn->node == NODE_TEXT || - ((pn = TAILQ_FIRST(&pn->childq)) != NULL && - pn->node == NODE_TEXT && TAILQ_NEXT(pn, child) == NULL)) { + while ((nc = TAILQ_FIRST(&pn->childq)) != NULL && + TAILQ_NEXT(nc, child) == NULL) + pn = nc; + + if (pn->node == NODE_TEXT || pn->node == NODE_ESCAPE) { macro_addarg(f, pn->b, flags); return; } @@ -192,9 +196,9 @@ macro_addnode(struct format *f, struct pnode *pn, int * inserting whitespace between nodes. */ - while (pn != NULL) { - macro_addnode(f, pn, flags); - pn = TAILQ_NEXT(pn, child); + while (nc != NULL) { + macro_addnode(f, nc, flags); + nc = TAILQ_NEXT(nc, child); flags |= ARG_SPACE; } if (quote_now) @@ -239,7 +243,7 @@ print_textnode(struct format *f, struct pnode *n) { struct pnode *nc; - if (n->node == NODE_TEXT) + if (n->node == NODE_TEXT || n->node == NODE_ESCAPE) print_text(f, n->b, ARG_SPACE); else TAILQ_FOREACH(nc, &n->childq, child)