jdict

command line tool for looking up terms in yomidict dictionaries
git clone anongit@rnpnr.xyz:jdict.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 7dd0bf5557d68cdba3c8d5637777a4c59438aa6d
Parent: 2e527fae957be180b6676204e242505c6d4c3f0a
Author: Randy Palamar
Date:   Tue, 31 Oct 2023 06:33:15 -0600

yomidict: drop use of libc headers

Diffstat:
Myomidict.c | 23++++++++++++-----------
Myomidict.h | 12++++++------
2 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/yomidict.c b/yomidict.c @@ -4,11 +4,13 @@ * all it knows how to do. Finding and reading term banks as well as searching * through parsed entries should be implemented elsewhere. */ -#include <ctype.h> -#include <stddef.h> - #include "yomidict.h" +#define NULL 0 +#define ul unsigned long + +#define ISDIGIT(c) ((c) >= '0' && (c) <= '9') + void yomi_init(YomiParser *p) { @@ -18,7 +20,7 @@ yomi_init(YomiParser *p) } static YomiTok * -yomi_alloc_tok(YomiParser *p, YomiTok *toks, size_t ntoks) +yomi_alloc_tok(YomiParser *p, YomiTok *toks, ul ntoks) { YomiTok *t; @@ -35,9 +37,9 @@ yomi_alloc_tok(YomiParser *p, YomiTok *toks, size_t ntoks) } static int -yomi_parse_str(YomiParser *p, YomiTok *t, const char *s, size_t slen) +yomi_parse_str(YomiParser *p, YomiTok *t, const char *s, ul slen) { - size_t start = p->pos++; + ul start = p->pos++; for (; p->pos < slen; p->pos++) { /* skip over escaped " */ @@ -61,9 +63,9 @@ yomi_parse_str(YomiParser *p, YomiTok *t, const char *s, size_t slen) } static int -yomi_parse_num(YomiParser *p, YomiTok *t, const char *s, size_t slen) +yomi_parse_num(YomiParser *p, YomiTok *t, const char *s, ul slen) { - size_t start = p->pos; + ul start = p->pos; for (; p->pos < slen && s[p->pos]; p->pos++) { switch (s[p->pos]) { @@ -80,7 +82,7 @@ yomi_parse_num(YomiParser *p, YomiTok *t, const char *s, size_t slen) p->pos--; return 0; } - if (!isdigit(s[p->pos])) { + if (!ISDIGIT(s[p->pos])) { p->pos = start; return YOMI_ERROR_INVAL; } @@ -90,8 +92,7 @@ yomi_parse_num(YomiParser *p, YomiTok *t, const char *s, size_t slen) } int -yomi_parse(YomiParser *p, YomiTok *toks, size_t ntoks, - const char *bank, size_t blen) +yomi_parse(YomiParser *p, YomiTok *toks, ul ntoks, const char *bank, ul blen) { YomiTok *tok; int r, count = p->toknext; diff --git a/yomidict.h b/yomidict.h @@ -8,16 +8,16 @@ typedef enum { } YomiType; typedef struct { - size_t start; - size_t end; - size_t len; + unsigned long start; + unsigned long end; + unsigned long len; int parent; /* parent tok number */ YomiType type; } YomiTok; typedef struct { - size_t pos; /* offset in yomi bank */ - size_t toknext; + unsigned long pos; /* offset in yomi bank */ + unsigned long toknext; int parent; /* parent tok of current element */ } YomiParser; @@ -28,4 +28,4 @@ enum { }; void yomi_init(YomiParser *); -int yomi_parse(YomiParser *, YomiTok *, size_t, const char *, size_t); +int yomi_parse(YomiParser *, YomiTok *, unsigned long, const char *, unsigned long);