aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roff.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2018-11-26 17:44:34 +0000
committerIngo Schwarze <schwarze@openbsd.org>2018-11-26 17:44:34 +0000
commitde2f386bd8f978f415e5e800fcbd3fce8cd8b1cc (patch)
tree37a941b10f4129f199970613fca51164bc54dcc3 /roff.c
parent9afc9f503996ea800d93d3aea67b2b9625c3ce9a (diff)
downloadmandoc-de2f386bd8f978f415e5e800fcbd3fce8cd8b1cc.tar.gz
mandoc-de2f386bd8f978f415e5e800fcbd3fce8cd8b1cc.tar.zst
mandoc-de2f386bd8f978f415e5e800fcbd3fce8cd8b1cc.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.
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/roff.c b/roff.c
index deac9560..0fca8b9d 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.342 2018/10/25 01:32:40 schwarze Exp $ */
+/* $Id: roff.c,v 1.343 2018/11/26 17:44:34 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -2107,7 +2107,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]) {
@@ -2150,15 +2153,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;