=================================================================== RCS file: /cvs/docbook2mdoc/docbook2mdoc.c,v retrieving revision 1.134 retrieving revision 1.139 diff -u -p -r1.134 -r1.139 --- docbook2mdoc/docbook2mdoc.c 2019/04/23 22:25:28 1.134 +++ docbook2mdoc/docbook2mdoc.c 2019/04/28 15:03:28 1.139 @@ -1,4 +1,4 @@ -/* $Id: docbook2mdoc.c,v 1.134 2019/04/23 22:25:28 schwarze Exp $ */ +/* $Id: docbook2mdoc.c,v 1.139 2019/04/28 15:03:28 schwarze Exp $ */ /* * Copyright (c) 2014 Kristaps Dzonsons * Copyright (c) 2019 Ingo Schwarze @@ -21,6 +21,7 @@ #include #include +#include "xmalloc.h" #include "node.h" #include "macro.h" #include "format.h" @@ -42,7 +43,8 @@ pnode_printtext(struct format *f, struct pnode *n) cp = n->b; accept_arg = f->flags & FMT_ARG; - if (f->linestate == LINE_MACRO && !n->spc && !accept_arg) { + if (f->linestate == LINE_MACRO && !accept_arg && + (n->flags & NFLAG_SPC) == 0) { for (;;) { if (*cp == '\0') return; @@ -71,14 +73,15 @@ pnode_printtext(struct format *f, struct pnode *n) */ if (f->linestate != LINE_MACRO && - (nn = TAILQ_NEXT(n, child)) != NULL && nn->spc == 0) { + (nn = TAILQ_NEXT(n, child)) != NULL && + (nn->flags & NFLAG_SPC) == 0) { switch (pnode_class(nn->node)) { case CLASS_LINE: case CLASS_ENCL: macro_open(f, "Pf"); accept_arg = 1; f->flags |= FMT_CHILD; - nn->spc = 1; + nn->flags |= NFLAG_SPC; break; default: break; @@ -89,18 +92,22 @@ pnode_printtext(struct format *f, struct pnode *n) case LINE_NEW: break; case LINE_TEXT: - if (n->spc) { - if (n->node == NODE_TEXT) + if (n->flags & NFLAG_SPC) { + if (n->flags & NFLAG_LINE && + pnode_class(n->node) == CLASS_TEXT) macro_close(f); else putchar(' '); } break; case LINE_MACRO: - if (accept_arg) - putchar(' '); - else + if (accept_arg == 0) macro_close(f); + else if (n->flags & NFLAG_SPC || + (f->flags & FMT_ARG) == 0 || + (nn = TAILQ_PREV(n, pnodeq, child)) == NULL || + pnode_class(nn->node) != CLASS_TEXT) + putchar(' '); break; } @@ -882,31 +889,19 @@ pnode_printrefentry(struct format *f, struct pnode *n) */ if (match == NULL) { - if ((match = calloc(1, sizeof(*match))) == NULL) { - perror(NULL); - exit(1); - } + match = xcalloc(1, sizeof(*match)); match->node = NODE_SECTION; - match->spc = 1; + match->flags |= NFLAG_SPC; match->parent = n; TAILQ_INIT(&match->childq); TAILQ_INIT(&match->attrq); - if ((nc = pnode_alloc(match)) == NULL) { - perror(NULL); - exit(1); - } + nc = pnode_alloc(match); nc->node = NODE_TITLE; - nc->spc = 1; - if ((nc = pnode_alloc(nc)) == NULL) { - perror(NULL); - exit(1); - } + nc->flags |= NFLAG_SPC; + nc = pnode_alloc(nc); nc->node = NODE_TEXT; - if ((nc->b = strdup("AUTHORS")) == NULL) { - perror(NULL); - exit(1); - } - nc->spc = 1; + nc->b = xstrdup("AUTHORS"); + nc->flags |= NFLAG_SPC; if (later == NULL) TAILQ_INSERT_TAIL(&n->childq, match, child); else @@ -1037,6 +1032,7 @@ pnode_printtgroup2(struct format *f, struct pnode *n) pnode_unlink(nr); } macro_line(f, "El"); + f->parastate = PARA_WANT; pnode_unlinksub(n); } @@ -1063,6 +1059,7 @@ pnode_printtgroup(struct format *f, struct pnode *n) pnode_printrow(f, nc); } macro_line(f, "El"); + f->parastate = PARA_WANT; pnode_unlinksub(n); } @@ -1082,6 +1079,7 @@ pnode_printlist(struct format *f, struct pnode *n) f->parastate = PARA_HAVE; } macro_line(f, "El"); + f->parastate = PARA_WANT; pnode_unlinksub(n); } @@ -1100,6 +1098,7 @@ pnode_printvariablelist(struct format *f, struct pnode macro_nodeline(f, "It", nc, 0); } macro_line(f, "El"); + f->parastate = PARA_WANT; pnode_unlinksub(n); } @@ -1119,7 +1118,7 @@ pnode_print(struct format *f, struct pnode *n) return; was_impl = f->flags & FMT_IMPL; - if (n->spc) + if (n->flags & NFLAG_SPC) f->flags &= ~FMT_NOSPC; else f->flags |= FMT_NOSPC; @@ -1284,8 +1283,8 @@ pnode_print(struct format *f, struct pnode *n) if ((nc = TAILQ_FIRST(&n->childq)) != NULL && nc->node == NODE_FILENAME && TAILQ_NEXT(nc, child) == NULL) { - if (n->spc) - nc->spc = 1; + if (n->flags & NFLAG_SPC) + nc->flags |= NFLAG_SPC; } else if (was_impl) macro_open(f, "Do"); else { @@ -1343,12 +1342,12 @@ pnode_print(struct format *f, struct pnode *n) else print_text(f, "_", 0); if ((nc = TAILQ_FIRST(&n->childq)) != NULL) - nc->spc = 0; + nc->flags &= ~(NFLAG_LINE | NFLAG_SPC); break; case NODE_SUPERSCRIPT: fputs("\\(ha", stdout); if ((nc = TAILQ_FIRST(&n->childq)) != NULL) - nc->spc = 0; + nc->flags &= ~(NFLAG_LINE | NFLAG_SPC); break; case NODE_TEXT: case NODE_ESCAPE: @@ -1480,6 +1479,7 @@ pnode_print(struct format *f, struct pnode *n) case NODE_SYNOPSIS: f->parastate = PARA_HAVE; macro_line(f, "Ed"); + f->parastate = PARA_WANT; break; case NODE_TITLE: case NODE_SUBTITLE: