From a93ca48fd3bad30132dff3df62637a6d8dcf28e2 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 20 Jun 2021 17:10:14 -0700 Subject: glob: support sequence of patterns argument. * glob.c (glob_wrap): Negate the GLOB_WRAP flag should it be present on input. If the input is a string, process it much like before. Otherwise loop over the pattern and call globl multiple times, adding the GLOB_APPEND flag for the second and subsequent times, and breaking out of the loop if a control transfer is detected. * txr.1: Document. --- glob.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'glob.c') diff --git a/glob.c b/glob.c index af72f04e..4044f675 100644 --- a/glob.c +++ b/glob.c @@ -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; -- cgit v1.2.3