2013-11-13 22:52:36 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
2015-03-16 17:25:09 +00:00
|
|
|
* YAP Prolog *
|
2013-11-13 22:52:36 +00:00
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
2014-04-21 11:14:18 +01:00
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-2014 *
|
2013-11-13 22:52:36 +00:00
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
|
2016-02-29 03:13:23 +00:00
|
|
|
/**
|
2015-12-15 08:54:21 +00:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
@file absf.yap
|
|
|
|
@author L.Damas, V.S.Costa
|
|
|
|
|
2017-04-07 23:10:59 +01:00
|
|
|
@defgroup AbsoluteFileName File Name Resolution
|
|
|
|
@ingroup builtins
|
2014-04-21 11:14:18 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
Support for file name resolution through absolute_file_name/3 and
|
2014-04-21 11:14:18 +01:00
|
|
|
friends. These utility built-ins describe a list of directories that
|
|
|
|
are used by load_files/2 to search. They include pre-compiled paths
|
|
|
|
plus user-defined directories, directories based on environment
|
|
|
|
variables and registry information to search for files.
|
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
@{
|
|
|
|
|
2017-04-07 23:10:59 +01:00
|
|
|
*/
|
|
|
|
:- system_module( absf, [absolute_file_name/2,
|
|
|
|
absolute_file_name/3,
|
|
|
|
add_to_path/1,
|
|
|
|
add_to_path/2,
|
|
|
|
path/1,
|
2017-10-02 08:58:51 +01:00
|
|
|
remove_from_path/1], ['$full_filename'/2,
|
2017-04-07 23:10:59 +01:00
|
|
|
'$system_library_directories'/2]).
|
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
|
2014-04-09 12:39:29 +01:00
|
|
|
:- use_system_module( '$_boot', ['$system_catch'/4]).
|
|
|
|
|
|
|
|
:- use_system_module( '$_errors', ['$do_error'/2]).
|
|
|
|
|
|
|
|
:- use_system_module( '$_lists', [member/2]).
|
2014-04-06 17:05:17 +01:00
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
/**
|
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
@pred absolute_file_name( -File:atom, +Path:atom, +Options:list) is nondet
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
_Options_ is a list of options to guide the conversion:
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
- extensions(+ _ListOfExtensions_)
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
List of file-name suffixes to add to try adding to the file. The
|
|
|
|
Default is the empty suffix, `''`. For each extension,
|
|
|
|
absolute_file_name/3 will first add the extension and then verify
|
|
|
|
the conditions imposed by the other options. If the condition
|
|
|
|
fails, the next extension of the list is tried. Extensions may
|
|
|
|
be specified both with dot, as `.ext`, or without, as plain
|
|
|
|
`ext`.
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
- relative_to(+ _FileOrDir_ )
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
Resolve the path relative to the given directory or directory the
|
|
|
|
holding the given file. Without this option, paths are resolved
|
|
|
|
relative to the working directory (see working_directory/2) or,
|
|
|
|
if _Spec_ is atomic and absolute_file_name/3 is executed
|
|
|
|
in a directive, it uses the current source-file as reference.
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
- access(+ _Mode_ )
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
Imposes the condition access_file( _File_ , _Mode_ ). _Mode_ is one of `read`, `write`, `append`, `exist` or
|
|
|
|
`none` (default).
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
See also access_file/2.
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
- file_type(+ _Type_ )
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
Defines suffixes matching one of several pre-specified type of files. Default mapping is as follows:
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
1. `txt` implies `[ '' ]`,
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
2. `prolog` implies `['.yap', '.pl', '.prolog', '']`,
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
3. `executable` implies `['.so', ',dylib', '.dll']` depending on the Operating system,
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
4. `qly` implies `['.qly', '']`,
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
5. `directory` implies `['']`,
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
6. The file-type `source` is an alias for `prolog` designed to support compatibility with SICStus Prolog. See also prolog_file_type/2.
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
Notice that this predicate only
|
|
|
|
returns non-directories, unless the option `file_type(directory)` is
|
|
|
|
specified, or unless `access(none)`.
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
- file_errors(`fail`/`error`)
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
If `error` (default), throw `existence_error` exception
|
|
|
|
if the file cannot be found. If `fail`, stay silent.
|
2016-01-03 02:06:09 +00:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
- solutions(`first`/`all`)
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
If `first` (default), commit to the first solution. Otherwise
|
|
|
|
absolute_file_name will enumerate all solutions via backtracking.
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
- expand(`true`/`false`)
|
2015-12-15 08:54:21 +00:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
If `true` (default is `false`) and _Spec_ is atomic, call
|
|
|
|
expand_file_name/2 followed by member/2 on _Spec_ before
|
|
|
|
proceeding. This is originally a SWI-Prolog extension, but
|
|
|
|
whereas SWI-Prolog implements its own conventions, YAP uses the
|
|
|
|
shell's `glob` primitive.
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
Notice that in `glob` mode YAP will fail if it cannot find a matching file, as `glob`
|
|
|
|
implicitely tests for existence when checking for patterns.
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
- glob(`Pattern`)
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
If _Pattern_ is atomic, add the pattern as a suffix to the current expansion, and call
|
|
|
|
expand_file_name/2 followed by member/2 on the result. This is originally a SICStus Prolog exception.
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
Both `glob` and `expand` rely on the same underlying
|
|
|
|
mechanism. YAP gives preference to `glob`.
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
- verbose_file_search(`true`/`false`)
|
2015-12-15 08:54:47 +00:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
If `true` (default is `false`) output messages during
|
|
|
|
search. This is often helpful when debugging. Corresponds to the
|
|
|
|
SWI-Prolog flag `verbose_file_search` (also available in YAP).
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
|
|
|
|
Compatibility considerations to common argument-order in ISO as well
|
|
|
|
as SICStus absolute_file_name/3 forced us to be flexible here.
|
|
|
|
If the last argument is a list and the second not, the arguments are
|
|
|
|
swapped, thus the call
|
|
|
|
~~~~~~~~~~~~
|
|
|
|
?- absolute_file_name( 'pl/absf.yap', [], Path)
|
|
|
|
~~~~~~~~~~~~
|
|
|
|
is valid as well.
|
|
|
|
*/
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-03-29 01:59:01 +01:00
|
|
|
absolute_file_name(File,TrueFileName,Opts) :-
|
2014-09-25 09:43:50 +01:00
|
|
|
( var(TrueFileName) ->
|
2016-03-17 00:01:09 +00:00
|
|
|
true ;
|
2015-02-16 11:43:42 +00:00
|
|
|
atom(TrueFileName), TrueFileName \= []
|
2016-03-17 00:01:09 +00:00
|
|
|
),
|
|
|
|
!,
|
2014-09-25 09:43:50 +01:00
|
|
|
absolute_file_name(File,Opts,TrueFileName).
|
2014-06-20 11:13:39 +01:00
|
|
|
absolute_file_name(File,Opts,TrueFileName) :-
|
2017-10-02 08:58:51 +01:00
|
|
|
'$absolute_file_name'(File,Opts,TrueFileName).
|
2014-04-21 11:14:18 +01:00
|
|
|
|
|
|
|
/**
|
2014-07-17 18:19:38 +01:00
|
|
|
@pred absolute_file_name(+Name:atom,+Path:atom) is nondet
|
2014-04-21 11:14:18 +01:00
|
|
|
|
2015-03-16 17:25:09 +00:00
|
|
|
Converts the given file specification into an absolute path, using default options. See absolute_file_name/3 for details on the options.
|
2014-04-21 11:14:18 +01:00
|
|
|
*/
|
2016-03-17 00:01:09 +00:00
|
|
|
absolute_file_name(V,Out) :- var(V),
|
|
|
|
!, % absolute_file_name needs commenting.
|
2014-04-21 11:14:18 +01:00
|
|
|
'$do_error'(instantiation_error, absolute_file_name(V, Out)).
|
|
|
|
absolute_file_name(user,user) :- !.
|
2015-12-15 08:54:47 +00:00
|
|
|
absolute_file_name(File0,File) :-
|
2017-10-02 08:58:51 +01:00
|
|
|
'$absolute_file_name'(File0,[access(none),file_type(txt),file_errors(fail),solutions(first)],File).
|
2014-04-21 11:14:18 +01:00
|
|
|
|
2017-10-02 08:58:51 +01:00
|
|
|
'$full_filename'(F0, F) :-
|
2015-12-15 08:54:47 +00:00
|
|
|
'$absolute_file_name'(F0,[access(read),
|
|
|
|
file_type(prolog),
|
|
|
|
file_errors(fail),
|
|
|
|
solutions(first),
|
2017-10-02 08:58:51 +01:00
|
|
|
expand(true)],F).
|
2016-02-29 03:13:23 +00:00
|
|
|
|
2017-10-02 08:58:51 +01:00
|
|
|
'$absolute_file_name'(File,LOpts,TrueFileName) :-
|
2016-05-13 11:41:55 +01:00
|
|
|
% must_be_of_type( atom, File ),
|
2017-10-02 08:58:51 +01:00
|
|
|
% look for solutions
|
|
|
|
gated_call(
|
|
|
|
'$enter_absf'( File, LOpts, Opts, HasSol, OldF, PreviousFileErrors, PreviousVerbose, Expand, Verbose, TakeFirst, FileErrors ),
|
|
|
|
'$find_in_path'(File, Opts,TrueFileName),
|
|
|
|
Port,
|
|
|
|
'$absf_port'(Port, File, TrueFileName, HasSol, OldF, PreviousFileErrors, PreviousVerbose, Expand, Verbose, TakeFirst, FileErrors )
|
|
|
|
).
|
|
|
|
|
|
|
|
'$enter_absf'( File, LOpts, Opts, HasSol, OldF, PreviousFileErrors, PreviousVerbose, Expand, Verbose, TakeFirst, FileErrors ) :-
|
2016-05-13 11:41:55 +01:00
|
|
|
( var(File) -> instantiation_error(File) ; true),
|
2016-02-11 14:17:30 +00:00
|
|
|
abs_file_parameters(LOpts,Opts),
|
2015-11-09 11:27:46 +00:00
|
|
|
current_prolog_flag(open_expands_filename, OldF),
|
2015-06-19 01:30:13 +01:00
|
|
|
current_prolog_flag( fileerrors, PreviousFileErrors ),
|
2015-09-21 23:05:36 +01:00
|
|
|
current_prolog_flag( verbose_file_search, PreviousVerbose ),
|
2017-05-08 18:51:29 +01:00
|
|
|
get_abs_file_parameter( verbose_file_search, Opts,Verbose ),
|
2015-09-21 23:05:36 +01:00
|
|
|
get_abs_file_parameter( expand, Opts, Expand ),
|
|
|
|
set_prolog_flag( verbose_file_search, Verbose ),
|
|
|
|
get_abs_file_parameter( file_errors, Opts, FErrors ),
|
2017-10-02 08:58:51 +01:00
|
|
|
get_abs_file_parameter( solutions, Opts, TakeFirst ),
|
2016-02-19 11:37:11 +00:00
|
|
|
( FErrors == fail -> FileErrors = false ; FileErrors = true ),
|
|
|
|
set_prolog_flag( fileerrors, FileErrors ),
|
2015-09-21 23:05:36 +01:00
|
|
|
set_prolog_flag(file_name_variables, Expand),
|
2016-02-11 14:17:30 +00:00
|
|
|
'$absf_trace'(File),
|
|
|
|
'$absf_trace_options'(LOpts),
|
2017-10-02 08:58:51 +01:00
|
|
|
HasSol = t(no).
|
|
|
|
|
|
|
|
'$absf_port'(answer, File, TrueFileName, HasSol, OldF, PreviousFileErrors, PreviousVerbose, Expand, Verbose, TakeFirst, FileErrors ) :-
|
|
|
|
'$absf_port'(exit, File, TrueFileName, HasSol, OldF, PreviousFileErrors, PreviousVerbose, Expand, Verbose, TakeFirst, FileErrors ).
|
|
|
|
'$absf_port'(exit, _File, TrueFileName, HasSol, OldF, PreviousFileErrors, PreviousVerbose, _Expand, _Verbose, TakeFirst, _FileErrors ) :-
|
|
|
|
(TakeFirst == first -> ! ; nb_setarg(1, HasSol, yes) ),
|
|
|
|
set_prolog_flag( fileerrors, PreviousFileErrors ),
|
|
|
|
set_prolog_flag( open_expands_filename, OldF),
|
|
|
|
set_prolog_flag( verbose_file_search, PreviousVerbose ),
|
|
|
|
'$absf_trace'(' |------- found ~a', [TrueFileName]).
|
|
|
|
'$absf_port'(redo, File, _TrueFileName, _HasSol, _OldF, _PreviousFileErrors, _PreviousVerbose, Expand, Verbose, _TakeFirst, FileErrors ) :-
|
|
|
|
set_prolog_flag( fileerrors, FileErrors ),
|
|
|
|
set_prolog_flag( verbose_file_search, Verbose ),
|
|
|
|
set_prolog_flag( file_name_variables, Expand ),
|
|
|
|
'$absf_trace'(' |------- restarted search for ~a', [File]).
|
|
|
|
'$absf_port'(fail, File, TrueFileName, HasSol, OldF, PreviousFileErrors, PreviousVerbose, _Expand, _Verbose, _TakeFirst, FileErrors ) :-
|
|
|
|
'$absf_trace'(' !------- failed.', []),
|
|
|
|
set_prolog_flag( fileerrors, PreviousFileErrors ),
|
|
|
|
set_prolog_flag( verbose_file_search, PreviousVerbose ),
|
|
|
|
set_prolog_flag(file_name_variables, OldF),
|
|
|
|
% check if no solution
|
|
|
|
arg(1,HasSol,no),
|
|
|
|
FileErrors = error,
|
|
|
|
'$do_error'(existence_error(file,File),absolute_file_name(File, TrueFileName, ['...'])).
|
|
|
|
'$absf_port'(!, _File, _TrueFileName, _HasSol, _OldF, _PreviousFileErrors, _PreviousVerbose, _Expand, _Verbose, _TakeFirst, _FileErrors ).
|
|
|
|
'$absf_port'(exception(_), File, TrueFileName, HasSol, OldF, PreviousFileErrors, PreviousVerbose, Expand, Verbose, TakeFirst, FileErrors ) :-
|
|
|
|
'$absf_port'(fail, File, TrueFileName, HasSol, OldF, PreviousFileErrors, PreviousVerbose, Expand, Verbose, TakeFirst, FileErrors ).
|
|
|
|
'$absf_port'(external_exception(_), File, TrueFileName, HasSol, OldF, PreviousFileErrors, PreviousVerbose, Expand, Verbose, TakeFirst, FileErrors ) :-
|
|
|
|
'$absf_port'(fail, File, TrueFileName, HasSol, OldF, PreviousFileErrors, PreviousVerbose, Expand, Verbose, TakeFirst, FileErrors ).
|
2016-02-29 03:13:23 +00:00
|
|
|
|
2013-11-13 22:52:36 +00:00
|
|
|
% This sequence must be followed:
|
|
|
|
% user and user_input are special;
|
|
|
|
% library(F) must check library_directories
|
|
|
|
% T(F) must check file_search_path
|
|
|
|
% all must try search in path
|
2016-02-11 14:17:30 +00:00
|
|
|
'$find_in_path'(user,_,user_input) :- !.
|
|
|
|
'$find_in_path'(user_input,_,user_input) :- !.
|
|
|
|
'$find_in_path'(user_output,_,user_ouput) :- !.
|
|
|
|
'$find_in_path'(user_error,_,user_error) :- !.
|
|
|
|
'$find_in_path'(Name, Opts, File) :-
|
|
|
|
% ( atom(Name) -> true ; start_low_level_trace ),
|
|
|
|
get_abs_file_parameter( file_type, Opts, Type ),
|
|
|
|
get_abs_file_parameter( access, Opts, Access ),
|
2016-02-29 03:13:23 +00:00
|
|
|
get_abs_file_parameter( expand, Opts, Expand ),
|
2016-02-11 14:17:30 +00:00
|
|
|
'$absf_trace'('start with ~w', [Name]),
|
|
|
|
'$core_file_name'(Name, Opts, CorePath, []),
|
|
|
|
'$absf_trace'(' after name/library unfolding: ~w', [Name]),
|
2016-02-13 03:07:04 +00:00
|
|
|
'$variable_expansion'(CorePath, Opts,ExpandedPath),
|
|
|
|
'$absf_trace'(' after environment variable expansion: ~s', [ExpandedPath]),
|
|
|
|
'$prefix'(ExpandedPath, Opts, Path , []),
|
|
|
|
'$absf_trace'(' after prefix expansion: ~s', [Path]),
|
2016-02-11 14:17:30 +00:00
|
|
|
atom_codes( APath, Path ),
|
|
|
|
(
|
2016-02-29 03:13:23 +00:00
|
|
|
Expand = true
|
2016-02-11 14:17:30 +00:00
|
|
|
->
|
2016-02-29 03:13:23 +00:00
|
|
|
expand_file_name( APath, EPaths),
|
|
|
|
'$absf_trace'(' after shell globbing: ~w', [EPaths]),
|
|
|
|
lists:member(EPath, EPaths)
|
2016-02-11 14:17:30 +00:00
|
|
|
;
|
2016-02-29 03:13:23 +00:00
|
|
|
EPath = APath
|
2016-02-11 14:17:30 +00:00
|
|
|
),
|
2016-03-17 00:01:09 +00:00
|
|
|
real_path( EPath, File),
|
2016-02-29 03:13:23 +00:00
|
|
|
'$absf_trace'(' after canonical path name: ~a', [File]),
|
2016-02-11 14:17:30 +00:00
|
|
|
'$check_file'( File, Type, Access ),
|
2016-02-29 03:13:23 +00:00
|
|
|
'$absf_trace'(' after testing ~a for ~a and ~a', [File,Type,Access]).
|
2013-11-13 22:52:36 +00:00
|
|
|
|
|
|
|
% allow paths in File Name
|
2016-02-11 14:17:30 +00:00
|
|
|
'$core_file_name'(Name, Opts) -->
|
2016-02-29 03:13:23 +00:00
|
|
|
'$file_name'(Name, Opts, E),
|
|
|
|
'$suffix'(E, Opts),
|
2016-03-17 00:01:09 +00:00
|
|
|
'$glob'(Opts).
|
2016-02-11 14:17:30 +00:00
|
|
|
|
|
|
|
%
|
|
|
|
% handle library(lists) or foreign(jpl)
|
|
|
|
%
|
2016-02-29 03:13:23 +00:00
|
|
|
'$file_name'(Name, Opts, E) -->
|
2016-02-11 14:17:30 +00:00
|
|
|
{ Name =.. [Lib, P0] },
|
|
|
|
!,
|
|
|
|
{ user:file_search_path(Lib, IDirs) },
|
|
|
|
{ '$paths'(IDirs, Dir ) },
|
|
|
|
'$absf_trace'(' ~w first', [Dir]),
|
|
|
|
'$file_name'(Dir, Opts, _),
|
|
|
|
'$dir',
|
2016-02-29 03:13:23 +00:00
|
|
|
{ '$absf_trace'(' ~w next', [P0]) },
|
2016-02-11 14:17:30 +00:00
|
|
|
'$cat_file_name'(P0, E).
|
2017-05-19 09:56:37 +01:00
|
|
|
'$file_name'(Name, _Opts, E) -->
|
2017-05-08 18:51:29 +01:00
|
|
|
'$cat_file_name'(Name, E ).
|
|
|
|
/*
|
|
|
|
(
|
|
|
|
{
|
2017-05-19 09:56:37 +01:00
|
|
|
get_abs_file_parameter( file_type, _Opts, Lib ),
|
2017-05-08 18:51:29 +01:00
|
|
|
nonvar(Lib)
|
|
|
|
}
|
|
|
|
->
|
|
|
|
{ user:file_search_path(Lib, IDirs) },
|
|
|
|
{ '$paths'(IDirs, Dir ) },
|
|
|
|
'$absf_trace'(' ~w first', [Dir]),
|
|
|
|
'$file_name'(Dir, Opts, _),
|
|
|
|
'$dir',
|
|
|
|
{ '$absf_trace'(' ~w next', [P0]) }
|
|
|
|
;
|
|
|
|
[]
|
|
|
|
).
|
|
|
|
*/
|
2016-02-11 14:17:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
'$cat_file_name'(A/B, E ) -->
|
|
|
|
'$cat_file_name'(A, _),
|
|
|
|
'$dir',
|
|
|
|
'$cat_file_name'(B, E).
|
|
|
|
'$cat_file_name'(File, F) -->
|
|
|
|
{ atom(File), atom_codes(File, F) },
|
|
|
|
!,
|
|
|
|
F.
|
|
|
|
'$cat_file_name'(File, S) -->
|
|
|
|
{string(File), string_to_codes(File, S) },
|
|
|
|
!,
|
2016-02-29 03:13:23 +00:00
|
|
|
S.
|
2016-02-11 14:17:30 +00:00
|
|
|
|
2016-02-13 03:07:04 +00:00
|
|
|
|
|
|
|
'$variable_expansion'( Path, Opts, APath ) :-
|
2016-02-11 14:17:30 +00:00
|
|
|
get_abs_file_parameter( expand, Opts, true ),
|
2016-02-13 03:07:04 +00:00
|
|
|
!,
|
|
|
|
'$expand_file_name'( Path, APath ).
|
|
|
|
'$variable_expansion'( Path, _, Path ).
|
|
|
|
|
2016-02-11 14:17:30 +00:00
|
|
|
|
|
|
|
'$var'(S) -->
|
|
|
|
"{", !, '$id'(S), "}".
|
|
|
|
'$var'(S) -->
|
|
|
|
'$id'(S).
|
|
|
|
|
2017-04-07 23:10:59 +01:00
|
|
|
'$drive'(C) -->
|
|
|
|
'$id'(C),
|
2016-02-11 14:17:30 +00:00
|
|
|
":\\\\".
|
|
|
|
|
2016-02-13 03:07:04 +00:00
|
|
|
'$id'([C|S]) --> [C],
|
2016-02-11 14:17:30 +00:00
|
|
|
{ C >= "a", C =< "z" ; C >= "A", C =< "Z" ;
|
|
|
|
C >= "0", C =< "9" ; C =:= "_" },
|
|
|
|
!,
|
|
|
|
'$id'(S).
|
|
|
|
'$id'([]) --> [].
|
|
|
|
|
|
|
|
|
|
|
|
% always verify if a directory
|
|
|
|
'$check_file'(F, directory, _) :-
|
|
|
|
!,
|
|
|
|
exists_directory(F).
|
|
|
|
'$check_file'(_F, _Type, none) :- !.
|
2016-02-13 03:07:04 +00:00
|
|
|
'$check_file'(F, _Type, exist) :-
|
2016-02-14 04:18:15 +00:00
|
|
|
'$access_file'(F, exist). % if it has a type cannot be a directory..
|
2016-02-11 14:17:30 +00:00
|
|
|
'$check_file'(F, _Type, Access) :-
|
2016-02-14 04:18:15 +00:00
|
|
|
'$access_file'(F, Access),
|
|
|
|
\+ exists_directory(F). % if it has a type cannot be a directory..
|
2016-02-11 14:17:30 +00:00
|
|
|
|
|
|
|
'$suffix'(Last, _Opts) -->
|
|
|
|
{ lists:append(_, [0'.|Alphas], Last), '$id'(Alphas, _, [] ) },
|
2017-10-02 08:58:51 +01:00
|
|
|
'$absf_trace'(' suffix in ~s', [Alphas]),
|
2016-02-11 14:17:30 +00:00
|
|
|
!.
|
|
|
|
'$suffix'(_, Opts) -->
|
|
|
|
{
|
|
|
|
(
|
|
|
|
get_abs_file_parameter( extensions, Opts, Exts ),
|
|
|
|
Exts \= []
|
|
|
|
->
|
|
|
|
lists:member(Ext, Exts),
|
|
|
|
'$absf_trace'(' trying suffix ~a from ~w', [Ext,Exts])
|
2015-11-09 11:27:46 +00:00
|
|
|
;
|
2016-02-11 14:17:30 +00:00
|
|
|
get_abs_file_parameter( file_type, Opts, Type ),
|
|
|
|
( Type == source -> NType = prolog ; NType = Type ),
|
|
|
|
user:prolog_file_type(Ext, NType)
|
2015-11-09 11:27:46 +00:00
|
|
|
),
|
2016-02-11 14:17:30 +00:00
|
|
|
'$absf_trace'(' trying suffix ~a from type ~a', [Ext, NType]),
|
|
|
|
atom_codes(Ext, Cs)
|
|
|
|
},
|
|
|
|
'$add_suffix'(Cs).
|
|
|
|
'$suffix'(_,_Opts) -->
|
|
|
|
'$absf_trace'(' try no suffix', []).
|
|
|
|
|
|
|
|
'$add_suffix'(Cs) -->
|
|
|
|
{ Cs = [0'. |_Codes] }
|
|
|
|
->
|
|
|
|
Cs
|
|
|
|
;
|
|
|
|
".", Cs.
|
|
|
|
|
|
|
|
'$glob'(Opts) -->
|
|
|
|
{
|
|
|
|
get_abs_file_parameter( glob, Opts, G ),
|
2016-02-29 03:13:23 +00:00
|
|
|
G \= '',
|
2016-02-11 14:17:30 +00:00
|
|
|
atom_codes( G, Gs )
|
|
|
|
},
|
2016-02-19 11:37:11 +00:00
|
|
|
!,
|
2016-02-11 14:17:30 +00:00
|
|
|
'$dir',
|
|
|
|
Gs.
|
|
|
|
'$glob'(_Opts) -->
|
|
|
|
[].
|
2015-12-15 08:54:47 +00:00
|
|
|
|
2016-01-31 10:43:42 +00:00
|
|
|
'$enumerate_glob'(_File1, [ExpFile], ExpFile) :-
|
2015-12-15 08:54:47 +00:00
|
|
|
!.
|
2016-01-31 10:43:42 +00:00
|
|
|
'$enumerate_glob'(_File1, ExpFiles, ExpFile) :-
|
2015-12-15 08:54:47 +00:00
|
|
|
lists:member(ExpFile, ExpFiles),
|
|
|
|
file_base_name( ExpFile, Base ),
|
|
|
|
Base \= '.',
|
|
|
|
Base \='..'.
|
|
|
|
|
2016-02-13 03:07:04 +00:00
|
|
|
'$prefix'( CorePath, _Opts) -->
|
|
|
|
{ is_absolute_file_name( CorePath ) },
|
|
|
|
!,
|
|
|
|
CorePath.
|
2016-02-11 14:17:30 +00:00
|
|
|
'$prefix'( CorePath, Opts) -->
|
|
|
|
{ get_abs_file_parameter( relative_to, Opts, Prefix ),
|
|
|
|
Prefix \= '',
|
|
|
|
'$absf_trace'(' relative_to ~a', [Prefix]),
|
|
|
|
sub_atom(Prefix, _, 1, 0, Last),
|
|
|
|
atom_codes(Prefix, S)
|
|
|
|
},
|
|
|
|
!,
|
|
|
|
S,
|
2016-02-13 03:07:04 +00:00
|
|
|
'$dir'(Last),
|
|
|
|
CorePath.
|
|
|
|
'$prefix'( CorePath, _) -->
|
2016-02-11 14:17:30 +00:00
|
|
|
{
|
|
|
|
recorded('$path',Prefix,_),
|
|
|
|
'$absf_trace'(' try YAP path database ~a', [Prefix]),
|
|
|
|
sub_atom(Prefix, _, _, 1, Last),
|
|
|
|
atom_codes(Prefix, S) },
|
|
|
|
S,
|
2016-02-13 03:07:04 +00:00
|
|
|
'$dir'(Last),
|
|
|
|
CorePath.
|
|
|
|
'$prefix'(CorePath, _ ) -->
|
|
|
|
'$absf_trace'(' empty prefix', []),
|
|
|
|
CorePath.
|
2016-02-11 14:17:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
'$dir' --> { current_prolog_flag(windows, true) },
|
2016-04-18 13:25:23 +01:00
|
|
|
"\\",
|
|
|
|
!.
|
2016-02-11 14:17:30 +00:00
|
|
|
'$dir' --> "/".
|
|
|
|
|
|
|
|
'$dir'('/') --> !.
|
|
|
|
'$dir'('\\') --> { current_prolog_flag(windows, true) },
|
|
|
|
!.
|
|
|
|
'$dir'(_) --> '$dir'.
|
2015-12-15 08:54:47 +00:00
|
|
|
|
2016-02-11 14:17:30 +00:00
|
|
|
%
|
2016-02-29 03:13:23 +00:00
|
|
|
%
|
2016-02-11 14:17:30 +00:00
|
|
|
%
|
2014-03-04 11:58:48 +00:00
|
|
|
'$system_library_directories'(library, Dir) :-
|
2015-02-16 11:43:42 +00:00
|
|
|
user:library_directory( Dir ).
|
2014-11-10 01:54:14 +00:00
|
|
|
% '$split_by_sep'(0, 0, Dirs, Dir).
|
2014-03-06 02:09:48 +00:00
|
|
|
'$system_library_directories'(foreign, Dir) :-
|
2017-05-08 18:51:29 +01:00
|
|
|
user:foreign_directory( Dir ).
|
2014-10-09 10:43:44 +01:00
|
|
|
% compatibility with old versions
|
2017-02-20 15:28:46 +00:00
|
|
|
%
|
|
|
|
% search the current directory first.
|
2014-04-06 17:05:17 +01:00
|
|
|
'$system_library_directories'(commons, Dir) :-
|
2017-05-08 18:51:29 +01:00
|
|
|
user:commons_directory( Dir ).
|
2013-11-13 22:52:36 +00:00
|
|
|
|
2016-02-11 14:17:30 +00:00
|
|
|
|
|
|
|
% enumerate all paths separated by a path_separator.
|
|
|
|
'$paths'(Cs, C) :-
|
|
|
|
atom(Cs),
|
|
|
|
( current_prolog_flag(windows, true) -> Sep = ';' ; Sep = ':' ),
|
|
|
|
sub_atom(Cs, N0, 1, N, Sep),
|
|
|
|
!,
|
|
|
|
(
|
2016-03-17 00:01:09 +00:00
|
|
|
sub_atom(Cs,0,N0,_,C)
|
2016-02-11 14:17:30 +00:00
|
|
|
;
|
2016-03-17 00:01:09 +00:00
|
|
|
sub_atom(Cs,_,N,0,RC),
|
|
|
|
'$paths'(RC, C)
|
2016-02-11 14:17:30 +00:00
|
|
|
).
|
|
|
|
'$paths'(S, S).
|
2016-02-29 03:13:23 +00:00
|
|
|
|
2016-02-11 14:17:30 +00:00
|
|
|
'$absf_trace'(Msg, Args ) -->
|
|
|
|
{ current_prolog_flag( verbose_file_search, true ) },
|
2016-04-18 13:25:23 +01:00
|
|
|
{ print_message( informational, absolute_file_path( Msg, Args ) ) },
|
|
|
|
!.
|
2016-02-11 14:17:30 +00:00
|
|
|
'$absf_trace'(_Msg, _Args ) --> [].
|
2013-11-13 22:52:36 +00:00
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
'$absf_trace'(Msg, Args ) :-
|
2016-02-11 14:17:30 +00:00
|
|
|
current_prolog_flag( verbose_file_search, true ),
|
2016-04-18 13:25:23 +01:00
|
|
|
print_message( informational, absolute_file_path( Msg, Args ) ),
|
|
|
|
!.
|
2016-02-11 14:17:30 +00:00
|
|
|
'$absf_trace'(_Msg, _Args ).
|
|
|
|
|
|
|
|
'$absf_trace'( File ) :-
|
2015-09-21 23:05:36 +01:00
|
|
|
current_prolog_flag( verbose_file_search, true ),
|
2016-04-18 13:25:23 +01:00
|
|
|
print_message( informational, absolute_file_path( File ) ),
|
|
|
|
!.
|
2016-02-11 14:17:30 +00:00
|
|
|
'$absf_trace'( _File ).
|
|
|
|
|
|
|
|
'$absf_trace_options'(Args ) :-
|
|
|
|
current_prolog_flag( verbose_file_search, true ),
|
2016-04-18 13:25:23 +01:00
|
|
|
print_message( informational, arguments( Args ) ),
|
|
|
|
!.
|
2016-02-11 14:17:30 +00:00
|
|
|
'$absf_trace_options'( _Args ).
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2015-11-09 11:27:46 +00:00
|
|
|
/** @pred prolog_file_name( +File, -PrologFileaNme)
|
2014-09-15 19:10:49 +01:00
|
|
|
|
|
|
|
Unify _PrologFileName_ with the Prolog file associated to _File_.
|
|
|
|
|
|
|
|
*/
|
|
|
|
prolog_file_name(File, PrologFileName) :-
|
|
|
|
var(File), !,
|
|
|
|
'$do_error'(instantiation_error, prolog_file_name(File, PrologFileName)).
|
|
|
|
prolog_file_name(user, Out) :- !, Out = user.
|
|
|
|
prolog_file_name(File, PrologFileName) :-
|
|
|
|
atom(File), !,
|
2015-11-05 17:18:29 +00:00
|
|
|
system:true_file_name(File, PrologFileName).
|
2014-09-15 19:10:49 +01:00
|
|
|
prolog_file_name(File, PrologFileName) :-
|
2014-10-07 01:35:41 +01:00
|
|
|
'$do_error'(type_error(atom,File), prolog_file_name(File, PrologFileName)).
|
2014-09-15 19:10:49 +01:00
|
|
|
|
2014-04-21 11:14:18 +01:00
|
|
|
/**
|
2014-07-17 18:19:38 +01:00
|
|
|
@pred path(-Directories:list) is det,deprecated
|
2014-04-06 17:05:17 +01:00
|
|
|
|
2014-05-25 20:52:45 +01:00
|
|
|
YAP specific procedure that returns a list of user-defined directories
|
|
|
|
in the library search-path.We suggest using user:file_search_path/2 for
|
|
|
|
compatibility with other Prologs.
|
2014-04-06 17:05:17 +01:00
|
|
|
*/
|
2015-09-21 23:05:36 +01:00
|
|
|
path(Path) :-
|
|
|
|
findall(X,'$in_path'(X),Path).
|
2014-04-06 17:05:17 +01:00
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
'$in_path'(X) :-
|
|
|
|
recorded('$path',Path,_),
|
|
|
|
atom_codes(Path,S),
|
|
|
|
( S = "" -> X = '.' ;
|
|
|
|
atom_codes(X,S) ).
|
2014-04-06 17:05:17 +01:00
|
|
|
|
2014-04-21 11:14:18 +01:00
|
|
|
/**
|
2014-07-17 18:19:38 +01:00
|
|
|
@pred add_to_path(+Directory:atom) is det,deprecated
|
2014-04-06 17:05:17 +01:00
|
|
|
|
2014-04-21 11:14:18 +01:00
|
|
|
YAP-specific predicate to include directory in library search path.
|
2014-05-25 20:52:45 +01:00
|
|
|
We suggest using user:file_search_path/2 for
|
|
|
|
compatibility with other Prologs.
|
2014-04-06 17:05:17 +01:00
|
|
|
*/
|
2015-09-21 23:05:36 +01:00
|
|
|
add_to_path(New) :-
|
|
|
|
add_to_path(New,last).
|
2014-04-06 17:05:17 +01:00
|
|
|
|
2014-04-21 11:14:18 +01:00
|
|
|
/**
|
2014-07-17 18:19:38 +01:00
|
|
|
@pred add_to_path(+Directory:atom, +Position:atom) is det,deprecated
|
2014-04-21 11:14:18 +01:00
|
|
|
|
2014-05-25 20:52:45 +01:00
|
|
|
YAP-specific predicate to include directory in front or back of
|
|
|
|
library search path. We suggest using user:file_search_path/2 for
|
|
|
|
compatibility with other Prologs and more extensive functionality.
|
2014-04-21 11:14:18 +01:00
|
|
|
*/
|
2014-04-06 17:05:17 +01:00
|
|
|
add_to_path(New,Pos) :-
|
|
|
|
atom(New), !,
|
|
|
|
'$check_path'(New,Str),
|
|
|
|
atom_codes(Path,Str),
|
|
|
|
'$add_to_path'(Path,Pos).
|
|
|
|
|
2015-09-21 23:05:36 +01:00
|
|
|
'$add_to_path'(New,_) :-
|
|
|
|
recorded('$path',New,R),
|
|
|
|
erase(R),
|
|
|
|
fail.
|
|
|
|
'$add_to_path'(New,last) :-
|
|
|
|
!,
|
|
|
|
recordz('$path',New,_).
|
|
|
|
'$add_to_path'(New,first) :-
|
|
|
|
recorda('$path',New,_).
|
2014-04-06 17:05:17 +01:00
|
|
|
|
2014-07-17 18:19:38 +01:00
|
|
|
/** @pred remove_from_path(+Directory:atom) is det,deprecated
|
2014-04-06 17:05:17 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
@}
|
|
|
|
|
2014-04-06 17:05:17 +01:00
|
|
|
*/
|
|
|
|
remove_from_path(New) :- '$check_path'(New,Path),
|
|
|
|
recorded('$path',Path,R), erase(R).
|
|
|
|
|
|
|
|
'$check_path'(At,SAt) :- atom(At), !, atom_codes(At,S), '$check_path'(S,SAt).
|
|
|
|
'$check_path'([],[]).
|
|
|
|
'$check_path'([Ch],[Ch]) :- '$dir_separator'(Ch), !.
|
|
|
|
'$check_path'([Ch],[Ch,A]) :- !, integer(Ch), '$dir_separator'(A).
|
|
|
|
'$check_path'([N|S],[N|SN]) :- integer(N), '$check_path'(S,SN).
|
2016-01-20 22:36:16 +00:00
|
|
|
|