[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Add parse-path-with-ellipsis, and use it for GUILE_LOAD_PATH et
From: |
Mark H Weaver |
Subject: |
[PATCH] Add parse-path-with-ellipsis, and use it for GUILE_LOAD_PATH et al |
Date: |
Wed, 28 Nov 2012 18:12:41 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) |
Hi Ludovic,
address@hidden (Ludovic Courtès) writes:
> I pretty much like Mark’s suggestion of using ‘...’ as a special marker,
> even though that’s a valid file name.
Here's a patch to implement the "..." special marker.
It would be good to have this in 2.0.7.
What do you think?
Mark
>From 4a78f4a638334a5bd8eb08308891b541bbde9b1e Mon Sep 17 00:00:00 2001
From: Mark H Weaver <address@hidden>
Date: Wed, 28 Nov 2012 18:01:35 -0500
Subject: [PATCH] Add parse-path-with-ellipsis, and use it for GUILE_LOAD_PATH
et al.
* libguile/load.c (scm_parse_path_with_ellipsis): New procedure.
(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/api-evaluation.texi (Load Paths): Add docs.
---
doc/ref/api-evaluation.texi | 9 +++++++++
libguile/load.c | 31 +++++++++++++++++++++++++++++--
libguile/load.h | 1 +
3 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/doc/ref/api-evaluation.texi b/doc/ref/api-evaluation.texi
index 37e41e1..6a442c7 100644
--- a/doc/ref/api-evaluation.texi
+++ b/doc/ref/api-evaluation.texi
@@ -943,6 +943,15 @@ a list and return the resulting list with @var{tail}
appended. If
@var{path} is @code{#f}, @var{tail} is returned.
@end deffn
address@hidden {Scheme Procedure} parse-path-with-ellipsis path base
address@hidden {C Function} scm_parse_path_with_ellipsis (path, base)
+Parse @var{path}, which is expected to be a colon-separated string, into
+a list and return the resulting list with @var{base} (a list) spliced in
+place of the @code{...} path component, if present, or else @var{base}
+is added to the end. If @var{path} is @code{#f}, @var{base} is
+returned.
address@hidden deffn
+
@deffn {Scheme Procedure} search-path path filename [extensions
[require-exts?]]
@deffnx {C Function} scm_search_path (path, filename, rest)
Search @var{path} for a directory containing a file named
diff --git a/libguile/load.c b/libguile/load.c
index af2ca45..76bbd83 100644
--- a/libguile/load.c
+++ b/libguile/load.c
@@ -243,6 +243,33 @@ 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 ellipsis = scm_from_latin1_string ("...");
+ 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), 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 +343,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;
diff --git a/libguile/load.h b/libguile/load.h
index 0bddac2..698bbaf 100644
--- a/libguile/load.h
+++ b/libguile/load.h
@@ -27,6 +27,7 @@
SCM_API SCM scm_parse_path (SCM path, SCM tail);
+SCM_API SCM scm_parse_path_with_ellipsis (SCM path, SCM base);
SCM_API SCM scm_primitive_load (SCM filename);
SCM_API SCM scm_c_primitive_load (const char *filename);
SCM_API SCM scm_sys_package_data_dir (void);
--
1.7.10.4
- Re: Adding to the end of the load path, (continued)
- Re: Adding to the end of the load path, Ludovic Courtès, 2012/11/13
- Re: Adding to the end of the load path, Andreas Rottmann, 2012/11/15
- Re: Adding to the end of the load path, Ludovic Courtès, 2012/11/15
- Re: Adding to the end of the load path, Mark H Weaver, 2012/11/15
- Re: Adding to the end of the load path, Ludovic Courtès, 2012/11/15
- Re: Adding to the end of the load path, Noah Lavine, 2012/11/15
- Re: Adding to the end of the load path, Noah Lavine, 2012/11/16
- Re: Adding to the end of the load path, Bruce Korb, 2012/11/16
- Re: Adding to the end of the load path, Mark H Weaver, 2012/11/16
- Re: Adding to the end of the load path, Noah Lavine, 2012/11/16
- [PATCH] Add parse-path-with-ellipsis, and use it for GUILE_LOAD_PATH et al,
Mark H Weaver <=
- Re: [PATCH] Add parse-path-with-ellipsis, and use it for GUILE_LOAD_PATH et al, Ludovic Courtès, 2012/11/28
- Re: [PATCH] Add parse-path-with-ellipsis, and use it for GUILE_LOAD_PATH et al, Mark H Weaver, 2012/11/28
- Re: [PATCH] Add parse-path-with-ellipsis, and use it for GUILE_LOAD_PATH et al, Ludovic Courtès, 2012/11/29