-
-
-/*
- * Trigger a literal context.
- */
-static int
-pre_dl(PRE_ARGS)
-{
-
- if (MDOC_BODY == n->type)
- m->flags |= MDOC_LITERAL;
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-pre_offset(PRE_ARGS)
-{
- int i;
-
- /*
- * Make sure that an empty offset produces an 8n length space as
- * stipulated by mdoc.samples.
- */
-
- assert(n->args);
- for (i = 0; i < (int)n->args->argc; i++) {
- if (MDOC_Offset != n->args->argv[i].arg)
- continue;
- if (n->args->argv[i].sz)
- break;
- assert(1 == n->args->refcnt);
- /* If no value set, length of <string>. */
- n->args->argv[i].sz++;
- n->args->argv[i].value = mandoc_malloc(sizeof(char *));
- n->args->argv[i].value[0] = mandoc_strdup("8n");
- break;
- }
-
- return(1);
-}
-
-
-static int
-pre_bl(PRE_ARGS)
-{
-
- return(MDOC_BLOCK == n->type ? pre_offset(m, n) : 1);
-}
-
-
-static int
-pre_bd(PRE_ARGS)
-{
- int i;
-
- if (MDOC_BLOCK == n->type)
- return(pre_offset(m, n));
- if (MDOC_BODY != n->type)
- return(1);
-
- /* Enter literal context if `Bd -literal' or `-unfilled'. */
-
- for (n = n->parent, i = 0; i < (int)n->args->argc; i++)
- if (MDOC_Literal == n->args->argv[i].arg)
- m->flags |= MDOC_LITERAL;
- else if (MDOC_Unfilled == n->args->argv[i].arg)
- m->flags |= MDOC_LITERAL;
-
- return(1);
-}
-
-
-static int
-post_display(POST_ARGS)
-{
-
- if (MDOC_BODY == n->type)
- m->flags &= ~MDOC_LITERAL;
- return(1);
-}
-
-
-static inline int
-order_rs(enum mdoct t)
-{
- int i;
-
- for (i = 0; i < (int)RSORD_MAX; i++)
- if (rsord[i] == t)
- return(i);
-
- abort();
- /* NOTREACHED */
-}
-
-
-/* ARGSUSED */
-static int
-post_rs(POST_ARGS)
-{
- struct mdoc_node *nn, *next, *prev;
- int o;
-
- if (MDOC_BLOCK != n->type)
- return(1);
-
- assert(n->body->child);
- for (next = NULL, nn = n->body->child->next; nn; nn = next) {
- o = order_rs(nn->tok);
-
- /* Remove `nn' from the chain. */
- next = nn->next;
- if (next)
- next->prev = nn->prev;
-
- prev = nn->prev;
- if (prev)
- prev->next = nn->next;
-
- nn->prev = nn->next = NULL;
-
- /*
- * Scan back until we reach a node that's ordered before
- * us, then set ourselves as being the next.
- */
- for ( ; prev; prev = prev->prev)
- if (order_rs(prev->tok) <= o)
- break;
-
- nn->prev = prev;
- if (prev) {
- if (prev->next)
- prev->next->prev = nn;
- nn->next = prev->next;
- prev->next = nn;
- continue;
- }
-
- n->body->child->prev = nn;
- nn->next = n->body->child;
- n->body->child = nn;
- }
- return(1);
-}