From bf8990a43e8374d98d37590f2a07c09c514a7127 Mon Sep 17 00:00:00 2001 From: Lieuwe Rooijakkers Date: Sun, 18 Aug 2024 23:04:12 +0200 Subject: vind: glob searching --- src/vind.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 #include #include +#include #include #include #include @@ -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; } -- cgit v1.2.3-70-g09d2