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: a4fb0124478e7fd3e1b758f343c5a7f3c433969c
Parent: 325cecc67dfc7dd267bc85b4f978f902dfb185a8
Author: Randy Palamar
Date:   Sat, 16 Jul 2022 13:10:51 -0600

move fix_newlines() to util.c

Diffstat:
Mjdict.c | 14--------------
Mutil.c | 16++++++++++++++++
Mutil.h | 1+
3 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/jdict.c b/jdict.c @@ -205,20 +205,6 @@ find_ent(const char *term, DictEnt *ents, size_t nents) return find_ent(term, &ents[nents/2 + 1], nents/2 - 1); } -static char * -fix_newlines(char *str) -{ - char *t = str; - - while ((t = strstr(t, "\\n")) != NULL) { - t[0] = '\n'; - t++; - memmove(t, t + 1, strlen(t + 1) + 1); - } - - return str; -} - static void print_ent(DictEnt *ent) { diff --git a/util.c b/util.c @@ -19,6 +19,7 @@ die(const char *fmt, ...) exit(1); } +/* trim whitespace from start and end of str */ void trim(char *s) { @@ -36,6 +37,21 @@ trim(char *s) memmove(s, p, len + 1); } +/* replace embedded escaped newlines with actual newlines */ +char * +fix_newlines(char *s) +{ + char *t = s; + + while ((t = strstr(t, "\\n")) != NULL) { + t[0] = '\n'; + t++; + memmove(t, t + 1, strlen(t + 1) + 1); + } + + return s; +} + void * xreallocarray(void *o, size_t n, size_t s) { diff --git a/util.h b/util.h @@ -2,5 +2,6 @@ #define LEN(a) (sizeof(a) / sizeof(*a)) void die(const char *, ...); +char *fix_newlines(char *); void trim(char *); void *xreallocarray(void *, size_t, size_t);