diff options
-rw-r--r-- | libman.h | 1 | ||||
-rw-r--r-- | libmandoc.h | 15 | ||||
-rw-r--r-- | libmdoc.h | 1 | ||||
-rw-r--r-- | man.c | 62 | ||||
-rw-r--r-- | mdoc.c | 84 | ||||
-rw-r--r-- | read.c | 62 | ||||
-rw-r--r-- | roff.c | 70 |
7 files changed, 100 insertions, 195 deletions
@@ -42,7 +42,6 @@ void man_block_alloc(struct roff_man *, int, int, int); void man_head_alloc(struct roff_man *, int, int, int); void man_body_alloc(struct roff_man *, int, int, int); void man_elem_alloc(struct roff_man *, int, int, int); -void man_node_delete(struct roff_man *, struct roff_node *); int man_hash_find(const char *); void man_macroend(struct roff_man *); void man_valid_post(struct roff_man *); diff --git a/libmandoc.h b/libmandoc.h index c46fa691..f91c8042 100644 --- a/libmandoc.h +++ b/libmandoc.h @@ -40,6 +40,7 @@ struct tbl_span; struct eqn; struct roff; struct roff_man; +struct roff_node; void mandoc_msg(enum mandocerr, struct mparse *, int, int, const char *); @@ -54,21 +55,15 @@ int mandoc_eos(const char *, size_t); int mandoc_strntoi(const char *, size_t, int); const char *mandoc_a2msec(const char*); -void mdoc_free(struct roff_man *); -struct roff_man *mdoc_alloc(struct roff *, struct mparse *, - const char *, int); -void mdoc_reset(struct roff_man *); void mdoc_hash_init(void); +void mdoc_node_delete(struct roff_man *, struct roff_node *); int mdoc_parseln(struct roff_man *, int, char *, int); void mdoc_endparse(struct roff_man *); void mdoc_addspan(struct roff_man *, const struct tbl_span *); void mdoc_addeqn(struct roff_man *, const struct eqn *); -void man_free(struct roff_man *); -struct roff_man *man_alloc(struct roff *, struct mparse *, - const char *, int); -void man_reset(struct roff_man *); void man_hash_init(void); +void man_node_delete(struct roff_man *, struct roff_node *); int man_parseln(struct roff_man *, int, char *, int); void man_endparse(struct roff_man *); void man_addspan(struct roff_man *, const struct tbl_span *); @@ -81,6 +76,10 @@ int preconv_encode(struct buf *, size_t *, void roff_free(struct roff *); struct roff *roff_alloc(struct mparse *, const struct mchars *, int); void roff_reset(struct roff *); +void roff_man_free(struct roff_man *); +struct roff_man *roff_man_alloc(struct roff *, struct mparse *, + const char *, int); +void roff_man_reset(struct roff_man *); enum rofferr roff_parseln(struct roff *, int, struct buf *, int *); void roff_endparse(struct roff *); void roff_setreg(struct roff *, const char *, int, char sign); @@ -78,7 +78,6 @@ void mdoc_tail_alloc(struct roff_man *, int, int, int); struct roff_node *mdoc_body_alloc(struct roff_man *, int, int, int); struct roff_node *mdoc_endbody_alloc(struct roff_man *, int, int, int, struct roff_node *, enum mdoc_endbody); -void mdoc_node_delete(struct roff_man *, struct roff_node *); void mdoc_node_relink(struct roff_man *, struct roff_node *); int mdoc_hash_find(const char *); const char *mdoc_a2att(const char *); @@ -49,10 +49,8 @@ const char *const __man_macronames[MAN_MAX] = { const char * const *man_macronames = __man_macronames; -static void man_alloc1(struct roff_man *); static void man_breakscope(struct roff_man *, int); static void man_descope(struct roff_man *, int, int); -static void man_free1(struct roff_man *); static struct roff_node *man_node_alloc(struct roff_man *, int, int, enum roff_type, int); static void man_node_append(struct roff_man *, @@ -79,38 +77,6 @@ man_meta(const struct roff_man *man) } void -man_reset(struct roff_man *man) -{ - - man_free1(man); - man_alloc1(man); -} - -void -man_free(struct roff_man *man) -{ - - man_free1(man); - free(man); -} - -struct roff_man * -man_alloc(struct roff *roff, struct mparse *parse, - const char *defos, int quick) -{ - struct roff_man *p; - - p = mandoc_calloc(1, sizeof(*p)); - p->parse = parse; - p->defos = defos; - p->quick = quick; - p->roff = roff; - - man_alloc1(p); - return(p); -} - -void man_endparse(struct roff_man *man) { @@ -130,34 +96,6 @@ man_parseln(struct roff_man *man, int ln, char *buf, int offs) } static void -man_free1(struct roff_man *man) -{ - - if (man->first) - man_node_delete(man, man->first); - free(man->meta.title); - free(man->meta.os); - free(man->meta.date); - free(man->meta.vol); - free(man->meta.msec); -} - -static void -man_alloc1(struct roff_man *man) -{ - - memset(&man->meta, 0, sizeof(man->meta)); - man->macroset = MACROSET_MAN; - man->flags = 0; - man->last = mandoc_calloc(1, sizeof(*man->last)); - man->first = man->last; - man->last->type = ROFFT_ROOT; - man->last->tok = MAN_MAX; - man->next = ROFF_NEXT_CHILD; -} - - -static void man_node_append(struct roff_man *man, struct roff_node *p) { @@ -86,8 +86,6 @@ const char * const *mdoc_argnames = __mdoc_argnames; static void mdoc_node_free(struct roff_node *); static void mdoc_node_unlink(struct roff_man *, struct roff_node *); -static void mdoc_free1(struct roff_man *); -static void mdoc_alloc1(struct roff_man *); static struct roff_node *node_alloc(struct roff_man *, int, int, int, enum roff_type); static void node_append(struct roff_man *, struct roff_node *); @@ -109,88 +107,6 @@ mdoc_meta(const struct roff_man *mdoc) return(&mdoc->meta); } -/* - * Frees volatile resources (parse tree, meta-data, fields). - */ -static void -mdoc_free1(struct roff_man *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 roff_man *mdoc) -{ - - memset(&mdoc->meta, 0, sizeof(mdoc->meta)); - mdoc->macroset = MACROSET_MDOC; - mdoc->flags = 0; - mdoc->lastnamed = mdoc->lastsec = SEC_NONE; - mdoc->last = mandoc_calloc(1, sizeof(*mdoc->last)); - mdoc->first = mdoc->last; - mdoc->last->type = ROFFT_ROOT; - mdoc->last->tok = MDOC_MAX; - mdoc->next = ROFF_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 roff_man *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 roff_man *mdoc) -{ - - mdoc_free1(mdoc); - free(mdoc); -} - -/* - * Allocate volatile and non-volatile parse resources. - */ -struct roff_man * -mdoc_alloc(struct roff *roff, struct mparse *parse, - const char *defos, int quick) -{ - struct roff_man *p; - - p = mandoc_calloc(1, sizeof(*p)); - - p->parse = parse; - p->defos = defos; - p->quick = quick; - p->roff = roff; - - mdoc_alloc1(p); - return(p); -} - void mdoc_endparse(struct roff_man *mdoc) { @@ -289,26 +289,22 @@ choose_parser(struct mparse *curp) } } - if (format == MPARSE_MDOC) { - if (curp->man == NULL) - curp->man = mdoc_alloc( - curp->roff, curp, curp->defos, - MPARSE_QUICK & curp->options ? 1 : 0); - else - curp->man->macroset = MACROSET_MDOC; - mdoc_hash_init(); - return; + if (curp->man == NULL) { + curp->man = roff_man_alloc(curp->roff, curp, curp->defos, + curp->options & MPARSE_QUICK ? 1 : 0); + curp->man->macroset = MACROSET_MAN; + curp->man->first->tok = MDOC_MAX; } - /* Fall back to man(7) as a last resort. */ - - if (curp->man == NULL) - curp->man = man_alloc( - curp->roff, curp, curp->defos, - MPARSE_QUICK & curp->options ? 1 : 0); - else + if (format == MPARSE_MDOC) { + mdoc_hash_init(); + curp->man->macroset = MACROSET_MDOC; + curp->man->first->tok = MDOC_MAX; + } else { + man_hash_init(); curp->man->macroset = MACROSET_MAN; - man_hash_init(); + curp->man->first->tok = MAN_MAX; + } } /* @@ -690,7 +686,7 @@ mparse_end(struct mparse *curp) { if (curp->man == NULL && curp->sodest == NULL) - curp->man = man_alloc(curp->roff, curp, curp->defos, + curp->man = roff_man_alloc(curp->roff, curp, curp->defos, curp->options & MPARSE_QUICK ? 1 : 0); if (curp->man->macroset == MACROSET_NONE) curp->man->macroset = MACROSET_MAN; @@ -892,19 +888,17 @@ mparse_alloc(int options, enum mandoclevel wlevel, mandocmsg mmsg, curp->mchars = mchars; curp->roff = roff_alloc(curp, curp->mchars, options); + curp->man = roff_man_alloc( curp->roff, curp, curp->defos, + curp->options & MPARSE_QUICK ? 1 : 0); if (curp->options & MPARSE_MDOC) { - curp->man = mdoc_alloc( - curp->roff, curp, curp->defos, - curp->options & MPARSE_QUICK ? 1 : 0); mdoc_hash_init(); - } - if (curp->options & MPARSE_MAN) { - curp->man = man_alloc( - curp->roff, curp, curp->defos, - curp->options & MPARSE_QUICK ? 1 : 0); + curp->man->macroset = MACROSET_MDOC; + curp->man->first->tok = MDOC_MAX; + } else if (curp->options & MPARSE_MAN) { man_hash_init(); + curp->man->macroset = MACROSET_MAN; + curp->man->first->tok = MAN_MAX; } - return(curp); } @@ -914,13 +908,8 @@ mparse_reset(struct mparse *curp) roff_reset(curp->roff); - if (curp->man != NULL) { - if (curp->man->macroset == MACROSET_MDOC) - mdoc_reset(curp->man); - else - man_reset(curp->man); - curp->man->macroset = MACROSET_NONE; - } + if (curp->man != NULL) + roff_man_reset(curp->man); if (curp->secondary) curp->secondary->sz = 0; @@ -934,10 +923,7 @@ void mparse_free(struct mparse *curp) { - if (curp->man->macroset == MACROSET_MDOC) - mdoc_free(curp->man); - if (curp->man->macroset == MACROSET_MAN) - man_free(curp->man); + roff_man_free(curp->man); if (curp->roff) roff_free(curp->roff); if (curp->secondary) @@ -1,6 +1,6 @@ /* $Id$ */ /* - * Copyright (c) 2010, 2011, 2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv> + * Copyright (c) 2009-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any @@ -28,6 +28,7 @@ #include "mandoc.h" #include "mandoc_aux.h" +#include "roff.h" #include "libmandoc.h" #include "libroff.h" @@ -412,6 +413,8 @@ static const char *roff_getstrn(const struct roff *, static enum rofferr roff_insec(ROFF_ARGS); static enum rofferr roff_it(ROFF_ARGS); static enum rofferr roff_line_ignore(ROFF_ARGS); +static void roff_man_alloc1(struct roff_man *); +static void roff_man_free1(struct roff_man *); static enum rofferr roff_nr(ROFF_ARGS); static enum rofft roff_parse(struct roff *, char *, int *, int, int); @@ -898,6 +901,71 @@ roff_alloc(struct mparse *parse, const struct mchars *mchars, int options) return(r); } +static void +roff_man_free1(struct roff_man *man) +{ + + if (man->first != NULL) { + if (man->macroset == MACROSET_MDOC) + mdoc_node_delete(man, man->first); + else + man_node_delete(man, man->first); + } + free(man->meta.msec); + free(man->meta.vol); + free(man->meta.os); + free(man->meta.arch); + free(man->meta.title); + free(man->meta.name); + free(man->meta.date); +} + +static void +roff_man_alloc1(struct roff_man *man) +{ + + memset(&man->meta, 0, sizeof(man->meta)); + man->first = mandoc_calloc(1, sizeof(*man->first)); + man->first->type = ROFFT_ROOT; + man->last = man->first; + man->last_es = NULL; + man->flags = 0; + man->macroset = MACROSET_NONE; + man->lastsec = man->lastnamed = SEC_NONE; + man->next = ROFF_NEXT_CHILD; +} + +void +roff_man_reset(struct roff_man *man) +{ + + roff_man_free1(man); + roff_man_alloc1(man); +} + +void +roff_man_free(struct roff_man *man) +{ + + roff_man_free1(man); + free(man); +} + +struct roff_man * +roff_man_alloc(struct roff *roff, struct mparse *parse, + const char *defos, int quick) +{ + struct roff_man *man; + + man = mandoc_calloc(1, sizeof(*man)); + man->parse = parse; + man->roff = roff; + man->defos = defos; + man->quick = quick; + roff_man_alloc1(man); + return(man); +} + /* * In the current line, expand escape sequences that tend to get * used in numerical expressions and conditional requests. |