-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 void node_append(struct mdoc *, struct mdoc_node *);
-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)
-{
-
- return(mdoc->first);
-}
-
-const struct mdoc_meta *
-mdoc_meta(const struct mdoc *mdoc)
-{
-
- 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);
- free(mdoc->meta.msec);
- free(mdoc->meta.vol);
- free(mdoc->meta.arch);
- free(mdoc->meta.date);
- free(mdoc->meta.title);
- free(mdoc->meta.os);
- free(mdoc->meta.name);
-}
-
-/*
- * 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,
- const 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);
-}
-
-int
-mdoc_endparse(struct mdoc *mdoc)
-{