]> git.cameronkatri.com Git - mandoc.git/blobdiff - mdocterm.c
Removed "regression" for OpenBSD (broken).
[mandoc.git] / mdocterm.c
index 1f7912584f95d2e52d67edd9fb96b72b287147c2..a41747b2c62e568fc092ddae115c0cf5654aaa2e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mdocterm.c,v 1.36 2009/03/08 18:02:36 kristaps Exp $ */
+/* $Id: mdocterm.c,v 1.40 2009/03/12 06:32:17 kristaps Exp $ */
 /*
  * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
  *
@@ -16,6 +16,8 @@
  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  * PERFORMANCE OF THIS SOFTWARE.
  */
+#include <sys/types.h>
+
 #include <assert.h>
 #include <ctype.h>
 #include <err.h>
@@ -23,9 +25,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifndef __OpenBSD__
-#include <time.h>
-#endif
 
 #include "mmain.h"
 #include "term.h"
@@ -53,6 +52,7 @@ static        void              chara(struct termp *, char);
 static void              stringa(struct termp *, 
                                const char *, size_t);
 static void              symbola(struct termp *, enum tsym);
+static void              sanity(const struct mdoc_node *);
 static void              stylea(struct termp *, enum tstyle);
 
 #ifdef __linux__
@@ -74,6 +74,8 @@ static        struct termenc    termenc1[] = {
 };
 
 static struct termenc    termenc2[] = {
+       { "rC",           TERMSYM_RBRACE },
+       { "lC",           TERMSYM_LBRACE },
        { "rB",           TERMSYM_RBRACK },
        { "lB",           TERMSYM_LBRACK },
        { "ra",           TERMSYM_RANGLE },
@@ -163,6 +165,8 @@ static      struct termsym    termsym_ansi[] = {
        { "", 0 },              /* TERMSYM_BREAK */
        { "<", 1 },             /* TERMSYM_LANGLE */
        { ">", 1 },             /* TERMSYM_RANGLE */
+       { "{", 1 },             /* TERMSYM_LBRACE */
+       { "}", 1 },             /* TERMSYM_RBRACE */
 };
 
 static const char        ansi_clear[]  = { 27, '[', '0', 'm' };
@@ -426,8 +430,8 @@ word(struct termp *p, const char *word)
                return;
        }
 
-       len = strlen(word);
-       assert(len > 0);
+       if (0 == (len = strlen(word)))
+               errx(1, "blank line not in literal context");
 
        if (mdoc_isdelim(word)) {
                if ( ! (p->flags & TERMP_IGNDELIM))
@@ -476,6 +480,10 @@ body(struct termp *p, struct termpair *ppair,
        int              dochild;
        struct termpair  pair;
 
+       /* Some quick sanity-checking. */
+
+       sanity(node);
+
        /* Pre-processing. */
 
        dochild = 1;
@@ -846,3 +854,114 @@ chara(struct termp *p, char c)
        }
        p->buf[(p->col)++] = c;
 }
+
+
+static void
+sanity(const struct mdoc_node *n)
+{
+
+       switch (n->type) {
+       case (MDOC_TEXT):
+               if (n->child) 
+                       errx(1, "regular form violated (1)");
+               if (NULL == n->parent) 
+                       errx(1, "regular form violated (2)");
+               if (NULL == n->string)
+                       errx(1, "regular form violated (3)");
+               switch (n->parent->type) {
+               case (MDOC_TEXT):
+                       /* FALLTHROUGH */
+               case (MDOC_ROOT):
+                       errx(1, "regular form violated (4)");
+                       /* NOTREACHED */
+               default:
+                       break;
+               }
+               break;
+       case (MDOC_ELEM):
+               if (NULL == n->parent)
+                       errx(1, "regular form violated (5)");
+               switch (n->parent->type) {
+               case (MDOC_TAIL):
+                       /* FALLTHROUGH */
+               case (MDOC_BODY):
+                       /* FALLTHROUGH */
+               case (MDOC_HEAD):
+                       break;
+               default:
+                       errx(1, "regular form violated (6)");
+                       /* NOTREACHED */
+               }
+               if (n->child) switch (n->child->type) {
+               case (MDOC_TEXT):
+                       break;
+               default:
+                       errx(1, "regular form violated (7(");
+                       /* NOTREACHED */
+               }
+               break;
+       case (MDOC_HEAD):
+               /* FALLTHROUGH */
+       case (MDOC_BODY):
+               /* FALLTHROUGH */
+       case (MDOC_TAIL):
+               if (NULL == n->parent)
+                       errx(1, "regular form violated (8)");
+               if (MDOC_BLOCK != n->parent->type)
+                       errx(1, "regular form violated (9)");
+               if (n->child) switch (n->child->type) {
+               case (MDOC_BLOCK):
+                       /* FALLTHROUGH */
+               case (MDOC_ELEM):
+                       /* FALLTHROUGH */
+               case (MDOC_TEXT):
+                       break;
+               default:
+                       errx(1, "regular form violated (a)");
+                       /* NOTREACHED */
+               }
+               break;
+       case (MDOC_BLOCK):
+               if (NULL == n->parent)
+                       errx(1, "regular form violated (b)");
+               if (NULL == n->child)
+                       errx(1, "regular form violated (c)");
+               switch (n->parent->type) {
+               case (MDOC_ROOT):
+                       /* FALLTHROUGH */
+               case (MDOC_HEAD):
+                       /* FALLTHROUGH */
+               case (MDOC_BODY):
+                       /* FALLTHROUGH */
+               case (MDOC_TAIL):
+                       break;
+               default:
+                       errx(1, "regular form violated (d)");
+                       /* NOTREACHED */
+               }
+               switch (n->child->type) {
+               case (MDOC_ROOT):
+                       /* FALLTHROUGH */
+               case (MDOC_ELEM):
+                       errx(1, "regular form violated (e)");
+                       /* NOTREACHED */
+               default:
+                       break;
+               }
+               break;
+       case (MDOC_ROOT):
+               if (n->parent)
+                       errx(1, "regular form violated (f)");
+               if (NULL == n->child)
+                       errx(1, "regular form violated (10)");
+               switch (n->child->type) {
+               case (MDOC_BLOCK):
+                       break;
+               default:
+                       errx(1, "regular form violated (11)");
+                       /* NOTREACHED */
+               }
+               break;
+       }
+}
+