X-Git-Url: https://git.cameronkatri.com/mandoc.git/blobdiff_plain/9ee0c488875a7038d68ac110a3ac03d81c6f14a1..e29a5b5a80c81fa6045785639e678bb968bd3e34:/chars.c diff --git a/chars.c b/chars.c index 3a5275c7..461ac067 100644 --- a/chars.c +++ b/chars.c @@ -1,4 +1,4 @@ -/* $Id: chars.c,v 1.5 2009/09/22 23:34:14 kristaps Exp $ */ +/* $Id: chars.c,v 1.17 2010/03/23 13:25:01 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 302 +#define LINES_MAX 369 #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); } @@ -156,18 +166,6 @@ find(struct tbl *tab, const char *p, size_t sz, size_t *rsz, int type) 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)) { prev = pp;