diff options
| author | Erik Andersen <andersen@codepoet.org> | 1999-12-21 08:52:04 +0000 |
|---|---|---|
| committer | Erik Andersen <andersen@codepoet.org> | 1999-12-21 08:52:04 +0000 |
| commit | 3fe2ecf0d92b5ff8984513d0a99f6152b61ea998 (patch) | |
| tree | c5847668267623f203b11efe5553ec8169d59ae9 | |
| parent | d387d01f11c3b9438322c951cd1eac8f29ea6afc (diff) | |
| download | busybox-w32-3fe2ecf0d92b5ff8984513d0a99f6152b61ea998.tar.gz busybox-w32-3fe2ecf0d92b5ff8984513d0a99f6152b61ea998.tar.bz2 busybox-w32-3fe2ecf0d92b5ff8984513d0a99f6152b61ea998.zip | |
Added grep -q, thanks to a patch from "Konstantin Boldyshev" <konst@voshod.com>
-Erik
| -rw-r--r-- | Changelog | 2 | ||||
| -rw-r--r-- | findutils/grep.c | 23 | ||||
| -rw-r--r-- | grep.c | 23 |
3 files changed, 42 insertions, 6 deletions
| @@ -7,6 +7,8 @@ | |||
| 7 | * Fixed the embarrasing failure of the -p opition in the logger app. -erik | 7 | * Fixed the embarrasing failure of the -p opition in the logger app. -erik |
| 8 | * Re-worked the whole source tree a bit so it will compile under glibc 2.0.7 | 8 | * Re-worked the whole source tree a bit so it will compile under glibc 2.0.7 |
| 9 | with the 2.0.x Linux kernel. | 9 | with the 2.0.x Linux kernel. |
| 10 | * Added 'grep -q' thanks to a patch from "Konstantin Boldyshev" | ||
| 11 | <konst@voshod.com>. | ||
| 10 | 12 | ||
| 11 | -Erik Andersen | 13 | -Erik Andersen |
| 12 | 14 | ||
diff --git a/findutils/grep.c b/findutils/grep.c index 84bb99667..a0457df91 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
| @@ -21,6 +21,14 @@ | |||
| 21 | * | 21 | * |
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | /* | ||
| 25 | 18-Dec-1999 Konstantin Boldyshev <konst@voshod.com> | ||
| 26 | |||
| 27 | + -q option (be quiet) | ||
| 28 | + exit code depending on grep result (TRUE or FALSE) | ||
| 29 | (useful for scripts) | ||
| 30 | */ | ||
| 31 | |||
| 24 | #include "internal.h" | 32 | #include "internal.h" |
| 25 | #include "regexp.h" | 33 | #include "regexp.h" |
| 26 | #include <stdio.h> | 34 | #include <stdio.h> |
| @@ -37,13 +45,15 @@ static const char grep_usage[] = | |||
| 37 | "OPTIONS:\n" | 45 | "OPTIONS:\n" |
| 38 | "\t-h\tsuppress the prefixing filename on output\n" | 46 | "\t-h\tsuppress the prefixing filename on output\n" |
| 39 | "\t-i\tignore case distinctions\n" | 47 | "\t-i\tignore case distinctions\n" |
| 40 | "\t-n\tprint line number with output lines\n\n" | 48 | "\t-n\tprint line number with output lines\n" |
| 49 | "\t-q\tbe quiet\n\n" | ||
| 41 | #if defined BB_REGEXP | 50 | #if defined BB_REGEXP |
| 42 | "This version of grep matches full regular expresions.\n"; | 51 | "This version of grep matches full regular expresions.\n"; |
| 43 | #else | 52 | #else |
| 44 | "This version of grep matches strings (not regular expresions).\n"; | 53 | "This version of grep matches strings (not regular expresions).\n"; |
| 45 | #endif | 54 | #endif |
| 46 | 55 | ||
| 56 | static int match = FALSE, beQuiet = FALSE; | ||
| 47 | 57 | ||
| 48 | static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine) | 58 | static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine) |
| 49 | { | 59 | { |
| @@ -65,7 +75,10 @@ static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ig | |||
| 65 | if (tellLine==TRUE) | 75 | if (tellLine==TRUE) |
| 66 | printf ("%ld:", line); | 76 | printf ("%ld:", line); |
| 67 | 77 | ||
| 68 | fputs (haystack, stdout); | 78 | if (beQuiet==FALSE) |
| 79 | fputs (haystack, stdout); | ||
| 80 | |||
| 81 | match = TRUE; | ||
| 69 | } | 82 | } |
| 70 | } | 83 | } |
| 71 | } | 84 | } |
| @@ -109,6 +122,10 @@ extern int grep_main (int argc, char **argv) | |||
| 109 | tellLine = TRUE; | 122 | tellLine = TRUE; |
| 110 | break; | 123 | break; |
| 111 | 124 | ||
| 125 | case 'q': | ||
| 126 | beQuiet = TRUE; | ||
| 127 | break; | ||
| 128 | |||
| 112 | default: | 129 | default: |
| 113 | usage(grep_usage); | 130 | usage(grep_usage); |
| 114 | } | 131 | } |
| @@ -136,7 +153,7 @@ extern int grep_main (int argc, char **argv) | |||
| 136 | fclose (fp); | 153 | fclose (fp); |
| 137 | } | 154 | } |
| 138 | } | 155 | } |
| 139 | exit( TRUE); | 156 | exit(match); |
| 140 | } | 157 | } |
| 141 | 158 | ||
| 142 | 159 | ||
| @@ -21,6 +21,14 @@ | |||
| 21 | * | 21 | * |
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | /* | ||
| 25 | 18-Dec-1999 Konstantin Boldyshev <konst@voshod.com> | ||
| 26 | |||
| 27 | + -q option (be quiet) | ||
| 28 | + exit code depending on grep result (TRUE or FALSE) | ||
| 29 | (useful for scripts) | ||
| 30 | */ | ||
| 31 | |||
| 24 | #include "internal.h" | 32 | #include "internal.h" |
| 25 | #include "regexp.h" | 33 | #include "regexp.h" |
| 26 | #include <stdio.h> | 34 | #include <stdio.h> |
| @@ -37,13 +45,15 @@ static const char grep_usage[] = | |||
| 37 | "OPTIONS:\n" | 45 | "OPTIONS:\n" |
| 38 | "\t-h\tsuppress the prefixing filename on output\n" | 46 | "\t-h\tsuppress the prefixing filename on output\n" |
| 39 | "\t-i\tignore case distinctions\n" | 47 | "\t-i\tignore case distinctions\n" |
| 40 | "\t-n\tprint line number with output lines\n\n" | 48 | "\t-n\tprint line number with output lines\n" |
| 49 | "\t-q\tbe quiet\n\n" | ||
| 41 | #if defined BB_REGEXP | 50 | #if defined BB_REGEXP |
| 42 | "This version of grep matches full regular expresions.\n"; | 51 | "This version of grep matches full regular expresions.\n"; |
| 43 | #else | 52 | #else |
| 44 | "This version of grep matches strings (not regular expresions).\n"; | 53 | "This version of grep matches strings (not regular expresions).\n"; |
| 45 | #endif | 54 | #endif |
| 46 | 55 | ||
| 56 | static int match = FALSE, beQuiet = FALSE; | ||
| 47 | 57 | ||
| 48 | static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine) | 58 | static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine) |
| 49 | { | 59 | { |
| @@ -65,7 +75,10 @@ static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ig | |||
| 65 | if (tellLine==TRUE) | 75 | if (tellLine==TRUE) |
| 66 | printf ("%ld:", line); | 76 | printf ("%ld:", line); |
| 67 | 77 | ||
| 68 | fputs (haystack, stdout); | 78 | if (beQuiet==FALSE) |
| 79 | fputs (haystack, stdout); | ||
| 80 | |||
| 81 | match = TRUE; | ||
| 69 | } | 82 | } |
| 70 | } | 83 | } |
| 71 | } | 84 | } |
| @@ -109,6 +122,10 @@ extern int grep_main (int argc, char **argv) | |||
| 109 | tellLine = TRUE; | 122 | tellLine = TRUE; |
| 110 | break; | 123 | break; |
| 111 | 124 | ||
| 125 | case 'q': | ||
| 126 | beQuiet = TRUE; | ||
| 127 | break; | ||
| 128 | |||
| 112 | default: | 129 | default: |
| 113 | usage(grep_usage); | 130 | usage(grep_usage); |
| 114 | } | 131 | } |
| @@ -136,7 +153,7 @@ extern int grep_main (int argc, char **argv) | |||
| 136 | fclose (fp); | 153 | fclose (fp); |
| 137 | } | 154 | } |
| 138 | } | 155 | } |
| 139 | exit( TRUE); | 156 | exit(match); |
| 140 | } | 157 | } |
| 141 | 158 | ||
| 142 | 159 | ||
