>From cce91d7062737dd5855c6252fdc75aaa982f6098 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Wed, 1 May 2013 14:20:58 +0200 Subject: [PATCH 1/2] Change test argument to find-files conversion to check for procedure and otherwise pass it to irregex, so that anything accepted by the irregex constructor is also allowed as a test (previously, SRE expressions were not accepted) --- NEWS | 1 + manual/Unit posix | 29 +++++++++++++++-------------- posix-common.scm | 6 +++--- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index d5ac72b..06eec3c 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,7 @@ - write and pp now correctly use escape sequences for control characters (thanks to Florian Zumbiehl) - posix: memory-mapped file support for Windows (thanks to "rivo") + - posix: find-file's test argument now also accepts SRE forms. - Runtime system - Special events in poll() are now handled, avoiding hangs in threaded apps. diff --git a/manual/Unit posix b/manual/Unit posix index 3f59078..fe0e057 100644 --- a/manual/Unit posix +++ b/manual/Unit posix @@ -1239,20 +1239,21 @@ These variables contain error codes as returned by {{errno}}. Recursively traverses the contents of {{DIRECTORY}} (which should be a string) and invokes the procedure {{action}} for all files in which the procedure {{test}} is true. {{test}} may be a procedure of one -argument or a regular-expression string that will be matched with a -full pathname using {{irregex-match}}. {{action}} should be a -procedure of two arguments: the currently encountered file and the -result of the previous invocation of {{action}}, or, if this is the -first invocation, the value of {{seed}}. {{test}} defaults to -{{(constantly #t)}}, {{action}} defaults to {{cons}}, {{seed}} -defaults to {{()}}. {{limit}} should be a procedure of one argument -that is called for each nested directory and which should return true, -if that directory is to be traversed recursively. {{limit}} may also -be an exact integer that gives the maximum recursion depth. For -example, a depth of {{0}} means that only files in the top-level, -specified directory are to be traversed. In this case, all nested -directories are ignored. {{limit}} may also be {{#f}} (the default), -which is equivalent to {{(constantly #t)}}. +argument or an irregex object, regex string or SRE expression that +will be matched with a full pathname using {{irregex-match}}. +{{action}} should be a procedure of two arguments: the currently +encountered file and the result of the previous invocation of +{{action}}, or, if this is the first invocation, the value of +{{seed}}. {{test}} defaults to {{(constantly #t)}}, {{action}} +defaults to {{cons}}, {{seed}} defaults to {{()}}. {{limit}} should +be a procedure of one argument that is called for each nested +directory and which should return true, if that directory is to be +traversed recursively. {{limit}} may also be an exact integer that +gives the maximum recursion depth. For example, a depth of {{0}} means +that only files in the top-level, specified directory are to be +traversed. In this case, all nested directories are ignored. +{{limit}} may also be {{#f}} (the default), which is equivalent to +{{(constantly #t)}}. If {{dotfiles}} is given and true, then files starting with a "{{.}}" character will not be ignored (but note that "{{.}}" and "{{..}}" are diff --git a/posix-common.scm b/posix-common.scm index 1f7c4b3..78669d1 100644 --- a/posix-common.scm +++ b/posix-common.scm @@ -399,10 +399,10 @@ EOF ((fixnum? limit) (lambda _ (fx< depth limit))) (else limit) ) ) (pproc - (if (or (string? pred) (irregex? pred)) + (if (procedure? pred) + pred (let ((pred (irregex pred))) ; force compilation - (lambda (x) (irregex-match pred x))) - pred) ) ) + (lambda (x) (irregex-match pred x))) ) ) ) (let loop ((fs (glob (make-pathname dir (if dot "?*" "*")))) (r id) ) (if (null? fs) -- 1.8.0.1