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: eaa1df96771e7ecdf08cc05e7ca75ae79b93f4a1
Parent: 0923ca5ba96e095fc674bab9091562ace8800a18
Author: Randy Palamar
Date:   Sun, 19 Jun 2022 09:24:26 -0600

stop using ssize_t

Diffstat:
Mjdict.c | 7++++---
Myomidict.c | 6++----
Myomidict.h | 8++++----
3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/jdict.c b/jdict.c @@ -6,7 +6,6 @@ #include <stdlib.h> #include <string.h> #include <sys/mman.h> -#include <sys/types.h> #include <unistd.h> #include "arg.h" @@ -74,8 +73,8 @@ make_ent(YomiTok *tok, char *data) static DictEnt * parse_term_bank(DictEnt *ents, size_t *nents, const char *tbank, size_t stride) { - int r, fd; - size_t i, ntoks, flen; + int r, ntoks, fd; + size_t i, flen; char *data; YomiTok *toks = NULL; YomiParser p; @@ -98,6 +97,8 @@ parse_term_bank(DictEnt *ents, size_t *nents, const char *tbank, size_t stride) switch (r) { case YOMI_ERROR_NOMEM: /* allocate more mem and try again */ + if (ntoks + YOMI_TOK_DELTA < 0) + die("too many toks: %s\n", tbank); ntoks += YOMI_TOK_DELTA; toks = xreallocarray(toks, ntoks, sizeof(YomiTok)); break; diff --git a/yomidict.c b/yomidict.c @@ -6,7 +6,6 @@ */ #include <ctype.h> #include <stddef.h> -#include <sys/types.h> #include "yomidict.h" @@ -119,13 +118,12 @@ yomi_parse_num(YomiParser *p, YomiTok *t, const char *s, size_t slen) return YOMI_ERROR_MALFO; } -ssize_t +int yomi_parse(YomiParser *p, YomiTok *toks, size_t ntoks, const char *bank, size_t blen) { YomiTok *tok, *t; - size_t count = p->toknext; - int r; + int r, count = p->toknext; if (toks == NULL) return -1; diff --git a/yomidict.h b/yomidict.h @@ -8,17 +8,17 @@ typedef enum { } YomiType; typedef struct { - YomiType type; size_t start; size_t end; size_t len; - size_t parent; /* parent tok number */ + int parent; /* parent tok number */ + YomiType type; } YomiTok; typedef struct { size_t pos; /* offset in yomi bank */ size_t toknext; - ssize_t parent; /* parent tok of current element */ + int parent; /* parent tok of current element */ } YomiParser; enum { @@ -28,4 +28,4 @@ enum { }; void yomi_init(YomiParser *); -ssize_t yomi_parse(YomiParser *, YomiTok *, size_t, const char *, size_t); +int yomi_parse(YomiParser *, YomiTok *, size_t, const char *, size_t);