aboutsummaryrefslogtreecommitdiff
path: root/findutils/grep.c
diff options
context:
space:
mode:
authorMark Whitley <markw@lineo.com>2001-05-21 21:13:00 +0000
committerMark Whitley <markw@lineo.com>2001-05-21 21:13:00 +0000
commit1d9d41150bea7e89a881eeee7f71f88ae1fc2381 (patch)
tree3152c5e0e8d07ab5d9be81808700e1db0fc68365 /findutils/grep.c
parent004015e9c4e8ff98bcbaf955cf42147218204da4 (diff)
downloadbusybox-w32-1d9d41150bea7e89a881eeee7f71f88ae1fc2381.tar.gz
busybox-w32-1d9d41150bea7e89a881eeee7f71f88ae1fc2381.tar.bz2
busybox-w32-1d9d41150bea7e89a881eeee7f71f88ae1fc2381.zip
Fixed mishandling of -c & -l options and accounted for case when we're
grepping only one file.
Diffstat (limited to 'findutils/grep.c')
-rw-r--r--findutils/grep.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index a2fff440c..061462ebc 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -104,9 +104,15 @@ static void grep_file(FILE *file)
104 exit(0); 104 exit(0);
105 } 105 }
106 106
107 /* otherwise, keep track of matches and print the matched line */ 107 /* keep track of matches */
108 nmatches++; 108 nmatches++;
109 if (print_match_counts==0 && print_files_with_matches==0) { 109
110 /* if we're just printing filenames, we stop after the first match */
111 if (print_files_with_matches)
112 break;
113
114 /* print the matched line */
115 if (print_match_counts == 0) {
110#ifdef BB_FEATURE_GREP_CONTEXT 116#ifdef BB_FEATURE_GREP_CONTEXT
111 int prevpos = (curpos == 0) ? lines_before - 1 : curpos - 1; 117 int prevpos = (curpos == 0) ? lines_before - 1 : curpos - 1;
112 118
@@ -162,14 +168,17 @@ static void grep_file(FILE *file)
162 168
163 169
164 /* special-case file post-processing for options where we don't print line 170 /* special-case file post-processing for options where we don't print line
165 * matches, just filenames */ 171 * matches, just filenames and possibly match counts */
166 172
167 /* grep -cl or just grep -c: print filename:count, even if count is zero */ 173 /* grep -c: print [filename:]count, even if count is zero */
168 if (print_match_counts) { 174 if (print_match_counts) {
169 printf("%s:%d\n", cur_file, nmatches); 175 if (print_filename)
176 printf("%s:", cur_file);
177 printf("%d\n", nmatches);
170 } 178 }
171 /* just grep -l: print just the filename, but only if we grepped the line in the file */ 179
172 else if (print_files_with_matches && !print_match_counts && nmatches > 0) { 180 /* grep -l: print just the filename, but only if we grepped the line in the file */
181 if (print_files_with_matches && nmatches > 0) {
173 puts(cur_file); 182 puts(cur_file);
174 } 183 }
175 184