static void print_matched_line(char *line, int linenum)
{
+ if (print_count_only)
+ return;
+
if (print_filename)
printf("%s:", cur_file);
if (print_line_num)
}
nmatches++;
+ print_matched_line(line, linenum);
- if (!print_count_only)
- print_matched_line(line, linenum);
-
- } else if (ret == REG_NOMATCH && invert_search) {
-
+ }
+ else if (ret == REG_NOMATCH && invert_search) {
nmatches++;
-
- if (!print_count_only)
- print_matched_line(line, linenum);
+ print_matched_line(line, linenum);
}
free(line);
* stdin. Otherwise, we grep through all the files specified. */
if (argv[optind+1] == NULL || (strcmp(argv[optind+1], "-") == 0)) {
grep_file(stdin);
- } else {
+ }
+ else {
int i;
FILE *file;
for (i = optind + 1; i < argc; i++) {
if (file == NULL) {
if (!suppress_err_msgs)
errorMsg("%s: %s\n", cur_file, strerror(errno));
- } else {
+ }
+ else {
grep_file(file);
fclose(file);
}
static void print_matched_line(char *line, int linenum)
{
+ if (print_count_only)
+ return;
+
if (print_filename)
printf("%s:", cur_file);
if (print_line_num)
}
nmatches++;
+ print_matched_line(line, linenum);
- if (!print_count_only)
- print_matched_line(line, linenum);
-
- } else if (ret == REG_NOMATCH && invert_search) {
-
+ }
+ else if (ret == REG_NOMATCH && invert_search) {
nmatches++;
-
- if (!print_count_only)
- print_matched_line(line, linenum);
+ print_matched_line(line, linenum);
}
free(line);
* stdin. Otherwise, we grep through all the files specified. */
if (argv[optind+1] == NULL || (strcmp(argv[optind+1], "-") == 0)) {
grep_file(stdin);
- } else {
+ }
+ else {
int i;
FILE *file;
for (i = optind + 1; i < argc; i++) {
if (file == NULL) {
if (!suppress_err_msgs)
errorMsg("%s: %s\n", cur_file, strerror(errno));
- } else {
+ }
+ else {
grep_file(file);
fclose(file);
}