From 2e894651f9955fabc905e8a517ba33b69c0e2593 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 31 Mar 2022 07:24:43 -0700 Subject: loading: bugfix: try specified path before suffixes. This is a partial revert of the May 1, 2019 commit 065dde19dfbe50e91e313e5b3ccc033cfbe47f74, titled "loading: try unsuffixed files directly last". Test cases added in prior commit now pass. * parser.c (open_txr_file); Like before the 2019 commit, we try the exact path that is specified first. Only if that is not found do we try adding suffixes to a file which has no recognizable suffix. This does mean that (load "foo") will probe the filesystem twice in order to find "foo.tl" or "foo.tlo" there is no obvious way around that that doesn't cause a problem. * txr.1: Update documentation that is outdated, incomplete, incorrect, or that is has become incorrect because of this fix. --- parser.c | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) (limited to 'parser.c') diff --git a/parser.c b/parser.c index ee2ab6df..dbb7e481 100644 --- a/parser.c +++ b/parser.c @@ -534,6 +534,33 @@ void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream, val spec_file_try = nil; FILE *in = 0; + { + spec_file_try = spec_file; + errno = 0; + in = w_fopen(c_str(spec_file_try, self), L"r"); + if (in != 0) { + switch (suffix) { + case tl: + *txr_lisp_p = t; + break; + case tlo: + *txr_lisp_p = chr('o'); + break; + case txr: + *txr_lisp_p = nil; + break; + default: + break; + } + goto found; + } else { +#ifdef ENOENT + if (errno != ENOENT) + goto except; +#endif + } + } + if (suffix == none && !*txr_lisp_p) { spec_file_try = scat(lit("."), spec_file, lit("txr"), nao); if ((in = w_fopen(c_str(spec_file_try, nil), L"r")) != 0) @@ -571,27 +598,6 @@ void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream, } } - { - spec_file_try = spec_file; - errno = 0; - in = w_fopen(c_str(spec_file_try, self), L"r"); - if (in != 0) { - switch (suffix) { - case tl: - *txr_lisp_p = t; - break; - case tlo: - *txr_lisp_p = chr('o'); - break; - case txr: - *txr_lisp_p = nil; - break; - default: - break; - } - } - } - if (in == 0) { #ifdef ENOENT except: -- cgit v1.2.3