aboutsummaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2004-05-26 11:47:55 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2004-05-26 11:47:55 +0000
commiteb6a1a28cdc8e1739f18644154f07aabf7a9dd48 (patch)
tree7ec9e4de6a7eda529bc016b74b75074c5aa1639d /findutils
parent38e487b19be34b85991e948c7e9fadc9ba4a6fa5 (diff)
downloadbusybox-w32-eb6a1a28cdc8e1739f18644154f07aabf7a9dd48.tar.gz
busybox-w32-eb6a1a28cdc8e1739f18644154f07aabf7a9dd48.tar.bz2
busybox-w32-eb6a1a28cdc8e1739f18644154f07aabf7a9dd48.zip
Rick Richardson writes:
Here is a patch that adds egrep -L support (the opposite of egrep -l). I realize this is probably too late for 1.0. But I offer it for your future consideration. egrep -L is used in some networking startup scripts I inherited. -Rick git-svn-id: svn://busybox.net/trunk/busybox@8874 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'findutils')
-rw-r--r--findutils/grep.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index 6ece0ab12..4e7e15920 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -34,7 +34,7 @@
34 34
35 35
36/* options */ 36/* options */
37#define GREP_OPTS "lnqvscFiHhe:f:" 37#define GREP_OPTS "lnqvscFiHhe:f:L"
38#define GREP_OPT_l 1 38#define GREP_OPT_l 1
39static char print_files_with_matches; 39static char print_files_with_matches;
40#define GREP_OPT_n 2 40#define GREP_OPT_n 2
@@ -55,15 +55,17 @@ static char fgrep_flag;
55#define GREP_OPT_h 512 55#define GREP_OPT_h 512
56#define GREP_OPT_e 1024 56#define GREP_OPT_e 1024
57#define GREP_OPT_f 2048 57#define GREP_OPT_f 2048
58#define GREP_OPT_L 4096
59static char print_files_without_matches;
58#ifdef CONFIG_FEATURE_GREP_CONTEXT 60#ifdef CONFIG_FEATURE_GREP_CONTEXT
59#define GREP_OPT_CONTEXT "A:B:C" 61#define GREP_OPT_CONTEXT "A:B:C"
60#define GREP_OPT_A 4096 62#define GREP_OPT_A 8192
61#define GREP_OPT_B 8192 63#define GREP_OPT_B 16384
62#define GREP_OPT_C 16384 64#define GREP_OPT_C 32768
63#define GREP_OPT_E 32768U 65#define GREP_OPT_E 65536
64#else 66#else
65#define GREP_OPT_CONTEXT "" 67#define GREP_OPT_CONTEXT ""
66#define GREP_OPT_E 4096 68#define GREP_OPT_E 8192
67#endif 69#endif
68#ifdef CONFIG_FEATURE_GREP_EGREP_ALIAS 70#ifdef CONFIG_FEATURE_GREP_EGREP_ALIAS
69# define OPT_EGREP "E" 71# define OPT_EGREP "E"
@@ -147,7 +149,7 @@ static int grep_file(FILE *file)
147 free(line); 149 free(line);
148 150
149 /* if we found a match but were told to be quiet, stop here */ 151 /* if we found a match but were told to be quiet, stop here */
150 if (be_quiet) 152 if (be_quiet || print_files_without_matches)
151 return -1; 153 return -1;
152 154
153 /* keep track of matches */ 155 /* keep track of matches */
@@ -227,6 +229,11 @@ static int grep_file(FILE *file)
227 puts(cur_file); 229 puts(cur_file);
228 } 230 }
229 231
232 /* grep -L: print just the filename, but only if we didn't grep the line in the file */
233 if (print_files_without_matches && nmatches == 0) {
234 puts(cur_file);
235 }
236
230 return nmatches; 237 return nmatches;
231} 238}
232 239
@@ -290,7 +297,7 @@ extern int grep_main(int argc, char **argv)
290 bb_error_msg_and_die("invalid context length argument"); 297 bb_error_msg_and_die("invalid context length argument");
291 } 298 }
292 /* sanity checks after parse may be invalid numbers ;-) */ 299 /* sanity checks after parse may be invalid numbers ;-) */
293 if ((opt & (GREP_OPT_c|GREP_OPT_q|GREP_OPT_l))) { 300 if ((opt & (GREP_OPT_c|GREP_OPT_q|GREP_OPT_l|GREP_OPT_L))) {
294 opt &= ~GREP_OPT_n; 301 opt &= ~GREP_OPT_n;
295 lines_before = 0; 302 lines_before = 0;
296 lines_after = 0; 303 lines_after = 0;
@@ -305,6 +312,7 @@ extern int grep_main(int argc, char **argv)
305 312
306#endif 313#endif
307 print_files_with_matches = opt & GREP_OPT_l; 314 print_files_with_matches = opt & GREP_OPT_l;
315 print_files_without_matches = (opt & GREP_OPT_L) != 0;
308 print_line_num = opt & GREP_OPT_n; 316 print_line_num = opt & GREP_OPT_n;
309 be_quiet = opt & GREP_OPT_q; 317 be_quiet = opt & GREP_OPT_q;
310 invert_search = (opt & GREP_OPT_v) != 0; /* 0 | 1 */ 318 invert_search = (opt & GREP_OPT_v) != 0; /* 0 | 1 */