diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-06-10 20:14:21 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-06-10 20:14:21 -0700 |
commit | 071c281c7f2652726ba123a917903c77f2144fa0 (patch) | |
tree | 16a17d7561823c48d9d96e1d4b5f2fb3e6b0592c /parser.c | |
parent | 6c331fcee3336398d5f3dd12e6850d26876bc712 (diff) | |
download | txr-071c281c7f2652726ba123a917903c77f2144fa0.tar.gz txr-071c281c7f2652726ba123a917903c77f2144fa0.tar.bz2 txr-071c281c7f2652726ba123a917903c77f2144fa0.zip |
regression: unsuffixed cmdline arg treated as Lisp.
This broke in TXR 216. TXR files with no suffix run
using #!/path/to/txr stopped working due to being interpreted
as Lisp. The rearrangement done in open_txr_file function
didn't respect the hacky treatment of the *txr_lisp_p flag,
which depended on the original order. The flag ends up being
set to t, because we tried (unsuccessfully) opening a .tl
suffix, and that then falsely indicates "Lisp" when the
unsuffixed file is open. That logic worked when we tried the
unsuffixed file first, and fell back on the added suffixes
last.
* parser.c (open-txr_file): Instead of repeatedly testing
for in == 0, we execute a forward goto when we successfully
open a file. Only in those successful cases, set *txr_lisp_p
to the appropriate value, not touching it otherwise.
Diffstat (limited to 'parser.c')
-rw-r--r-- | parser.c | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -452,7 +452,8 @@ void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream) if (suffix == none && !*txr_lisp_p) { spec_file_try = scat(lit("."), spec_file, lit("txr"), nao); - in = w_fopen(c_str(spec_file_try), L"r"); + if ((in = w_fopen(c_str(spec_file_try), L"r")) != 0) + goto found; #ifdef ENOENT if (in == 0 && errno != ENOENT) goto except; @@ -460,21 +461,25 @@ void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream) } if (suffix == none) { - if (in == 0) { + { spec_file_try = scat(lit("."), spec_file, lit("tlo"), nao); errno = 0; - in = w_fopen(c_str(spec_file_try), L"r"); - *txr_lisp_p = chr('o'); + if ((in = w_fopen(c_str(spec_file_try), L"r")) != 0) { + *txr_lisp_p = chr('o'); + goto found; + } #ifdef ENOENT if (in == 0 && errno != ENOENT) goto except; #endif } - if (in == 0) { + { spec_file_try = scat(lit("."), spec_file, lit("tl"), nao); errno = 0; - in = w_fopen(c_str(spec_file_try), L"r"); - *txr_lisp_p = t; + if ((in = w_fopen(c_str(spec_file_try), L"r")) != 0) { + *txr_lisp_p = t; + goto found; + } #ifdef ENOENT if (in == 0 && errno != ENOENT) goto except; @@ -482,7 +487,7 @@ void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream) } } - if (in == 0) { + { spec_file_try = spec_file; errno = 0; in = w_fopen(c_str(spec_file_try), L"r"); @@ -511,6 +516,7 @@ except: lit("unable to open ~a"), spec_file_try, nao); } +found: *stream = make_stdio_stream(in, spec_file_try); *name = spec_file_try; } |