]> git.cameronkatri.com Git - mandoc.git/blobdiff - roff.c
Have conditional closure for both text and macro lines call through to
[mandoc.git] / roff.c
diff --git a/roff.c b/roff.c
index e36138c830978084b07ca3c02da3fd34d205e149..4960d947d4168a80908d9d29acfe165edcb3d538 100644 (file)
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/*     $Id: roff.c,v 1.138 2011/05/14 16:06:08 kristaps Exp $ */
+/*     $Id: roff.c,v 1.140 2011/05/24 15:22:14 kristaps Exp $ */
 /*
  * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -840,21 +840,29 @@ roff_cond_sub(ROFF_ARGS)
 {
        enum rofft       t;
        enum roffrule    rr;
+       char            *ep;
 
        rr = r->last->rule;
+       roffnode_cleanscope(r);
 
-       /* 
-        * Clean out scope.  If we've closed ourselves, then don't
-        * continue. 
+       /*
+        * If the macro is unknown, first check if it contains a closing
+        * delimiter `\}'.  If it does, close out our scope and return
+        * the currently-scoped rule (ignore or continue).  Else, drop
+        * into the currently-scoped rule.
         */
 
-       roffnode_cleanscope(r);
-
        if (ROFF_MAX == (t = roff_parse(r, *bufp, &pos))) {
-               if ('\\' == (*bufp)[pos] && '}' == (*bufp)[pos + 1])
-                       return(roff_ccond
-                               (r, ROFF_ccond, bufp, szp,
-                                ln, pos, pos + 2, offs));
+               ep = &(*bufp)[pos];
+               for ( ; NULL != (ep = strchr(ep, '\\')); ep++) {
+                       ep++;
+                       if ('}' != *ep)
+                               continue;
+                       *ep = '&';
+                       roff_ccond(r, ROFF_ccond, bufp, szp, 
+                                       ln, pos, pos + 2, offs);
+                       break;
+               }
                return(ROFFRULE_DENY == rr ? ROFF_IGN : ROFF_CONT);
        }
 
@@ -863,6 +871,7 @@ roff_cond_sub(ROFF_ARGS)
         * if they're either structurally required (such as loops and
         * conditionals) or a closing macro.
         */
+
        if (ROFFRULE_DENY == rr)
                if ( ! (ROFFMAC_STRUCT & roffs[t].flags))
                        if (ROFF_ccond != t)
@@ -873,37 +882,28 @@ roff_cond_sub(ROFF_ARGS)
                                ln, ppos, pos, offs));
 }
 
-
 /* ARGSUSED */
 static enum rofferr
 roff_cond_text(ROFF_ARGS)
 {
-       char            *ep, *st;
+       char            *ep;
        enum roffrule    rr;
 
        rr = r->last->rule;
+       roffnode_cleanscope(r);
 
-       /*
-        * We display the value of the text if out current evaluation
-        * scope permits us to do so.
-        */
-
-       /* FIXME: use roff_ccond? */
-
-       st = &(*bufp)[pos];
-       if (NULL == (ep = strstr(st, "\\}"))) {
-               roffnode_cleanscope(r);
-               return(ROFFRULE_DENY == rr ? ROFF_IGN : ROFF_CONT);
+       ep = &(*bufp)[pos];
+       for ( ; NULL != (ep = strchr(ep, '\\')); ep++) {
+               ep++;
+               if ('}' != *ep)
+                       continue;
+               *ep = '&';
+               roff_ccond(r, ROFF_ccond, bufp, szp, 
+                               ln, pos, pos + 2, offs);
        }
-
-       if (ep == st || (ep > st && '\\' != *(ep - 1)))
-               roffnode_pop(r);
-
-       roffnode_cleanscope(r);
        return(ROFFRULE_DENY == rr ? ROFF_IGN : ROFF_CONT);
 }
 
-
 static enum roffrule
 roff_evalcond(const char *v, int *pos)
 {