1/* 2% =================================================================== 3% File 'mpred_db_preds.pl' 4% Purpose: Emulation of OpenCyc for SWI-Prolog 5% Maintainer: Douglas Miles 6% Contact: $Author: dmiles $@users.sourceforge.net ; 7% Version: 'interface.pl' 1.0.0 8% Revision: $Revision: 1.9 $ 9% Revised At: $Date: 2002/06/27 14:13:20 $ 10% =================================================================== 11% File used as storage place for all predicates which change as 12% the world is run. 13% 14% 15% Dec 13, 2035 16% Douglas Miles 17*/ 18 19:- module(mpred_prolog_file,[ 20 guess_file_type_loader/2, 21 prolog_load_file_loop_checked/2, 22 prolog_load_file_loop_checked_0/2, 23 prolog_load_file_nlc/2, 24 prolog_load_file_nlc_0/2, 25 load_file_dir/2, 26 load_file_some_type/2, 27 use_file_type_loader/2, 28 never_load_special/2 29 ]). 30 31:- include('mpred_header.pi'). 32 33:- multifile(user:prolog_load_file/2). 34:- dynamic(user:prolog_load_file/2). 35% :- '$set_source_module'(system).
48never_load_special(_, [if(not_loaded)]):-!. 49never_load_special(_:library(make), [if(not_loaded)]):-!. 50% never_load_special(Module:Spec, Options) :- with_dmsg_to_main((dmsg_pretty(check_load(Module:Spec,Options)))),fail. 51never_load_special(_, Options) :- memberchk(must_be_module(true),Options),!. 52never_load_special(_, Options) :- memberchk(autoload(true),Options),!. 53never_load_special(_Module:_Spec, Options) :- memberchk(if(not_loaded),Options),memberchk(imports([_/_]),Options),!. 54 55 56% :- use_module(library(logicmoo/util/logicmoo_util_filesystem)). 57:- dynamic(prolog_load_file_loop_checked/2). 58:- export(prolog_load_file_loop_checked/2). 59 60% probably an autoload (SKIP)
69prolog_load_file_loop_checked(ModuleSpec, Options) :- 70 filematch(ModuleSpec,F), 71 system:'$load_context_module'(F, Was, _), 72 strip_module(ModuleSpec,To,File), 73 To\==Was, 74 Was==user, 75 wdmsg_pretty(warn(loading_into_wrong_module(Was:File->To:File,Options))),!, 76 loop_check(load_files(Was:File,Options)),!. 77prolog_load_file_loop_checked(ModuleSpec, Options) :- never_load_special(ModuleSpec, Options),!,fail. 78prolog_load_file_loop_checked(ModuleSpec, Options) :- 79 loop_check(show_success(prolog_load_file,prolog_load_file_loop_checked_0(ModuleSpec, Options))).
88prolog_load_file_loop_checked_0(ModuleSpec, Options) :- current_predicate(_,_:exists_file_safe(_)), 89 catch(prolog_load_file_nlc_pre(ModuleSpec, Options),E,(nop((dtrace,prolog_load_file_nlc(ModuleSpec, Options))),throw(E))). 90 91 92prolog_load_file_nlc_pre(Module:Spec, Options) :- 93 call_from_module(Module,prolog_load_file_nlc(Module:Spec, Options)).
:- export(prolog_load_file_nlc/2)
.
100prolog_load_file_nlc(Module:Spec, Options) :- 101 filematch(Module:Spec,Where1),Where1\=Spec,!,forall(filematch(Module:Spec,Where),Module:load_files(Module:Where,Options)). 102 103prolog_load_file_nlc(Module:Spec, Options):- baseKB:never_reload_file(Spec), 104 wdmsg_pretty(warn(error(skip_prolog_load_file_nlc(baseKB:never_reload_file(Module:Spec, Options))))),!. 105 106prolog_load_file_nlc(Module:Spec, Options):- thread_self(TID), \+ thread_self_main, 107 nop(wdmsg_pretty(warn(error(skip_prolog_load_file_nlc(wrong_thread(TID):-thread(Module:Spec, Options)))))),!. 108 109prolog_load_file_nlc(Module:Spec, Options):- thread_self(TID), \+ thread_self_main, 110 nop(wdmsg_pretty(warn(error(skip_prolog_load_file_nlc(wrong_thread(TID):-thread(Module:Spec, Options)))))),!,fail,dumpST. 111 112prolog_load_file_nlc(Module:DirName, Options):- atom(DirName), is_directory(DirName)-> 113 current_predicate(_,_:'load_file_dir'/2)->loop_check(show_call(why,call(load_file_dir,Module:DirName, Options))). 114 115prolog_load_file_nlc(Module:Spec, Options):- absolute_file_name(Spec,AFN,[extensions(['pl'])]), 116 (Spec\==AFN),exists_file_safe(AFN),!,prolog_load_file_nlc(Module:AFN, Options). 117 118prolog_load_file_nlc(Module:FileName, Options):- exists_file_safe(FileName),!, 119 prolog_load_file_nlc_0(Module:FileName, Options). 120 121prolog_load_file_nlc(Module:Spec, Options):- term_to_atom(Spec,String),member(S,['?','*']),sub_atom(String,_,1,_,S),!, 122 foreach(baseKB:filematch(Module:Spec,FileName), 123 (loop_check((prolog_load_file_nlc_0(Module:FileName, Options))),TF=true)),!, 124 nonvar(TF).
131prolog_load_file_nlc_0(Module:Spec, Options):- thread_self(TID), \+ thread_self_main, 132 wdmsg_pretty(warn(error(skip_prolog_load_file_nlc(wrong_thread(TID):-thread(Module:Spec, Options))))),!. 133 134prolog_load_file_nlc_0(Module:FileName, Options):- 135 '$set_source_module'(SM,SM), 136 (source_file_property(FileName,load_context(MC,SubFile:Line)),MC\==user,SM==user),!, 137 wdmsg_pretty(skipping(prolog_load_file_nlc(Module:FileName, Options):source_file_property(FileName,load_context(MC,SubFile:Line)))),!. 138 139prolog_load_file_nlc_0(Module:FileName, Options):- 140 file_name_extension(_Base,Ext,FileName), 141 use_file_type_loader(Ext,Loader)-> loop_check(call(Loader,Module:FileName, Options)). 142 143prolog_load_file_nlc_0(Module:FileName, Options):- fail, fail, fail, fail, fail, fail, fail, fail, fail, fail, fail, fail, 144 file_name_extension(_Base,Ext,FileName), 145 guess_file_type_loader(Ext,Loader)-> loop_check(call(Loader,Module:FileName, Options)).
153guess_file_type_loader(Ext,Loader):-use_file_type_loader(Ext,Loader). 154guess_file_type_loader(Ext,Pred):- atom(Ext), 155 (Ext==''->Pred='load_file_some_type';system:atom_concat('load_file_type_,',Ext,Pred)), 156 current_predicate(Pred/2).
165load_file_dir(Module:DirName, Options):- fail,
166 directory_files(DirName,Files),
167 foreach((member(F,Files),
168 file_name_extension(_,Ext,F),
169 guess_file_type_loader(Ext,Loader),
170 current_predicate(_,_:Loader/2),
171 directory_file_path(DirName,F,FileName)),
172 (user:prolog_load_file(Module:FileName, Options),TF=true)),
173 nonvar(TF).
183use_file_type_loader(pfc,ensure_mpred_file_consulted). 184use_file_type_loader(pddl,ensure_mpred_file_consulted). 185use_file_type_loader(plmoo,ensure_mpred_file_consulted). 186% use_file_type_loader(pl,ensure_prolog_file_consulted).
195ensure_prolog_file_consulted(M:File,Options):-must(load_files(M:File,Options)),!.
204ensure_mpred_file_consulted(M:File,Options):-
205 call_from_module(M,
206 with_mpred_expansions(locally_tl(pretend_loading_file(File),
207 must((file_begin(pfc),
208 load_files(M:File,Options)))))),!.
217load_file_some_type(M:File,Options):- call_from_module(M,must(load_files(M:File,Options))),!. 218 219 220 221:- multifile(user:prolog_load_file/2). 222:- dynamic(user:prolog_load_file/2).
231maybe_load_pfc_files(Module:Spec, Options):- 232 \+ exists_source(Spec), 233 findall(SpecO,(logicmoo_util_filesystem:filematch(Module:Spec,SpecO),exists_file(SpecO)),SpecOList),!, 234 SpecOList\==[], !, 235 forall(member(SpecO,SpecOList),load_files(Module:SpecO, Options)),!. 236 237 238maybe_load_pfc_files(Module:Spec, Options):- fail, 239 Spec \== 'MKINDEX.pl', 240 catch(find_and_call(prolog_load_file_loop_checked(Module:Spec, Options)), 241 E, 242 ((wdmsg_pretty(E),dtrace,find_and_call(prolog_load_file_loop_checked(Module:Spec, Options)),throw(E)))),!. 243%user:prolog_load_file(_,_):- get_lang(pl),!,fail. 244%user:prolog_load_file(_,_):- set_file_lang(pl),set_lang(pl),fail. 245 246 247:- fixup_exports. 248 249:- module_transparent(user:prolog_load_file/1). 250 251userprolog_load_file(ModuleSpec, Options):- maybe_load_pfc_files(ModuleSpec, Options),!