diff options
| -rw-r--r-- | grep.c | 27 |
1 files changed, 12 insertions, 15 deletions
@@ -43,8 +43,8 @@ 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 SUPPRESS 1 << 2 #define WHOLELINE 1 << 4 #define FILENAMES 1 << 5 @@ -66,18 +66,16 @@ static int grep_match(struct grep_list *head, const char *buf) return grep_inverse; } -static uintmax_t grep(struct grep_list *head, const char *path, int flags) +static uintmax_t grep(struct grep_list *head, const char *path) { - (void)flags; - FILE *f = stdin; if (path && strcmp(path, "-")) { f = fopen(path, "r"); if (f == NULL) { - if (/*!suppress ||*/ (errno != ENOENT && errno != EPERM)) { + if (!grep_silent || (errno != ENOENT && errno != EPERM)) { fprintf(stderr, "grep: %s: %s\n", path, strerror(errno)); } - return 0; + return 2; } } @@ -118,7 +116,7 @@ static uintmax_t grep(struct grep_list *head, const char *path, int flags) printf("%s\n", path); } - return found; + return found == 0; } static struct grep_list * grep_add_list(struct grep_list *head, char *s) @@ -216,7 +214,7 @@ int main(int argc, char *argv[]) break; case 's': - //flags |= SUPPRESS; + grep_silent = 1; break; case 'v': @@ -258,14 +256,13 @@ int main(int argc, char *argv[]) grep_filenames = (argc > optind + 1); - uintmax_t found = 0; + int ret = 1; do { - found += grep(head, argv[optind++], flags); + int r = grep(head, argv[optind++]); + if (r != 1) { + ret = r; + } } while (optind < argc); - if (found) { - return 0; - } - - return 1; + return ret; } |
