grep: fix 'echo aaa | grep -o a' + ENABLE_EXTRA_COMPAT case
authorDenis Vlasenko <vda.linux@googlemail.com>
Tue, 30 Sep 2008 22:37:29 +0000 (22:37 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Tue, 30 Sep 2008 22:37:29 +0000 (22:37 -0000)
 by Natanael Copa

findutils/grep.c

index 9d38ef9128e29bdb5641a7a1b1baba8834bd75f3..73e74f4b38383b00897014c1630bc015fbbaadeb 100644 (file)
@@ -363,12 +363,22 @@ static int grep_file(FILE *file)
                                                 * (unless -v: -Fov doesnt print anything at all) */
                                                if (found)
                                                        print_line(gl->pattern, strlen(gl->pattern), linenum, ':');
-                                       } else {
+                                       } else while (1) {
+                                               char old = line[gl->matched_range.rm_eo];
                                                line[gl->matched_range.rm_eo] = '\0';
                                                print_line(line + gl->matched_range.rm_so,
                                                                gl->matched_range.rm_eo - gl->matched_range.rm_so,
                                                                linenum, ':');
-                                       }
+                                               line[gl->matched_range.rm_eo] = old;
+#if !ENABLE_EXTRA_COMPAT
+                                               break;
+#else
+                                               if (re_search(&gl->compiled_regex, line, line_len,
+                                                               gl->matched_range.rm_eo, line_len - gl->matched_range.rm_eo, 
+                                                               &gl->matched_range) < 0)
+                                                       break;
+#endif
+                                       } 
                                } else {
                                        print_line(line, line_len, linenum, ':');
                                }