=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.64 retrieving revision 1.67 diff -u -p -r1.64 -r1.67 --- mandoc/mdoc.c 2009/03/12 16:30:50 1.64 +++ mandoc/mdoc.c 2009/03/19 11:49:00 1.67 @@ -1,6 +1,6 @@ -/* $Id: mdoc.c,v 1.64 2009/03/12 16:30:50 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.67 2009/03/19 11:49:00 kristaps Exp $ */ /* - * Copyright (c) 2008 Kristaps Dzonsons + * Copyright (c) 2008, 2009 Kristaps Dzonsons * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the @@ -74,7 +74,8 @@ const char *const __mdoc_macronames[MDOC_MAX] = { "Fr", "Ud", "Lb", "Ap", "Lp", "Lk", "Mt", "Brq", /* LINTED */ - "Bro", "Brc", "\%C" + "Bro", "Brc", "\%C", "Es", + "En", "Dx" }; const char *const __mdoc_argnames[MDOC_ARG_MAX] = { @@ -110,6 +111,34 @@ mdoc_meta(const struct mdoc *mdoc) void +mdoc_reset(struct mdoc *mdoc) +{ + + if (mdoc->first) + mdoc_node_freelist(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); + + bzero(&mdoc->meta, sizeof(struct mdoc_meta)); + mdoc->flags = 0; + mdoc->lastnamed = mdoc->lastsec = 0; + + mdoc->first = mdoc->last = + xcalloc(1, sizeof(struct mdoc_node)); + mdoc->last->type = MDOC_ROOT; + mdoc->next = MDOC_NEXT_CHILD; +} + + +void mdoc_free(struct mdoc *mdoc) { @@ -143,13 +172,12 @@ mdoc_alloc(void *data, int pflags, const struct mdoc_c if (cb) (void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb)); - p->last = xcalloc(1, sizeof(struct mdoc_node)); + p->last = p->first = + xcalloc(1, sizeof(struct mdoc_node)); p->last->type = MDOC_ROOT; - p->first = p->last; p->pflags = pflags; p->next = MDOC_NEXT_CHILD; p->htab = mdoc_tokhash_alloc(); - return(p); } @@ -527,9 +555,9 @@ parsemacro(struct mdoc *m, int ln, char *buf) if (0 == buf[1]) return(1); - if (isspace((unsigned char)buf[1])) { + if (' ' == buf[1]) { i = 2; - while (buf[i] && isspace((unsigned char)buf[i])) + while (buf[i] && ' ' == buf[i]) i++; if (0 == buf[i]) return(1); @@ -545,7 +573,7 @@ parsemacro(struct mdoc *m, int ln, char *buf) for (i = 1; i < 5; i++) { if (0 == (mac[i - 1] = buf[i])) break; - else if (isspace((unsigned char)buf[i])) + else if (' ' == buf[i]) break; } @@ -565,7 +593,7 @@ parsemacro(struct mdoc *m, int ln, char *buf) /* The macro is sane. Jump to the next word. */ - while (buf[i] && isspace((unsigned char)buf[i])) + while (buf[i] && ' ' == buf[i]) i++; /* Begin recursive parse sequence. */