]> git.cameronkatri.com Git - mandoc.git/blobdiff - roff.c
During validation, drop .br before a text line starting with a
[mandoc.git] / roff.c
diff --git a/roff.c b/roff.c
index deac95600aeddd8f17aa3c8ae23d1433b2ab9668..6f54a9a80aa1c17767ee1dd47999e1deca12fd9d 100644 (file)
--- 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.344 2018/12/04 02:53:51 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -1066,6 +1066,14 @@ roff_node_unlink(struct roff_man *man, struct roff_node *n)
                man->first = NULL;
 }
 
+void
+roff_node_relink(struct roff_man *man, struct roff_node *n)
+{
+       roff_node_unlink(man, n);
+       n->prev = n->next = NULL;
+       roff_node_append(man, n);
+}
+
 void
 roff_node_free(struct roff_node *n)
 {
@@ -2107,7 +2115,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 +2161,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;