From ce356e22db97a05982f3b8beacf22cc6d479f933 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 21 Jan 2024 04:00:09 +0100 Subject: Move common code out into islbrk() --- src/grab.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/grab.c b/src/grab.c index 738d7c6..38ce94f 100644 --- a/src/grab.c +++ b/src/grab.c @@ -71,17 +71,17 @@ static void cmdy(struct sv, struct ops, size_t, const char *); static void putm(struct sv, regmatch_t *, const char *); static void putm_nc(struct sv, regmatch_t *, const char *); -static void grab(struct ops, FILE *, const char *); -static bool sgrvalid(const char *); -static regex_t mkregex(char *, size_t); -static struct ops comppat(char *); -static char *env_or_default(const char *, const char *); #if GIT_GRAB static FILE *getfstream(int n, char *v[n]); #endif - +static void grab(struct ops, FILE *, const char *); +static struct ops comppat(char *); +static regex_t mkregex(char *, size_t); +static bool islbrk(struct u8view); +static bool sgrvalid(const char *); static bool xisspace(char); static char *xstrchrnul(const char *, char); +static char *env_or_default(const char *, const char *); static int filecnt, rv; static bool bflag, cflag, nflag, sflag, Uflag, zflag; @@ -499,7 +499,7 @@ putm(struct sv sv, regmatch_t *rm, const char *filename) len = (char8_t *)sv.p - pos.p; while (u8gnext(&v, &pos.p, &len)) { - if (*v.p == '\n' || memeq(v.p, "\r\n", 2)) { + if (islbrk(v)) { pos.col = 1; pos.row++; } else @@ -552,7 +552,7 @@ putm_nc(struct sv sv, regmatch_t *rm, const char *filename) len = (char8_t *)sv.p - pos.p; while (u8gnext(&v, &pos.p, &len)) { - if (*v.p == '\n' || memeq(v.p, "\r\n", 2)) { + if (islbrk(v)) { pos.col = 1; pos.row++; } else @@ -567,6 +567,12 @@ putm_nc(struct sv sv, regmatch_t *rm, const char *filename) putchar(zflag ? '\0' : '\n'); } +bool +islbrk(struct u8view v) +{ + return *v.p == '\n' || (v.len == 2 && memeq(v.p, "\r\n", 2)); +} + bool sgrvalid(const char *s) { -- cgit v1.2.3