diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2010-07-01 22:56:17 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2010-07-01 22:56:17 +0000 |
commit | 68ee78dc7731e4adb30a4b384fa171f2116f8561 (patch) | |
tree | b091c0f021833dae369e100a2ca9257ce6d2fa9e /mdoc_validate.c | |
parent | 0bae01a379ba9702c03dfcf16874c3ec9beaa711 (diff) | |
download | mandoc-68ee78dc7731e4adb30a4b384fa171f2116f8561.tar.gz |
Make struct_bl and struct_bd into pointers. This removes the need to do
copying on internals after modification. Even more importantly, if an
ENDBODY token is provided, it would have been impossible for post-change
copying of the data to take place in the BLOCK. This allows it to
happen by dint of pointers.
Also did some bikeshedding in mdoc_term.c: checking against enum type
and explicitly casting to the "post" function to void. This is for my
own readability.
Diffstat (limited to 'mdoc_validate.c')
-rw-r--r-- | mdoc_validate.c | 117 |
1 files changed, 65 insertions, 52 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c index 3e960331..7e4d2d32 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -154,7 +154,7 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, posts_notext }, /* Pp */ { pres_d1, posts_wline }, /* D1 */ { pres_d1, posts_wline }, /* Dl */ - { pres_bd, posts_bd_bk }, /* Bd */ + { pres_bd, posts_bd_bk }, /* Bd */ { NULL, NULL }, /* Ed */ { pres_bl, posts_bl }, /* Bl */ { NULL, NULL }, /* El */ @@ -537,19 +537,23 @@ pre_display(PRE_ARGS) static int pre_bl(PRE_ARGS) { - int i, comp, dup; - const char *offs, *width; - enum mdoc_list lt; + int i, comp, dup; + const char *offs, *width; + enum mdoc_list lt; + struct mdoc_node *np; if (MDOC_BLOCK != n->type) { - assert(n->parent); - if (ENDBODY_NOT != n->end) - return(1); - assert(MDOC_BLOCK == n->parent->type); - assert(MDOC_Bl == n->parent->tok); - assert(LIST__NONE != n->parent->data.Bl.type); - memcpy(&n->data.Bl, &n->parent->data.Bl, - sizeof(struct mdoc_bl)); + if (ENDBODY_NOT != n->end) { + assert(n->pending); + np = n->pending->parent; + } else + np = n->parent; + + assert(np); + assert(MDOC_BLOCK == np->type); + assert(MDOC_Bl == np->tok); + assert(np->data.Bl); + n->data.Bl = np->data.Bl; return(1); } @@ -559,7 +563,8 @@ pre_bl(PRE_ARGS) * ones. If we find no list type, we default to LIST_item. */ - assert(LIST__NONE == n->data.Bl.type); + assert(NULL == n->data.Bl); + n->data.Bl = mandoc_calloc(1, sizeof(struct mdoc_bl)); /* LINTED */ for (i = 0; n->args && i < (int)n->args->argc; i++) { @@ -603,18 +608,18 @@ pre_bl(PRE_ARGS) break; /* Set list arguments. */ case (MDOC_Compact): - dup = n->data.Bl.comp; + dup = n->data.Bl->comp; comp = 1; break; case (MDOC_Width): - dup = (NULL != n->data.Bl.width); + dup = (NULL != n->data.Bl->width); width = n->args->argv[i].value[0]; break; case (MDOC_Offset): /* NB: this can be empty! */ if (n->args->argv[i].sz) { offs = n->args->argv[i].value[0]; - dup = (NULL != n->data.Bl.offs); + dup = (NULL != n->data.Bl->offs); break; } if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV)) @@ -628,29 +633,29 @@ pre_bl(PRE_ARGS) return(0); if (comp && ! dup) - n->data.Bl.comp = comp; + n->data.Bl->comp = comp; if (offs && ! dup) - n->data.Bl.offs = offs; + n->data.Bl->offs = offs; if (width && ! dup) - n->data.Bl.width = width; + n->data.Bl->width = width; /* Check: multiple list types. */ - if (LIST__NONE != lt && n->data.Bl.type != LIST__NONE) + if (LIST__NONE != lt && n->data.Bl->type != LIST__NONE) if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_LISTREP)) return(0); /* Assign list type. */ - if (LIST__NONE != lt && n->data.Bl.type == LIST__NONE) - n->data.Bl.type = lt; + if (LIST__NONE != lt && n->data.Bl->type == LIST__NONE) + n->data.Bl->type = lt; /* The list type should come first. */ - if (n->data.Bl.type == LIST__NONE) - if (n->data.Bl.width || - n->data.Bl.offs || - n->data.Bl.comp) + if (n->data.Bl->type == LIST__NONE) + if (n->data.Bl->width || + n->data.Bl->offs || + n->data.Bl->comp) if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_LISTFIRST)) return(0); @@ -659,10 +664,10 @@ pre_bl(PRE_ARGS) /* Allow lists to default to LIST_item. */ - if (LIST__NONE == n->data.Bl.type) { + if (LIST__NONE == n->data.Bl->type) { if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_LISTTYPE)) return(0); - n->data.Bl.type = LIST_item; + n->data.Bl->type = LIST_item; } /* @@ -671,9 +676,9 @@ pre_bl(PRE_ARGS) * and must also be warned. */ - switch (n->data.Bl.type) { + switch (n->data.Bl->type) { case (LIST_tag): - if (n->data.Bl.width) + if (n->data.Bl->width) break; if (mdoc_nmsg(mdoc, n, MANDOCERR_NOWIDTHARG)) break; @@ -687,7 +692,7 @@ pre_bl(PRE_ARGS) case (LIST_inset): /* FALLTHROUGH */ case (LIST_item): - if (NULL == n->data.Bl.width) + if (NULL == n->data.Bl->width) break; if (mdoc_nmsg(mdoc, n, MANDOCERR_WIDTHARG)) break; @@ -703,21 +708,28 @@ pre_bl(PRE_ARGS) static int pre_bd(PRE_ARGS) { - int i, dup, comp; - enum mdoc_disp dt; - const char *offs; + int i, dup, comp; + enum mdoc_disp dt; + const char *offs; + struct mdoc_node *np; if (MDOC_BLOCK != n->type) { - assert(n->parent); - assert(MDOC_BLOCK == n->parent->type); - assert(MDOC_Bd == n->parent->tok); - assert(DISP__NONE != n->parent->data.Bd.type); - memcpy(&n->data.Bd, &n->parent->data.Bd, - sizeof(struct mdoc_bd)); + if (ENDBODY_NOT != n->end) { + assert(n->pending); + np = n->pending->parent; + } else + np = n->parent; + + assert(np); + assert(MDOC_BLOCK == np->type); + assert(MDOC_Bd == np->tok); + assert(np->data.Bd); + n->data.Bd = np->data.Bd; return(1); } - assert(DISP__NONE == n->data.Bd.type); + assert(NULL == n->data.Bd); + n->data.Bd = mandoc_calloc(1, sizeof(struct mdoc_bd)); /* LINTED */ for (i = 0; n->args && i < (int)n->args->argc; i++) { @@ -748,7 +760,7 @@ pre_bd(PRE_ARGS) /* NB: this can be empty! */ if (n->args->argv[i].sz) { offs = n->args->argv[i].value[0]; - dup = (NULL != n->data.Bd.offs); + dup = (NULL != n->data.Bd->offs); break; } if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV)) @@ -756,7 +768,7 @@ pre_bd(PRE_ARGS) break; case (MDOC_Compact): comp = 1; - dup = n->data.Bd.comp; + dup = n->data.Bd->comp; break; default: abort(); @@ -771,26 +783,26 @@ pre_bd(PRE_ARGS) /* Make our auxiliary assignments. */ if (offs && ! dup) - n->data.Bd.offs = offs; + n->data.Bd->offs = offs; if (comp && ! dup) - n->data.Bd.comp = comp; + n->data.Bd->comp = comp; /* Check whether a type has already been assigned. */ - if (DISP__NONE != dt && n->data.Bd.type != DISP__NONE) + if (DISP__NONE != dt && n->data.Bd->type != DISP__NONE) if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_DISPREP)) return(0); /* Make our type assignment. */ - if (DISP__NONE != dt && n->data.Bd.type == DISP__NONE) - n->data.Bd.type = dt; + if (DISP__NONE != dt && n->data.Bd->type == DISP__NONE) + n->data.Bd->type = dt; } - if (DISP__NONE == n->data.Bd.type) { + if (DISP__NONE == n->data.Bd->type) { if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_DISPTYPE)) return(0); - n->data.Bd.type = DISP_ragged; + n->data.Bd->type = DISP_ragged; } return(1); @@ -1053,7 +1065,8 @@ post_it(POST_ARGS) return(1); n = mdoc->last->parent->parent; - lt = n->data.Bl.type; + assert(n->data.Bl); + lt = n->data.Bl->type; if (LIST__NONE == lt) { mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_LISTTYPE); @@ -1145,7 +1158,7 @@ post_bl_head(POST_ARGS) assert(mdoc->last->parent); n = mdoc->last->parent; - if (LIST_column == n->data.Bl.type) { + if (LIST_column == n->data.Bl->type) { for (i = 0; i < (int)n->args->argc; i++) if (MDOC_Column == n->args->argv[i].arg) break; |