From d4ed02bdd3dff26daf585a5e0d780912af600cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Wed, 22 Jun 2011 12:29:35 +0100 Subject: [PATCH] absolute_file_name --- pl/consult.yap | 45 +++++++++++++++++++-------------------------- pl/init.yap | 21 ++++++++++++++------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/pl/consult.yap b/pl/consult.yap index 5ca36d83a..0bbdc14f0 100755 --- a/pl/consult.yap +++ b/pl/consult.yap @@ -687,21 +687,27 @@ absolute_file_name(File,Opts,TrueFileName) :- '$do_error'(instantiation_error, G). '$absolute_file_name'(File,Opts,TrueFileName, G) :- '$process_fn_opts'(Opts,Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,G), - FoundOne = a(false), + /* our own local findall */ + nb:nb_queue(Ref), ( - '$find_in_path'(File,opts(Extensions,RelTo,Type,Access,FErrors,Expand,Debug),TrueFileName,G), - (Solutions = first -> ! ; true), - nb_setarg(1, FoundOne, true) - ; + '$find_in_path'(File,opts(Extensions,RelTo,Type,Access,FErrors,Expand,Debug),TrueFileName,G), + nb:nb_queue_enqueue(Ref, TrueFileName), + fail + ; + nb:nb_queue_close(Ref, FileNames, []) + ), + '$absolute_file_names'(Solutions, FileNames, FError, TrueFileName, File, G). - FErrors = error, FoundOne = a(false) -> - '$do_error'(existence_error(file,File),G) - ). +'$absolute_file_names'(Solutions, [], error, _, File, G) :- !, + '$do_error'(existence_error(file,File),G). +'$absolute_file_names'(Solutions, FileNames, _, TrueFileName, _, _) :- + lists:member(TrueFileName, FileNames), + (Solutions == first -> ! ; true). '$process_fn_opts'(V,_,_,_,_,_,_,_,_,G) :- var(V), !, '$do_error'(instantiation_error, G). -'$process_fn_opts'([],[],_,source,none,error,first,false,false,_) :- !. +'$process_fn_opts'([],[],_,txt,none,error,first,false,false,_) :- !. '$process_fn_opts'([Opt|Opts],Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,G) :- !, '$process_fn_opt'(Opt,Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,Extensions0,RelTo0,Type0,Access0,FErrors0,Solutions0,Expand0,Debug0,G), '$process_fn_opts'(Opts,Extensions0,RelTo0,Type0,Access0,FErrors0,Solutions0,Expand0,Debug0,G). @@ -727,7 +733,7 @@ absolute_file_name(File,Opts,TrueFileName) :- '$process_fn_opt'(verbose_file_search(Debug),Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,_,G) :- !, '$check_true_false'(Debug,G). '$process_fn_opt'(Opt,Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,Extensions,RelTo,Type,Access,FErrors,Solutions,Expand,Debug,G) :- !, - '$do_error'(domain_error(file_name_option,T),G). + '$do_error'(domain_error(file_name_option,Opt),G). '$check_fn_extensions'(V,G) :- var(V), !, '$do_error'(instantiation_error, G). @@ -886,23 +892,10 @@ absolute_file_name(File,Opts,TrueFileName) :- '$mk_sure_true_ext'(Ext,Ext). '$add_type_extensions'(Type,File,F) :- - '$type_extension'(Type,Ext), - atom_concat([File,Ext],F). -'$add_type_extensions'(Type,File,F) :- - user:prolog_file_type(Ext, Type), + ( Type == source -> NType = prolog ; NType = Type ), + user:prolog_file_type(Ext, NType), atom_concat([File,'.',Ext],F). - -'$type_extension'(txt,''). -'$type_extension'(prolog,'.yap'). -'$type_extension'(prolog,'.pl'). -'$type_extension'(prolog,''). -'$type_extension'(source,'.yap'). -'$type_extension'(source,'.pl'). -'$type_extension'(source,''). -'$type_extension'(executable,Suffix) :- '$obj_suffix'(String), atom_codes(Suffix, String). -'$type_extension'(qlf,'.qlf'). -'$type_extension'(qlf,''). -'$type_extension'(directory,''). +'$add_type_extensions'(_,File,File). '$add_path'(File,File). '$add_path'(File,PFile) :- diff --git a/pl/init.yap b/pl/init.yap index bcb208182..08117c934 100644 --- a/pl/init.yap +++ b/pl/init.yap @@ -42,6 +42,7 @@ otherwise. :- '$handle_throw'(_,_,_), !. :- bootstrap('errors.yap'). +:- bootstrap('lists.yap'). :- bootstrap('consult.yap'). :- [ 'utils.yap', @@ -54,7 +55,6 @@ otherwise. :- [ % lists is often used. - 'lists.yap', 'yio.yap', 'debug.yap', 'checker.yap', @@ -73,8 +73,8 @@ otherwise. 'callcount.yap', 'load_foreign.yap', 'save.yap', - 'sort.yap', 'setof.yap', + 'sort.yap', 'statistics.yap', 'strict_iso.yap', 'tabling.yap', @@ -171,14 +171,21 @@ yap_hacks:cut_by(CP) :- '$$cut_by'(CP). :- dynamic goal_expansion/3. -:- multifile prolog_file_type/2. +:- multifile user:prolog_file_type/2. -:- dynamic prolog_file_type/2. +:- dynamic user:prolog_file_type/2. +user:prolog_file_type(yap, prolog). user:prolog_file_type(pl, prolog). -% user:prolog_file_type(Ext, prolog) :- -% current_prolog_flag(associate, Ext), -% Ext \== pl. +user:prolog_file_type(A, prolog) :- + current_prolog_flag(associate, A), + A\==pl, + A \== yap. +%user:prolog_file_type(qlf, prolog). +%user:prolog_file_type(qlf, qlf). +user:prolog_file_type(A, executable) :- + current_prolog_flag(shared_object_extension, A). + :- multifile goal_expansion/2.