X-Git-Url: https://git.cameronkatri.com/mandoc.git/blobdiff_plain/3e23d66c0abbb35f937f3969d2a6a54cb8827037..c5cc67f801d437ed8601ac67e37ccdc77f0cac0b:/chars.c diff --git a/chars.c b/chars.c index 72754ca9..aa6de429 100644 --- a/chars.c +++ b/chars.c @@ -1,4 +1,4 @@ -/* $Id: chars.c,v 1.21 2010/07/16 22:33:30 kristaps Exp $ */ +/* $Id: chars.c,v 1.24 2010/07/26 13:59:00 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -32,9 +32,7 @@ struct ln { struct ln *next; const char *code; - size_t codesz; const char *ascii; - size_t asciisz; int unicode; int type; #define CHARS_CHAR (1 << 0) @@ -44,12 +42,12 @@ struct ln { #define LINES_MAX 370 -#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(in, ch, code) \ + { NULL, (in), (ch), (code), CHARS_CHAR }, +#define STRING(in, ch, code) \ + { NULL, (in), (ch), (code), CHARS_STRING }, +#define BOTH(in, ch, code) \ + { NULL, (in), (ch), (code), CHARS_BOTH }, #define CHAR_TBL_START static struct ln lines[LINES_MAX] = { #define CHAR_TBL_END }; @@ -166,7 +164,7 @@ chars_spec2str(void *arg, const char *p, size_t sz, size_t *rsz) if (NULL == ln) return(NULL); - *rsz = ln->asciisz; + *rsz = strlen(ln->ascii); return(ln->ascii); } @@ -183,7 +181,7 @@ chars_res2str(void *arg, const char *p, size_t sz, size_t *rsz) if (NULL == ln) return(NULL); - *rsz = ln->asciisz; + *rsz = strlen(ln->ascii); return(ln->ascii); } @@ -196,7 +194,8 @@ find(struct tbl *tab, const char *p, size_t sz, int type) int hash; assert(p); - assert(sz > 0); + if (0 == sz) + return(NULL); if (p[0] < PRINT_LO || p[0] > PRINT_HI) return(NULL); @@ -238,7 +237,7 @@ match(const struct ln *ln, const char *p, size_t sz, int type) if ( ! (ln->type & type)) return(0); - if (ln->codesz != sz) + if (strncmp(ln->code, p, sz)) return(0); - return(0 == strncmp(ln->code, p, sz)); + return('\0' == ln->code[(int)sz]); }