Modul "path"
Jan Burse, erstellt 27. Sep 2020
/**
* A relative path that is not wrapped into a compound is resolved
* against the current base in write or append mode. The current base
* is the Prolog flag “base_url”. Otherwise in read mode, if the call-site
* is not user it is resolved against the path of the call-site itself.
* In both cases the suffixes of the sys_add_file_extension/2
* command are used:
*
* Example:
* ?- set_prolog_flag(base_url, '/C:/Users/Jan Burse/Desktop/').
*
* ?- sys_add_file_extension('.dcg', [mime('text/prolog')]).
*
* ?- absolute_file_name('my folder/my file', X).
* X = 'file:/C:/Users/Jan Burse/Desktop/my folder/my file.dcg'
*
* Paths should not use a system specific directory separator but
* always use the forward slash (/). For convenience, paths have
* an automatic prefixing of a schema. Paths starting with a double
* slash (//) are prefixed by the “http” schema. Paths starting with
* a single slash (/) are prefixed by the “file” schema. Drive
* letters are not considered schema.
*
* If the path is wrapped into a compound and if the functor of the
* compound is either library/1, foreign/1, verbatim/1 or resource/1
* then the path is looked up in the class path. The class path can
* be updated and queried by the predicates sys_add_path/1 and
* sys_current_path/1. The prefixes of the package/1 and use_package/1
* command are also used.
*
* Write or append access resolution:
* <path> resolve <path> in base.
*
* Read access resolution:
* library(<path>) lookup text <path> in class path.
* foreign(<path>) lookup class <path> in class path.
* verbatim(<path>) like library(<path>) or take as is.
* resource(<path>) lookup resource <path> in class path.
* <path> resolve <path> in scope or base.
*
* The predicates absolute_file_name/[2,3] provide file name resolving.
* The predicate absolute_file_name/2 works bi-directionally. For a
* given already resolved path it will make a best effort attempt
* to reconstruct either a compound form foreign/1, library/1, verbatim/1
* or resource/1. Otherwise, only a relative path is attempt.
*
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies GmbH makes no warranties
* regarding the provided information. XLOG Technologies GmbH assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies GmbH.
*
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies GmbH. If the company was not the originator of some
* excerpts, XLOG Technologies GmbH has at least obtained the right to
* reproduce, change and translate the information.
*
* Reproduction is restricted to the whole unaltered document. Reproduction
* of the information is only allowed for non-commercial uses. Selling,
* giving away or letting of the execution of the library is prohibited.
* The library can be distributed as part of your applications and libraries
* for execution provided this comment remains unchanged.
*
* Restrictions
* Only to be distributed with programs that add significant and primary
* functionality to the library. Not to be distributed with additional
* software intended to replace any components of the library.
*
* Trademarks
* Jekejeke is a registered trademark of XLOG Technologies GmbH.
*/
/****************************************************************/
/* Class Path Modification & Access */
/****************************************************************/
* sys_add_path(R):
* The predicate succeeds in adding the relative path R
* to the current class loader.
*/
% sys_add_path(+Path)
sysAddClassdPath('Interpreter', 'String')).
* sys_current_path(A):
* The predicate succeeds in A with the currently added
* absolute paths A along the class loaders.
*/
% sys_current_path(-Path)
:- foreign(sys_get_class_paths
/1, 'ForeignPath',
sysGetClassPaths('Interpreter')).
* sys_add_file_extension(E, O):
* The predicate succeeds in adding the file extension database
* entry E with type and mime options O to the current knowledge base.
* For a list of recognized mime options see the API documentation.
*/
:- foreign(sys_add_file_extension
/2, 'ForeignPath',
sysAddFileExtenstion('Interpreter', 'String', 'Object')).
* sys_remove_file_extension(E):
* The predicate succeeds in removing file extension database entry
* with the name suffix E from the current knowledge base
*/
:- foreign(sys_remove_file_extension
/1, 'ForeignPath',
sysRemoveFileExtenstion('Interpreter', 'String')).
* sys_current_file_extension(E, O):
* The predicate succeeds in E and O with the currently added
* file extension database entries and their type and mime options
* along the knowledge bases.
*/
:- foreign(sys_get_file_extensions
/1, 'ForeignPath',
sysGetFileExtenstions('CallOut', 'Interpreter')).
/****************************************************************/
/* File Resolution */
/****************************************************************/
* absolute_file_name(R, A):
* absolute_file_name(R, A, O):
* The binary predicate succeeds when the read path R resolves to an
* absolute path and this absolute path unifies with S. The ternary
* predicate additionally recognizes the following path option. The
* predicates can be also used in a backward manner.
*/
% absolute_file_name(+Slash, -Pin)
% absolute_file_name(+Slash, -Pin, +Opt)
% absolute_file_name2(+Slash, -Pin, +Opt)
throw(error
(existence_error
(library
, Slash), _)).
throw(error
(existence_error
(class
, Slash), _)).
throw(error
(existence_error
(verbatim
, Slash), _)).
throw(error
(existence_error
(resource
, Slash), _)).
throw(error
(existence_error
(source_sink
, Slash), _)).
/****************************************************************/
/* Search File */
/****************************************************************/
% sys_search_file_name2(+Spec, -Pin, +Integer)
/* library */
/* verbatim */
/* foreign */
/* resource */
/* absolute and relative */
% sys_search_file_name(+Spec, -Pin, +Opt)
% sys_search_options(+List, -Integer)
:- foreign(sys_search_options
/2, 'ForeignPath',
sysSearchOptions('Object')).
% sys_search_read(+Integer)
sysSearchRead('Integer')).
% sys_find_write(+Atom, -Atom)
sysFindWrite('Interpreter', 'String')).
% sys_find_prefix(+Atom, +Atom, +Integer, -Atom)
sysFindPrefix('Interpreter', 'String', 'TermAtomic', 'Integer')).
% sys_find_key(+Atom, +Atom, +Integer, -Atom)
sysFindKey('Interpreter', 'String', 'TermAtomic', 'Integer')).
/****************************************************************/
/* File Unprobing */
/****************************************************************/
% sys_unsearch_file_name2(+Pin, -Spec)
% sys_unsearch_file_name3(+Spec, +Context, -Spec)
% sys_unsearch_file_name4(+Spec, +Context, -Spec)
% sys_unsearch_file_name2(+Pin, -Spec, +Opt)
% sys_is_relative_uri(+Atom)
:- foreign(sys_is_relative_uri
/1, 'ForeignUri',
sysUriIsRelative('String')).
% sys_unfind_write(+Atom, -Atom)
:- foreign(sys_unfind_write
/2, 'ForeignPath',
sysUnfindWrite('Interpreter', 'String')).
% sys_unfind_key(+Atom, +Atom, +Integer, -Atom)
sysUnfindKey('Interpreter', 'String', 'TermAtomic', 'Integer')).
% sys_unfind_prefix(+Atom, +Atom, +Integer, -Atom)
:- foreign(sys_unfind_prefix
/4, 'ForeignPath',
sysUnfindPrefix('Interpreter', 'String', 'TermAtomic', 'Integer')).
/****************************************************************/
/* Term Representation */
/****************************************************************/
* sys_path_to_atom(A, B):
* Succeeds when B unifies with the atom representing the path A.
*/
% sys_path_to_atom(+-Slash, -+Atom)
% sys_path_to_atom(+Slash, -Atom)
throw(error
(instantiation_error
, _)).
throw(error
(type_error
(path
, X), _)).
% sys_path_to_atom2(+Atom, -Slash)
Kommentare