From 8d661219c56f4eb2abeb958e96d7699c82b666cb Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 10 Jun 2019 20:14:21 -0700 Subject: 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. --- parser.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/parser.c b/parser.c index f879e50f..bfb7c353 100644 --- a/parser.c +++ b/parser.c @@ -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; } -- cgit v1.2.3