summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--grep.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/grep.c b/grep.c
index 16f80eb..85a6d8f 100644
--- a/grep.c
+++ b/grep.c
@@ -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);