/* $Id: docbook2mdoc.c,v 1.100 2019/04/07 19:33:27 schwarze Exp $ */ /* * Copyright (c) 2014 Kristaps Dzonsons * Copyright (c) 2019 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include "node.h" #include "macro.h" #include "format.h" /* * The implementation of the mdoc(7) formatter. */ static void pnode_print(struct format *, struct pnode *); static void pnode_printtext(struct format *f, struct pnode *n) { struct pnode *nn; char *cp; char last; if (n->bsz == 0) { assert(n->real < n->b); return; } /* * Text preceding a macro without intervening whitespace * requires a .Pf macro. * Set the spacing flag to avoid a redundant .Ns macro. */ if (f->linestate != LINE_MACRO && (nn = TAILQ_NEXT(n, child)) != NULL && nn->spc == 0 && (nn->node != NODE_TEXT && nn->node != NODE_ESCAPE)) { macro_open(f, "Pf"); nn->spc = 1; } if (f->linestate == LINE_NEW) { last = '\n'; f->linestate = LINE_TEXT; } else { last = ' '; if (n->spc || f->linestate == LINE_MACRO) putchar(' '); } if (n->node == NODE_ESCAPE) { fputs(n->b, stdout); return; } /* * Remove the prefix '-' from