Merge pull request #1033 from aarroyoc/fix-1022

Add a -f switch to load alternative initialization files
This commit is contained in:
Mark Thom
2021-08-23 22:26:15 -06:00
committed by GitHub

View File

@@ -10,12 +10,14 @@
:- use_module(library('$project_atts')). :- use_module(library('$project_atts')).
:- use_module(library('$atts')). :- use_module(library('$atts')).
:- dynamic(disabled_init_file/0).
load_scryerrc :- load_scryerrc :-
( '$home_directory'(HomeDir) -> ( '$home_directory'(HomeDir) ->
append(HomeDir, "/.scryerrc", ScryerrcFile), append(HomeDir, "/.scryerrc", ScryerrcFile),
( file_exists(ScryerrcFile) -> ( file_exists(ScryerrcFile) ->
atom_chars(ScryerrcFileAtom, ScryerrcFile), atom_chars(ScryerrcFileAtom, ScryerrcFile),
catch(use_module(ScryerrcFileAtom), E, print_exception(E)) catch(consult(ScryerrcFileAtom), E, print_exception(E))
; true ; true
) )
; true ; true
@@ -31,8 +33,8 @@ load_scryerrc :-
; asserta('$toplevel':argv([])), ; asserta('$toplevel':argv([])),
Args = Args0 Args = Args0
), ),
load_scryerrc,
delegate_task(Args, []), delegate_task(Args, []),
(\+ disabled_init_file -> load_scryerrc ; true),
repl. repl.
'$repl'(_) :- '$repl'(_) :-
( \+ argv(_) -> asserta('$toplevel':argv([])) ( \+ argv(_) -> asserta('$toplevel':argv([]))
@@ -44,14 +46,17 @@ load_scryerrc :-
delegate_task([], []). delegate_task([], []).
delegate_task([], Goals0) :- delegate_task([], Goals0) :-
reverse(Goals0, Goals), reverse(Goals0, Goals),
(\+ disabled_init_file -> load_scryerrc ; true),
run_goals(Goals), run_goals(Goals),
repl. repl.
delegate_task([Arg0|Args], Goals0) :- delegate_task([Arg0|Args], Goals0) :-
( member(Arg0, ["-h", "--help"]) -> print_help ( member(Arg0, ["-h", "--help"]) -> print_help
; member(Arg0, ["-v", "--version"]) -> print_version ; member(Arg0, ["-v", "--version"]) -> print_version
; member(Arg0, ["-g", "--goal"]) -> gather_goal(g, Args, Goals0) ; member(Arg0, ["-g", "--goal"]) -> gather_goal(g, Args, Goals0)
; member(Arg0, ["-f"]) -> disable_init_file
; atom_chars(Mod, Arg0), ; atom_chars(Mod, Arg0),
catch(use_module(Mod), E, print_exception(E)) catch(consult(Mod), E, print_exception(E))
), ),
delegate_task(Args, Goals0). delegate_task(Args, Goals0).
@@ -65,6 +70,8 @@ print_help :-
write('Print version information and exit'), nl, write('Print version information and exit'), nl,
write(' -g, --goal GOAL '), write(' -g, --goal GOAL '),
write('Run the query GOAL'), nl, write('Run the query GOAL'), nl,
write(' -f '),
write('Fast startup. Do not load initialization file (~/.scryerrc)'),nl,
% write(' '), % write(' '),
halt. halt.
@@ -82,6 +89,9 @@ gather_goal(Type, Args0, Goals) :-
Gs =.. [Type, Gs1], Gs =.. [Type, Gs1],
delegate_task(Args, [Gs|Goals]). delegate_task(Args, [Gs|Goals]).
disable_init_file :-
asserta('disabled_init_file').
arg_type(g). arg_type(g).
arg_type(t). arg_type(t).
arg_type(g(_)). arg_type(g(_)).