summaryrefslogtreecommitdiffstats
path: root/txr.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-04-25 00:14:23 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-04-25 00:14:23 -0700
commite3a06759eebdc2b4e2d0b8d08cb64eb99a40d3e3 (patch)
treef9a7c20e14a49a92a156a1f9a652cc18fd1e1e45 /txr.c
parentec69fdce7fae00a34d0ae88dae388705fedc1f8f (diff)
downloadtxr-e3a06759eebdc2b4e2d0b8d08cb64eb99a40d3e3.tar.gz
txr-e3a06759eebdc2b4e2d0b8d08cb64eb99a40d3e3.tar.bz2
txr-e3a06759eebdc2b4e2d0b8d08cb64eb99a40d3e3.zip
New: load can search multiple directories.
* eval.c (load_search_dirs_s): New symbol variable. (load): Initialize the name variable whose address is passed as the third argument of open_txr_file, which is now an in-out parameter. Pass t for the new search_dirs parameter, so that load benefits from the searching. (eval_init): Initialize load_search_dirs_s and register the *load-search-dirs* special variable. * eval.h (load_search_dirs_s): Declared. (load_search_dirs): New macro. * match.c (v_load): Initialize the variable passed as third argument of open_txr_file. * parser.c (open_txr_file): Take a new argument, search_dirs. If this is t, it tells the function "if the path is not found, then recurse on the *load-search-dirs* variable. Otherwise, if the value is not t, it is a list of the remaining directories to try. The existing parameter orig_in_resolved_out must now point to a location which is initialized. It is assumed to hold the original target that was passed to the load function. The first_try_path is a the path to actually try, derived from that one. Thus, the caller of open_txr_file gets to determine the initial try path using its own algorithm. Then any recursive calls that go through *load-search-dirs* will pass a first argument which is made of the original name, combined with a search dir. (load_rcfile): Pass pointer to initialized location as third argument of open-txr_file, and pass a nil value for search_dirs: no search takes place when looking for that file, which is at a single, fixed location. * parser.h (open_txr_file): Declaration updated. * txr.c (sysroot_init): Initialize *load-search-dirs*. (txr_main): Ensure third argument in all calls to open_txr_file points to initialized variable, with the correct value, and pass t for the search_dirs argument. * txr.1: Documented. * stdlib/doc-syms.tl: Updated. New: load can search multiple directories. * eval.c (load_search_dirs_s): New symbol variable. (load): Initialize the name variable whose address is passed as the third argument of open_txr_file, which is now an in-out parameter. Pass t for the new search_dirs parameter, so that load benefits from the searching. (eval_init): Initialize load_search_dirs_s and register the *load-search-dirs* special variable. * eval.h (load_search_dirs_s): Declared. (load_search_dirs): New macro. * match.c (v_load): Initialize the variable passed as third * argument of open_txr_file. * parser.c (open_txr_file): Take a new argument, search_dirs. If this is t, it tells the function "if the path is not found, then recurse on the *load-search-dirs* variable. Otherwise, if the value is not t, it is a list of the remaining directories to try. The existing parameter orig_in_resolved_out must now point to a location which is initialized. It is assumed to hold the original target that was passed to the load function. The first_try_path is a the path to actually try, derived from that one. Thus, the caller of open_txr_file gets to determine the initial try path using its own algorithm. Then any recursive calls that go through *load-search-dirs* will pass a first argument which is made of the original name, combined with a search dir. (load_rcfile): Pass pointer to initialized location as third argument of open-txr_file, and pass a nil value for search_dirs: no search takes place when looking for that file, which is at a single, fixed location. * parser.h (open_txr_file): Declaration updated. * txr.c (sysroot_init): Initialize *load-search-dirs*. (txr_main): Ensure third argument in all calls to open_txr_file points to initialized variable, with the correct value, and pass t for the search_dirs argument. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
Diffstat (limited to 'txr.c')
-rw-r--r--txr.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/txr.c b/txr.c
index df3f9b14..0af94623 100644
--- a/txr.c
+++ b/txr.c
@@ -345,6 +345,14 @@ static void sysroot_init(void)
lit("share/txr/stdlib/"),
lit("stdlib/")));
+ {
+ loc lsd = lookup_var_l(nil, load_search_dirs_s);
+ set(lsd, cons(sysroot(if3(share_txr_stdlib,
+ lit("share/txr/lib/"),
+ lit("lib/"))),
+ nil));
+ }
+
reg_varl(intern(lit("stdlib"), user_package), stdlib_path);
reg_varl(intern(lit("*txr-version*"), user_package),
toint(lit(TXR_VER), nil));
@@ -599,7 +607,7 @@ int txr_main(int argc, char **argv)
if (car(arg) != chr('-')) {
if (!parse_stream) {
spec_file_str = arg;
- open_txr_file(arg, &txr_lisp_p, &spec_file_str, &parse_stream, self);
+ open_txr_file(arg, &txr_lisp_p, &spec_file_str, &parse_stream, t, self);
simulate_setuid_setgid(parse_stream);
dyn_env = make_env(nil, nil, dyn_env);
env_vbind(dyn_env, load_path_s, spec_file_str);
@@ -968,8 +976,9 @@ int txr_main(int argc, char **argv)
return EXIT_FAILURE;
}
if (wcscmp(c_str(spec_file, self), L"-") != 0) {
+ spec_file_str = spec_file;
open_txr_file(spec_file, &txr_lisp_p, &spec_file_str,
- &parse_stream, self);
+ &parse_stream, t, self);
simulate_setuid_setgid(parse_stream);
dyn_env = make_env(nil, nil, dyn_env);
env_vbind(dyn_env, load_path_s, spec_file_str);