diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2013-12-24 19:11:45 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2013-12-24 19:11:45 +0000 |
commit | 8d226e7d9f28fbbca5bd6969e8fe3e6ee69ec94e (patch) | |
tree | e007bba721cb9d9e5ad54d2316dd8d2fd6ff6fdd | |
parent | 843cccd2fcf4de8a13a16071c949374ee597d16e (diff) | |
download | mandoc-8d226e7d9f28fbbca5bd6969e8fe3e6ee69ec94e.tar.gz |
When deciding whether two consecutive macros are on the same input line,
we have to compare the line where the first one *ends* (not where it begins)
to the line where the second one starts.
This fixes the bug that .Bk allowed output line breaks right after block
macros spanning more than one input line, even when the next macro follows
on the same line.
-rw-r--r-- | mdoc.c | 1 | ||||
-rw-r--r-- | mdoc.h | 1 | ||||
-rw-r--r-- | mdoc_html.c | 10 | ||||
-rw-r--r-- | mdoc_macro.c | 5 | ||||
-rw-r--r-- | mdoc_term.c | 2 | ||||
-rw-r--r-- | tree.c | 6 |
6 files changed, 16 insertions, 9 deletions
@@ -434,6 +434,7 @@ node_alloc(struct mdoc *mdoc, int line, int pos, p->sec = mdoc->lastsec; p->line = line; p->pos = pos; + p->lastline = line; p->tok = tok; p->type = type; @@ -351,6 +351,7 @@ struct mdoc_node { int nchild; /* number children */ int line; /* parse line */ int pos; /* parse column */ + int lastline; /* the node ends on this line */ enum mdoct tok; /* tok or MDOC__MAX if none */ int flags; #define MDOC_VALID (1 << 0) /* has been validated */ diff --git a/mdoc_html.c b/mdoc_html.c index a5f3841d..c25b009c 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -459,15 +459,11 @@ print_mdoc_node(MDOC_ARGS) break; } - if (HTML_KEEP & h->flags) { - if (n->prev && n->prev->line != n->line) { + if (HTML_KEEP & h->flags || MDOC_SYNPRETTY & n->flags) { + if (n->prev ? (n->prev->lastline != n->line) : + (n->parent && n->parent->line != n->line)) { h->flags &= ~HTML_KEEP; h->flags |= HTML_PREKEEP; - } else if (NULL == n->prev) { - if (n->parent && n->parent->line != n->line) { - h->flags &= ~HTML_KEEP; - h->flags |= HTML_PREKEEP; - } } } diff --git a/mdoc_macro.c b/mdoc_macro.c index 61ca534a..fd3f8764 100644 --- a/mdoc_macro.c +++ b/mdoc_macro.c @@ -561,6 +561,9 @@ rew_sub(enum mdoc_type t, struct mdoc *mdoc, case (REWIND_NONE): return(1); case (REWIND_THIS): + n->lastline = line - + (MDOC_NEWLINE & mdoc->flags && + ! (MDOC_EXPLICIT & mdoc_macros[tok].flags)); break; case (REWIND_FORCE): mandoc_vmsg(MANDOCERR_SCOPEBROKEN, mdoc->parse, @@ -569,6 +572,8 @@ rew_sub(enum mdoc_type t, struct mdoc *mdoc, mdoc_macronames[n->tok]); /* FALLTHROUGH */ case (REWIND_MORE): + n->lastline = line - + (MDOC_NEWLINE & mdoc->flags ? 1 : 0); n = n->parent; continue; case (REWIND_LATER): diff --git a/mdoc_term.c b/mdoc_term.c index 244be965..1eaa47db 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -313,7 +313,7 @@ print_mdoc_node(DECL_ARGS) */ if (TERMP_KEEP & p->flags || MDOC_SYNPRETTY & n->flags) { - if (n->prev ? (n->prev->line != n->line) : + if (n->prev ? (n->prev->lastline != n->line) : (n->parent && n->parent->line != n->line)) { p->flags &= ~TERMP_KEEP; p->flags |= TERMP_PREKEEP; @@ -1,6 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2008, 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv> + * Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -163,7 +164,10 @@ print_mdoc(const struct mdoc_node *n, int indent) putchar(' '); if (MDOC_LINE & n->flags) putchar('*'); - printf("%d:%d\n", n->line, n->pos); + printf("%d:%d", n->line, n->pos); + if (n->lastline != n->line) + printf("-%d", n->lastline); + putchar('\n'); } if (n->child) |