From 51cdc93b40dbebd65b14e931385cb3bd354a8082 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 22 Apr 2016 06:50:55 -0700 Subject: Support list of paths in ftw. * ftw.c (ftw_wrap): Handle case when dirpath is a list, by recursion. * txr.1: Documented. --- ftw.c | 12 ++++++++++++ txr.1 | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/ftw.c b/ftw.c index 6128a652..c906d6a3 100644 --- a/ftw.c +++ b/ftw.c @@ -91,6 +91,18 @@ val ftw_wrap(val dirpath, val fn, val flags_in, val nopenfd_in) if (s_callback) { uw_throwf(error_s, lit("ftw: cannot be re-entered from " "ftw callback"), nao); + } else if (dirpath == nil) { + return t; + } else if (consp(dirpath)) { + uses_or2; + val ret = nil; + for (; dirpath; dirpath = cdr(dirpath)) { + val res = ftw_wrap(car(dirpath), fn, flags_in, nopenfd_in); + if (res != t && res != nil) + return res; + ret = or2(ret, res); + } + return ret; } else { int nopenfd = c_num(default_arg(nopenfd_in, num_fast(20))); int flags = c_num(default_arg(flags_in, zero)); diff --git a/txr.1 b/txr.1 index 5c68b8f6..0384aa82 100644 --- a/txr.1 +++ b/txr.1 @@ -38020,6 +38020,12 @@ defaults to zero, and .meta nopenfd defaults to 20. +Also note that, unlike in the C function, multiple +paths may be processed by passing a list +for the +.meta path +argument. + The .code nftw function walks the filesystem, as directed by the @@ -38102,6 +38108,47 @@ is terminated by a return value from .metn callback-func , then that value is returned. Such a value is always a nonzero integer. +If the +.meta path +passed to +.code ftw +is a list, then all of the paths contained in that +list are walked, as if by recursive application of +.code ftw +to each element of the list taken as the +.meta path +argument, the other argument values being the same. +The traversal stops when any recursive +invocation of +.code ftw +returns a value other than +.codn t +or +.codn nil , +and that value is returned. If +.code t +or +.code nil +is returned, the traversal continues with the +application of +.code ftw +to the next list element, if any. +If the list is completely traversed, and some recursive +invocations of +.code ftw +return +.codn t , +then the return value is +.codn t . +If all recursive invocations return +.code nil +then +.code nil +is returned. +If the list is empty, +.code t +is returned. + The .meta callback-func may terminate the traversal by a nonlocal exit, such as by throwing -- cgit v1.2.3