diff options
Diffstat (limited to 'chars.c')
-rw-r--r-- | chars.c | 87 |
1 files changed, 64 insertions, 23 deletions
@@ -32,11 +32,10 @@ struct ln { struct ln *next; const char *code; - const char *ascii; - const char *html; size_t codesz; + const char *ascii; size_t asciisz; - size_t htmlsz; + int unicode; int type; #define CHARS_CHAR (1 << 0) #define CHARS_STRING (1 << 1) @@ -45,12 +44,12 @@ struct ln { #define LINES_MAX 370 -#define CHAR(w, x, y, z, a, b) \ - { NULL, (w), (y), (a), (x), (z), (b), CHARS_CHAR }, -#define STRING(w, x, y, z, a, b) \ - { NULL, (w), (y), (a), (x), (z), (b), CHARS_STRING }, -#define BOTH(w, x, y, z, a, b) \ - { NULL, (w), (y), (a), (x), (z), (b), CHARS_BOTH }, +#define CHAR(in, insz, ch, chsz, code) \ + { NULL, (in), (insz), (ch), (chsz), (code), CHARS_CHAR }, +#define STRING(in, insz, ch, chsz, code) \ + { NULL, (in), (insz), (ch), (chsz), (code), CHARS_STRING }, +#define BOTH(in, insz, ch, chsz, code) \ + { NULL, (in), (insz), (ch), (chsz), (code), CHARS_BOTH }, #define CHAR_TBL_START static struct ln lines[LINES_MAX] = { #define CHAR_TBL_END }; @@ -64,8 +63,7 @@ struct tbl { static inline int match(const struct ln *, const char *, size_t, int); -static const char *find(struct tbl *, const char *, - size_t, size_t *, int); +static const struct ln *find(struct tbl *, const char *, size_t, int); void @@ -126,24 +124,72 @@ chars_init(enum chars type) } +/* + * Special character to Unicode codepoint. + */ +int +chars_spec2cp(void *arg, const char *p, size_t sz) +{ + const struct ln *ln; + + ln = find((struct tbl *)arg, p, sz, CHARS_CHAR); + if (NULL == ln) + return(-1); + return(ln->unicode); +} + + +/* + * Reserved word to Unicode codepoint. + */ +int +chars_res2cp(void *arg, const char *p, size_t sz) +{ + const struct ln *ln; + + ln = find((struct tbl *)arg, p, sz, CHARS_STRING); + if (NULL == ln) + return(-1); + return(ln->unicode); +} + + +/* + * Special character to string array. + */ const char * -chars_a2ascii(void *arg, const char *p, size_t sz, size_t *rsz) +chars_spec2str(void *arg, const char *p, size_t sz, size_t *rsz) { + const struct ln *ln; + + ln = find((struct tbl *)arg, p, sz, CHARS_CHAR); + if (NULL == ln) + return(NULL); - return(find((struct tbl *)arg, p, sz, rsz, CHARS_CHAR)); + *rsz = ln->asciisz; + return(ln->ascii); } +/* + * Reserved word to string array. + */ const char * -chars_a2res(void *arg, const char *p, size_t sz, size_t *rsz) +chars_res2str(void *arg, const char *p, size_t sz, size_t *rsz) { + const struct ln *ln; - return(find((struct tbl *)arg, p, sz, rsz, CHARS_STRING)); + ln = find((struct tbl *)arg, p, sz, CHARS_STRING); + if (NULL == ln) + return(NULL); + + *rsz = ln->asciisz; + return(ln->ascii); } -static const char * -find(struct tbl *tab, const char *p, size_t sz, size_t *rsz, int type) +static const struct ln * +find(struct tbl *tab, const char *p, size_t sz, int type) { struct ln *pp, *prev; struct ln **htab; @@ -179,12 +225,7 @@ find(struct tbl *tab, const char *p, size_t sz, size_t *rsz, int type) htab[hash] = pp; } - if (CHARS_HTML == tab->type) { - *rsz = pp->htmlsz; - return(pp->html); - } - *rsz = pp->asciisz; - return(pp->ascii); + return(pp); } return(NULL); |