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: 960bd6fdcc4a285820d128b6ff5677700477e470
Parent: 73bf2291378804a941c0c87af2635c54999b97a1
Author: Randy Palamar
Date:   Sat, 25 Jun 2022 20:58:04 -0600

remove useless cleanup() fn and fix some style issues

Diffstat:
Mjdict.c | 36+++++++++++++++---------------------
1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/jdict.c b/jdict.c @@ -26,13 +26,6 @@ typedef struct { char *argv0; static void -cleanup(char **terms) -{ - free(terms); - terms = NULL; -} - -static void usage(void) { die("usage: %s [-d path] term ...\n", argv0); @@ -114,14 +107,16 @@ parse_term_bank(DictEnt *ents, size_t *nents, const char *tbank, size_t *stride) ents = xreallocarray(ents, (*nents) + r/YOMI_TOKS_PER_ENT, sizeof(DictEnt)); for (i = 0; i < r; i++) { - if (toks[i].type == YOMI_ENTRY) { - e = make_ent(&toks[i], r - i, data); - if (e == NULL) { - free(ents); - ents = NULL; - goto cleanup; - } + if (toks[i].type != YOMI_ENTRY) + continue; + + e = make_ent(&toks[i], r - i, data); + if (e != NULL) { memcpy(&ents[(*nents)++], e, sizeof(DictEnt)); + } else { + free(ents); + ents = NULL; + break; } } @@ -226,15 +221,14 @@ find_and_print_defs(struct Dict *dict, char **terms, size_t nterms) if (ents == NULL) return -1; qsort(ents, nents, sizeof(DictEnt), entcmp); - printf("%s\n", dict->name); + printf("%s\n", dict->name); for (i = 0; i < nterms; i++) { ent = find_ent(terms[i], ents, nents); - if (ent == NULL) { + if (ent != NULL) + print_ent(ent); + else printf("term not found: %s\n\n", terms[i]); - continue; - } - print_ent(ent); } for (i = 0; i < nents; i++) { for (j = 0; j < ents[i].ndefs; j++) @@ -286,14 +280,14 @@ main(int argc, char *argv[]) } if (nterms == 0) { - cleanup(terms); + free(terms); usage(); } for (i = 0; i < ndicts; i++) find_and_print_defs(&dicts[i], terms, nterms); - cleanup(terms); + free(terms); return 0; }