Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 6f5b9efbd09b44b25cd6bdb23a8593337075a919 Mon Sep 17 00:00:00 2001
- From: Daniel Hilst Selli <danielhilst@gmail.com>
- Date: Sat, 4 Oct 2014 03:26:01 +0000
- Subject: [PATCH] diff.c Add new option --only-that-matches
- This option is the oposite of --exclude, only files
- that match the regex passed to it will be parsed
- ---
- src/diff.c | 15 +++++++++++++++
- src/diff.h | 2 ++
- src/dir.c | 7 +++++++
- 3 files changed, 24 insertions(+)
- diff --git a/src/diff.c b/src/diff.c
- index 397815e..b5992e2 100644
- --- a/src/diff.c
- +++ b/src/diff.c
- @@ -126,6 +126,7 @@ enum
- SUPPRESS_COMMON_LINES_OPTION,
- TABSIZE_OPTION,
- TO_FILE_OPTION,
- + ONLY_THAT_MATCHES_OPTION,
- /* These options must be in sequence. */
- UNCHANGED_LINE_FORMAT_OPTION,
- @@ -191,6 +192,7 @@ static struct option const longopts[] =
- {"normal", 0, 0, NORMAL_OPTION},
- {"old-group-format", 1, 0, OLD_GROUP_FORMAT_OPTION},
- {"old-line-format", 1, 0, OLD_LINE_FORMAT_OPTION},
- + {"only-that-matches", 1, 0, ONLY_THAT_MATCHES_OPTION},
- {"paginate", 0, 0, 'l'},
- {"rcs", 0, 0, 'n'},
- {"recursive", 0, 0, 'r'},
- @@ -609,6 +611,19 @@ main (int argc, char **argv)
- specify_value (&to_file, optarg, "--to-file");
- break;
- + case ONLY_THAT_MATCHES_OPTION:
- + {
- + char regex_error[256];
- + int rc = regcomp(&otm_regex, optarg, REG_NOSUB | REG_EXTENDED);
- + if (rc)
- + {
- + regerror(rc, &otm_regex, regex_error, 256);
- + error(EXIT_TROUBLE, 0, "Can't compile regex %s: %s", optarg, regex_error);
- + abort();
- + }
- + }
- + break;
- +
- case UNCHANGED_LINE_FORMAT_OPTION:
- case OLD_LINE_FORMAT_OPTION:
- case NEW_LINE_FORMAT_OPTION:
- diff --git a/src/diff.h b/src/diff.h
- index e9f0471..5c91bfa 100644
- --- a/src/diff.h
- +++ b/src/diff.h
- @@ -328,6 +328,8 @@ XTERN FILE *outfile;
- /* Declare various functions. */
- +XTERN regex_t otm_regex;
- +
- /* analyze.c */
- extern int diff_2_files (struct comparison *);
- diff --git a/src/dir.c b/src/dir.c
- index d3b0a2d..d6207a8 100644
- --- a/src/dir.c
- +++ b/src/dir.c
- @@ -90,12 +90,19 @@ dir_read (struct file_data const *dir, struct dirdata *dirdata)
- {
- char *d_name = next->d_name;
- size_t d_size = _D_EXACT_NAMLEN (next) + 1;
- + int rmatch;
- /* Ignore "." and "..". */
- if (d_name[0] == '.'
- && (d_name[1] == 0 || (d_name[1] == '.' && d_name[2] == 0)))
- continue;
- + rmatch = regexec(&otm_regex, d_name, 0, 0, 0);
- + if (rmatch == REG_NOMATCH)
- + continue;
- + else if (rmatch)
- + fatal("Out of memory while executing regexp");
- +
- if (excluded_file_name (excluded, d_name))
- continue;
- --
- 2.1.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement