- if (m->regs->regs[(int)REG_nS].set) {
- if (m->regs->regs[(int)REG_nS].v.u)
- m->flags |= MDOC_SYNOPSIS;
- else
- m->flags &= ~MDOC_SYNOPSIS;
- }
-
- return(('.' == buf[offs] || '\'' == buf[offs]) ?
- mdoc_pmacro(m, ln, buf, offs) :
- mdoc_ptext(m, ln, buf, offs));
-}
-
-
-int
-mdoc_vmsg(struct mdoc *mdoc, enum mandocerr t,
- int ln, int pos, const char *fmt, ...)
-{
- char buf[256];
- va_list ap;
-
- va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
- va_end(ap);
-
- return((*mdoc->msg)(t, mdoc->data, ln, pos, buf));
-}
-
-
-int
-mdoc_macro(MACRO_PROT_ARGS)
-{
- assert(tok < MDOC_MAX);
-
- /* If we're in the body, deny prologue calls. */
-
- if (MDOC_PROLOGUE & mdoc_macros[tok].flags &&
- MDOC_PBODY & m->flags)
- return(mdoc_pmsg(m, line, ppos, MANDOCERR_BADBODY));
-
- /* If we're in the prologue, deny "body" macros. */
-
- if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) &&
- ! (MDOC_PBODY & m->flags)) {
- if ( ! mdoc_pmsg(m, line, ppos, MANDOCERR_BADPROLOG))
- return(0);
- if (NULL == m->meta.title)
- m->meta.title = mandoc_strdup("UNKNOWN");
- if (NULL == m->meta.vol)
- m->meta.vol = mandoc_strdup("LOCAL");
- if (NULL == m->meta.os)
- m->meta.os = mandoc_strdup("LOCAL");
- if (0 == m->meta.date)
- m->meta.date = time(NULL);
- m->flags |= MDOC_PBODY;
- }
-
- return((*mdoc_macros[tok].fp)(m, tok, line, ppos, pos, buf));
-}
-
-
-static int
-node_append(struct mdoc *mdoc, struct mdoc_node *p)
-{
-
- assert(mdoc->last);
- assert(mdoc->first);
- assert(MDOC_ROOT != p->type);
-
- switch (mdoc->next) {
- case (MDOC_NEXT_SIBLING):
- mdoc->last->next = p;
- p->prev = mdoc->last;
- p->parent = mdoc->last->parent;
- break;
- case (MDOC_NEXT_CHILD):
- mdoc->last->child = p;
- p->parent = mdoc->last;
- break;
- default:
- abort();
- /* NOTREACHED */
- }
-
- p->parent->nchild++;
-
- if ( ! mdoc_valid_pre(mdoc, p))
- return(0);
- if ( ! mdoc_action_pre(mdoc, p))
- return(0);
-
- switch (p->type) {
- case (MDOC_HEAD):
- assert(MDOC_BLOCK == p->parent->type);
- p->parent->head = p;
- break;
- case (MDOC_TAIL):
- assert(MDOC_BLOCK == p->parent->type);
- p->parent->tail = p;
- break;
- case (MDOC_BODY):
- if (p->end)
- break;
- assert(MDOC_BLOCK == p->parent->type);
- p->parent->body = p;
- break;
- default:
- break;
- }
-
- mdoc->last = p;
-
- switch (p->type) {
- case (MDOC_TEXT):
- if ( ! mdoc_valid_post(mdoc))
- return(0);
- if ( ! mdoc_action_post(mdoc))
- return(0);
- break;
- default:
- break;
- }
-
- return(1);
-}
-
-
-static struct mdoc_node *
-node_alloc(struct mdoc *m, int line, int pos,
- enum mdoct tok, enum mdoc_type type)
-{
- struct mdoc_node *p;
-
- p = mandoc_calloc(1, sizeof(struct mdoc_node));
- p->sec = m->lastsec;
- p->line = line;
- p->pos = pos;
- p->tok = tok;
- p->type = type;
-
- /* Flag analysis. */
-
- if (MDOC_SYNOPSIS & m->flags)
- p->flags |= MDOC_SYNPRETTY;