-static void mdoc_node_free(struct mdoc_node *);
-static void mdoc_node_unlink(struct mdoc *,
- struct mdoc_node *);
-static void mdoc_free1(struct mdoc *);
-static void mdoc_alloc1(struct mdoc *);
-static struct mdoc_node *node_alloc(struct mdoc *, int, int,
- enum mdoct, enum mdoc_type);
-static int node_append(struct mdoc *,
- struct mdoc_node *);
-#if 0
-static int mdoc_preptext(struct mdoc *, int, char *, int);
-#endif
-static int mdoc_ptext(struct mdoc *, int, char *, int);
-static int mdoc_pmacro(struct mdoc *, int, char *, int);
-
-const struct mdoc_node *
-mdoc_node(const struct mdoc *mdoc)
-{
-
- assert( ! (MDOC_HALT & mdoc->flags));
- return(mdoc->first);
-}
-
-
-const struct mdoc_meta *
-mdoc_meta(const struct mdoc *mdoc)
-{
-
- assert( ! (MDOC_HALT & mdoc->flags));
- return(&mdoc->meta);
-}
-
-
-/*
- * Frees volatile resources (parse tree, meta-data, fields).
- */
-static void
-mdoc_free1(struct mdoc *mdoc)
-{
-
- if (mdoc->first)
- mdoc_node_delete(mdoc, mdoc->first);
- if (mdoc->meta.title)
- free(mdoc->meta.title);
- if (mdoc->meta.os)
- free(mdoc->meta.os);
- if (mdoc->meta.name)
- free(mdoc->meta.name);
- if (mdoc->meta.arch)
- free(mdoc->meta.arch);
- if (mdoc->meta.vol)
- free(mdoc->meta.vol);
- if (mdoc->meta.msec)
- free(mdoc->meta.msec);
- if (mdoc->meta.date)
- free(mdoc->meta.date);
-}
-
-
-/*
- * Allocate all volatile resources (parse tree, meta-data, fields).
- */
-static void
-mdoc_alloc1(struct mdoc *mdoc)
-{
-
- memset(&mdoc->meta, 0, sizeof(struct mdoc_meta));
- mdoc->flags = 0;
- mdoc->lastnamed = mdoc->lastsec = SEC_NONE;
- mdoc->last = mandoc_calloc(1, sizeof(struct mdoc_node));
- mdoc->first = mdoc->last;
- mdoc->last->type = MDOC_ROOT;
- mdoc->last->tok = MDOC_MAX;
- mdoc->next = MDOC_NEXT_CHILD;
-}
-
-
-/*
- * Free up volatile resources (see mdoc_free1()) then re-initialises the
- * data with mdoc_alloc1(). After invocation, parse data has been reset
- * and the parser is ready for re-invocation on a new tree; however,
- * cross-parse non-volatile data is kept intact.
- */
-void
-mdoc_reset(struct mdoc *mdoc)
-{
-
- mdoc_free1(mdoc);
- mdoc_alloc1(mdoc);
-}
-
-
-/*
- * Completely free up all volatile and non-volatile parse resources.
- * After invocation, the pointer is no longer usable.
- */
-void
-mdoc_free(struct mdoc *mdoc)
-{
-
- mdoc_free1(mdoc);
- free(mdoc);
-}
-
-
-/*
- * Allocate volatile and non-volatile parse resources.
- */
-struct mdoc *
-mdoc_alloc(struct roff *roff, struct mparse *parse,
- char *defos, int quick)
-{
- struct mdoc *p;
-
- p = mandoc_calloc(1, sizeof(struct mdoc));
-
- p->parse = parse;
- p->defos = defos;
- p->quick = quick;
- p->roff = roff;
-
- mdoc_hash_init();
- mdoc_alloc1(p);
- return(p);
-}
-
-
-/*
- * Climb back up the parse tree, validating open scopes. Mostly calls
- * through to macro_end() in macro.c.
- */
-int
-mdoc_endparse(struct mdoc *mdoc)
-{
-
- assert( ! (MDOC_HALT & mdoc->flags));
- if (mdoc_macroend(mdoc))
- return(1);
- mdoc->flags |= MDOC_HALT;
- return(0);
-}
-
-int
-mdoc_addeqn(struct mdoc *mdoc, const struct eqn *ep)
-{
- struct mdoc_node *n;
-
- assert( ! (MDOC_HALT & mdoc->flags));
-
- /* No text before an initial macro. */
-
- if (SEC_NONE == mdoc->lastnamed) {
- mdoc_pmsg(mdoc, ep->ln, ep->pos, MANDOCERR_NOTEXT);
- return(1);
- }
-
- n = node_alloc(mdoc, ep->ln, ep->pos, MDOC_MAX, MDOC_EQN);
- n->eqn = ep;
-
- if ( ! node_append(mdoc, n))
- return(0);
-
- mdoc->next = MDOC_NEXT_SIBLING;
- return(1);
-}
-
-int
-mdoc_addspan(struct mdoc *mdoc, const struct tbl_span *sp)
-{
- struct mdoc_node *n;
-
- assert( ! (MDOC_HALT & mdoc->flags));
-
- /* No text before an initial macro. */
-
- if (SEC_NONE == mdoc->lastnamed) {
- mdoc_pmsg(mdoc, sp->line, 0, MANDOCERR_NOTEXT);
- return(1);
- }
-
- n = node_alloc(mdoc, sp->line, 0, MDOC_MAX, MDOC_TBL);
- n->span = sp;
-
- if ( ! node_append(mdoc, n))
- return(0);
-
- mdoc->next = MDOC_NEXT_SIBLING;
- return(1);
-}