summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/vind.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/vind.c b/src/vind.c
index 5e5ba90..098e12c 100644
--- a/src/vind.c
+++ b/src/vind.c
@@ -1,6 +1,7 @@
#include <assert.h>
#include <ftw.h>
#include <getopt.h>
+#include <fnmatch.h>
#include <limits.h>
#include <pwd.h>
#include <stdbool.h>
@@ -18,6 +19,8 @@ static int max_depth = -1;
static ssize_t min_size = 0;
static ssize_t max_size = SSIZE_MAX;
+static char *nameglob = NULL;
+
static void usage(FILE *f) {
fprintf(f,
"Gebruik: vind [-thV] [STARTPUNTEN]...\n"
@@ -27,6 +30,7 @@ static void usage(FILE *f) {
" -t Bestandtypes om weer te geven, kan zijn b(estand), m(apje) of een combinatie gescheiden door komma's\n"
" -d Maximale diepte\n"
" -o Omvang van n beten (+, - voor meer of minder)\n"
+ " -n Filter bestanden die voldoen aan het gegeven klodder-gebasseerde draadje\n"
" -h Toon deze hulptekst\n"
" -V Toon versienummer\n");
}
@@ -56,7 +60,7 @@ static int parse_filetypes(char *s) {
// Returns pointer to argument array containing the starting points
static char** parse_options(int argc, char **argv) {
int opt;
- while ((opt = getopt(argc, argv, "t:d:o:hV")) != -1) {
+ while ((opt = getopt(argc, argv, "t:d:o:n:hV")) != -1) {
switch (opt) {
case 't':
ftmap = parse_filetypes(optarg);
@@ -76,6 +80,10 @@ static char** parse_options(int argc, char **argv) {
}
break;
+ case 'n':
+ nameglob = optarg;
+ break;
+
case 'h':
usage(stdout);
exit(0);
@@ -115,6 +123,9 @@ static int f(const char *fpath, const struct stat *sb, int typeflag, struct FTW
if (sb->st_size < min_size) return 0;
if (sb->st_size > max_size) return 0;
+ // check filename
+ if (!(nameglob == NULL || fnmatch(nameglob, basename(fpath), 0) == 0)) return 0;
+
puts(fpath);
return 0;
}