summaryrefslogtreecommitdiff
path: root/libguile/load.c
diff options
context:
space:
mode:
authorMark H Weaver <mhw@netris.org>2012-11-28 18:01:35 -0500
committerMark H Weaver <mhw@netris.org>2012-11-28 21:58:05 -0500
commitbd31bce6ac5df7e45d0ec802d9d0738cbc32d9bf (patch)
treef519aaa54e6f7743c9551c8d317c2ea6cf30ab1a /libguile/load.c
parent99b94347f9c93459e2111e9cacbe3632b8041072 (diff)
downloadguile-bd31bce6ac5df7e45d0ec802d9d0738cbc32d9bf.tar.gz
Add parse-path-with-ellipsis, and use it for GUILE_LOAD_PATH et al.
* libguile/load.c (scm_ellipsis): New Variable. (scm_parse_path_with_ellipsis): New procedure. (scm_init_load): Initialize 'scm_ellipsis'. (scm_init_load_path): Use 'scm_parse_path_with_ellipsis' to handle GUILE_LOAD_PATH and GUILE_LOAD_COMPILED_PATH. * libguile/load.h (scm_parse_path_with_ellipsis): Add prototype. * doc/ref/guile-invoke.texi (Environment Variables): doc/ref/api-evaluation.texi (Load Paths): Add documentation. Correct description of default load path to reflect reality. Remove 'GUILE_LOAD_PATH' from the concept index; it is already in the variable index. Add cross references between these two sections of the manual.
Diffstat (limited to 'libguile/load.c')
-rw-r--r--libguile/load.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/libguile/load.c b/libguile/load.c
index af2ca45c7..723f3fdbd 100644
--- a/libguile/load.c
+++ b/libguile/load.c
@@ -221,6 +221,9 @@ static SCM *scm_loc_fresh_auto_compile;
/* The fallback path for auto-compilation */
static SCM *scm_loc_compile_fallback_path;
+/* Ellipsis: "..." */
+static SCM scm_ellipsis;
+
SCM_DEFINE (scm_parse_path, "parse-path", 1, 1, 0,
(SCM path, SCM tail),
"Parse @var{path}, which is expected to be a colon-separated\n"
@@ -243,6 +246,32 @@ SCM_DEFINE (scm_parse_path, "parse-path", 1, 1, 0,
}
#undef FUNC_NAME
+SCM_DEFINE (scm_parse_path_with_ellipsis, "parse-path-with-ellipsis", 2, 0, 0,
+ (SCM path, SCM base),
+ "Parse @var{path}, which is expected to be a colon-separated\n"
+ "string, into a list and return the resulting list with\n"
+ "@var{base} (a list) spliced in place of the @code{...} path\n"
+ "component, if present, or else @var{base} is added to the end.\n"
+ "If @var{path} is @code{#f}, @var{base} is returned.")
+#define FUNC_NAME s_scm_parse_path_with_ellipsis
+{
+ SCM lst = scm_parse_path (path, SCM_EOL);
+ SCM walk = lst;
+ SCM *prev = &lst;
+
+ while (!scm_is_null (walk) &&
+ scm_is_false (scm_equal_p (scm_car (walk), scm_ellipsis)))
+ {
+ prev = SCM_CDRLOC (walk);
+ walk = *prev;
+ }
+ *prev = scm_is_null (walk)
+ ? base
+ : scm_append (scm_list_2 (base, scm_cdr (walk)));
+ return lst;
+}
+#undef FUNC_NAME
+
/* Initialize the global variable %load-path, given the value of the
SCM_SITE_DIR and SCM_LIBRARY_DIR preprocessor symbols and the
@@ -316,11 +345,11 @@ scm_init_load_path ()
env = getenv ("GUILE_LOAD_PATH");
if (env)
- path = scm_parse_path (scm_from_locale_string (env), path);
+ path = scm_parse_path_with_ellipsis (scm_from_locale_string (env), path);
env = getenv ("GUILE_LOAD_COMPILED_PATH");
if (env)
- cpath = scm_parse_path (scm_from_locale_string (env), cpath);
+ cpath = scm_parse_path_with_ellipsis (scm_from_locale_string (env), cpath);
*scm_loc_load_path = path;
*scm_loc_load_compiled_path = cpath;
@@ -1047,6 +1076,8 @@ scm_init_load ()
scm_loc_fresh_auto_compile
= SCM_VARIABLE_LOC (scm_c_define ("%fresh-auto-compile", SCM_BOOL_F));
+ scm_ellipsis = scm_from_latin1_string ("...");
+
the_reader = scm_make_fluid_with_default (SCM_BOOL_F);
scm_c_define("current-reader", the_reader);