This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/pl/pathconf.yap

201 lines
5.7 KiB
Plaintext
Raw Normal View History

2018-06-05 20:51:49 +01:00
/**
* @file pathconf.yap
*
*/
2016-07-31 16:36:57 +01:00
/**
@defgroup pathconf Configuration of the Prolog file search path
2018-06-05 20:51:49 +01:00
@{
2016-07-31 16:36:57 +01:00
@ingroup AbsoluteFileName
Prolog systems search follow a complex search on order to track down files.
**/
2017-05-08 18:51:29 +01:00
:- module(user).
2016-07-31 16:36:57 +01:00
/**
2019-01-09 09:32:09 +00:00
@pred user:library_directory(?Directory:atom) is nondet, dynamic
2016-07-31 16:36:57 +01:00
Dynamic, multi-file predicate that succeeds when _Directory_ is a
current library directory name. Asserted in the user module.
Library directories are the places where files specified in the form
`library( _File_ )` are searched by the predicates consult/1,
reconsult/1, use_module/1, ensure_loaded/1, and load_files/2.
This directory is initialized by a rule that calls the system predicate
system_library/1.
*/
2019-01-09 09:32:09 +00:00
:- multifile user:library_directory/1.
:- discontiguous user:library_directory/1.
:- dynamic user:library_directory/1.
2016-07-31 16:36:57 +01:00
%% Specifies the set of directories where
% one can find Prolog libraries.
%
2019-01-09 09:32:09 +00:00
user:library_directory(Home) :-
current_prolog_flag(library_directory, Home),
2017-05-08 18:51:29 +01:00
Home \= ''.
2016-07-31 16:36:57 +01:00
% 1. honor YAPSHAREDIR
2019-01-09 09:32:09 +00:00
user:library_directory( Dir ) :-
2016-07-31 16:36:57 +01:00
getenv( 'YAPSHAREDIR', Dir).
%% 2. honor user-library
2019-01-09 09:32:09 +00:00
user:library_directory( '~/share/Yap' ).
2016-07-31 16:36:57 +01:00
%% 3. honor current directory
2019-01-09 09:32:09 +00:00
user:library_directory( '.' ).
2016-07-31 16:36:57 +01:00
%% 4. honor default location.
2019-01-09 09:32:09 +00:00
user:library_directory( Dir ) :-
2016-07-31 16:36:57 +01:00
system_library( Dir ).
/**
@pred commons_directory(? _Directory_:atom) is nondet, dynamic
State the location of the Commons Prolog Initiative.
This directory is initialized as a rule that calls the system predicate
library_directories/2.
2017-05-08 18:51:29 +01:00
*/
2019-01-09 09:32:09 +00:00
:- dynamic user:commons_directory/1.
:- discontiguous user:commons_directory/1.
:- multifile user:commons_directory/1.
2017-05-08 18:51:29 +01:00
2016-07-31 16:36:57 +01:00
2019-01-09 09:32:09 +00:00
user:commons_directory( Path ):-
2016-07-31 16:36:57 +01:00
system_commons( Path ).
/**
@pred foreign_directory(? _Directory_:atom) is nondet, dynamic
State the location of the Foreign Prolog Initiative.
This directory is initialized as a rule that calls the system predicate
library_directories/2.
*/
:- multifile foreign_directory/1.
2018-11-23 00:01:55 +00:00
:- discontiguous foreign_directory/1.
2016-07-31 16:36:57 +01:00
:- dynamic foreign_directory/1.
2017-05-08 18:51:29 +01:00
%foreign_directory( Path ):-
foreign_directory(Home) :-
current_prolog_flag(prolog_foreign_directory, Home),
Home \= ''.
2017-09-02 23:50:09 +01:00
foreign_directory(C) :-
current_prolog_flag(windows, true),
2019-01-09 09:32:09 +00:00
user:file_search_path(path, C).
2017-05-08 18:51:29 +01:00
foreign_directory( '.').
foreign_directory(yap('lib/Yap')).
2017-09-02 23:50:09 +01:00
%foreign_directory( Path ):-
% system_foreign( Path ).
2016-07-31 16:36:57 +01:00
/**
@pred prolog_file_type(?Suffix:atom, ?Handler:atom) is nondet, dynamic
This multifile/dynamic predicate relates a file extension _Suffix_
to a language or file type _Handler_. By
default, it supports the extensions yap, pl, and prolog for prolog files and
uses one of dll, so, or dylib for shared objects. Initial definition is:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~prolog
2019-01-09 09:32:09 +00:00
user:prolog_file_type(yap, prolog).
user:prolog_file_type(pl, prolog).
user:prolog_file_type(prolog, prolog).
user:prolog_file_type(qly, prolog).
user:prolog_file_type(qly, qly).
user:prolog_file_type(A, prolog) :-
2016-07-31 16:36:57 +01:00
current_prolog_flag(associate, A),
A \== prolog,
A \==pl,
A \== yap.
2019-01-09 09:32:09 +00:00
user:prolog_file_type(A, executable) :-
2016-07-31 16:36:57 +01:00
current_prolog_flag(shared_object_extension, A).
2019-01-09 09:32:09 +00:00
user:prolog_file_type(pyd, executable).
~~~~~~~~~~~~~~~~~~~~~
2016-07-31 16:36:57 +01:00
*/
2019-01-09 09:32:09 +00:00
:- multifile user:prolog_file_type/2.
:- discontiguous user:prolog_file_type/2.
:- dynamic user:prolog_file_type/2.
2016-07-31 16:36:57 +01:00
2019-01-09 09:32:09 +00:00
user:prolog_file_type(yap, prolog).
user:prolog_file_type(pl, prolog).
user:prolog_file_type(prolog, prolog).
user:prolog_file_type(A, prolog) :-
2016-07-31 16:36:57 +01:00
current_prolog_flag(associate, A),
A \== prolog,
A \== pl,
A \== yap.
2019-01-09 09:32:09 +00:00
user:prolog_file_type(qly, qly).
user:prolog_file_type(A, executable) :-
2016-07-31 16:36:57 +01:00
current_prolog_flag(shared_object_extension, A).
2019-01-09 09:32:09 +00:00
user:prolog_file_type(pyd, executable).
2017-09-02 23:50:09 +01:00
2016-07-31 16:36:57 +01:00
/**
2019-01-09 09:32:09 +00:00
@pred user:file_search_path(+Name:atom, -Directory:atom) is nondet
2016-07-31 16:36:57 +01:00
Allows writing file names as compound terms. The _Name_ and
_DIRECTORY_ must be atoms. The predicate may generate multiple
solutions. The predicate is originally defined as follows:
2018-11-23 00:01:55 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~pl
2019-01-09 09:32:09 +00:00
user:file_search_path(library, Dir) :-
user:library_directory(Dir).
user:file_search_path(commons, Dir) :-
2016-07-31 16:36:57 +01:00
commons_directory(Dir).
2019-01-09 09:32:09 +00:00
user:file_search_path(swi, Home) :-
2016-07-31 16:36:57 +01:00
current_prolog_flag(home, Home).
2019-01-09 09:32:09 +00:00
user:file_search_path(yap, Home) :-
2016-07-31 16:36:57 +01:00
current_prolog_flag(home, Home).
2019-01-09 09:32:09 +00:00
user:file_search_path(system, Dir) :-
2016-07-31 16:36:57 +01:00
prolog_flag(host_type, Dir).
2019-01-09 09:32:09 +00:00
user:file_search_path(foreign, Dir) :-
2016-07-31 16:36:57 +01:00
foreign_directory(Dir).
2019-01-09 09:32:09 +00:00
user:file_search_path(executable, Dir) :-
2017-05-08 18:51:29 +01:00
foreign_directory(Dir).
2019-01-09 09:32:09 +00:00
user:file_search_path(executable, Dir) :-
2018-11-23 00:01:55 +00:00
foreign_directory(Dir).
2019-01-09 09:32:09 +00:00
user:file_search_path(path, C) :-
2016-07-31 16:36:57 +01:00
( getenv('PATH', A),
( current_prolog_flag(windows, true)
-> atomic_list_concat(B, ;, A)
; atomic_list_concat(B, :, A)
),
lists:member(C, B)
).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thus, `compile(library(A))` will search for a file using
2019-01-09 09:32:09 +00:00
user:library_directory/1 to obtain the prefix,
2016-07-31 16:36:57 +01:00
whereas 'compile(system(A))` would look at the `host_type` flag.
*/
2019-01-09 09:32:09 +00:00
:- multifile user:file_search_path/2.
2016-07-31 16:36:57 +01:00
2019-01-09 09:32:09 +00:00
:- dynamic user:file_search_path/2.
:- discontiguous user:file_search_path/2.
2017-05-08 18:51:29 +01:00
2019-01-09 09:32:09 +00:00
user:file_search_path(library, Dir) :-
user:library_directory(Dir).
user:file_search_path(commons, Dir) :-
user:commons_directory(Dir).
user:file_search_path(swi, Home) :-
2016-07-31 16:36:57 +01:00
current_prolog_flag(home, Home).
2019-01-09 09:32:09 +00:00
user:file_search_path(yap, Home) :-
2016-07-31 16:36:57 +01:00
current_prolog_flag(home, Home).
2019-01-09 09:32:09 +00:00
user:file_search_path(system, Dir) :-
2016-07-31 16:36:57 +01:00
prolog_flag(host_type, Dir).
2019-01-09 09:32:09 +00:00
user:file_search_path(foreign, Dir) :-
2017-05-08 18:51:29 +01:00
foreign_directory(Dir).
2019-01-09 09:32:09 +00:00
user:file_search_path(executable, Dir) :-
2017-05-08 18:51:29 +01:00
foreign_directory(Dir).
2019-01-09 09:32:09 +00:00
user:file_search_path(path, C) :-
2016-07-31 16:36:57 +01:00
( getenv('PATH', A),
( current_prolog_flag(windows, true)
-> atomic_list_concat(B, ;, A)
; atomic_list_concat(B, :, A)
),
lists:member(C, B)
).
%% @}