2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
2015-08-18 21:08:52 +01:00
|
|
|
** Yap Prolog was developed at NCCUP - Universidade do Porto *
|
2001-04-09 20:54:03 +01:00
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: init.yap *
|
|
|
|
* Last rev: *
|
|
|
|
* mods: *
|
|
|
|
* comments: initializing the full prolog system *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
2018-05-10 13:11:56 +01:00
|
|
|
/**
|
|
|
|
* @file init.yap
|
|
|
|
*
|
|
|
|
* @brief how to boot and run the top-level.
|
|
|
|
*
|
|
|
|
*/
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2018-05-10 13:11:56 +01:00
|
|
|
/**
|
2018-06-05 20:51:49 +01:00
|
|
|
* @ingroup YAPControl
|
|
|
|
* @{
|
2018-05-10 13:11:56 +01:00
|
|
|
*
|
|
|
|
*/
|
2018-03-14 00:41:05 +00:00
|
|
|
|
|
|
|
'$init_globals' :-
|
|
|
|
% set_prolog_flag(break_level, 0),
|
|
|
|
% '$set_read_error_handler'(error), let the user do that
|
|
|
|
nb_setval('$chr_toplevel_show_store',false).
|
|
|
|
|
|
|
|
'$init_consult' :-
|
2018-07-11 22:15:54 +01:00
|
|
|
set_value('$open_expands_filename',true),
|
|
|
|
nb_setval('$assert_all',off),
|
|
|
|
nb_setval('$if_level',0),
|
|
|
|
nb_setval('$endif',off),
|
|
|
|
nb_setval('$initialization_goals',off),
|
|
|
|
nb_setval('$included_file',[]),
|
|
|
|
nb_setval('$loop_streams',[]),
|
2018-07-12 11:02:09 +01:00
|
|
|
(
|
|
|
|
'$undefined'('$init_preds',prolog)
|
|
|
|
->
|
|
|
|
true
|
|
|
|
;
|
|
|
|
'$init_preds'
|
|
|
|
).
|
2018-03-14 00:41:05 +00:00
|
|
|
|
|
|
|
'$init_win_graphics' :-
|
|
|
|
'$undefined'(window_title(_,_), system), !.
|
|
|
|
'$init_win_graphics' :-
|
|
|
|
load_files([library(win_menu)], [silent(true),if(not_loaded)]),
|
|
|
|
fail.
|
|
|
|
'$init_win_graphics'.
|
|
|
|
|
|
|
|
'$init_or_threads' :-
|
|
|
|
'$c_yapor_workers'(W), !,
|
|
|
|
'$start_orp_threads'(W).
|
|
|
|
'$init_or_threads'.
|
|
|
|
|
|
|
|
'$start_orp_threads'(1) :- !.
|
|
|
|
'$start_orp_threads'(W) :-
|
|
|
|
thread_create('$c_worker',_,[detached(true)]),
|
|
|
|
W1 is W-1,
|
|
|
|
'$start_orp_threads'(W1).
|
|
|
|
|
|
|
|
'$version' :-
|
|
|
|
current_prolog_flag(verbose, normal), !,
|
|
|
|
current_prolog_flag(version_git,VersionGit),
|
|
|
|
current_prolog_flag(compiled_at,AT),
|
|
|
|
current_prolog_flag(version_data, yap(Mj, Mi, Patch, _) ),
|
|
|
|
sub_atom( VersionGit, 0, 8, _, VERSIONGIT ),
|
|
|
|
current_prolog_flag(version_data, yap(Mj, Mi, Patch, _) ),
|
|
|
|
current_prolog_flag(resource_database, Saved ),
|
|
|
|
format(user_error, '% YAP ~d.~d.~d-~a (compiled ~a)~n', [Mj,Mi, Patch, VERSIONGIT, AT]),
|
|
|
|
format(user_error, '% database loaded from ~a~n', [Saved]).
|
|
|
|
'$version'.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise a Prolog engine.
|
|
|
|
*
|
|
|
|
* Must be called after restoring.
|
|
|
|
*/
|
|
|
|
'$init_prolog' :-
|
|
|
|
% do catch as early as possible
|
|
|
|
'$version',
|
|
|
|
yap_flag(file_name_variables, _OldF, true),
|
|
|
|
'$init_consult',
|
|
|
|
%set_prolog_flag(file_name_variables, OldF),
|
|
|
|
'$init_globals',
|
|
|
|
set_prolog_flag(fileerrors, true),
|
|
|
|
set_value('$gc',on),
|
|
|
|
('$exit_undefp' -> true ; true),
|
|
|
|
prompt1(' ?- '),
|
|
|
|
set_prolog_flag(debug, false),
|
|
|
|
% simple trick to find out if this is we are booting from Prolog.
|
|
|
|
% boot from a saved state
|
2019-01-30 15:24:06 +00:00
|
|
|
'$init_from_saved_state_and_args', %start_low_level_trace,
|
2018-03-14 00:41:05 +00:00
|
|
|
|
2019-01-30 15:24:06 +00:00
|
|
|
'$db_clean_queues'(_),
|
2018-03-14 00:41:05 +00:00
|
|
|
% this must be executed from C-code.
|
|
|
|
% '$startup_saved_state',
|
|
|
|
set_input(user_input),
|
|
|
|
set_output(user_output),
|
|
|
|
'$init_or_threads',
|
|
|
|
'$run_at_thread_start'.
|
|
|
|
|
|
|
|
|
|
|
|
% then we can execute the programs.
|
|
|
|
'$startup_goals' :-
|
|
|
|
module(user),
|
|
|
|
fail.
|
2019-01-31 11:54:17 +00:00
|
|
|
'$startup_goals' :-
|
|
|
|
recorded('$startup_goal',G,_),
|
2018-11-03 10:49:35 +00:00
|
|
|
catch(once(user:G),Error,user:'$Error'(Error)),
|
2018-03-14 00:41:05 +00:00
|
|
|
fail.
|
|
|
|
'$startup_goals' :-
|
|
|
|
get_value('$init_goal',GA),
|
|
|
|
GA \= [],
|
|
|
|
set_value('$init_goal',[]),
|
|
|
|
'$run_atom_goal'(GA),
|
|
|
|
fail.
|
|
|
|
'$startup_goals' :-
|
|
|
|
recorded('$restore_flag', goal(Module:GA), R),
|
|
|
|
erase(R),
|
2018-11-03 10:49:35 +00:00
|
|
|
catch(once(Module:GA),Error,user:'$Error'(Error)),
|
2018-03-14 00:41:05 +00:00
|
|
|
fail.
|
|
|
|
'$startup_goals' :-
|
|
|
|
get_value('$myddas_goal',GA), GA \= [],
|
|
|
|
set_value('$myddas_goal',[]),
|
|
|
|
get_value('$myddas_user',User), User \= [],
|
|
|
|
set_value('$myddas_user',[]),
|
|
|
|
get_value('$myddas_db',Db), Db \= [],
|
|
|
|
set_value('$myddas_db',[]),
|
|
|
|
get_value('$myddas_host',HostT),
|
|
|
|
( HostT \= [] ->
|
|
|
|
Host = HostT,
|
|
|
|
set_value('$myddas_host',[])
|
|
|
|
;
|
|
|
|
Host = localhost
|
|
|
|
),
|
|
|
|
get_value('$myddas_pass',PassT),
|
|
|
|
( PassT \= [] ->
|
|
|
|
Pass = PassT,
|
|
|
|
set_value('$myddas_pass',[])
|
|
|
|
;
|
|
|
|
Pass = ''
|
|
|
|
),
|
|
|
|
use_module(library(myddas)),
|
|
|
|
call(db_open(mysql,myddas,Host/Db,User,Pass)),
|
|
|
|
'$myddas_import_all',
|
|
|
|
fail.
|
|
|
|
'$startup_goals'.
|
|
|
|
|
|
|
|
%
|
|
|
|
% MYDDAS: Import all the tables from one database
|
|
|
|
%
|
|
|
|
|
|
|
|
'$myddas_import_all':-
|
|
|
|
call(db_my_show_tables(myddas,table(Table))),
|
|
|
|
call(db_import(myddas,Table,Table)),
|
|
|
|
fail.
|
|
|
|
'$myddas_import_all'.
|
|
|
|
|
|
|
|
% use if we come from a save_program and we have SWI's shlib
|
|
|
|
'$init_from_saved_state_and_args' :-
|
|
|
|
current_prolog_flag(hwnd, _HWND),
|
|
|
|
load_files(library(win_menu), [silent(true)]),
|
|
|
|
fail.
|
|
|
|
'$init_from_saved_state_and_args' :-
|
|
|
|
recorded('$reload_foreign_libraries',_G,R),
|
|
|
|
erase(R),
|
|
|
|
shlib:reload_foreign_libraries,
|
|
|
|
fail.
|
|
|
|
% this should be done before -l kicks in.
|
|
|
|
'$init_from_saved_state_and_args' :-
|
|
|
|
current_prolog_flag(fast_boot, false),
|
|
|
|
( exists('~/.yaprc') -> load_files('~/.yaprc', []) ; true ),
|
|
|
|
( exists('~/.prologrc') -> load_files('~/.prologrc', []) ; true ),
|
|
|
|
( exists('~/prolog.ini') -> load_files('~/prolog.ini', []) ; true ),
|
|
|
|
fail.
|
|
|
|
% use if we come from a save_program and we have a goal to execute
|
|
|
|
'$init_from_saved_state_and_args' :-
|
|
|
|
get_value('$consult_on_boot',X), X \= [],
|
|
|
|
set_value('$consult_on_boot',[]),
|
|
|
|
'$do_startup_reconsult'(X),
|
2019-01-31 11:54:17 +00:00
|
|
|
fail.
|
2018-03-14 00:41:05 +00:00
|
|
|
'$init_from_saved_state_and_args' :-
|
|
|
|
recorded('$restore_flag', init_file(M:B), R),
|
|
|
|
erase(R),
|
|
|
|
'$do_startup_reconsult'(M:B),
|
|
|
|
fail.
|
|
|
|
'$init_from_saved_state_and_args' :-
|
|
|
|
recorded('$restore_flag', unknown(M:B), R),
|
|
|
|
erase(R),
|
|
|
|
yap_flag(M:unknown,B),
|
|
|
|
fail.
|
|
|
|
'$init_from_saved_state_and_args' :-
|
|
|
|
'$startup_goals',
|
|
|
|
fail.
|
|
|
|
'$init_from_saved_state_and_args' :-
|
|
|
|
recorded('$restore_goal',G,R),
|
|
|
|
erase(R),
|
|
|
|
prompt(_,'| '),
|
2018-11-03 10:49:35 +00:00
|
|
|
catch(once(user:G),Error,user:'$Error'(Error)),
|
2018-03-14 00:41:05 +00:00
|
|
|
fail.
|
|
|
|
|
|
|
|
'$init_path_extensions' :-
|
|
|
|
get_value('$extend_file_search_path',P), !,
|
|
|
|
P \= [],
|
|
|
|
set_value('$extend_file_search_path',[]),
|
|
|
|
'$extend_file_search_path'(P).
|
|
|
|
'$init_path_extensions'.
|
|
|
|
|
2018-06-05 20:51:49 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|