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: 614d6295f6c26d321f5f7e3ebacae511e0545b93
Parent: e73beb9967a6456dac0961027ef0b0eb884f5755
Author: Randy Palamar
Date:   Sun,  5 Jan 2025 15:58:19 -0700

delete c braindamage

NULL is 0. that is all

Diffstat:
Mjdict.c | 28++++++++++------------------
Mplatform_linux.c | 2--
Myomidict.c | 8++++----
3 files changed, 14 insertions(+), 24 deletions(-)

diff --git a/jdict.c b/jdict.c @@ -353,28 +353,20 @@ parse_term_bank(Arena *a, struct ht *ht, s8 data) if (base_tok->type != YOMI_ENTRY) continue; - YomiTok *tstr = NULL, *tdefs = NULL; + YomiTok *tstr = 0, *tdefs = 0; for (usize j = 1; j < base_tok->len; j++) { - switch (base_tok[j].type) { - case YOMI_STR: - if (tstr == NULL) - tstr = base_tok + j; - break; - case YOMI_ARRAY: - if (tdefs == NULL) - tdefs = base_tok + j; - default: /* FALLTHROUGH */ - break; + case YOMI_STR: if (!tstr) tstr = base_tok + j; break; + case YOMI_ARRAY: if (!tdefs) tdefs = base_tok + j; break; + default: break; } } /* check if entry was valid */ - if (tdefs == NULL || tstr == NULL) { - stream_append_s8(&error_stream, s8("parse_term_bank: invalid entry: got ")); - if (!tdefs) stream_append_s8(&error_stream, s8("tdefs")); - else stream_append_s8(&error_stream, s8("tstr")); - stream_append_s8(&error_stream, s8(" == NULL\n")); + if (!tdefs || !tstr) { + stream_append_s8(&error_stream, s8("parse_term_bank: invalid entry: missing ")); + if (!tdefs) stream_append_s8(&error_stream, s8("definition token\n")); + else stream_append_s8(&error_stream, s8("name token\n")); break; } @@ -547,7 +539,7 @@ repl(Arena *a, Dict *dicts, u32 ndicts) static i32 jdict(Arena *a, i32 argc, char *argv[]) { - Dict *dicts = NULL; + Dict *dicts = 0; i32 ndicts = 0, nterms = 0; i32 iflag = 0; @@ -577,7 +569,7 @@ jdict(Arena *a, i32 argc, char *argv[]) break; } } - if (dicts == NULL) { + if (!dicts) { stream_append_s8(&error_stream, s8("invalid dictionary name: ")); stream_append_s8(&error_stream, dname); die(&error_stream); diff --git a/platform_linux.c b/platform_linux.c @@ -1,8 +1,6 @@ /* See LICENSE for license details. */ #define os_path_sep s8("/") -#define NULL ((void *)0) - #include "jdict.c" #define PROT_READ 0x01 diff --git a/yomidict.c b/yomidict.c @@ -56,7 +56,7 @@ alloctok(YomiScanner *s, YomiTok *toks, ul ntoks) YomiTok *t; if (ntoks <= s->toknext) - return NULL; + return 0; t = &toks[s->toknext++]; t->parent = -1; @@ -130,7 +130,7 @@ yomi_scan(YomiScanner *s, YomiTok *toks, ul ntoks) YomiTok *tok; int r, count = s->toknext; - if (toks == NULL) + if (!toks) return -1; for (; s->pos < s->len; s->pos++) { @@ -183,7 +183,7 @@ yomi_scan(YomiScanner *s, YomiTok *toks, ul ntoks) case '\"': tok = alloctok(s, toks, ntoks); - if (tok == NULL) + if (!tok) return YOMI_ERROR_NOMEM; r = string(s, tok); @@ -204,7 +204,7 @@ yomi_scan(YomiScanner *s, YomiTok *toks, ul ntoks) default: tok = alloctok(s, toks, ntoks); - if (tok == NULL) + if (!tok) return YOMI_ERROR_NOMEM; r = number(s, tok);