summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2018-11-26 17:44:29 +0000
committerschwarze <schwarze@openbsd.org>2018-11-26 17:44:29 +0000
commit6ac4ca49a652cc8b58765ff06dae30b790cc491f (patch)
treec8120509f82e8f399cc221bcdbe6a765c7c082a3
parentPlace mandoc.css into the public domain. (diff)
downloadwireguard-openbsd-6ac4ca49a652cc8b58765ff06dae30b790cc491f.tar.xz
wireguard-openbsd-6ac4ca49a652cc8b58765ff06dae30b790cc491f.zip
When a conditional block is closed by putting "\}" on a text line
by itself (which is somewhat unusual but not invalid; most authors use the empty macro line ".\}" instead), agree more closely with groff and do not produce a double space in the output. Quirk reported by millert@. While here, tweak the rest of the function body of roff_cond_text() to more closely match roff_cond_sub(). The subtly different handling could make people (including myself) wonder whether there is any point in being different. Testing shows there is not.
-rw-r--r--regress/usr.bin/mandoc/roff/cond/close.in20
-rw-r--r--regress/usr.bin/mandoc/roff/cond/close.out_ascii12
-rw-r--r--regress/usr.bin/mandoc/roff/cond/close.out_lint4
-rw-r--r--usr.bin/mandoc/roff.c36
4 files changed, 60 insertions, 12 deletions
diff --git a/regress/usr.bin/mandoc/roff/cond/close.in b/regress/usr.bin/mandoc/roff/cond/close.in
index 6bdf3781503..da3f302e1aa 100644
--- a/regress/usr.bin/mandoc/roff/cond/close.in
+++ b/regress/usr.bin/mandoc/roff/cond/close.in
@@ -1,5 +1,5 @@
-.\" $OpenBSD: close.in,v 1.3 2017/07/04 14:53:26 schwarze Exp $
-.TH COND-CLOSE 1 2013-06-27
+.\" $OpenBSD: close.in,v 1.4 2018/11/26 17:44:29 schwarze Exp $
+.TH COND-CLOSE 1 "November 26, 2018"
.SH NAME
cond-close \- closing conditional macros
.SH DESCRIPTION
@@ -12,5 +12,21 @@ closing after an ignored macro
.if t \{text \}
closing after plain text
.PP
+.if n \{conditional content \} following words with whitespace
+.PP
+.if n \{conditional content\}following words without whitespace
+.PP
+preceding words
+.if n \{\
+standard multi-line style
+.\}
+following words
+.PP
+preceding words
+.if n \{
+non-standard multi-line style
+\}
+following words
+.PP
.if n \{
still open at the end of the file
diff --git a/regress/usr.bin/mandoc/roff/cond/close.out_ascii b/regress/usr.bin/mandoc/roff/cond/close.out_ascii
index 244d41548df..d049154d3e0 100644
--- a/regress/usr.bin/mandoc/roff/cond/close.out_ascii
+++ b/regress/usr.bin/mandoc/roff/cond/close.out_ascii
@@ -12,8 +12,18 @@ DDEESSCCRRIIPPTTIIOONN
closing after plain text
+ conditional content following words with whitespace
+
+ conditional contentfollowing words without whitespace
+
+ preceding words standard multi-line style following words
+
+ preceding words
+
+ non-standard multi-line style following words
+
still open at the end of the file
-OpenBSD 2013-06-27 COND-CLOSE(1)
+OpenBSD November 26, 2018 COND-CLOSE(1)
diff --git a/regress/usr.bin/mandoc/roff/cond/close.out_lint b/regress/usr.bin/mandoc/roff/cond/close.out_lint
index 4387b057d3b..d6f52146e15 100644
--- a/regress/usr.bin/mandoc/roff/cond/close.out_lint
+++ b/regress/usr.bin/mandoc/roff/cond/close.out_lint
@@ -1,2 +1,2 @@
-mandoc: close.in:15:2: ERROR: appending missing end of block: if
-mandoc: close.in:15:9: WARNING: skipping paragraph macro: sp after PP
+mandoc: close.in:31:2: ERROR: appending missing end of block: if
+mandoc: close.in:31:9: WARNING: skipping paragraph macro: sp after PP
diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c
index aa3a3f53493..caed1da5cc5 100644
--- a/usr.bin/mandoc/roff.c
+++ b/usr.bin/mandoc/roff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: roff.c,v 1.214 2018/10/25 01:21:30 schwarze Exp $ */
+/* $OpenBSD: roff.c,v 1.215 2018/11/26 17:44:29 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -2105,7 +2105,10 @@ roff_cond_sub(ROFF_ARGS)
if (ep[0] == '\\' && ep[1] == '}')
rr = 0;
- /* Always check for the closing delimiter `\}'. */
+ /*
+ * The closing delimiter `\}' rewinds the conditional scope
+ * but is otherwise ignored when interpreting the line.
+ */
while ((ep = strchr(ep, '\\')) != NULL) {
switch (ep[1]) {
@@ -2148,15 +2151,34 @@ roff_cond_text(ROFF_ARGS)
if (roffnode_cleanscope(r))
irc |= endloop;
+ /*
+ * If `\}' occurs on a text line with neither preceding
+ * nor following characters, drop the line completely.
+ */
+
ep = buf->buf + pos;
+ if (strcmp(ep, "\\}") == 0)
+ rr = 0;
+
+ /*
+ * The closing delimiter `\}' rewinds the conditional scope
+ * but is otherwise ignored when interpreting the line.
+ */
+
while ((ep = strchr(ep, '\\')) != NULL) {
- if (*(++ep) == '}') {
- *ep = '&';
- if (roff_ccond(r, ln, ep - buf->buf - 1))
+ switch (ep[1]) {
+ case '}':
+ memmove(ep, ep + 2, strlen(ep + 2) + 1);
+ if (roff_ccond(r, ln, ep - buf->buf))
irc |= endloop;
- }
- if (*ep != '\0')
+ break;
+ case '\0':
++ep;
+ break;
+ default:
+ ep += 2;
+ break;
+ }
}
if (rr)
irc |= ROFF_CONT;