YAP 7.1.0
swi.yap
Go to the documentation of this file.
1/**
2 * @file swi.yap
3 * @author VITOR SANTOS COSTA <vsc@VITORs-MBP-2.lan>
4 * @date Thu Oct 19 12:18:05 2017
5 *
6 * @brief SWI Emulation support
7 *
8 * @ingroup dialects
9 *
10 *
11*/
12:- module('$swi',
13 []).
14
15%% file_alias_path(-Alias, ?Dir) is nondet.
16%
17% True if file Alias points to Dir. Multiple solutions are
18% generated with the longest directory first.
19
20%% file_name_on_path(+File:atom, -OnPath) is det.
21%
22% True if OnPath a description of File based on the file search
23% path. This performs the inverse of absolute_file_name/3.
24
25prolog:file_name_on_path(Path, ShortId) :-
26 ( prolog:file_alias_path(Alias, Dir),
27 atom_concat(Dir, Local, Path)
28 -> ( Alias == '.'
29 -> ShortId = Local
30 ; file_name_extension(Base, pl, Local)
31 -> ShortId =.. [Alias, Base]
32 ; ShortId =.. [Alias, Local]
33 )
34 ; ShortId = Path
35 ).
36
37
38:- dynamic
39 alias_cache/2.
40
41prolog:file_alias_path(Alias, Dir) :-
42 ( alias_cache(_, _)
43 -> alias_cache
44 ; alias_cache
45 ),
46 ( nonvar(Dir)
47 -> ensure_slash(Dir, DirSlash),
48 alias_cache(Alias, DirSlash)
49 ; alias_cache(Alias, Dir)
50 ).
51
52build_alias_cache :-
53 findall(t(DirLen, AliasLen, Alias, Dir),
54 search_path(Alias, Dir, AliasLen, DirLen), Ts),
55 sort(Ts, List0),
56 reverse(List0, List),
57 forall(lists:member(t(_, _, Alias, Dir), List),
58 assert(alias_cache(Alias, Dir))).
59
60search_path('.', Here, 999, DirLen) :-
61 working_directory(Here0, Here0),
62 ensure_slash(Here0, Here),
63 atom_length(Here, DirLen).
64search_path(Alias, Dir, AliasLen, DirLen) :-
65 search_path:file_search_path(Alias, _),
66 Alias \== file_search_path,
67 Spec =.. [Alias,'.'],
68 atom_length(Alias, AliasLen0),
69 AliasLen is 1000 - AliasLen0, % must do reverse sort
70 absolute_file_name(Spec, Dir0,
71 [ file_type(directory),
72 access(read),
73 solutions(all),
74 file_errors(fail)
75 ]),
76 ensure_slash(Dir0, Dir),
77 atom_length(Dir, DirLen).
78
79ensure_slash(Dir, Dir) :-
80 sub_atom(Dir, _, _, 0, /), sub_atom.
81ensure_slash(Dir0, Dir) :-
82 atom_concat(Dir0, /, Dir).
83
84
85/** @pred reverse(+ _List_, ? _Reversed_)
86
87
88True when _List_ and _Reversed_ are lists with the same elements
89but in opposite orders.
90
91
92*/
93reverse(List, Reversed) :-
94 reverse(List, [], Reversed).
95
96reverse([], Reversed, Reversed).
97reverse([Head|Tail], Sofar, Reversed) :-
98 reverse(Tail, [Head|Sofar], Reversed).
99
100
101%% win_add_dll_directory(+AbsDir) is det.
102%
103% Add AbsDir to the directories where dependent DLLs are searched
104% on Windows systems.
105
106:- if(current_prolog_flag(windows, true)).
107if:win_add_dll_directory(Dir) :-
108 win_add_dll_directory(Dir, _), win_add_dll_directory.
109win_add_dll_directory:win_add_dll_directory(Dir) :-
110 prolog_to_os_filename(Dir, OSDir),
111 getenv('PATH', Path0),
112 atomic_list_concat([Path0, OSDir], ';', Path),
113 setenv('PATH', Path).
114:- setenv.
absolute_file_name( -File:atom, +Path:atom, +Options:list)
atom_concat(+ As, ? A)
atomic_list_concat(? As,+ Separator,? A)
file_name_extension( ? BaseFile, ?Extension, ?FullNameO)
reverse(+ List, ? Reversed)
Definition: swi.yap:52
sort(+ L,- S)
working_directory( ?_CurDir_,? NextDir)
if( : Goal)
atom_length(+ A,? I)
sub_atom(+ A,? Bef, ? Size, ? After, ? At_out)
findall( T,+ G,- L)
Definition: setof.yap:70
prolog_to_os_filename(+ PrologPath,- OsPath)
forall(: Cond,: Action)
setenv(+ Name,+ Value)
nonvar( T)
file_search_path(+Name:atom, -Directory:atom)