From: Mark H Weaver <mhw@netris.org>
To: ludo@gnu.org (Ludovic Courtès)
Cc: guile-devel@gnu.org
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 [thread overview]
Message-ID: <87624pxqxi.fsf_-_@tines.lan> (raw)
In-Reply-To: <87k3tpkyeg.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Tue, 13 Nov 2012 22:04:23 +0100")
[-- Attachment #1: Type: text/plain, Size: 319 bytes --]
Hi Ludovic,
ludo@gnu.org (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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] Add parse-path-with-ellipsis, and use it for GUILE_LOAD_PATH et al --]
[-- Type: text/x-diff, Size: 3958 bytes --]
From 4a78f4a638334a5bd8eb08308891b541bbde9b1e Mon Sep 17 00:00:00 2001
From: Mark H Weaver <mhw@netris.org>
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
+@deffn {Scheme Procedure} parse-path-with-ellipsis path base
+@deffnx {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.
+@end 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 @@
\f
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
next prev parent reply other threads:[~2012-11-28 23:12 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-05 3:18 Adding to the end of the load path Ian Price
2012-11-08 1:03 ` Andreas Rottmann
2012-11-11 7:50 ` Mark H Weaver
2012-11-11 19:02 ` Andreas Rottmann
2012-11-11 21:51 ` Mark H Weaver
2012-11-12 16:35 ` Bruce Korb
2012-11-13 21:04 ` Ludovic Courtès
2012-11-15 22:06 ` Andreas Rottmann
2012-11-15 22:37 ` Ludovic Courtès
2012-11-15 22:44 ` Mark H Weaver
2012-11-15 23:06 ` Ludovic Courtès
2012-11-16 0:10 ` Noah Lavine
2012-11-16 14:00 ` Noah Lavine
2012-11-16 18:06 ` Bruce Korb
2012-11-16 18:52 ` Mark H Weaver
2012-11-16 21:38 ` Noah Lavine
2012-11-28 23:12 ` Mark H Weaver [this message]
2012-11-28 23:46 ` [PATCH] Add parse-path-with-ellipsis, and use it for GUILE_LOAD_PATH et al Ludovic Courtès
2012-11-29 3:04 ` Mark H Weaver
2012-11-29 10:27 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87624pxqxi.fsf_-_@tines.lan \
--to=mhw@netris.org \
--cc=guile-devel@gnu.org \
--cc=ludo@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).