diff options
-rw-r--r-- | mdocterm.c | 116 | ||||
-rw-r--r-- | term.c | 40 |
2 files changed, 120 insertions, 36 deletions
@@ -52,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__ @@ -475,6 +476,10 @@ body(struct termp *p, struct termpair *ppair, int dochild; struct termpair pair; + /* Some quick sanity-checking. */ + + sanity(node); + /* Pre-processing. */ dochild = 1; @@ -845,3 +850,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; + } +} + @@ -733,12 +733,8 @@ termp_st_pre(DECL_ARGS) { const char *cp; - if (node->child) { - if (MDOC_TEXT != node->child->type) - errx(1, "expected text line arguments"); - if ((cp = mdoc_a2st(node->child->string))) - word(p, cp); - } + if (node->child && (cp = mdoc_a2st(node->child->string))) + word(p, cp); return(0); } @@ -847,23 +843,15 @@ termp_xr_pre(DECL_ARGS) if (NULL == (n = node->child)) errx(1, "expected text line argument"); - if (MDOC_TEXT != n->type) - errx(1, "expected text line argument"); - word(p, n->string); - if (NULL == (n = n->next)) return(0); - if (MDOC_TEXT != n->type) - errx(1, "expected text line argument"); - p->flags |= TERMP_NOSPACE; word(p, "("); p->flags |= TERMP_NOSPACE; word(p, n->string); p->flags |= TERMP_NOSPACE; word(p, ")"); - return(0); } @@ -990,14 +978,10 @@ termp_lb_pre(DECL_ARGS) if (NULL == node->child) errx(1, "expected text line argument"); - if (MDOC_TEXT != node->child->type) - errx(1, "expected text line argument"); - if ((lb = mdoc_a2lib(node->child->string))) { word(p, lb); return(0); } - word(p, "library"); return(1); } @@ -1103,8 +1087,6 @@ termp_fn_pre(DECL_ARGS) if (NULL == node->child) errx(1, "expected text line arguments"); - if (MDOC_TEXT != node->child->type) - errx(1, "expected text line arguments"); /* FIXME: can be "type funcname" "type varname"... */ @@ -1116,8 +1098,6 @@ termp_fn_pre(DECL_ARGS) p->flags |= TERMP_NOSPACE; for (n = node->child->next; n; n = n->next) { - if (MDOC_TEXT != n->type) - errx(1, "expected text line arguments"); p->flags |= ttypes[TTYPE_FUNC_ARG]; word(p, n->string); p->flags &= ~ttypes[TTYPE_FUNC_ARG]; @@ -1167,13 +1147,9 @@ termp_fa_pre(DECL_ARGS) } for (n = node->child; n; n = n->next) { - if (MDOC_TEXT != n->type) - errx(1, "expected text line arguments"); - p->flags |= ttypes[TTYPE_FUNC_ARG]; word(p, n->string); p->flags &= ~ttypes[TTYPE_FUNC_ARG]; - if (n->next) word(p, ","); } @@ -1536,12 +1512,8 @@ termp_at_pre(DECL_ARGS) att = NULL; - if (node->child) { - if (MDOC_TEXT != node->child->type) - errx(1, "expected text line argument"); + if (node->child) att = mdoc_a2att(node->child->string); - } - if (NULL == att) att = "AT&T UNIX"; @@ -1764,9 +1736,7 @@ termp_lk_pre(DECL_ARGS) const struct mdoc_node *n; if (NULL == (n = node->child)) - errx(1, "expected text line argument"); - if (MDOC_TEXT != n->type) - errx(1, "expected text line argument"); + errx(1, "expected line argument"); p->flags |= ttypes[TTYPE_LINK_ANCHOR]; word(p, n->string); @@ -1776,8 +1746,6 @@ termp_lk_pre(DECL_ARGS) p->flags |= ttypes[TTYPE_LINK_TEXT]; for ( ; n; n = n->next) { - if (MDOC_TEXT != n->type) - errx(1, "expected text line argument"); word(p, n->string); } p->flags &= ~ttypes[TTYPE_LINK_TEXT]; |