=================================================================== RCS file: /cvs/mandoc/chars.c,v retrieving revision 1.4 retrieving revision 1.16 diff -u -p -r1.4 -r1.16 --- mandoc/chars.c 2009/09/22 23:15:58 1.4 +++ mandoc/chars.c 2010/01/28 06:04:59 1.16 @@ -1,4 +1,4 @@ -/* $Id: chars.c,v 1.4 2009/09/22 23:15:58 kristaps Exp $ */ +/* $Id: chars.c,v 1.16 2010/01/28 06:04:59 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -14,8 +14,12 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include -#include +#include #include #include @@ -35,10 +39,10 @@ struct ln { int type; #define CHARS_CHAR (1 << 0) #define CHARS_STRING (1 << 1) -#define CHARS_BOTH (0x03) +#define CHARS_BOTH (CHARS_CHAR | CHARS_STRING) }; -#define LINES_MAX 300 +#define LINES_MAX 350 #define CHAR(w, x, y, z, a, b) \ { NULL, (w), (y), (a), (x), (z), (b), CHARS_CHAR }, @@ -47,9 +51,10 @@ struct ln { #define BOTH(w, x, y, z, a, b) \ { NULL, (w), (y), (a), (x), (z), (b), CHARS_BOTH }, -static struct ln lines[LINES_MAX] = { +#define CHAR_TBL_START static struct ln lines[LINES_MAX] = { +#define CHAR_TBL_END }; + #include "chars.in" -}; struct tbl { enum chars type; @@ -89,13 +94,17 @@ chars_init(enum chars type) * (they're in-line re-ordered during lookup). */ - if (NULL == (tab = malloc(sizeof(struct tbl)))) - err(1, "malloc"); - tab->type = type; + tab = malloc(sizeof(struct tbl)); + if (NULL == tab) { + perror(NULL); + exit(EXIT_FAILURE); + } htab = calloc(PRINT_HI - PRINT_LO + 1, sizeof(struct ln **)); - if (NULL == htab) - err(1, "malloc"); + if (NULL == htab) { + perror(NULL); + exit(EXIT_FAILURE); + } for (i = 0; i < LINES_MAX; i++) { hash = (int)lines[i].code[0] - PRINT_LO; @@ -111,6 +120,7 @@ chars_init(enum chars type) } tab->htab = htab; + tab->type = type; return(tab); } @@ -155,18 +165,6 @@ find(struct tbl *tab, const char *p, size_t sz, size_t if (NULL == (pp = htab[hash])) return(NULL); - - if (NULL == pp->next) { - if ( ! match(pp, p, sz, type)) - return(NULL); - - if (CHARS_HTML == tab->type) { - *rsz = pp->htmlsz; - return(pp->html); - } - *rsz = pp->asciisz; - return(pp->ascii); - } for (prev = NULL; pp; pp = pp->next) { if ( ! match(pp, p, sz, type)) {