diff options
author | Mark Whitley <markw@lineo.com> | 2000-07-18 21:02:06 +0000 |
---|---|---|
committer | Mark Whitley <markw@lineo.com> | 2000-07-18 21:02:06 +0000 |
commit | 2ef880b23697b552303ab3dbbdea84569f809ddc (patch) | |
tree | 633d5a24e9f08bc5d5f01457c265ae4234c5d350 /findutils/grep.c | |
parent | a9d69fb5680c28a2f3d68b066e42d6d954d790bf (diff) | |
download | busybox-w32-2ef880b23697b552303ab3dbbdea84569f809ddc.tar.gz busybox-w32-2ef880b23697b552303ab3dbbdea84569f809ddc.tar.bz2 busybox-w32-2ef880b23697b552303ab3dbbdea84569f809ddc.zip |
Consolodated some common code into print_matched_line to make 'grep_file' a
little more terse & clean. Also made a few minor formatting changes.
Diffstat (limited to 'findutils/grep.c')
-rw-r--r-- | findutils/grep.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/findutils/grep.c b/findutils/grep.c index 10ad76c46..2f240e4c2 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -48,6 +48,9 @@ static char *cur_file = NULL; /* the current file we are reading */ | |||
48 | 48 | ||
49 | static void print_matched_line(char *line, int linenum) | 49 | static void print_matched_line(char *line, int linenum) |
50 | { | 50 | { |
51 | if (print_count_only) | ||
52 | return; | ||
53 | |||
51 | if (print_filename) | 54 | if (print_filename) |
52 | printf("%s:", cur_file); | 55 | printf("%s:", cur_file); |
53 | if (print_line_num) | 56 | if (print_line_num) |
@@ -75,16 +78,12 @@ static void grep_file(FILE *file) | |||
75 | } | 78 | } |
76 | 79 | ||
77 | nmatches++; | 80 | nmatches++; |
81 | print_matched_line(line, linenum); | ||
78 | 82 | ||
79 | if (!print_count_only) | 83 | } |
80 | print_matched_line(line, linenum); | 84 | else if (ret == REG_NOMATCH && invert_search) { |
81 | |||
82 | } else if (ret == REG_NOMATCH && invert_search) { | ||
83 | |||
84 | nmatches++; | 85 | nmatches++; |
85 | 86 | print_matched_line(line, linenum); | |
86 | if (!print_count_only) | ||
87 | print_matched_line(line, linenum); | ||
88 | } | 87 | } |
89 | 88 | ||
90 | free(line); | 89 | free(line); |
@@ -161,7 +160,8 @@ extern int grep_main(int argc, char **argv) | |||
161 | * stdin. Otherwise, we grep through all the files specified. */ | 160 | * stdin. Otherwise, we grep through all the files specified. */ |
162 | if (argv[optind+1] == NULL || (strcmp(argv[optind+1], "-") == 0)) { | 161 | if (argv[optind+1] == NULL || (strcmp(argv[optind+1], "-") == 0)) { |
163 | grep_file(stdin); | 162 | grep_file(stdin); |
164 | } else { | 163 | } |
164 | else { | ||
165 | int i; | 165 | int i; |
166 | FILE *file; | 166 | FILE *file; |
167 | for (i = optind + 1; i < argc; i++) { | 167 | for (i = optind + 1; i < argc; i++) { |
@@ -170,7 +170,8 @@ extern int grep_main(int argc, char **argv) | |||
170 | if (file == NULL) { | 170 | if (file == NULL) { |
171 | if (!suppress_err_msgs) | 171 | if (!suppress_err_msgs) |
172 | errorMsg("%s: %s\n", cur_file, strerror(errno)); | 172 | errorMsg("%s: %s\n", cur_file, strerror(errno)); |
173 | } else { | 173 | } |
174 | else { | ||
174 | grep_file(file); | 175 | grep_file(file); |
175 | fclose(file); | 176 | fclose(file); |
176 | } | 177 | } |