summaryrefslogtreecommitdiffstats
path: root/parser.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-06-10 19:32:02 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-06-10 19:32:02 -0700
commitfbf525ae910ae48b1e6401fd2307772e214b1baa (patch)
tree01375a1d08b4fb2cc5cbe526998bec9ed35eced9 /parser.c
parent421b7c3aec0b60d126cdec79f2647c901323389f (diff)
downloadtxr-fbf525ae910ae48b1e6401fd2307772e214b1baa.tar.gz
txr-fbf525ae910ae48b1e6401fd2307772e214b1baa.tar.bz2
txr-fbf525ae910ae48b1e6401fd2307772e214b1baa.zip
Preparing for lisp loading.
* parser.c (open_txr_file): Rewritten to take new argument which indicates whether to treat an unsuffixed file as TXR or TXR Lisp, and is updated to indicate which is the case by looking at the suffix. * parser.h (open_txr_file): Declaration updated. * match.c (v_load): Follow change in open_txr_file. * txr.c (txr_main): Likewise.
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c65
1 files changed, 58 insertions, 7 deletions
diff --git a/parser.c b/parser.c
index 34903ce9..2cebed04 100644
--- a/parser.c
+++ b/parser.c
@@ -33,6 +33,7 @@
#include <setjmp.h>
#include <wchar.h>
#include <signal.h>
+#include <errno.h>
#include "config.h"
#include "lib.h"
#include "signal.h"
@@ -120,17 +121,67 @@ val prime_parser(val parser)
return parser;
}
-void open_txr_file(val spec_file, val *name, val *stream)
+void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream)
{
+ enum { none, tl, txr } suffix;
+
+ if (match_str(spec_file, lit(".txr"), negone))
+ suffix = txr;
+ else if (match_str(spec_file, lit(".tl"), negone))
+ suffix = tl;
+ else
+ suffix = none;
+
+ errno = 0;
+
{
- FILE *in = w_fopen(c_str(spec_file), L"r");
+ val spec_file_try = spec_file;
+ FILE *in = w_fopen(c_str(spec_file_try), L"r");
+
+ if (in != 0) {
+ switch (suffix) {
+ case tl:
+ *txr_lisp_p = t;
+ break;
+ case txr:
+ *txr_lisp_p = nil;
+ break;
+ default:
+ break;
+ }
+ }
+
+#ifdef ENOENT
+ if (in == 0 && errno != ENOENT)
+ goto except;
+ errno = 0;
+#endif
+
+ if (suffix == none && in == 0 && !*txr_lisp_p) {
+ spec_file_try = cat_str(list(spec_file, lit("txr"), nao), lit("."));
+ in = w_fopen(c_str(spec_file_try), L"r");
+#ifdef ENOENT
+ if (in == 0 && errno != ENOENT)
+ goto except;
+ errno = 0;
+#endif
+ }
+
+
+ if (suffix == none && in == 0) {
+ spec_file_try = cat_str(list(spec_file, lit("tl"), nao), lit("."));
+ in = w_fopen(c_str(spec_file_try), L"r");
+ *txr_lisp_p = t;
+ }
+
if (in == 0) {
- spec_file = cat_str(list(spec_file, lit("txr"), nao), lit("."));
- in = w_fopen(c_str(spec_file), L"r");
- if (in == 0)
- uw_throwf(file_error_s, lit("unable to open ~a"), spec_file, nao);
+#ifdef ENOENT
+except:
+#endif
+ uw_throwf(file_error_s, lit("unable to open ~a"), spec_file_try, nao);
}
- *stream = make_stdio_stream(in, spec_file);
+
+ *stream = make_stdio_stream(in, spec_file_try);
*name = spec_file;
}
}