summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2012-11-16 17:16:29 +0000
committerschwarze <schwarze@openbsd.org>2012-11-16 17:16:29 +0000
commitd0f586adfbff8c248f90697399ae9513575eac35 (patch)
tree5b0e48cb7993d358e089e476cb6eec0fa6a43991
parentCall discover_interface() before forking, so both processes will know (diff)
downloadwireguard-openbsd-d0f586adfbff8c248f90697399ae9513575eac35.tar.xz
wireguard-openbsd-d0f586adfbff8c248f90697399ae9513575eac35.zip
Improve formatting of badly nested font blocks.
The basic idea is to already pop the font at the end marker instead of allowing it to linger until the final end of the block. This requires a few preliminaries: * For each block, save a pointer to the previous font to be used in case the block breaks another and gets extended. * That requires making node information writable during rendering. * Now fonts may get popped in the wrong order; hence, after the stack has already been rewound further by some block that began earlier, ignore popping a font that was put on the stack later. * To be able to exploit all this for font blocks, tie processing to their body, not their block, which is more logical anyway. Triggered by florian@ reporting vaguely similar issues with list blocks.
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bf/Makefile12
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bf/break.in16
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bf/break.out_ascii9
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bf/broken.in15
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bf/broken.out_ascii9
-rw-r--r--usr.bin/mandoc/mdoc.h3
-rw-r--r--usr.bin/mandoc/mdoc_term.c14
-rw-r--r--usr.bin/mandoc/term.c4
8 files changed, 70 insertions, 12 deletions
diff --git a/regress/usr.bin/mandoc/mdoc/Bf/Makefile b/regress/usr.bin/mandoc/mdoc/Bf/Makefile
index bf943fcd0e3..ed22f8ea87c 100644
--- a/regress/usr.bin/mandoc/mdoc/Bf/Makefile
+++ b/regress/usr.bin/mandoc/mdoc/Bf/Makefile
@@ -1,5 +1,13 @@
-# $OpenBSD: Makefile,v 1.1 2012/07/09 18:55:40 schwarze Exp $
+# $OpenBSD: Makefile,v 1.2 2012/11/16 17:16:29 schwarze Exp $
-REGRESS_TARGETS = nest
+REGRESS_TARGETS = nest break broken
+
+# groff-1.20.1 defect:
+# - If a font block breaks another block,
+# fonts get mixed up when the other block finally ends.
+
+SKIP_GROFF = break
+
+SKIP_TMAN = break broken
.include <bsd.regress.mk>
diff --git a/regress/usr.bin/mandoc/mdoc/Bf/break.in b/regress/usr.bin/mandoc/mdoc/Bf/break.in
new file mode 100644
index 00000000000..5a905655ec4
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Bf/break.in
@@ -0,0 +1,16 @@
+.Dd November 10, 2012
+.Dt BF-BREAK 1
+.Os OpenBSD
+.Sh NAME
+.Nm Bf-break
+.Nd font block breaking another block
+.Sh DESCRIPTION
+before both
+.Bf Em
+before bracket
+.Bo
+inside both
+.Ef
+after font block
+.Bc
+after both
diff --git a/regress/usr.bin/mandoc/mdoc/Bf/break.out_ascii b/regress/usr.bin/mandoc/mdoc/Bf/break.out_ascii
new file mode 100644
index 00000000000..ab8270d49d5
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Bf/break.out_ascii
@@ -0,0 +1,9 @@
+BF-BREAK(1) OpenBSD Reference Manual BF-BREAK(1)
+
+NNAAMMEE
+ BBff--bbrreeaakk - font block breaking another block
+
+DDEESSCCRRIIPPTTIIOONN
+ before both _b_e_f_o_r_e _b_r_a_c_k_e_t _[_i_n_s_i_d_e _b_o_t_h after font block] after both
+
+OpenBSD November 10, 2012 OpenBSD
diff --git a/regress/usr.bin/mandoc/mdoc/Bf/broken.in b/regress/usr.bin/mandoc/mdoc/Bf/broken.in
new file mode 100644
index 00000000000..228e4c5f1d5
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Bf/broken.in
@@ -0,0 +1,15 @@
+.Dd November 10, 2012
+.Dt BF-BROKEN 1
+.Os OpenBSD
+.Sh NAME
+.Nm Bf-broken
+.Nd font block broken by another block
+.Sh DESCRIPTION
+before both
+.Bo before font block
+.Bf Em
+inside both
+.Bc
+after bracket
+.Ef
+after both
diff --git a/regress/usr.bin/mandoc/mdoc/Bf/broken.out_ascii b/regress/usr.bin/mandoc/mdoc/Bf/broken.out_ascii
new file mode 100644
index 00000000000..b626dbb0d70
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Bf/broken.out_ascii
@@ -0,0 +1,9 @@
+BF-BROKEN(1) OpenBSD Reference Manual BF-BROKEN(1)
+
+NNAAMMEE
+ BBff--bbrrookkeenn - font block broken by another block
+
+DDEESSCCRRIIPPTTIIOONN
+ before both [before font block _i_n_s_i_d_e _b_o_t_h] after bracket after both
+
+OpenBSD November 10, 2012 OpenBSD
diff --git a/usr.bin/mandoc/mdoc.h b/usr.bin/mandoc/mdoc.h
index 109e7f4b6bc..bdd289b7249 100644
--- a/usr.bin/mandoc/mdoc.h
+++ b/usr.bin/mandoc/mdoc.h
@@ -1,4 +1,4 @@
-/* $Id: mdoc.h,v 1.47 2012/07/10 14:35:57 schwarze Exp $ */
+/* $Id: mdoc.h,v 1.48 2012/11/16 17:16:29 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -363,6 +363,7 @@ struct mdoc_node {
enum mdoc_type type; /* AST node type */
enum mdoc_sec sec; /* current named section */
union mdoc_data *norm; /* normalised args */
+ const void *prev_font; /* before entering this node */
/* FIXME: these can be union'd to shave a few bytes. */
struct mdoc_arg *args; /* BLOCK/ELEM */
struct mdoc_node *pending; /* BLOCK */
diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index 8a0f571d9c7..43f61a708b4 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.145 2012/07/11 16:55:29 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.146 2012/11/16 17:16:29 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012 Ingo Schwarze <schwarze@openbsd.org>
@@ -38,7 +38,7 @@ struct termpair {
#define DECL_ARGS struct termp *p, \
struct termpair *pair, \
const struct mdoc_meta *m, \
- const struct mdoc_node *n
+ struct mdoc_node *n
struct termact {
int (*pre)(DECL_ARGS);
@@ -289,14 +289,13 @@ static void
print_mdoc_node(DECL_ARGS)
{
int chld;
- const void *font;
struct termpair npair;
size_t offset, rmargin;
chld = 1;
offset = p->offset;
rmargin = p->rmargin;
- font = term_fontq(p);
+ n->prev_font = term_fontq(p);
memset(&npair, 0, sizeof(struct termpair));
npair.ppair = pair;
@@ -362,7 +361,8 @@ print_mdoc_node(DECL_ARGS)
if (chld && n->child)
print_mdoc_nodelist(p, &npair, m, n->child);
- term_fontpopq(p, font);
+ term_fontpopq(p,
+ (ENDBODY_NOT == n->end ? n : n->pending)->prev_font);
switch (n->type) {
case (MDOC_TEXT):
@@ -1602,7 +1602,7 @@ static int
termp_bd_pre(DECL_ARGS)
{
size_t tabwidth, rm, rmax;
- const struct mdoc_node *nn;
+ struct mdoc_node *nn;
if (MDOC_BLOCK == n->type) {
print_bvspace(p, n, n);
@@ -2071,7 +2071,7 @@ termp_bf_pre(DECL_ARGS)
if (MDOC_HEAD == n->type)
return(0);
- else if (MDOC_BLOCK != n->type)
+ else if (MDOC_BODY != n->type)
return(1);
if (FONT_Em == n->norm->Bf.font)
diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c
index 4a40dcf7840..945d8504423 100644
--- a/usr.bin/mandoc/term.c
+++ b/usr.bin/mandoc/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.66 2012/07/16 21:28:12 schwarze Exp $ */
+/* $Id: term.c,v 1.67 2012/11/16 17:16:29 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org>
@@ -372,7 +372,7 @@ void
term_fontpopq(struct termp *p, const void *key)
{
- while (p->fonti >= 0 && key != &p->fontq[p->fonti])
+ while (p->fonti >= 0 && key < (void *)(p->fontq + p->fonti))
p->fonti--;
assert(p->fonti >= 0);
}