mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-20 22:29:16 +02:00
Reporting a more sensible error when the initialization
file isn't found, per issue #2: http://code.google.com/p/chibi-scheme/issues/detail?id=2
This commit is contained in:
parent
b1c0ea895b
commit
e8985cd84c
1 changed files with 35 additions and 11 deletions
46
main.c
46
main.c
|
@ -48,6 +48,29 @@ sexp find_module_file (sexp ctx, char *file) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sexp sexp_load_module_file (sexp ctx, char *file, sexp env) {
|
||||||
|
sexp res = SEXP_VOID;
|
||||||
|
sexp_gc_var(ctx, path, s_path);
|
||||||
|
sexp_gc_var(ctx, irr, s_irr);
|
||||||
|
sexp_gc_preserve(ctx, path, s_path);
|
||||||
|
sexp_gc_preserve(ctx, irr, s_irr);
|
||||||
|
path = find_module_file(ctx, file);
|
||||||
|
if (! sexp_stringp(path)) {
|
||||||
|
path = sexp_c_string(ctx, chibi_module_dir, -1);
|
||||||
|
irr = sexp_cons(ctx, path, SEXP_NULL);
|
||||||
|
path = sexp_c_string(ctx, file, -1);
|
||||||
|
irr = sexp_cons(ctx, path, irr);
|
||||||
|
res = sexp_user_exception(ctx,
|
||||||
|
SEXP_FALSE,
|
||||||
|
"couldn't find file to load in ./ or module dir",
|
||||||
|
irr);
|
||||||
|
} else {
|
||||||
|
res = sexp_load(ctx, path, env);
|
||||||
|
}
|
||||||
|
sexp_gc_release(ctx, path, s_path);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
void repl (sexp ctx) {
|
void repl (sexp ctx) {
|
||||||
sexp tmp, res, env, in, out, err;
|
sexp tmp, res, env, in, out, err;
|
||||||
sexp_gc_var(ctx, obj, s_obj);
|
sexp_gc_var(ctx, obj, s_obj);
|
||||||
|
@ -98,7 +121,7 @@ void run_main (int argc, char **argv) {
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'p':
|
case 'p':
|
||||||
if (! init_loaded++)
|
if (! init_loaded++)
|
||||||
sexp_load(ctx, str=find_module_file(ctx, sexp_init_file), env);
|
sexp_load_module_file(ctx, sexp_init_file, env);
|
||||||
res = sexp_read_from_string(ctx, argv[i+1]);
|
res = sexp_read_from_string(ctx, argv[i+1]);
|
||||||
if (! sexp_exceptionp(res))
|
if (! sexp_exceptionp(res))
|
||||||
res = sexp_eval(ctx, res);
|
res = sexp_eval(ctx, res);
|
||||||
|
@ -115,8 +138,8 @@ void run_main (int argc, char **argv) {
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
if (! init_loaded++)
|
if (! init_loaded++)
|
||||||
sexp_load(ctx, str=find_module_file(ctx, sexp_init_file), env);
|
sexp_load_module_file(ctx, sexp_init_file, env);
|
||||||
sexp_load(ctx, str=find_module_file(ctx, argv[++i]), env);
|
sexp_load_module_file(ctx, argv[++i], env);
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
init_loaded = 1;
|
init_loaded = 1;
|
||||||
|
@ -131,14 +154,15 @@ void run_main (int argc, char **argv) {
|
||||||
|
|
||||||
if (! quit) {
|
if (! quit) {
|
||||||
if (! init_loaded)
|
if (! init_loaded)
|
||||||
res = sexp_load(ctx, str=find_module_file(ctx, sexp_init_file), env);
|
res = sexp_load_module_file(ctx, sexp_init_file, env);
|
||||||
if (! sexp_exceptionp(res)) {
|
if (res && sexp_exceptionp(res))
|
||||||
if (i < argc)
|
sexp_print_exception(ctx, res,
|
||||||
for ( ; i < argc; i++)
|
sexp_eval_string(ctx, "(current-error-port)"));
|
||||||
sexp_load(ctx, str=sexp_c_string(ctx, argv[i], -1), env);
|
if (i < argc)
|
||||||
else
|
for ( ; i < argc; i++)
|
||||||
repl(ctx);
|
res = sexp_load(ctx, str=sexp_c_string(ctx, argv[i], -1), env);
|
||||||
}
|
else
|
||||||
|
repl(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
sexp_gc_release(ctx, str, s_str);
|
sexp_gc_release(ctx, str, s_str);
|
||||||
|
|
Loading…
Add table
Reference in a new issue