>From 1f72ddd3971a796a6f83a68ebedde7d7324c50b5 Mon Sep 17 00:00:00 2001 From: Andreas Rottmann Date: Thu, 8 Nov 2012 01:59:56 +0100 Subject: [PATCH] More flexible %load-path and %load-compiled-path handling --- libguile/load.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/libguile/load.c b/libguile/load.c index af2ca45..a05cf76 100644 --- a/libguile/load.c +++ b/libguile/load.c @@ -226,7 +226,9 @@ SCM_DEFINE (scm_parse_path, "parse-path", 1, 1, 0, "Parse @var{path}, which is expected to be a colon-separated\n" "string, into a list and return the resulting list with\n" "@var{tail} appended. If @var{path} is @code{#f}, @var{tail}\n" - "is returned.") + "is returned. In case an empty string occurs as an element\n" + "of @var{path}, @var{tail} is inserted at that point instead of\n" + "being append at the end of the list.") #define FUNC_NAME s_scm_parse_path { #ifdef __MINGW32__ @@ -237,9 +239,24 @@ SCM_DEFINE (scm_parse_path, "parse-path", 1, 1, 0, if (SCM_UNBNDP (tail)) tail = SCM_EOL; - return (scm_is_false (path) - ? tail - : scm_append_x (scm_list_2 (scm_string_split (path, sep), tail))); + if (scm_is_false (path)) + return tail; + else + { + SCM elements = scm_string_split (path, sep); + SCM seen = SCM_EOL; + SCM rest = elements; + + for (; scm_is_pair (rest); rest = SCM_CDR (rest)) + { + if (scm_is_true (scm_string_null_p (SCM_CAR (rest)))) + return scm_append_x (scm_list_2 (scm_reverse_x (seen, tail), + SCM_CDR (rest))); + seen = scm_cons (SCM_CAR (rest), seen); + } + + return scm_append_x (scm_list_2 (elements, tail)); + } } #undef FUNC_NAME -- 1.7.10.4