diff options
| author | Jakob Kaivo <jkk@ung.org> | 2022-04-21 09:32:15 -0400 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2022-04-21 09:32:15 -0400 |
| commit | a2d6323436f4d80fbd3f7d80b7d839ba247076a2 (patch) | |
| tree | c5991bf8e5f70181a03d18dfcc86a3da6f0da740 | |
| parent | 7865aed19c65e11c98e6b8174c9e27dbeb8f67ab (diff) | |
fix return value when -q is specified
| -rw-r--r-- | grep.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -39,14 +39,12 @@ struct grep_list { regex_t re; }; -enum { NORMAL, COUNT, LIST, QUIET } grep_display = NORMAL; +static enum { NORMAL, COUNT, LIST, QUIET } grep_display = NORMAL; static int grep_filenames = 0; static int grep_linenumbers = 0; static int grep_inverse = 0; static int grep_silent = 0; - -#define WHOLELINE 1 << 4 -#define FILENAMES 1 << 5 +static int grep_exact = 0; static int grep_match(struct grep_list *head, const char *buf) { @@ -75,6 +73,9 @@ static uintmax_t grep(struct grep_list *head, const char *path) if (!grep_silent || (errno != ENOENT && errno != EPERM)) { fprintf(stderr, "grep: %s: %s\n", path, strerror(errno)); } + if (grep_display == QUIET) { + return 1; + } return 2; } } @@ -222,7 +223,7 @@ int main(int argc, char *argv[]) break; case 'x': - //flags |= WHOLELINE; + grep_exact = 1; break; default: @@ -259,8 +260,11 @@ int main(int argc, char *argv[]) int ret = 1; do { int r = grep(head, argv[optind++]); - if (r != 1) { - ret = r; + if (r == 2) { + ret = 2; + } + if (r == 0 && ret == 1) { + ret = 0; } } while (optind < argc); |
