From 910294bcb183aa31de761c39f500d21d9448bd67 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 12 Sep 2023 20:59:25 -0700 Subject: New glob* function. The glob* function supports brace expansion, the ** pattern for matching zero or more path components, as well as a sane sort for path names. glob* relies on brace expansion written in Lisp; the ** processing and sorting is done by a glob-compatible C function called super_glob that uses glob. * autoload.c (glob_set_entries, glob_instantiate): New static functions. (autoload_init): Register autoload of stdlib/glob module. * glob.c (GLOB_XNOBRACE, GLOB_XSTAR): New macros. (glob_wrap): Call super_glob instead of glob if GLOB_XSTAR is present in flags. Avoid passing extension flags to glob. (super_glob_find_inner, super_glob_rec, glob_path_cmp, glob_str_cmp, super_glob): New static functions. (glob_init): Register sys:glob-xstar, and glob-xnobrace. sys:glob-xstar is used by glob* to request support for the ** pattern from glob. * stdlib/glob.tl: New file. * tests/018/glob.tl: New file. * txr.1: Documented. --- autoload.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'autoload.c') diff --git a/autoload.c b/autoload.c index 81641d4e..fcc5e014 100644 --- a/autoload.c +++ b/autoload.c @@ -973,6 +973,28 @@ static val csort_instantiate(void) return nil; } +static val glob_set_entries(val fun) +{ + val sys_name[] = { + lit("brace-expand"), + nil + }; + val name[] = { + lit("glob*"), + nil + }; + autoload_sys_set(al_fun, sys_name, fun); + autoload_set(al_fun, name, fun); + return nil; +} + +static val glob_instantiate(void) +{ + load(scat2(stdlib_path, lit("glob"))); + return nil; +} + + val autoload_reg(val (*instantiate)(void), val (*set_entries)(val)) { @@ -1043,6 +1065,7 @@ void autoload_init(void) autoload_reg(expander_let_instantiate, expander_let_set_entries); autoload_reg(load_args_instantiate, load_args_set_entries); autoload_reg(csort_instantiate, csort_set_entries); + autoload_reg(glob_instantiate, glob_set_entries); reg_fun(intern(lit("autoload-try-fun"), system_package), func_n1(autoload_try_fun)); } -- cgit v1.2.3