* mandoc: When a conditional block is closed by putting "\}" on a text
@ 2018-11-26 17:44 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2018-11-26 17:44 UTC (permalink / raw)
To: source
Log Message:
-----------
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.
Modified Files:
--------------
mandoc:
roff.c
mandoc/regress/roff/cond:
close.in
close.out_ascii
close.out_lint
Revision Data
-------------
Index: roff.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff.c,v
retrieving revision 1.342
retrieving revision 1.343
diff -Lroff.c -Lroff.c -u -p -r1.342 -r1.343
--- roff.c
+++ roff.c
@@ -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;
Index: close.out_ascii
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/roff/cond/close.out_ascii,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lregress/roff/cond/close.out_ascii -Lregress/roff/cond/close.out_ascii -u -p -r1.1 -r1.2
--- regress/roff/cond/close.out_ascii
+++ regress/roff/cond/close.out_ascii
@@ -12,8 +12,18 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
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)
Index: close.in
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/roff/cond/close.in,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lregress/roff/cond/close.in -Lregress/roff/cond/close.in -u -p -r1.2 -r1.3
--- regress/roff/cond/close.in
+++ regress/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
+.TH COND-CLOSE 1 "November 26, 2018"
.SH NAME
cond-close \- closing conditional macros
.SH DESCRIPTION
@@ -11,6 +11,22 @@ closing after an ignored macro
.PP
.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
Index: close.out_lint
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/roff/cond/close.out_lint,v
retrieving revision 1.6
retrieving revision 1.7
diff -Lregress/roff/cond/close.out_lint -Lregress/roff/cond/close.out_lint -u -p -r1.6 -r1.7
--- regress/roff/cond/close.out_lint
+++ regress/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
--
To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-11-26 17:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-26 17:44 mandoc: When a conditional block is closed by putting "\}" on a text schwarze
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).