diff options
author | Rory Bradford <roryrjb@gmail.com> | 2020-04-14 15:51:46 +0100 |
---|---|---|
committer | Rory Bradford <roryrjb@gmail.com> | 2020-04-14 15:51:46 +0100 |
commit | ed433c3540e3ee1d89f15331688b7d48c063c626 (patch) | |
tree | b8a50fe019bc5116843b1f17b063b2c96c476372 | |
parent | bba4156d518540d2e939b7e5a06102be56505f52 (diff) | |
download | rf-ed433c3540e3ee1d89f15331688b7d48c063c626.tar.gz |
Fix invert logic
Signed-off-by: Rory Bradford <roryrjb@gmail.com>
-rw-r--r-- | rf.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/rf.c b/rf.c index 68d7e59..1bd532a 100644 --- a/rf.c +++ b/rf.c @@ -107,7 +107,7 @@ static int excluded_extension(char *filename) { static void print_result( char *path, struct switches *switches, struct dirent *entry) { - if (switches->basename) { + if (switches->basename && is_child(entry->d_name) != 0) { printf("%s\n", entry->d_name); } else { char full_path[MAXPATHLEN]; @@ -119,7 +119,9 @@ static void print_result( strcat(full_path, entry->d_name); } - printf("%s\n", full_path); + if (is_child(entry->d_name) != 0) { + printf("%s\n", full_path); + } } } @@ -137,7 +139,7 @@ static int recurse_find(char **patterns, int *pattern_count, char *dirname, struct dirent *entry; while ((entry = readdir(dir)) != NULL) { - int matched = 0; + int matched = switches->invert ? 1 : 0; int p = 0; switch (entry->d_type) { @@ -164,14 +166,9 @@ static int recurse_find(char **patterns, int *pattern_count, char *dirname, for (; p < *pattern_count; p++) { char *pattern = patterns[p]; - char *parsed = NULL; if (fnmatch(pattern, entry->d_name, 0) == 0) { - matched = 1; - } - - if (parsed != NULL) { - free(parsed); + matched = switches->invert ? 0 : 1; } } @@ -185,8 +182,7 @@ static int recurse_find(char **patterns, int *pattern_count, char *dirname, return 1; } - if ((matched && (switches->invert == 0)) || - (matched == 0 && (switches->invert == 1))) { + if (matched) { print_result(path, switches, entry); if (switches->limit > 0 && |