From 2ed80f831006815e37374a74218af4572703229f Mon Sep 17 00:00:00 2001 From: Taylan Kammer Date: Mon, 17 May 2021 19:31:40 +0200 Subject: [PATCH] Make load try to add an extension to files that already have one. * libguile/load.c (load_thunk_from_path, search_path): Remove the code that checks whether the filename already has an extension. Add the empty string to the head of the extensions list. --- libguile/load.c | 67 +++++-------------------------------------------- 1 file changed, 6 insertions(+), 61 deletions(-) diff --git a/libguile/load.c b/libguile/load.c index e95c36db1..0c198f165 100644 --- a/libguile/load.c +++ b/libguile/load.c @@ -649,7 +649,6 @@ load_thunk_from_path (SCM filename, SCM source_file_name, struct stringbuf buf; struct stat stat_buf; char *filename_chars; - size_t filename_len; SCM path, extensions; SCM result = SCM_BOOL_F; char initial_buffer[256]; @@ -667,7 +666,6 @@ load_thunk_from_path (SCM filename, SCM source_file_name, scm_dynwind_begin (0); filename_chars = scm_to_locale_string (filename); - filename_len = strlen (filename_chars); scm_dynwind_free (filename_chars); /* If FILENAME is absolute and is still valid, return it unchanged. */ @@ -680,34 +678,6 @@ load_thunk_from_path (SCM filename, SCM source_file_name, goto end; } - /* If FILENAME has an extension, don't try to add EXTENSIONS to it. */ - { - char *endp; - - for (endp = filename_chars + filename_len - 1; - endp >= filename_chars; - endp--) - { - if (*endp == '.') - { - if (!string_has_an_ext (filename, extensions)) - { - /* This filename has an extension, but not one of the right - ones... */ - goto end; - } - /* This filename already has an extension, so cancel the - list of extensions. */ - extensions = SCM_EOL; - break; - } - else if (is_file_name_separator (SCM_MAKE_CHAR (*endp))) - /* This filename has no extension, so keep the current list - of extensions. */ - break; - } - } - /* This simplifies the loop below a bit. */ if (scm_is_null (extensions)) @@ -736,6 +706,9 @@ load_thunk_from_path (SCM filename, SCM source_file_name, stringbuf_cat (&buf, filename_chars); sans_ext_len = buf.ptr - buf.buf; + /* Add the empty string as the first "extension." */ + extensions = scm_cons (scm_nullstr, extensions); + /* Try every extension. */ for (exts = extensions; scm_is_pair (exts); exts = SCM_CDR (exts)) { @@ -805,7 +778,6 @@ search_path (SCM path, SCM filename, SCM extensions, SCM require_exts, { struct stringbuf buf; char *filename_chars; - size_t filename_len; SCM result = SCM_BOOL_F; char initial_buffer[256]; @@ -819,7 +791,6 @@ search_path (SCM path, SCM filename, SCM extensions, SCM require_exts, scm_dynwind_begin (0); filename_chars = scm_to_locale_string (filename); - filename_len = strlen (filename_chars); scm_dynwind_free (filename_chars); /* If FILENAME is absolute and is still valid, return it unchanged. */ @@ -833,35 +804,6 @@ search_path (SCM path, SCM filename, SCM extensions, SCM require_exts, goto end; } - /* If FILENAME has an extension, don't try to add EXTENSIONS to it. */ - { - char *endp; - - for (endp = filename_chars + filename_len - 1; - endp >= filename_chars; - endp--) - { - if (*endp == '.') - { - if (scm_is_true (require_exts) && - !string_has_an_ext (filename, extensions)) - { - /* This filename has an extension, but not one of the right - ones... */ - goto end; - } - /* This filename already has an extension, so cancel the - list of extensions. */ - extensions = SCM_EOL; - break; - } - else if (is_file_name_separator (SCM_MAKE_CHAR (*endp))) - /* This filename has no extension, so keep the current list - of extensions. */ - break; - } - } - /* This simplifies the loop below a bit. */ if (scm_is_null (extensions)) @@ -890,6 +832,9 @@ search_path (SCM path, SCM filename, SCM extensions, SCM require_exts, stringbuf_cat (&buf, filename_chars); sans_ext_len = buf.ptr - buf.buf; + /* Add the empty string as the first "extension." */ + extensions = scm_cons (scm_nullstr, extensions); + /* Try every extension. */ for (exts = extensions; scm_is_pair (exts); exts = SCM_CDR (exts)) { -- 2.30.2