-const char *const __man_macronames[MAN_MAX] = {
- "br", "TH", "SH", "SS",
- "TP", "LP", "PP", "P",
- "IP", "HP", "SM", "SB",
- "BI", "IB", "BR", "RB",
- "R", "B", "I", "IR",
- "RI", "na", "sp", "nf",
- "fi", "RE", "RS", "DT",
- "UC", "PD", "AT", "in",
- "ft"
- };
-
-const char * const *man_macronames = __man_macronames;
-
-static struct man_node *man_node_alloc(struct man *, int, int,
- enum man_type, enum mant);
-static int man_node_append(struct man *,
- struct man_node *);
-static void man_node_free(struct man_node *);
-static void man_node_unlink(struct man *,
- struct man_node *);
-static int man_ptext(struct man *, int, char *, int);
-static int man_pmacro(struct man *, int, char *, int);
-static void man_free1(struct man *);
-static void man_alloc1(struct man *);
-static int man_descope(struct man *, int, int);
-
-
-const struct man_node *
-man_node(const struct man *m)
-{
-
- assert( ! (MAN_HALT & m->flags));
- return(m->first);
-}
-
-
-const struct man_meta *
-man_meta(const struct man *m)
-{
-
- assert( ! (MAN_HALT & m->flags));
- return(&m->meta);
-}
-
-
-void
-man_reset(struct man *man)
-{
-
- man_free1(man);
- man_alloc1(man);
-}
-
-
-void
-man_free(struct man *man)
-{
-
- man_free1(man);
- free(man);
-}
-
-
-struct man *
-man_alloc(struct roff *roff, struct mparse *parse)
-{
- struct man *p;
-
- p = mandoc_calloc(1, sizeof(struct man));
-
- man_hash_init();
- p->parse = parse;
- p->roff = roff;
-
- man_alloc1(p);
- return(p);
-}
-
-
-int
-man_endparse(struct man *m)
-{
-
- assert( ! (MAN_HALT & m->flags));
- if (man_macroend(m))
- return(1);
- m->flags |= MAN_HALT;
- return(0);
-}
-
-
-int
-man_parseln(struct man *m, int ln, char *buf, int offs)
-{
-
- m->flags |= MAN_NEWLINE;
-
- assert( ! (MAN_HALT & m->flags));
-
- return (mandoc_getcontrol(buf, &offs) ?
- man_pmacro(m, ln, buf, offs) :
- man_ptext(m, ln, buf, offs));
-}
-
-
-static void
-man_free1(struct man *man)
-{
-
- if (man->first)
- man_node_delete(man, man->first);
- if (man->meta.title)
- free(man->meta.title);
- if (man->meta.source)
- free(man->meta.source);
- if (man->meta.date)
- free(man->meta.date);
- if (man->meta.vol)
- free(man->meta.vol);
- if (man->meta.msec)
- free(man->meta.msec);
-}
-
-
-static void
-man_alloc1(struct man *m)
-{
-
- memset(&m->meta, 0, sizeof(struct man_meta));
- m->flags = 0;
- m->last = mandoc_calloc(1, sizeof(struct man_node));
- m->first = m->last;
- m->last->type = MAN_ROOT;
- m->last->tok = MAN_MAX;
- m->next = MAN_NEXT_CHILD;
-}
-
-
-static int
-man_node_append(struct man *man, struct man_node *p)
-{
-
- assert(man->last);
- assert(man->first);
- assert(MAN_ROOT != p->type);
-
- switch (man->next) {
- case (MAN_NEXT_SIBLING):
- man->last->next = p;
- p->prev = man->last;
- p->parent = man->last->parent;
- break;
- case (MAN_NEXT_CHILD):
- man->last->child = p;
- p->parent = man->last;
- break;
- default:
- abort();
- /* NOTREACHED */
- }
-
- assert(p->parent);
- p->parent->nchild++;
-
- if ( ! man_valid_pre(man, p))
- return(0);
-
- switch (p->type) {
- case (MAN_HEAD):
- assert(MAN_BLOCK == p->parent->type);
- p->parent->head = p;
- break;
- case (MAN_TAIL):
- assert(MAN_BLOCK == p->parent->type);
- p->parent->tail = p;
- break;
- case (MAN_BODY):
- assert(MAN_BLOCK == p->parent->type);
- p->parent->body = p;
- break;
- default:
- break;
- }
-
- man->last = p;
-
- switch (p->type) {
- case (MAN_TBL):
- /* FALLTHROUGH */
- case (MAN_TEXT):
- if ( ! man_valid_post(man))
- return(0);
- break;
- default:
- break;
- }
-
- return(1);
-}
-
-
-static struct man_node *
-man_node_alloc(struct man *m, int line, int pos,
- enum man_type type, enum mant tok)
-{
- struct man_node *p;
-
- p = mandoc_calloc(1, sizeof(struct man_node));
- p->line = line;
- p->pos = pos;
- p->type = type;
- p->tok = tok;
-
- if (MAN_NEWLINE & m->flags)
- p->flags |= MAN_LINE;
- m->flags &= ~MAN_NEWLINE;
- return(p);
-}
-
-
-int
-man_elem_alloc(struct man *m, int line, int pos, enum mant tok)
-{
- struct man_node *p;
-
- p = man_node_alloc(m, line, pos, MAN_ELEM, tok);
- if ( ! man_node_append(m, p))
- return(0);
- m->next = MAN_NEXT_CHILD;
- return(1);
-}
-
-
-int
-man_tail_alloc(struct man *m, int line, int pos, enum mant tok)
-{
- struct man_node *p;
-
- p = man_node_alloc(m, line, pos, MAN_TAIL, tok);
- if ( ! man_node_append(m, p))
- return(0);
- m->next = MAN_NEXT_CHILD;
- return(1);
-}
-
-
-int
-man_head_alloc(struct man *m, int line, int pos, enum mant tok)
-{
- struct man_node *p;
-
- p = man_node_alloc(m, line, pos, MAN_HEAD, tok);
- if ( ! man_node_append(m, p))
- return(0);
- m->next = MAN_NEXT_CHILD;
- return(1);
-}
-
-
-int
-man_body_alloc(struct man *m, int line, int pos, enum mant tok)
-{
- struct man_node *p;
-
- p = man_node_alloc(m, line, pos, MAN_BODY, tok);
- if ( ! man_node_append(m, p))
- return(0);
- m->next = MAN_NEXT_CHILD;
- return(1);
-}
-
-
-int
-man_block_alloc(struct man *m, int line, int pos, enum mant tok)
-{
- struct man_node *p;