diff options
-rw-r--r-- | glob.c | 27 | ||||
-rw-r--r-- | txr.1 | 38 |
2 files changed, 53 insertions, 12 deletions
@@ -68,21 +68,36 @@ val glob_wrap(val pattern, val flags, val errfun) { val self = lit("glob"); cnum c_flags = c_num(default_arg(flags, zero), self); - char *pat_u8 = utf8_dup_to(c_str(pattern)); glob_t gl; - if (s_errfunc) { - free(pat_u8); + if (s_errfunc) uw_throwf(error_s, lit("~a: glob cannot be re-entered from " "its error callback function"), self, nao); - } s_errfunc = default_null_arg(errfun); - (void) glob(pat_u8, c_flags, s_errfunc ? errfunc_thunk : 0, &gl); + c_flags &= ~GLOB_APPEND; + + if (stringp(pattern)) { + char *pat_u8 = utf8_dup_to(c_str(pattern)); + (void) glob(pat_u8, c_flags, s_errfunc ? errfunc_thunk : 0, &gl); + free(pat_u8); + } else { + seq_iter_t iter; + val elem; + seq_iter_init(self, &iter, pattern); + + while (seq_get(&iter, &elem)) { + char *pat_u8 = utf8_dup_to(c_str(elem)); + (void) glob(pat_u8, c_flags, s_errfunc ? errfunc_thunk : 0, &gl); + if (s_exit_point) + break; + c_flags |= GLOB_APPEND; + free(pat_u8); + } + } s_errfunc = nil; - free(pat_u8); if (s_exit_point) { uw_frame_t *ep = s_exit_point; @@ -68125,19 +68125,29 @@ variables may not be available. They are extensions in the GNU C library implementation of .codn glob . +The standard +.code GLOB_APPEND +flag is not represented as a \*(TX variable. The +.code glob +function uses it internally when calling the C library function +multiple times, due to having been given multiple patterns. + .coNP Function @ glob .synb -.mets (glob < pattern >> [ flags <> [ errfun ]]) +.mets (glob >> { pattern | << patterns } >> [ flags <> [ errfun ]]) .syne .desc The .code glob function is a interface to the Unix function of the same name. -The -.meta pattern -argument must be a string, which holds a glob pattern: a pattern which +The first argument must either be a single +.metn pattern , +which is a string, or else sequence of strings specifying multiple +.metn patterns , +which are strings. +Each string is a glob pattern: a pattern which matches zero or more pathnames, similar to a regular expression. -The function tries to expand the pattern and return a list of strings +The function tries to expand the patterns and return a list of strings representing the matching pathnames in the file system. If there are no matches, then an empty list is returned. @@ -68149,7 +68159,8 @@ values of the variables .codn glob-err , .codn glob-mark , .code glob-nosort -and others. +and others. The +.code glob-append If the .meta errfun @@ -68183,6 +68194,21 @@ which surrounds the .code glob call. Such an attempt is detected and diagnosed by an exception. +If a sequence of +.meta patterns +is specified instead of a single pattern, +.code glob +makes multiple calls to the underlying C library function. The +second and subsequent calls specify the +.code GLOB_APPEND +flag to add the matches to the result. The following equivalence applies: + +.verb + (glob (list p0 p1 ...) f e) <--> (append (glob p0 f e) + (glob p1 f e) + ...) +.brev + Details of the semantics of the .code glob function, and the meaning of all the |