=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mdoc.c,v retrieving revision 1.7 retrieving revision 1.8 diff -c -r1.7 -r1.8 *** src/usr.bin/mandoc/mdoc.c 2009/06/18 23:34:53 1.7 --- src/usr.bin/mandoc/mdoc.c 2009/06/18 23:51:12 1.8 *************** *** 1,4 **** ! /* $Id: mdoc.c,v 1.7 2009/06/18 23:34:53 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * --- 1,4 ---- ! /* $Id: mdoc.c,v 1.8 2009/06/18 23:51:12 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * *************** *** 97,107 **** static int macrowarn(struct mdoc *, int, const char *); static int perr(struct mdoc *, int, int, enum merr); - #define verr(m, t) perr((m), (m)->last->line, (m)->last->pos, (t)) - - /* - * Get the first (root) node of the parse tree. - */ const struct mdoc_node * mdoc_node(const struct mdoc *m) { --- 97,102 ---- *************** *** 118,123 **** --- 113,121 ---- } + /* + * Frees volatile resources (parse tree, meta-data, fields). + */ static void mdoc_free1(struct mdoc *mdoc) { *************** *** 137,142 **** --- 135,143 ---- } + /* + * Allocate all volatile resources (parse tree, meta-data, fields). + */ static int mdoc_alloc1(struct mdoc *mdoc) { *************** *** 156,164 **** /* ! * Free up all resources contributed by a parse: the node tree, ! * meta-data and so on. Then reallocate the root node for another ! * parse. */ int mdoc_reset(struct mdoc *mdoc) --- 157,166 ---- /* ! * 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. */ int mdoc_reset(struct mdoc *mdoc) *************** *** 170,176 **** /* ! * Completely free up all resources. */ void mdoc_free(struct mdoc *mdoc) --- 172,179 ---- /* ! * Completely free up all volatile and non-volatile parse resources. ! * After invocation, the pointer is no longer usable. */ void mdoc_free(struct mdoc *mdoc) *************** *** 183,188 **** --- 186,194 ---- } + /* + * Allocate volatile and non-volatile parse resources. + */ struct mdoc * mdoc_alloc(void *data, int pflags, const struct mdoc_cb *cb) { *************** *** 209,215 **** /* * Climb back up the parse tree, validating open scopes. Mostly calls ! * through to macro_end in macro.c. */ int mdoc_endparse(struct mdoc *m) --- 215,221 ---- /* * Climb back up the parse tree, validating open scopes. Mostly calls ! * through to macro_end() in macro.c. */ int mdoc_endparse(struct mdoc *m) *************** *** 226,239 **** /* * Main parse routine. Parses a single line -- really just hands off to ! * the macro or text parser. */ int mdoc_parseln(struct mdoc *m, int ln, char *buf) { - /* If in error-mode, then we parse no more. */ - if (MDOC_HALT & m->flags) return(0); --- 232,243 ---- /* * Main parse routine. Parses a single line -- really just hands off to ! * the macro (parsemacro()) or text parser (parsetext()). */ int mdoc_parseln(struct mdoc *m, int ln, char *buf) { if (MDOC_HALT & m->flags) return(0); *************** *** 277,283 **** int ! mdoc_nerr(struct mdoc *mdoc, const struct mdoc_node *node, const char *fmt, ...) { char buf[256]; va_list ap; --- 281,288 ---- int ! mdoc_nerr(struct mdoc *mdoc, const struct mdoc_node *node, ! const char *fmt, ...) { char buf[256]; va_list ap; *************** *** 288,299 **** va_start(ap, fmt); (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); va_end(ap); ! return((*mdoc->cb.mdoc_err)(mdoc->data, node->line, node->pos, buf)); } int ! mdoc_warn(struct mdoc *mdoc, enum mdoc_warn type, const char *fmt, ...) { char buf[256]; va_list ap; --- 293,306 ---- va_start(ap, fmt); (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); va_end(ap); ! return((*mdoc->cb.mdoc_err)(mdoc->data, ! node->line, node->pos, buf)); } int ! mdoc_warn(struct mdoc *mdoc, enum mdoc_warn type, ! const char *fmt, ...) { char buf[256]; va_list ap; *************** *** 305,311 **** (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); va_end(ap); return((*mdoc->cb.mdoc_warn)(mdoc->data, mdoc->last->line, ! mdoc->last->pos, type, buf)); } --- 312,318 ---- (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); va_end(ap); return((*mdoc->cb.mdoc_warn)(mdoc->data, mdoc->last->line, ! mdoc->last->pos, type, buf)); } *************** *** 322,328 **** (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); va_end(ap); return((*mdoc->cb.mdoc_err)(mdoc->data, mdoc->last->line, ! mdoc->last->pos, buf)); } --- 329,335 ---- (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); va_end(ap); return((*mdoc->cb.mdoc_err)(mdoc->data, mdoc->last->line, ! mdoc->last->pos, buf)); } *************** *** 339,345 **** va_start(ap, fmt); (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); va_end(ap); ! return((*mdoc->cb.mdoc_warn)(mdoc->data, line, pos, type, buf)); } int --- 346,353 ---- va_start(ap, fmt); (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); va_end(ap); ! return((*mdoc->cb.mdoc_warn)(mdoc->data, ! line, pos, type, buf)); } int *************** *** 483,489 **** struct mdoc_node *p; if (NULL == (p = calloc(1, sizeof(struct mdoc_node)))) { ! (void)verr(mdoc, EMALLOC); return(NULL); } --- 491,498 ---- struct mdoc_node *p; if (NULL == (p = calloc(1, sizeof(struct mdoc_node)))) { ! (void)perr(mdoc, (mdoc)->last->line, ! (mdoc)->last->pos, EMALLOC); return(NULL); } *************** *** 579,585 **** if (NULL == p) return(0); if (NULL == (p->string = strdup(word))) { ! (void)verr(mdoc, EMALLOC); return(0); } return(node_append(mdoc, p)); --- 588,595 ---- if (NULL == p) return(0); if (NULL == (p->string = strdup(word))) { ! (void)perr(mdoc, (mdoc)->last->line, ! (mdoc)->last->pos, EMALLOC); return(0); } return(node_append(mdoc, p)); *************** *** 644,650 **** "unknown macro: %s%s", buf, strlen(buf) > 3 ? "..." : "")); } - /* --- 654,659 ----