summaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>1999-12-21 08:52:04 +0000
committerErik Andersen <andersen@codepoet.org>1999-12-21 08:52:04 +0000
commit3fe2ecf0d92b5ff8984513d0a99f6152b61ea998 (patch)
treec5847668267623f203b11efe5553ec8169d59ae9 /grep.c
parentd387d01f11c3b9438322c951cd1eac8f29ea6afc (diff)
downloadbusybox-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
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/grep.c b/grep.c
index 84bb99667..a0457df91 100644
--- a/grep.c
+++ b/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
56static int match = FALSE, beQuiet = FALSE;
47 57
48static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine) 58static 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