From 59e17afe291f9df52d2334b92e88a889c2fe8f6a Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Tue, 11 Jul 2023 13:08:06 +0200 Subject: cftw: Allow user callback to stop recursive search So far, cftw would search through all directories and files recursively, until all objects are processed. However, it is interesting for the user callback to be able to stop this process under specific circumstances. Now, cftw will pass a pointer to a bool, initialised to false by default, that can be optionally assigned to true by the user callback. Future commits will make use of this feature. For example, this will be used to limit the number of search results when a user enters a search term that is too generic and would otherwise generate a large amount of search results. --- main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index b75d556..19178f4 100644 --- a/main.c +++ b/main.c @@ -619,7 +619,7 @@ struct search_args }; static int search_fn(const char *const fpath, const struct stat *const sb, - void *const user) + bool *const done, void *const user) { const struct search_args *const sa = user; const char *rel = fpath + strlen(sa->root); @@ -810,7 +810,7 @@ end: } static int add_length(const char *const fpath, const struct stat *const sb, - void *const user) + bool *const done, void *const user) { if (!S_ISREG(sb->st_mode)) return 0; @@ -1481,7 +1481,7 @@ static const char *find_rm_dir(const struct form *const forms, const size_t n, } static int rm_dir_contents(const char *const fpath, - const struct stat *const sb, void *const user) + const struct stat *const sb, bool *const done, void *const user) { if (S_ISDIR(sb->st_mode) && rmdir(fpath)) { -- cgit v1.2.3