From 1647177908a654f41234e4c457fd17cf4e61d926 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 28 Jan 2024 22:17:34 +0100 Subject: Exit with EXIT_FAILURE if we got no matches --- src/grab.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/grab.c b/src/grab.c index f262451..97c77ef 100644 --- a/src/grab.c +++ b/src/grab.c @@ -94,6 +94,7 @@ static int svposcmp(const void *, const void *); static char *env_or_default(const char *, const char *); static int filecnt, rv; +static bool got_match; static bool bflag, cflag, nflag, iflag, sflag, Uflag, zflag; static bool fflag = GIT_GRAB; static put_func *putf; @@ -260,7 +261,7 @@ main(int argc, char **argv) free(ops.buf); #endif - return rv; + return got_match ? rv : EXIT_FAILURE; } struct ops @@ -593,6 +594,8 @@ putm(struct sv sv, struct matches *ms, const char *filename) struct matches valid; static const char *fn, *hl, *ln, *se; + got_match = true; + if (cflag && !fn) { char *optstr; if ((optstr = env_or_default("GRAB_COLORS", nullptr))) { @@ -743,6 +746,8 @@ putm_nc(struct sv sv, struct matches *ms, const char *filename) { (void)ms; + got_match = true; + if (fflag || filecnt > 1) { char sep = zflag ? '\0' : ':'; printf("%s%c", filename, sep); -- cgit v1.2.3