1/* Part of SWI-Prolog 2 3 Author: Jan Wielemaker 4 E-mail: J.Wielemaker@vu.nl 5 WWW: http://www.swi-prolog.org 6 Copyright (c) 2019, VU University Amsterdam 7 CWI, Amsterdam 8 All rights reserved. 9 10 Redistribution and use in source and binary forms, with or without 11 modification, are permitted provided that the following conditions 12 are met: 13 14 1. Redistributions of source code must retain the above copyright 15 notice, this list of conditions and the following disclaimer. 16 17 2. Redistributions in binary form must reproduce the above copyright 18 notice, this list of conditions and the following disclaimer in 19 the documentation and/or other materials provided with the 20 distribution. 21 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 POSSIBILITY OF SUCH DAMAGE. 34*/ 35 36:- module(consult, 37 [ consult/1, % :File 38 ensure_dync_loaded/1, % +File 39 add_lib_dir/1, % +Directories 40 add_lib_dir/2 % +Root, +Directories 41 ]). 42:- use_module(library(error)). 43:- use_module(library(filesex)). 44 45:- meta_predicate 46 ensure_dync_loaded( ). 47 48ensure_dync_loaded(File) :- 49 load_files(File, [if(not_loaded), dialect(xsb)]). 50 51%! add_lib_dir(+Directories) is det. 52%! add_lib_dir(+Root, +Directories) is det. 53% 54% Add members of the comma list Directories to 55% user:library_directory/1. If Root is given, all members of 56% Directories are interpreted relative to Root. 57 58add_lib_dir(Directories) :- 59 add_lib_dir('.', Directories). 60 61add_lib_dir(_, Var) :- 62 var(Var), 63 !, 64 instantiation_error(Var). 65add_lib_dir(Root, (A,B)) :- 66 !, 67 add_lib_dir(Root, A), 68 add_lib_dir(Root, B). 69add_lib_dir(Root, a(Dir)) :- 70 !, 71 add_to_library_directory(Root, Dir, asserta). 72add_lib_dir(Root, Dir) :- 73 add_to_library_directory(Root, Dir, assertz). 74 75add_to_library_directory(Root, Dir, How) :- 76 ( expand_file_name(Dir, [Dir1]) 77 -> true 78 ; Dir1 = Dir 79 ), 80 relative_file_name(TheDir, Root, Dir1), 81 exists_directory(TheDir), 82 !, 83 ( user:library_directory(TheDir) 84 -> true 85 ; call(How, user:library_directory(TheDir)) 86 ). 87add_to_library_directory(_, _, _)