Advertisement
danielhilst

0001-diff.c-Add-new-option-only-that-matches.patch

Feb 26th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.76 KB | None | 0 0
  1. From 6f5b9efbd09b44b25cd6bdb23a8593337075a919 Mon Sep 17 00:00:00 2001
  2. From: Daniel Hilst Selli <danielhilst@gmail.com>
  3. Date: Sat, 4 Oct 2014 03:26:01 +0000
  4. Subject: [PATCH] diff.c Add new option --only-that-matches
  5.  
  6. This option is the oposite of --exclude, only files
  7. that match the regex passed to it will be parsed
  8.  
  9. The thread on bug-diffutils: http://lists.gnu.org/archive/html/bug-diffutils/2014-10/msg00000.html
  10. ---
  11. src/diff.c | 15 +++++++++++++++
  12.  src/diff.h |  2 ++
  13.  src/dir.c  |  7 +++++++
  14.  3 files changed, 24 insertions(+)
  15.  
  16. diff --git a/src/diff.c b/src/diff.c
  17. index 397815e..b5992e2 100644
  18. --- a/src/diff.c
  19. +++ b/src/diff.c@
  20. @ -126,6 +126,7 @@ enum
  21.    SUPPRESS_COMMON_LINES_OPTION,
  22.    TABSIZE_OPTION,
  23.    TO_FILE_OPTION,
  24. +  ONLY_THAT_MATCHES_OPTION,
  25.  
  26.    /* These options must be in sequence.  */
  27.    UNCHANGED_LINE_FORMAT_OPTION,
  28. @@ -191,6 +192,7 @@ static struct option const longopts[] =
  29.    {"normal", 0, 0, NORMAL_OPTION},
  30.    {"old-group-format", 1, 0, OLD_GROUP_FORMAT_OPTION},
  31.    {"old-line-format", 1, 0, OLD_LINE_FORMAT_OPTION},
  32. +  {"only-that-matches", 1, 0, ONLY_THAT_MATCHES_OPTION},
  33.    {"paginate", 0, 0, 'l'},
  34.    {"rcs", 0, 0, 'n'},
  35.    {"recursive", 0, 0, 'r'},
  36. @@ -609,6 +611,19 @@ main (int argc, char **argv)
  37.       specify_value (&to_file, optarg, "--to-file");
  38.       break;
  39.  
  40. +        case ONLY_THAT_MATCHES_OPTION:
  41. +          {
  42. +            char regex_error[256];
  43. +            int rc = regcomp(&otm_regex, optarg, REG_NOSUB | REG_EXTENDED);
  44. +            if (rc)
  45. +              {
  46. +                regerror(rc, &otm_regex, regex_error, 256);
  47. +                error(EXIT_TROUBLE, 0, "Can't compile regex %s: %s", optarg, regex_error);
  48. +                abort();
  49. +              }
  50. +          }
  51. +          break;
  52. +
  53.     case UNCHANGED_LINE_FORMAT_OPTION:
  54.     case OLD_LINE_FORMAT_OPTION:
  55.     case NEW_LINE_FORMAT_OPTION:
  56. diff --git a/src/diff.h b/src/diff.h
  57. index e9f0471..5c91bfa 100644
  58. --- a/src/diff.h
  59. +++ b/src/diff.h
  60. @@ -328,6 +328,8 @@ XTERN FILE *outfile;
  61.  
  62.  /* Declare various functions.  */
  63.  
  64. +XTERN regex_t otm_regex;
  65. +
  66.  /* analyze.c */
  67.  extern int diff_2_files (struct comparison *);
  68.  
  69. diff --git a/src/dir.c b/src/dir.c
  70. index d3b0a2d..d6207a8 100644
  71. --- a/src/dir.c
  72. +++ b/src/dir.c
  73. @@ -90,12 +90,19 @@ dir_read (struct file_data const *dir, struct dirdata *dirdata)
  74.     {
  75.       char *d_name = next->d_name;
  76.       size_t d_size = _D_EXACT_NAMLEN (next) + 1;
  77. +          int rmatch;
  78.  
  79.       /* Ignore "." and "..".  */
  80.       if (d_name[0] == '.'
  81.           && (d_name[1] == 0 || (d_name[1] == '.' && d_name[2] == 0)))
  82.         continue;
  83.  
  84. +          rmatch = regexec(&otm_regex, d_name, 0, 0, 0);
  85. +          if (rmatch == REG_NOMATCH)
  86. +            continue;
  87. +          else if (rmatch)
  88. +              fatal("Out of memory while executing regexp");
  89. +
  90.       if (excluded_file_name (excluded, d_name))
  91.         continue;
  92.  
  93. --
  94. 2.1.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement