busybox-1.7.4-grep.patch 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. diff -urN busybox-1.7.4/findutils/grep.c busybox-1.7.4-grep/findutils/grep.c
  2. --- busybox-1.7.4/findutils/grep.c 2007-09-03 04:48:54.000000000 -0700
  3. +++ busybox-1.7.4-grep/findutils/grep.c 2007-12-08 19:02:33.000000000 -0800
  4. @@ -154,14 +154,14 @@
  5. while ((line = xmalloc_getline(file)) != NULL) {
  6. llist_t *pattern_ptr = pattern_head;
  7. - grep_list_data_t * gl;
  8. + grep_list_data_t *gl = gl; /* for gcc */
  9. linenum++;
  10. ret = 0;
  11. while (pattern_ptr) {
  12. gl = (grep_list_data_t *)pattern_ptr->data;
  13. if (FGREP_FLAG) {
  14. - ret = strstr(line, gl->pattern) != NULL;
  15. + ret |= (strstr(line, gl->pattern) != NULL);
  16. } else {
  17. /*
  18. * test for a postitive-assertion match (regexec returns success (0)
  19. @@ -255,8 +255,15 @@
  20. print_n_lines_after = lines_after;
  21. #endif
  22. if (option_mask32 & OPT_o) {
  23. - line[regmatch.rm_eo] = '\0';
  24. - print_line(line + regmatch.rm_so, linenum, ':');
  25. + if (FGREP_FLAG) {
  26. + /* -Fo just prints the pattern
  27. + * (unless -v: -Fov doesnt print anything at all) */
  28. + if (ret)
  29. + print_line(gl->pattern, linenum, ':');
  30. + } else {
  31. + line[regmatch.rm_eo] = '\0';
  32. + print_line(line + regmatch.rm_so, linenum, ':');
  33. + }
  34. } else {
  35. print_line(line, linenum, ':');
  36. }