From f7bdb1a2ed64b531d6a5bd917c4e67a96a4a362b Mon Sep 17 00:00:00 2001 From: schwarze Date: Tue, 24 Dec 2013 19:10:34 +0000 Subject: [PATCH] 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. --- regress/usr.bin/mandoc/mdoc/Bk/inputlines.in | 3 --- regress/usr.bin/mandoc/mdoc/Bk/inputlines.out_ascii | 6 ++++++ usr.bin/mandoc/mdoc.c | 3 ++- usr.bin/mandoc/mdoc.h | 3 ++- usr.bin/mandoc/mdoc_html.c | 12 ++++-------- usr.bin/mandoc/mdoc_macro.c | 7 ++++++- usr.bin/mandoc/mdoc_term.c | 4 ++-- usr.bin/mandoc/tree.c | 8 ++++++-- 8 files changed, 28 insertions(+), 18 deletions(-) diff --git a/regress/usr.bin/mandoc/mdoc/Bk/inputlines.in b/regress/usr.bin/mandoc/mdoc/Bk/inputlines.in index 6d9f4272a4f..50db65fb1ee 100644 --- a/regress/usr.bin/mandoc/mdoc/Bk/inputlines.in +++ b/regress/usr.bin/mandoc/mdoc/Bk/inputlines.in @@ -18,8 +18,6 @@ .Oo No a Oc Oo No b Oc Oc Pq "break after first Oo" .Ek .Pp -.\" XXX does not work yet -.ig .Nm .Ar x x x x x x x x x x x x x x x x x x x x x x x x x x x .Bk -words @@ -34,7 +32,6 @@ .Oc Oo No b Oc Oc Pq "break before first Oc" .Ek .Pp -.. .Nm .Ar x x x x x x x x x x x x x x x x x x x x x x x x x x x .Bk -words diff --git a/regress/usr.bin/mandoc/mdoc/Bk/inputlines.out_ascii b/regress/usr.bin/mandoc/mdoc/Bk/inputlines.out_ascii index c6c1deba57a..52da2ec6e77 100644 --- a/regress/usr.bin/mandoc/mdoc/Bk/inputlines.out_ascii +++ b/regress/usr.bin/mandoc/mdoc/Bk/inputlines.out_ascii @@ -10,6 +10,12 @@ SSYYNNOOPPSSIISS BBkk--iinnppuuttlliinneess _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x [[a] [b]] (break after first Oo) + BBkk--iinnppuuttlliinneess _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x + [[a] [b]] (break after second Oo) + + BBkk--iinnppuuttlliinneess _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x + [[a] [b]] (break before first Oc) + BBkk--iinnppuuttlliinneess _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x _x [[a] [b]] (break after first Oc) diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c index 3464c0b48c2..6c8ad34b404 100644 --- a/usr.bin/mandoc/mdoc.c +++ b/usr.bin/mandoc/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.95 2013/10/21 23:32:32 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.96 2013/12/24 19:10:34 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012, 2013 Ingo Schwarze @@ -430,6 +430,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; diff --git a/usr.bin/mandoc/mdoc.h b/usr.bin/mandoc/mdoc.h index bdd289b7249..763cc2a9c95 100644 --- a/usr.bin/mandoc/mdoc.h +++ b/usr.bin/mandoc/mdoc.h @@ -1,4 +1,4 @@ -/* $Id: mdoc.h,v 1.48 2012/11/16 17:16:29 schwarze Exp $ */ +/* $Id: mdoc.h,v 1.49 2013/12/24 19:10:34 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * @@ -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/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c index d1c544e177a..ec49796ead2 100644 --- a/usr.bin/mandoc/mdoc_html.c +++ b/usr.bin/mandoc/mdoc_html.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.67 2012/11/17 00:25:20 schwarze Exp $ */ +/* $Id: mdoc_html.c,v 1.68 2013/12/24 19:10:34 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * @@ -455,15 +455,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/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c index 276e5a2c24d..759adc273b6 100644 --- a/usr.bin/mandoc/mdoc_macro.c +++ b/usr.bin/mandoc/mdoc_macro.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_macro.c,v 1.80 2013/10/21 23:32:32 schwarze Exp $ */ +/* $Id: mdoc_macro.c,v 1.81 2013/12/24 19:10:34 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010, 2012, 2013 Ingo Schwarze @@ -557,6 +557,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, @@ -565,6 +568,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/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index fdf0b2b3858..a2626ac51bc 100644 --- a/usr.bin/mandoc/mdoc_term.c +++ b/usr.bin/mandoc/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.153 2013/12/23 02:19:57 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.154 2013/12/24 19:10:34 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012, 2013 Ingo Schwarze @@ -309,7 +309,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; diff --git a/usr.bin/mandoc/tree.c b/usr.bin/mandoc/tree.c index dad34f56702..ef4eed4ecd6 100644 --- a/usr.bin/mandoc/tree.c +++ b/usr.bin/mandoc/tree.c @@ -1,6 +1,7 @@ -/* $Id: tree.c,v 1.18 2013/09/15 17:33:47 schwarze Exp $ */ +/* $Id: tree.c,v 1.19 2013/12/24 19:10:34 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2011 Kristaps Dzonsons + * Copyright (c) 2013 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 @@ -159,7 +160,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) -- 2.20.1