=================================================================== RCS file: /cvs/mandoc/Attic/ascii.c,v retrieving revision 1.1 retrieving revision 1.4 diff -u -p -r1.1 -r1.4 --- mandoc/Attic/ascii.c 2009/03/16 22:19:19 1.1 +++ mandoc/Attic/ascii.c 2009/03/20 21:58:38 1.4 @@ -1,4 +1,4 @@ -/* $Id: ascii.c,v 1.1 2009/03/16 22:19:19 kristaps Exp $ */ +/* $Id: ascii.c,v 1.4 2009/03/20 21:58:38 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -33,16 +33,16 @@ */ struct line { - const char *code; - const char *out; + const char *code; + const char *out; /* 32- and 64-bit alignment safe. */ - size_t codesz; - size_t outsz; + size_t codesz; + size_t outsz; }; struct linep { const struct line *line; - struct linep *next; + struct linep *next; }; #define LINE(w, x, y, z) \ @@ -51,14 +51,33 @@ static const struct line lines[] = { #include "ascii.in" }; +struct asciitab { + struct linep *lines; + void **htab; +}; -static inline int match(const struct line *, + +static inline int match(const struct line *, const char *, size_t); +void +term_asciifree(void *arg) +{ + struct asciitab *tab; + + tab = (struct asciitab *)arg; + + free(tab->lines); + free(tab->htab); + free(tab); +} + + void * -ascii2htab(void) +term_ascii2htab(void) { + struct asciitab *tab; void **htab; struct linep *pp, *p; int i, len, hash; @@ -70,7 +89,9 @@ ascii2htab(void) * (they're in-line re-ordered during lookup). */ - assert(0 == sizeof(lines) % sizeof(struct line)); + if (NULL == (tab = malloc(sizeof(struct asciitab)))) + err(1, "malloc"); + len = sizeof(lines) / sizeof(struct line); if (NULL == (p = calloc((size_t)len, sizeof(struct linep)))) @@ -102,18 +123,23 @@ ascii2htab(void) pp->next = &p[i]; } - return((void *)htab); + tab->htab = htab; + tab->lines = p; + + return(tab); } const char * -a2ascii(void *htabp, const char *p, size_t sz, size_t *rsz) +term_a2ascii(void *arg, const char *p, size_t sz, size_t *rsz) { + struct asciitab *tab; struct linep *pp, *prev; void **htab; int hash; - htab = (void **)htabp; + tab = (struct asciitab *)arg; + htab = tab->htab; assert(p); assert(sz > 0);