Mercurial > octave-nkf
annotate libinterp/corefcn/load-path.cc @ 20087:8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
* load-path.h, load-path.cc (load_path::::is_package): New function.
(load_path::dir_info::is_package): New function.
(load_path::get_loader): Don't insert name into loader map unless is
it is also a +package directory somewhere in the load path.
* ov-classdef.cc (cdef_manager::do_find_package_symbol):
Undo change from changeset 8fe29850fb74.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 02 Apr 2015 17:16:03 -0400 |
parents | 19755f4fc851 |
children | a8769ccb2c4e |
rev | line source |
---|---|
5832 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19631
diff
changeset
|
3 Copyright (C) 2006-2015 John W. Eaton |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10446
diff
changeset
|
4 Copyright (C) 2010 VZLU Prague |
5832 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
5832 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
5832 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include <algorithm> | |
29 | |
30 #include "dir-ops.h" | |
31 #include "file-ops.h" | |
32 #include "file-stat.h" | |
33 #include "oct-env.h" | |
34 #include "pathsearch.h" | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
35 #include "singleton-cleanup.h" |
5832 | 36 |
37 #include "defaults.h" | |
38 #include "defun.h" | |
39 #include "input.h" | |
40 #include "load-path.h" | |
18203
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
41 #include "ov-usr-fcn.h" |
5832 | 42 #include "pager.h" |
43 #include "parse.h" | |
44 #include "toplev.h" | |
45 #include "unwind-prot.h" | |
46 #include "utils.h" | |
47 | |
48 load_path *load_path::instance = 0; | |
7336 | 49 load_path::hook_fcn_ptr load_path::add_hook = execute_pkg_add; |
50 load_path::hook_fcn_ptr load_path::remove_hook = execute_pkg_del; | |
5832 | 51 std::string load_path::command_line_path; |
6630 | 52 std::string load_path::sys_path; |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
53 load_path::abs_dir_cache_type load_path::abs_dir_cache; |
5832 | 54 |
55 void | |
56 load_path::dir_info::update (void) | |
57 { | |
8330
8303f0e912bc
load-path.cc (load_path::dir_info::update): simplify previous change
John W. Eaton <jwe@octave.org>
parents:
8329
diff
changeset
|
58 file_stat fs (dir_name); |
8303f0e912bc
load-path.cc (load_path::dir_info::update): simplify previous change
John W. Eaton <jwe@octave.org>
parents:
8329
diff
changeset
|
59 |
8303f0e912bc
load-path.cc (load_path::dir_info::update): simplify previous change
John W. Eaton <jwe@octave.org>
parents:
8329
diff
changeset
|
60 if (fs) |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
61 { |
8330
8303f0e912bc
load-path.cc (load_path::dir_info::update): simplify previous change
John W. Eaton <jwe@octave.org>
parents:
8329
diff
changeset
|
62 if (is_relative) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
63 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
64 try |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
65 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
66 std::string abs_name = octave_env::make_absolute (dir_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
67 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
68 abs_dir_cache_iterator p = abs_dir_cache.find (abs_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
69 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
70 if (p != abs_dir_cache.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
71 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
72 // The directory is in the cache of all directories |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
73 // we have visited (indexed by its absolute name). |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
74 // If it is out of date, initialize it. Otherwise, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
75 // copy the info from the cache. By doing that, we |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
76 // avoid unnecessary calls to stat that can slow |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
77 // things down tremendously for large directories. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
78 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
79 const dir_info& di = p->second; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
80 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
81 if (fs.mtime () + fs.time_resolution () |
19895
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
82 > di.dir_time_last_checked) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
83 initialize (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
84 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
85 *this = di; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
86 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
87 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
88 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
89 // We haven't seen this directory before. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
90 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
91 initialize (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
92 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
93 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
94 catch (octave_execution_exception) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
95 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
96 // Skip updating if we don't know where we are, but |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
97 // don't treat it as an error. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
98 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
99 error_state = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
100 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
101 } |
9764
7922a24f78c0
fix relative directory caching
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
102 else if (fs.mtime () + fs.time_resolution () > dir_time_last_checked) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
103 initialize (); |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
104 } |
5832 | 105 else |
106 { | |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
107 std::string msg = fs.error (); |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
108 warning ("load_path: %s: %s", dir_name.c_str (), msg.c_str ()); |
5832 | 109 } |
110 } | |
111 | |
20087
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
112 bool |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
113 load_path::dir_info::is_package (const std::string& name) const |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
114 { |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
115 return package_dir_map.find (name) != package_dir_map.end (); |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
116 } |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
117 |
5832 | 118 void |
119 load_path::dir_info::initialize (void) | |
120 { | |
121 is_relative = ! octave_env::absolute_pathname (dir_name); | |
122 | |
9748
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
9581
diff
changeset
|
123 dir_time_last_checked = octave_time (static_cast<time_t> (0)); |
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
9581
diff
changeset
|
124 |
5832 | 125 file_stat fs (dir_name); |
126 | |
127 if (fs) | |
128 { | |
10907
6105ed2db9d7
load_path::dir_info::initialize: clear method_file_map before updating file list
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
129 method_file_map.clear (); |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
130 package_dir_map.clear (); |
10907
6105ed2db9d7
load_path::dir_info::initialize: clear method_file_map before updating file list
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
131 |
5832 | 132 dir_mtime = fs.mtime (); |
9748
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
9581
diff
changeset
|
133 dir_time_last_checked = octave_time (); |
5832 | 134 |
7336 | 135 get_file_list (dir_name); |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
136 |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
137 try |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
138 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
139 std::string abs_name = octave_env::make_absolute (dir_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
140 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
141 // FIXME: nothing is ever removed from this cache of |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
142 // directory information, so there could be some resource |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
143 // problems. Perhaps it should be pruned from time to time. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
144 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
145 abs_dir_cache[abs_name] = *this; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
146 } |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
147 catch (octave_execution_exception) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
148 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
149 // Skip updating if we don't know where we are. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
150 } |
5832 | 151 } |
152 else | |
153 { | |
154 std::string msg = fs.error (); | |
155 warning ("load_path: %s: %s", dir_name.c_str (), msg.c_str ()); | |
156 } | |
157 } | |
158 | |
7336 | 159 void |
5832 | 160 load_path::dir_info::get_file_list (const std::string& d) |
161 { | |
162 dir_entry dir (d); | |
163 | |
164 if (dir) | |
165 { | |
166 string_vector flist = dir.read (); | |
167 | |
168 octave_idx_type len = flist.length (); | |
169 | |
170 all_files.resize (len); | |
171 fcn_files.resize (len); | |
172 | |
173 octave_idx_type all_files_count = 0; | |
174 octave_idx_type fcn_files_count = 0; | |
175 | |
176 for (octave_idx_type i = 0; i < len; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
177 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
178 std::string fname = flist[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
179 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
180 std::string full_name = file_ops::concat (d, fname); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
181 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
182 file_stat fs (full_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
183 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
184 if (fs) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
185 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
186 if (fs.is_dir ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
187 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
188 if (fname == "private") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
189 get_private_file_map (full_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
190 else if (fname[0] == '@') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
191 get_method_file_map (full_name, fname.substr (1)); |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
192 else if (fname[0] == '+') |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
193 get_package_dir (full_name, fname.substr (1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
194 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
195 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
196 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
197 all_files[all_files_count++] = fname; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
198 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
199 size_t pos = fname.rfind ('.'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
200 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
201 if (pos != std::string::npos) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
202 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
203 std::string ext = fname.substr (pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
204 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
205 if (ext == ".m" || ext == ".oct" || ext == ".mex") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
206 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
207 std::string base = fname.substr (0, pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
208 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
209 if (valid_identifier (base)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
210 fcn_files[fcn_files_count++] = fname; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
211 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
212 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
213 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
214 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
215 } |
5832 | 216 |
217 all_files.resize (all_files_count); | |
218 fcn_files.resize (fcn_files_count); | |
219 } | |
220 else | |
221 { | |
222 std::string msg = dir.error (); | |
223 warning ("load_path: %s: %s", d.c_str (), msg.c_str ()); | |
224 } | |
225 } | |
226 | |
7336 | 227 load_path::dir_info::fcn_file_map_type |
228 get_fcn_files (const std::string& d) | |
5832 | 229 { |
7336 | 230 load_path::dir_info::fcn_file_map_type retval; |
231 | |
5832 | 232 dir_entry dir (d); |
233 | |
234 if (dir) | |
235 { | |
236 string_vector flist = dir.read (); | |
237 | |
238 octave_idx_type len = flist.length (); | |
239 | |
240 for (octave_idx_type i = 0; i < len; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
241 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
242 std::string fname = flist[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
243 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
244 std::string ext; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
245 std::string base = fname; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
246 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
247 size_t pos = fname.rfind ('.'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
248 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
249 if (pos != std::string::npos) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
250 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
251 base = fname.substr (0, pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
252 ext = fname.substr (pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
253 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
254 if (valid_identifier (base)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
255 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
256 int t = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
257 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
258 if (ext == ".m") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
259 t = load_path::M_FILE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
260 else if (ext == ".oct") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
261 t = load_path::OCT_FILE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
262 else if (ext == ".mex") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
263 t = load_path::MEX_FILE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
264 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
265 retval[base] |= t; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
266 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
267 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
268 } |
5832 | 269 } |
270 else | |
271 { | |
272 std::string msg = dir.error (); | |
273 warning ("load_path: %s: %s", d.c_str (), msg.c_str ()); | |
274 } | |
7336 | 275 |
276 return retval; | |
277 } | |
278 | |
279 void | |
280 load_path::dir_info::get_private_file_map (const std::string& d) | |
281 { | |
282 private_file_map = get_fcn_files (d); | |
283 } | |
284 | |
285 void | |
286 load_path::dir_info::get_method_file_map (const std::string& d, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
287 const std::string& class_name) |
7336 | 288 { |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
289 method_file_map[class_name].method_file_map = get_fcn_files (d); |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
290 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
291 std::string pd = file_ops::concat (d, "private"); |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
292 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
293 file_stat fs (pd); |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
294 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
295 if (fs && fs.is_dir ()) |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
296 method_file_map[class_name].private_file_map = get_fcn_files (pd); |
5832 | 297 } |
298 | |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
299 void |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
300 load_path::dir_info::get_package_dir (const std::string& d, |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
301 const std::string& package_name) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
302 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
303 package_dir_map[package_name] = dir_info (d); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
304 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
305 |
5832 | 306 bool |
307 load_path::instance_ok (void) | |
308 { | |
309 bool retval = true; | |
310 | |
311 if (! instance) | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
312 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
313 instance = new load_path (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
314 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
315 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
316 singleton_cleanup_list::add (cleanup_instance); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
317 } |
5832 | 318 |
319 if (! instance) | |
320 { | |
321 ::error ("unable to create load path object!"); | |
322 | |
323 retval = false; | |
324 } | |
325 | |
326 return retval; | |
327 } | |
328 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
329 // FIXME: maybe we should also maintain a map to speed up this method of access. |
7336 | 330 |
5832 | 331 load_path::const_dir_info_list_iterator |
5919 | 332 load_path::find_dir_info (const std::string& dir_arg) const |
5832 | 333 { |
5919 | 334 std::string dir = file_ops::tilde_expand (dir_arg); |
335 | |
5832 | 336 const_dir_info_list_iterator retval = dir_info_list.begin (); |
337 | |
338 while (retval != dir_info_list.end ()) | |
339 { | |
340 if (retval->dir_name == dir) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
341 break; |
5832 | 342 |
343 retval++; | |
344 } | |
345 | |
346 return retval; | |
347 } | |
348 | |
349 load_path::dir_info_list_iterator | |
5919 | 350 load_path::find_dir_info (const std::string& dir_arg) |
5832 | 351 { |
5919 | 352 std::string dir = file_ops::tilde_expand (dir_arg); |
353 | |
5832 | 354 dir_info_list_iterator retval = dir_info_list.begin (); |
355 | |
356 while (retval != dir_info_list.end ()) | |
357 { | |
358 if (retval->dir_name == dir) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
359 break; |
5832 | 360 |
361 retval++; | |
362 } | |
363 | |
364 return retval; | |
365 } | |
366 | |
367 bool | |
368 load_path::contains (const std::string& dir) const | |
369 { | |
370 return find_dir_info (dir) != dir_info_list.end (); | |
371 } | |
372 | |
16547
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
373 bool |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
374 load_path::do_contains_canonical (const std::string& dir) const |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
375 { |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
376 bool retval = false; |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
377 |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
378 for (const_dir_info_list_iterator i = dir_info_list.begin (); |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
379 i != dir_info_list.end (); |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
380 i++) |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
381 { |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
382 if (same_file (dir, i->dir_name)) |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
383 { |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
384 retval = true; |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
385 break; |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
386 } |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
387 } |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
388 |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
389 return retval; |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
390 } |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
391 |
5832 | 392 void |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
393 load_path::loader::move_fcn_map (const std::string& dir_name, |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
394 const string_vector& fcn_files, bool at_end) |
5832 | 395 { |
7336 | 396 octave_idx_type len = fcn_files.length (); |
397 | |
398 for (octave_idx_type k = 0; k < len; k++) | |
5832 | 399 { |
7336 | 400 std::string fname = fcn_files[k]; |
5832 | 401 |
7336 | 402 std::string ext; |
403 std::string base = fname; | |
404 | |
405 size_t pos = fname.rfind ('.'); | |
5832 | 406 |
8021 | 407 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
408 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
409 base = fname.substr (0, pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
410 ext = fname.substr (pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
411 } |
5832 | 412 |
7336 | 413 file_info_list_type& file_info_list = fcn_map[base]; |
5832 | 414 |
7336 | 415 if (file_info_list.size () == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
416 continue; |
7336 | 417 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
418 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
419 for (file_info_list_iterator p = file_info_list.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
420 p != file_info_list.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
421 p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
422 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
423 if (p->dir_name == dir_name) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
424 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
425 file_info fi = *p; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
426 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
427 file_info_list.erase (p); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
428 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
429 if (at_end) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
430 file_info_list.push_back (fi); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
431 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
432 file_info_list.push_front (fi); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
433 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
434 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
435 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
436 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
437 } |
7336 | 438 } |
439 } | |
5832 | 440 |
7336 | 441 void |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
442 load_path::loader::move_method_map (const std::string& dir_name, bool at_end) |
7336 | 443 { |
444 for (method_map_iterator i = method_map.begin (); | |
445 i != method_map.end (); | |
446 i++) | |
447 { | |
448 std::string class_name = i->first; | |
5832 | 449 |
7336 | 450 fcn_map_type& fm = i->second; |
451 | |
452 std::string full_dir_name | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
453 = file_ops::concat (dir_name, "@" + class_name); |
7336 | 454 |
455 for (fcn_map_iterator q = fm.begin (); q != fm.end (); q++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
456 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
457 file_info_list_type& file_info_list = q->second; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
458 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
459 if (file_info_list.size () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
460 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
461 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
462 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
463 for (file_info_list_iterator p = file_info_list.begin (); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
464 p != file_info_list.end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
465 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
466 if (p->dir_name == full_dir_name) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
467 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
468 file_info fi = *p; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
469 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
470 file_info_list.erase (p); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
471 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
472 if (at_end) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
473 file_info_list.push_back (fi); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
474 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
475 file_info_list.push_front (fi); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
476 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
477 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
478 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
479 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
480 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
481 } |
5832 | 482 } |
483 } | |
484 | |
7336 | 485 void |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
486 load_path::do_move (dir_info_list_iterator i, bool at_end) |
7336 | 487 { |
488 if (dir_info_list.size () > 1) | |
489 { | |
490 dir_info di = *i; | |
491 | |
492 dir_info_list.erase (i); | |
493 | |
494 if (at_end) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
495 dir_info_list.push_back (di); |
7336 | 496 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
497 dir_info_list.push_front (di); |
7336 | 498 |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
499 move (di, at_end); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
500 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
501 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
502 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
503 void |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
504 load_path::move (const dir_info& di, bool at_end, const std::string& pname) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
505 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
506 loader& l = get_loader (pname); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
507 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
508 l.move (di, at_end); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
509 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
510 dir_info::package_dir_map_type package_dir_map = di.package_dir_map; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
511 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
512 for (dir_info::const_package_dir_map_iterator p = package_dir_map.begin (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
513 p != package_dir_map.end (); ++p) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
514 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
515 std::string full_name = p->first; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
516 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
517 if (! pname.empty ()) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
518 full_name = pname + "." + full_name; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
519 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
520 move (p->second, at_end, full_name); |
7336 | 521 } |
522 } | |
523 | |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
524 void |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
525 load_path::loader::move (const dir_info& di, bool at_end) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
526 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
527 std::string dir_name = di.dir_name; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
528 |
19631
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19579
diff
changeset
|
529 std::list<std::string>::iterator s = |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
530 std::find (dir_list.begin (), dir_list.end (), dir_name); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
531 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
532 if (s != dir_list.end ()) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
533 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
534 dir_list.erase (s); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
535 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
536 if (at_end) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
537 dir_list.push_back (dir_name); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
538 else |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
539 dir_list.push_front (dir_name); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
540 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
541 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
542 move_fcn_map (dir_name, di.fcn_files, at_end); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
543 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
544 // No need to move elements of private function map. |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
545 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
546 move_method_map (dir_name, at_end); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
547 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
548 |
5832 | 549 static void |
550 maybe_add_path_elts (std::string& path, const std::string& dir) | |
551 { | |
552 std::string tpath = genpath (dir); | |
553 | |
554 if (! tpath.empty ()) | |
7374 | 555 { |
556 if (path.empty ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
557 path = tpath; |
7374 | 558 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
559 path += dir_path::path_sep_str () + tpath; |
7374 | 560 } |
5832 | 561 } |
562 | |
563 void | |
6365 | 564 load_path::do_initialize (bool set_initial_path) |
5832 | 565 { |
7374 | 566 sys_path = ""; |
5832 | 567 |
6365 | 568 if (set_initial_path) |
569 { | |
6626 | 570 maybe_add_path_elts (sys_path, Vlocal_ver_oct_file_dir); |
571 maybe_add_path_elts (sys_path, Vlocal_api_oct_file_dir); | |
572 maybe_add_path_elts (sys_path, Vlocal_oct_file_dir); | |
573 maybe_add_path_elts (sys_path, Vlocal_ver_fcn_file_dir); | |
574 maybe_add_path_elts (sys_path, Vlocal_api_fcn_file_dir); | |
575 maybe_add_path_elts (sys_path, Vlocal_fcn_file_dir); | |
576 maybe_add_path_elts (sys_path, Voct_file_dir); | |
577 maybe_add_path_elts (sys_path, Vfcn_file_dir); | |
19066
d902542221c8
new data directory for storing data files we distribute
John W. Eaton <jwe@octave.org>
parents:
18960
diff
changeset
|
578 maybe_add_path_elts (sys_path, Voct_data_dir); |
6365 | 579 } |
5832 | 580 |
581 std::string tpath = load_path::command_line_path; | |
582 | |
583 if (tpath.empty ()) | |
8141
31d7885d9869
load-path.cc (load_path::do_initialize): look for OCTAVE_PATH in the environment, not OCTAVE_LOADPATH
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
584 tpath = octave_env::getenv ("OCTAVE_PATH"); |
5832 | 585 |
10242
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
586 std::string xpath; |
5832 | 587 |
588 if (! tpath.empty ()) | |
10242
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
589 { |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
590 xpath = tpath; |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
591 |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
592 if (! sys_path.empty ()) |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
593 xpath += dir_path::path_sep_str () + sys_path; |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
594 } |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
595 else |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
596 xpath = sys_path; |
5832 | 597 |
14376
7dd6ac033e69
Warn when the default path is overwritten
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14360
diff
changeset
|
598 do_set (xpath, false, true); |
5832 | 599 } |
600 | |
601 void | |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
602 load_path::do_clear (void) |
5832 | 603 { |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
604 dir_info_list.clear (); |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
605 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
606 default_loader.clear (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
607 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
608 loader_map.clear (); |
5832 | 609 } |
610 | |
611 static std::list<std::string> | |
612 split_path (const std::string& p) | |
613 { | |
614 std::list<std::string> retval; | |
615 | |
616 size_t beg = 0; | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
617 size_t end = p.find (dir_path::path_sep_char ()); |
5832 | 618 |
619 size_t len = p.length (); | |
620 | |
8021 | 621 while (end != std::string::npos) |
5832 | 622 { |
623 std::string elt = p.substr (beg, end-beg); | |
624 | |
625 if (! elt.empty ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
626 retval.push_back (elt); |
5832 | 627 |
628 beg = end + 1; | |
629 | |
630 if (beg == len) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
631 break; |
5832 | 632 |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
633 end = p.find (dir_path::path_sep_char (), beg); |
5832 | 634 } |
635 | |
636 std::string elt = p.substr (beg); | |
637 | |
638 if (! elt.empty ()) | |
639 retval.push_back (elt); | |
640 | |
641 return retval; | |
642 } | |
643 | |
644 void | |
14376
7dd6ac033e69
Warn when the default path is overwritten
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14360
diff
changeset
|
645 load_path::do_set (const std::string& p, bool warn, bool is_init) |
5832 | 646 { |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
647 // Use a list when we need to preserve order. |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
648 std::list<std::string> elts = split_path (p); |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
649 |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
650 // Use a set when we need to search and order is not important. |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
651 std::set<std::string> elts_set (elts.begin (), elts.end ()); |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
652 |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
653 if (is_init) |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
654 init_dirs = elts_set; |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
655 else |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
656 { |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
657 for (std::set<std::string>::const_iterator it = init_dirs.begin (); |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
658 it != init_dirs.end (); it++) |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
659 { |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
660 if (elts_set.find (*it) == elts_set.end ()) |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
661 { |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
662 warning_with_id ("Octave:remove-init-dir", |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
663 "default load path altered. Some built-in functions may not be found. Try restoredefaultpath() to recover it."); |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
664 break; |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
665 } |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
666 } |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
667 } |
5832 | 668 |
669 // Temporarily disable add hook. | |
670 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9807
diff
changeset
|
671 unwind_protect frame; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9807
diff
changeset
|
672 frame.protect_var (add_hook); |
5832 | 673 |
674 add_hook = 0; | |
675 | |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
676 do_clear (); |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
677 |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
678 for (std::list<std::string>::const_iterator i = elts.begin (); |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
679 i != elts.end (); i++) |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
680 do_append (*i, warn); |
5832 | 681 |
682 // Restore add hook and execute for all newly added directories. | |
15469
72868cae7624
eliminate some deprecated function warnings
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
683 frame.run_first (); |
5832 | 684 |
685 for (dir_info_list_iterator i = dir_info_list.begin (); | |
686 i != dir_info_list.end (); | |
687 i++) | |
688 { | |
689 if (add_hook) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
690 add_hook (i->dir_name); |
5832 | 691 } |
10242
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
692 |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
693 // Always prepend current directory. |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
694 do_prepend (".", warn); |
5832 | 695 } |
696 | |
697 void | |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
698 load_path::do_append (const std::string& dir, bool warn) |
5832 | 699 { |
700 if (! dir.empty ()) | |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
701 do_add (dir, true, warn); |
5867 | 702 } |
5832 | 703 |
5867 | 704 void |
705 load_path::do_prepend (const std::string& dir, bool warn) | |
706 { | |
707 if (! dir.empty ()) | |
708 do_add (dir, false, warn); | |
5832 | 709 } |
710 | |
11578
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
711 // Strip trailing directory separators. |
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
712 |
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
713 static std::string |
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
714 strip_trailing_separators (const std::string& dir_arg) |
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
715 { |
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
716 std::string dir = dir_arg; |
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
717 |
12438
ab4c6bbff14a
use correct type for std::string length
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
718 size_t k = dir.length (); |
ab4c6bbff14a
use correct type for std::string length
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
719 |
11578
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
720 while (k > 1 && file_ops::is_dir_sep (dir[k-1])) |
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
721 k--; |
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
722 |
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
723 if (k < dir.length ()) |
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
724 dir.resize (k); |
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
725 |
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
726 return dir; |
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
727 } |
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
728 |
5832 | 729 void |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14884
diff
changeset
|
730 load_path::do_add (const std::string& dir_arg, bool at_end, bool warn) |
5832 | 731 { |
5919 | 732 size_t len = dir_arg.length (); |
5911 | 733 |
5919 | 734 if (len > 1 && dir_arg.substr (len-2) == "//") |
5911 | 735 warning_with_id ("Octave:recursive-path-search", |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
736 "trailing '//' is no longer special in search path elements"); |
5911 | 737 |
5919 | 738 std::string dir = file_ops::tilde_expand (dir_arg); |
739 | |
11578
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
740 dir = strip_trailing_separators (dir); |
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
741 |
5867 | 742 dir_info_list_iterator i = find_dir_info (dir); |
743 | |
744 if (i != dir_info_list.end ()) | |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
745 do_move (i, at_end); |
5867 | 746 else |
5832 | 747 { |
5867 | 748 file_stat fs (dir); |
5832 | 749 |
5867 | 750 if (fs) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
751 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
752 if (fs.is_dir ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
753 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
754 dir_info di (dir); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
755 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
756 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
757 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
758 if (at_end) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
759 dir_info_list.push_back (di); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
760 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
761 dir_info_list.push_front (di); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
762 |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
763 add (di, at_end); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
764 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
765 if (add_hook) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
766 add_hook (dir); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
767 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
768 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
769 else if (warn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
770 warning ("addpath: %s: not a directory", dir_arg.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
771 } |
5867 | 772 else if (warn) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
773 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
774 std::string msg = fs.error (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
775 warning ("addpath: %s: %s", dir_arg.c_str (), msg.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
776 } |
5867 | 777 } |
5832 | 778 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
779 // FIXME: is there a better way to do this? |
5832 | 780 |
5867 | 781 i = find_dir_info ("."); |
5832 | 782 |
5867 | 783 if (i != dir_info_list.end ()) |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
784 do_move (i, false); |
5832 | 785 } |
786 | |
7336 | 787 void |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
788 load_path::loader::remove_fcn_map (const std::string& dir, |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
789 const string_vector& fcn_files) |
7336 | 790 { |
791 octave_idx_type len = fcn_files.length (); | |
792 | |
793 for (octave_idx_type k = 0; k < len; k++) | |
794 { | |
795 std::string fname = fcn_files[k]; | |
796 | |
797 std::string ext; | |
798 std::string base = fname; | |
799 | |
800 size_t pos = fname.rfind ('.'); | |
801 | |
8021 | 802 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
803 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
804 base = fname.substr (0, pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
805 ext = fname.substr (pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
806 } |
7336 | 807 |
808 file_info_list_type& file_info_list = fcn_map[base]; | |
809 | |
810 for (file_info_list_iterator p = file_info_list.begin (); | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
811 p != file_info_list.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
812 p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
813 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
814 if (p->dir_name == dir) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
815 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
816 file_info_list.erase (p); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
817 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
818 if (file_info_list.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
819 fcn_map.erase (fname); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
820 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
821 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
822 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
823 } |
7336 | 824 } |
825 } | |
826 | |
827 void | |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
828 load_path::loader::remove_private_fcn_map (const std::string& dir) |
7336 | 829 { |
830 private_fcn_map_iterator p = private_fcn_map.find (dir); | |
831 | |
832 if (p != private_fcn_map.end ()) | |
833 private_fcn_map.erase (p); | |
834 } | |
835 | |
836 void | |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
837 load_path::loader::remove_method_map (const std::string& dir) |
7336 | 838 { |
839 for (method_map_iterator i = method_map.begin (); | |
840 i != method_map.end (); | |
841 i++) | |
842 { | |
843 std::string class_name = i->first; | |
844 | |
845 fcn_map_type& fm = i->second; | |
846 | |
847 std::string full_dir_name = file_ops::concat (dir, "@" + class_name); | |
848 | |
849 for (fcn_map_iterator q = fm.begin (); q != fm.end (); q++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
850 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
851 file_info_list_type& file_info_list = q->second; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
852 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
853 if (file_info_list.size () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
854 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
855 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
856 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
857 for (file_info_list_iterator p = file_info_list.begin (); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
858 p != file_info_list.end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
859 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
860 if (p->dir_name == full_dir_name) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
861 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
862 file_info_list.erase (p); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
863 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
864 // FIXME: if there are no other elements, we |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
865 // should remove this element of fm but calling |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
866 // erase here would invalidate the iterator q. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
867 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
868 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
869 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
870 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
871 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
872 } |
7336 | 873 } |
874 } | |
875 | |
5832 | 876 bool |
5919 | 877 load_path::do_remove (const std::string& dir_arg) |
5832 | 878 { |
879 bool retval = false; | |
880 | |
5919 | 881 if (! dir_arg.empty ()) |
5832 | 882 { |
5919 | 883 if (dir_arg == ".") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
884 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
885 warning ("rmpath: can't remove \".\" from path"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
886 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
887 // Avoid additional warnings. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
888 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
889 } |
5867 | 890 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
891 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
892 std::string dir = file_ops::tilde_expand (dir_arg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
893 |
11578
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
894 dir = strip_trailing_separators (dir); |
06cfda4c07e5
load_path::do_add, load_path::do_remove: strip trailing directory separators
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
895 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
896 dir_info_list_iterator i = find_dir_info (dir); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
897 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
898 if (i != dir_info_list.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
899 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
900 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
901 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
902 if (remove_hook) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
903 remove_hook (dir); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
904 |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
905 dir_info& di = *i; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
906 |
17650
a98902bda11a
Fix invalid memory read in rmpath.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17577
diff
changeset
|
907 remove (di); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
908 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
909 dir_info_list.erase (i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
910 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
911 } |
5832 | 912 } |
913 | |
914 return retval; | |
915 } | |
916 | |
917 void | |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
918 load_path::remove (const dir_info& di, const std::string& pname) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
919 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
920 loader& l = get_loader (pname); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
921 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
922 l.remove (di); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
923 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
924 dir_info::package_dir_map_type package_dir_map = di.package_dir_map; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
925 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
926 for (dir_info::const_package_dir_map_iterator p = package_dir_map.begin (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
927 p != package_dir_map.end (); ++p) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
928 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
929 std::string full_name = p->first; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
930 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
931 if (! pname.empty ()) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
932 full_name = pname + "." + full_name; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
933 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
934 remove (p->second, full_name); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
935 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
936 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
937 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
938 void |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
939 load_path::loader::remove (const dir_info& di) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
940 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
941 std::string dir = di.dir_name; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
942 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
943 string_vector fcn_files = di.fcn_files; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
944 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
945 dir_list.remove (dir); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
946 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
947 remove_fcn_map (dir, fcn_files); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
948 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
949 remove_private_fcn_map (dir); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
950 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
951 remove_method_map (dir); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
952 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
953 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
954 void |
5832 | 955 load_path::do_update (void) const |
956 { | |
957 // I don't see a better way to do this because we need to | |
958 // preserve the correct directory ordering for new files that | |
959 // have appeared. | |
960 | |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
961 default_loader.clear (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
962 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
963 loader_map.clear (); |
7336 | 964 |
5832 | 965 for (dir_info_list_iterator p = dir_info_list.begin (); |
966 p != dir_info_list.end (); | |
967 p++) | |
968 { | |
969 dir_info& di = *p; | |
970 | |
971 di.update (); | |
972 | |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
973 add (di, true); |
5832 | 974 } |
975 } | |
976 | |
7336 | 977 bool |
978 load_path::check_file_type (std::string& fname, int type, int possible_types, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
979 const std::string& fcn, const char *who) |
7336 | 980 { |
981 bool retval = false; | |
982 | |
983 if (type == load_path::OCT_FILE) | |
984 { | |
985 if ((type & possible_types) == load_path::OCT_FILE) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
986 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
987 fname += ".oct"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
988 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
989 } |
7336 | 990 } |
991 else if (type == load_path::M_FILE) | |
992 { | |
993 if ((type & possible_types) == load_path::M_FILE) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
994 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
995 fname += ".m"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
996 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
997 } |
7336 | 998 } |
999 else if (type == load_path::MEX_FILE) | |
1000 { | |
1001 if ((type & possible_types) == load_path::MEX_FILE) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1002 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1003 fname += ".mex"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1004 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1005 } |
7336 | 1006 } |
1007 else if (type == (load_path::M_FILE | load_path::OCT_FILE)) | |
1008 { | |
1009 if (possible_types & load_path::OCT_FILE) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1010 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1011 fname += ".oct"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1012 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1013 } |
7336 | 1014 else if (possible_types & load_path::M_FILE) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1015 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1016 fname += ".m"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1017 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1018 } |
7336 | 1019 } |
1020 else if (type == (load_path::M_FILE | load_path::MEX_FILE)) | |
1021 { | |
1022 if (possible_types & load_path::MEX_FILE) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1023 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1024 fname += ".mex"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1025 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1026 } |
7336 | 1027 else if (possible_types & load_path::M_FILE) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1028 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1029 fname += ".m"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1030 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1031 } |
7336 | 1032 } |
1033 else if (type == (load_path::OCT_FILE | load_path::MEX_FILE)) | |
1034 { | |
1035 if (possible_types & load_path::OCT_FILE) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1036 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1037 fname += ".oct"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1038 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1039 } |
7336 | 1040 else if (possible_types & load_path::MEX_FILE) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1041 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1042 fname += ".mex"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1043 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1044 } |
7336 | 1045 } |
1046 else if (type == (load_path::M_FILE | load_path::OCT_FILE | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1047 | load_path::MEX_FILE)) |
7336 | 1048 { |
1049 if (possible_types & load_path::OCT_FILE) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1050 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1051 fname += ".oct"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1052 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1053 } |
7336 | 1054 else if (possible_types & load_path::MEX_FILE) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1055 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1056 fname += ".mex"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1057 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1058 } |
7336 | 1059 else if (possible_types & load_path::M_FILE) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1060 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1061 fname += ".m"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1062 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1063 } |
7336 | 1064 } |
1065 else | |
1066 error ("%s: %s: invalid type code = %d", who, fcn.c_str (), type); | |
1067 | |
1068 return retval; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11578
diff
changeset
|
1069 } |
7336 | 1070 |
5832 | 1071 std::string |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1072 load_path::loader::find_fcn (const std::string& fcn, std::string& dir_name, |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1073 int type) const |
5832 | 1074 { |
1075 std::string retval; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11578
diff
changeset
|
1076 |
7336 | 1077 // update (); |
5832 | 1078 |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
1079 if (fcn.length () > 0 && fcn[0] == '@') |
5832 | 1080 { |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
1081 size_t pos = fcn.find ('/'); |
5832 | 1082 |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
1083 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1084 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1085 std::string class_name = fcn.substr (1, pos-1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1086 std::string meth = fcn.substr (pos+1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1087 |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1088 retval = find_method (class_name, meth, dir_name); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1089 } |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
1090 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1091 retval = std::string (); |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
1092 } |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
1093 else |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
1094 { |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
1095 dir_name = std::string (); |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
1096 |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
1097 const_fcn_map_iterator p = fcn_map.find (fcn); |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
1098 |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
1099 if (p != fcn_map.end ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1100 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1101 const file_info_list_type& file_info_list = p->second; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1102 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1103 for (const_file_info_list_iterator i = file_info_list.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1104 i != file_info_list.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1105 i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1106 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1107 const file_info& fi = *i; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1108 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1109 retval = file_ops::concat (fi.dir_name, fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1110 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1111 if (check_file_type (retval, type, fi.types, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1112 fcn, "load_path::do_find_fcn")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1113 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1114 dir_name = fi.dir_name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1115 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1116 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1117 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1118 retval = std::string (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1119 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1120 } |
7336 | 1121 } |
1122 | |
1123 return retval; | |
1124 } | |
1125 | |
1126 std::string | |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1127 load_path::loader::find_private_fcn (const std::string& dir, |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1128 const std::string& fcn, int type) const |
7336 | 1129 { |
1130 std::string retval; | |
1131 | |
1132 // update (); | |
1133 | |
1134 const_private_fcn_map_iterator q = private_fcn_map.find (dir); | |
1135 | |
1136 if (q != private_fcn_map.end ()) | |
1137 { | |
1138 const dir_info::fcn_file_map_type& m = q->second; | |
1139 | |
1140 dir_info::const_fcn_file_map_iterator p = m.find (fcn); | |
1141 | |
1142 if (p != m.end ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1143 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1144 std::string fname |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1145 = file_ops::concat (file_ops::concat (dir, "private"), fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1146 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1147 if (check_file_type (fname, type, p->second, fcn, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1148 "load_path::find_private_fcn")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1149 retval = fname; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1150 } |
7336 | 1151 } |
1152 | |
1153 return retval; | |
1154 } | |
1155 | |
1156 std::string | |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1157 load_path::loader::find_method (const std::string& class_name, |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1158 const std::string& meth, |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1159 std::string& dir_name, int type) const |
7336 | 1160 { |
1161 std::string retval; | |
1162 | |
1163 // update (); | |
1164 | |
1165 dir_name = std::string (); | |
1166 | |
1167 const_method_map_iterator q = method_map.find (class_name); | |
1168 | |
1169 if (q != method_map.end ()) | |
1170 { | |
1171 const fcn_map_type& m = q->second; | |
1172 | |
1173 const_fcn_map_iterator p = m.find (meth); | |
1174 | |
9581
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1175 if (p != m.end ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1176 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1177 const file_info_list_type& file_info_list = p->second; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1178 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1179 for (const_file_info_list_iterator i = file_info_list.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1180 i != file_info_list.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1181 i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1182 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1183 const file_info& fi = *i; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1184 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1185 retval = file_ops::concat (fi.dir_name, meth); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1186 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1187 bool found = check_file_type (retval, type, fi.types, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1188 meth, "load_path::do_find_method"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1189 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1190 if (found) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1191 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1192 dir_name = fi.dir_name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1193 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1194 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1195 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1196 retval = std::string (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1197 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1198 } |
5832 | 1199 } |
1200 | |
1201 return retval; | |
1202 } | |
1203 | |
7336 | 1204 std::list<std::string> |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1205 load_path::loader::methods (const std::string& class_name) const |
7336 | 1206 { |
1207 std::list<std::string> retval; | |
1208 | |
1209 // update (); | |
1210 | |
1211 const_method_map_iterator q = method_map.find (class_name); | |
1212 | |
1213 if (q != method_map.end ()) | |
1214 { | |
1215 const fcn_map_type& m = q->second; | |
1216 | |
1217 for (const_fcn_map_iterator p = m.begin (); p != m.end (); p++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1218 retval.push_back (p->first); |
7336 | 1219 } |
1220 | |
1221 if (! retval.empty ()) | |
1222 retval.sort (); | |
1223 | |
1224 return retval; | |
1225 } | |
1226 | |
20087
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
1227 bool |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
1228 load_path::is_package (const std::string& name) const |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
1229 { |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
1230 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
1231 p != dir_info_list.end (); |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
1232 p++) |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
1233 { |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
1234 if (p->is_package (name)) |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
1235 return true; |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
1236 } |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
1237 |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
1238 return false; |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
1239 } |
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19895
diff
changeset
|
1240 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1241 std::list<std::string> |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1242 load_path::do_overloads (const std::string& meth) const |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1243 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1244 std::list<std::string> retval; |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1245 |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1246 // update (); |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1247 |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1248 default_loader.overloads (meth, retval); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1249 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1250 for (const_loader_map_iterator l = loader_map.begin (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1251 l != loader_map.end (); ++l) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1252 l->second.overloads (meth, retval); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1253 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1254 return retval; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1255 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1256 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1257 void |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1258 load_path::loader::overloads (const std::string& meth, |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1259 std::list<std::string>& l) const |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1260 { |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1261 for (const_method_map_iterator q = method_map.begin (); |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1262 q != method_map.end (); q++) |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1263 { |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1264 const fcn_map_type& m = q->second; |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1265 |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1266 if (m.find (meth) != m.end ()) |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1267 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1268 std::string class_name = q->first; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1269 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1270 if (! prefix.empty ()) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1271 class_name = prefix + "." + class_name; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1272 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1273 l.push_back (class_name); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1274 } |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1275 } |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1276 } |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1277 |
18203
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1278 // Should we cache all files in private directories, or is it OK to just |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1279 // look them up each time as needed? |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1280 |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1281 std::string |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1282 find_private_file (const std::string& fname) |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1283 { |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1284 std::string retval; |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1285 |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1286 // Look in private directory corresponding to current function (if |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1287 // any). |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1288 |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1289 octave_user_function *curr_fcn = symbol_table::get_curr_fcn (); |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1290 |
18841
ebf6a1e5ff59
load files in private directories from private functions (bug #42500)
John W. Eaton <jwe@octave.org>
parents:
18203
diff
changeset
|
1291 if (curr_fcn) |
18203
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1292 { |
18841
ebf6a1e5ff59
load files in private directories from private functions (bug #42500)
John W. Eaton <jwe@octave.org>
parents:
18203
diff
changeset
|
1293 // Even for private functions, dir_name doesn't contain the |
ebf6a1e5ff59
load files in private directories from private functions (bug #42500)
John W. Eaton <jwe@octave.org>
parents:
18203
diff
changeset
|
1294 // "private" directory component so we append it here in all |
ebf6a1e5ff59
load files in private directories from private functions (bug #42500)
John W. Eaton <jwe@octave.org>
parents:
18203
diff
changeset
|
1295 // cases. |
ebf6a1e5ff59
load files in private directories from private functions (bug #42500)
John W. Eaton <jwe@octave.org>
parents:
18203
diff
changeset
|
1296 |
18203
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1297 std::string dir_name = curr_fcn->dir_name (); |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1298 |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1299 if (! dir_name.empty ()) |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1300 { |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1301 std::string pfname = dir_name + file_ops::dir_sep_str () |
19895
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
1302 + "private" + file_ops::dir_sep_str () + fname; |
18203
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1303 |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1304 file_stat fs (pfname); |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1305 |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1306 if (fs.exists () && fs.is_reg ()) |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1307 retval = pfname; |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1308 } |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1309 } |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1310 |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1311 return retval; |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1312 } |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1313 |
5832 | 1314 std::string |
1315 load_path::do_find_file (const std::string& file) const | |
1316 { | |
1317 std::string retval; | |
1318 | |
18203
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1319 if (octave_env::absolute_pathname (file) |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1320 || octave_env::rooted_relative_pathname (file)) |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1321 { |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1322 file_stat fs (file); |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1323 |
18960
cc8aaf9c9e33
exist: don't search path for absolute or rooted relative file names
John W. Eaton <jwe@octave.org>
parents:
18841
diff
changeset
|
1324 return fs.exists () ? file : retval; |
18203
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1325 } |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1326 else |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1327 { |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1328 std::string tfile = find_private_file (file); |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1329 |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1330 if (! tfile.empty ()) |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1331 return tfile; |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1332 } |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1333 |
8021 | 1334 if (file.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos) |
5832 | 1335 { |
18203
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1336 // Given name has a directory separator, so append it to each |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1337 // element of the load path in turn. |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1338 |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1339 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1340 p != dir_info_list.end (); |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1341 p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1342 { |
18203
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1343 std::string tfile = file_ops::concat (p->dir_name, file); |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1344 |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1345 file_stat fs (tfile); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1346 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1347 if (fs.exists ()) |
18203
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1348 return tfile; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1349 } |
5832 | 1350 } |
6838 | 1351 else |
1352 { | |
18203
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1353 // Look in cache. |
adbbacce8aaf
find load file in private directories (bug #35697)
John W. Eaton <jwe@octave.org>
parents:
18136
diff
changeset
|
1354 |
6838 | 1355 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1356 p != dir_info_list.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1357 p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1358 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1359 string_vector all_files = p->all_files; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1360 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1361 octave_idx_type len = all_files.length (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1362 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1363 for (octave_idx_type i = 0; i < len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1364 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1365 if (all_files[i] == file) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1366 return file_ops::concat (p->dir_name, file); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1367 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1368 } |
6838 | 1369 } |
5832 | 1370 |
1371 return retval; | |
1372 } | |
1373 | |
1374 std::string | |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1375 load_path::do_find_dir (const std::string& dir) const |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1376 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1377 std::string retval; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1378 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1379 if (dir.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1380 && (octave_env::absolute_pathname (dir) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1381 || octave_env::rooted_relative_pathname (dir))) |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1382 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1383 file_stat fs (dir); |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1384 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1385 if (fs.exists () && fs.is_dir ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1386 return dir; |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1387 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1388 else |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1389 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1390 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1391 p != dir_info_list.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1392 p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1393 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1394 std::string dname = octave_env::make_absolute (p->dir_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1395 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1396 size_t dname_len = dname.length (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1397 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1398 if (dname.substr (dname_len - 1) == file_ops::dir_sep_str ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1399 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1400 dname = dname.substr (0, dname_len - 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1401 dname_len--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1402 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1403 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1404 size_t dir_len = dir.length (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1405 |
19576
b9cb664404b9
avoid indexing before beginning of string
John W. Eaton <jwe@octave.org>
parents:
19438
diff
changeset
|
1406 if (dname_len > dir_len |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1407 && file_ops::is_dir_sep (dname[dname_len - dir_len - 1]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1408 && dir.compare (dname.substr (dname_len - dir_len)) == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1409 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1410 file_stat fs (p->dir_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1411 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1412 if (fs.exists () && fs.is_dir ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1413 return p->dir_name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1414 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1415 } |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1416 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1417 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1418 return retval; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1419 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1420 |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1421 string_vector |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1422 load_path::do_find_matching_dirs (const std::string& dir) const |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1423 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1424 std::list<std::string> retlist; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1425 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1426 if (dir.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1427 && (octave_env::absolute_pathname (dir) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1428 || octave_env::rooted_relative_pathname (dir))) |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1429 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1430 file_stat fs (dir); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1431 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1432 if (fs.exists () && fs.is_dir ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1433 retlist.push_back (dir); |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1434 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1435 else |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1436 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1437 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1438 p != dir_info_list.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1439 p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1440 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1441 std::string dname = octave_env::make_absolute (p->dir_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1442 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1443 size_t dname_len = dname.length (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1444 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1445 if (dname.substr (dname_len - 1) == file_ops::dir_sep_str ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1446 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1447 dname = dname.substr (0, dname_len - 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1448 dname_len--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1449 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1450 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1451 size_t dir_len = dir.length (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1452 |
19579
e2b570e7224b
avoid indexing before beginning of string
John W. Eaton <jwe@octave.org>
parents:
19578
diff
changeset
|
1453 if (dname_len > dir_len |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1454 && file_ops::is_dir_sep (dname[dname_len - dir_len - 1]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1455 && dir.compare (dname.substr (dname_len - dir_len)) == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1456 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1457 file_stat fs (p->dir_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1458 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1459 if (fs.exists () && fs.is_dir ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1460 retlist.push_back (p->dir_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1461 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1462 } |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1463 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1464 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1465 return retlist; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1466 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1467 |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1468 std::string |
5832 | 1469 load_path::do_find_first_of (const string_vector& flist) const |
1470 { | |
1471 std::string retval; | |
1472 | |
1473 std::string dir_name; | |
1474 std::string file_name; | |
1475 | |
1476 octave_idx_type flen = flist.length (); | |
1477 octave_idx_type rel_flen = 0; | |
1478 | |
1479 string_vector rel_flist (flen); | |
1480 | |
1481 for (octave_idx_type i = 0; i < flen; i++) | |
1482 { | |
11105
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1483 std::string file = flist[i]; |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1484 |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1485 if (file.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1486 { |
11105
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1487 if (octave_env::absolute_pathname (file) |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1488 || octave_env::rooted_relative_pathname (file)) |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1489 { |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1490 file_stat fs (file); |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1491 |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1492 if (fs.exists ()) |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1493 return file; |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1494 } |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1495 else |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1496 { |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1497 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1498 p != dir_info_list.end (); |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1499 p++) |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1500 { |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1501 std::string tfile = file_ops::concat (p->dir_name, file); |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1502 |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1503 file_stat fs (tfile); |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1504 |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1505 if (fs.exists ()) |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1506 return tfile; |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1507 } |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1508 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1509 } |
5832 | 1510 else |
11105
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1511 rel_flist[rel_flen++] = file; |
5832 | 1512 } |
1513 | |
1514 rel_flist.resize (rel_flen); | |
1515 | |
1516 for (const_dir_info_list_iterator p = dir_info_list.begin (); | |
1517 p != dir_info_list.end (); | |
1518 p++) | |
1519 { | |
1520 string_vector all_files = p->all_files; | |
1521 | |
1522 octave_idx_type len = all_files.length (); | |
1523 | |
1524 for (octave_idx_type i = 0; i < len; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1525 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1526 for (octave_idx_type j = 0; j < rel_flen; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1527 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1528 if (all_files[i] == rel_flist[j]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1529 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1530 dir_name = p->dir_name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1531 file_name = rel_flist[j]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1532 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1533 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1534 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1535 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1536 } |
5832 | 1537 } |
1538 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1539 done: |
6159 | 1540 |
5832 | 1541 if (! dir_name.empty ()) |
7272 | 1542 retval = file_ops::concat (dir_name, file_name); |
5832 | 1543 |
1544 return retval; | |
1545 } | |
1546 | |
1547 string_vector | |
1548 load_path::do_find_all_first_of (const string_vector& flist) const | |
1549 { | |
1550 std::list<std::string> retlist; | |
1551 | |
1552 std::string dir_name; | |
1553 std::string file_name; | |
1554 | |
1555 octave_idx_type flen = flist.length (); | |
1556 octave_idx_type rel_flen = 0; | |
1557 | |
1558 string_vector rel_flist (flen); | |
1559 | |
1560 for (octave_idx_type i = 0; i < flen; i++) | |
1561 { | |
11105
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1562 std::string file = flist[i]; |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1563 |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1564 if (file.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1565 { |
11105
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1566 if (octave_env::absolute_pathname (file) |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1567 || octave_env::rooted_relative_pathname (file)) |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1568 { |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1569 file_stat fs (file); |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1570 |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1571 if (fs.exists ()) |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1572 retlist.push_back (file); |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1573 } |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1574 else |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1575 { |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1576 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1577 p != dir_info_list.end (); |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1578 p++) |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1579 { |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1580 std::string tfile = file_ops::concat (p->dir_name, file); |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1581 |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1582 file_stat fs (tfile); |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1583 |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1584 if (fs.exists ()) |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1585 retlist.push_back (tfile); |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1586 } |
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1587 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1588 } |
5832 | 1589 else |
11105
a6ab46b5926f
load_path::do_find{all,}first_of: search path for relative file names
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
1590 rel_flist[rel_flen++] = file; |
5832 | 1591 } |
1592 | |
1593 rel_flist.resize (rel_flen); | |
1594 | |
1595 for (const_dir_info_list_iterator p = dir_info_list.begin (); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1596 p != dir_info_list.end (); p++) |
5832 | 1597 { |
1598 string_vector all_files = p->all_files; | |
1599 | |
1600 octave_idx_type len = all_files.length (); | |
1601 | |
1602 for (octave_idx_type i = 0; i < len; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1603 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1604 for (octave_idx_type j = 0; j < rel_flen; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1605 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1606 if (all_files[i] == rel_flist[j]) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1607 retlist.push_back (file_ops::concat (p->dir_name, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1608 rel_flist[j])); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1609 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1610 } |
5832 | 1611 } |
1612 | |
9807
645c478aa89d
load-path.cc (load_path::do_find_all_first_of): take advantage of string_vector (std::list<std:string>) constructor
John W. Eaton <jwe@octave.org>
parents:
9806
diff
changeset
|
1613 return retlist; |
5832 | 1614 } |
1615 | |
1616 string_vector | |
1617 load_path::do_dirs (void) const | |
1618 { | |
1619 size_t len = dir_info_list.size (); | |
1620 | |
1621 string_vector retval (len); | |
1622 | |
1623 octave_idx_type k = 0; | |
1624 | |
1625 for (const_dir_info_list_iterator i = dir_info_list.begin (); | |
1626 i != dir_info_list.end (); | |
1627 i++) | |
1628 retval[k++] = i->dir_name; | |
1629 | |
1630 return retval; | |
1631 } | |
1632 | |
1633 std::list<std::string> | |
1634 load_path::do_dir_list (void) const | |
1635 { | |
1636 std::list<std::string> retval; | |
1637 | |
1638 for (const_dir_info_list_iterator i = dir_info_list.begin (); | |
1639 i != dir_info_list.end (); | |
1640 i++) | |
1641 retval.push_back (i->dir_name); | |
1642 | |
1643 return retval; | |
1644 } | |
1645 | |
1646 string_vector | |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1647 load_path::do_files (const std::string& dir, bool omit_exts) const |
5832 | 1648 { |
1649 string_vector retval; | |
1650 | |
9282
2ed8d2d92507
load_path::do_files: avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
9261
diff
changeset
|
1651 const_dir_info_list_iterator p = find_dir_info (dir); |
5832 | 1652 |
9282
2ed8d2d92507
load_path::do_files: avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
9261
diff
changeset
|
1653 if (p != dir_info_list.end ()) |
2ed8d2d92507
load_path::do_files: avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
9261
diff
changeset
|
1654 retval = p->fcn_files; |
5832 | 1655 |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1656 if (omit_exts) |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1657 { |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1658 octave_idx_type len = retval.length (); |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1659 |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1660 for (octave_idx_type i = 0; i < len; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1661 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1662 std::string fname = retval[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1663 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1664 size_t pos = fname.rfind ('.'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1665 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1666 if (pos != std::string::npos) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1667 retval[i] = fname.substr (0, pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1668 } |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1669 } |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1670 |
5832 | 1671 return retval; |
1672 } | |
1673 | |
1674 string_vector | |
1675 load_path::do_fcn_names (void) const | |
1676 { | |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1677 return default_loader.fcn_names (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1678 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1679 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1680 string_vector |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1681 load_path::loader::fcn_names (void) const |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1682 { |
5832 | 1683 size_t len = fcn_map.size (); |
1684 | |
1685 string_vector retval (len); | |
1686 | |
1687 octave_idx_type count = 0; | |
1688 | |
1689 for (const_fcn_map_iterator p = fcn_map.begin (); | |
1690 p != fcn_map.end (); | |
1691 p++) | |
1692 retval[count++] = p->first; | |
1693 | |
1694 return retval; | |
1695 } | |
1696 | |
1697 std::string | |
1698 load_path::do_path (void) const | |
1699 { | |
1700 std::string xpath; | |
1701 | |
1702 string_vector xdirs = load_path::dirs (); | |
1703 | |
1704 octave_idx_type len = xdirs.length (); | |
1705 | |
1706 if (len > 0) | |
1707 xpath = xdirs[0]; | |
1708 | |
1709 for (octave_idx_type i = 1; i < len; i++) | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
1710 xpath += dir_path::path_sep_str () + xdirs[i]; |
5832 | 1711 |
1712 return xpath; | |
1713 } | |
1714 | |
1715 void | |
7336 | 1716 print_types (std::ostream& os, int types) |
1717 { | |
1718 bool printed_type = false; | |
1719 | |
1720 if (types & load_path::OCT_FILE) | |
1721 { | |
1722 os << "oct"; | |
1723 printed_type = true; | |
1724 } | |
1725 | |
1726 if (types & load_path::MEX_FILE) | |
1727 { | |
1728 if (printed_type) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1729 os << "|"; |
7336 | 1730 os << "mex"; |
1731 printed_type = true; | |
1732 } | |
1733 | |
1734 if (types & load_path::M_FILE) | |
1735 { | |
1736 if (printed_type) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1737 os << "|"; |
7336 | 1738 os << "m"; |
1739 printed_type = true; | |
1740 } | |
1741 } | |
1742 | |
1743 void | |
1744 print_fcn_list (std::ostream& os, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1745 const load_path::dir_info::fcn_file_map_type& lst) |
7336 | 1746 { |
1747 for (load_path::dir_info::const_fcn_file_map_iterator p = lst.begin (); | |
1748 p != lst.end (); | |
1749 p++) | |
1750 { | |
1751 os << " " << p->first << " ("; | |
1752 | |
1753 print_types (os, p->second); | |
1754 | |
1755 os << ")\n"; | |
1756 } | |
1757 } | |
1758 | |
1759 string_vector | |
1760 get_file_list (const load_path::dir_info::fcn_file_map_type& lst) | |
1761 { | |
1762 octave_idx_type n = lst.size (); | |
1763 | |
1764 string_vector retval (n); | |
1765 | |
1766 octave_idx_type count = 0; | |
1767 | |
1768 for (load_path::dir_info::const_fcn_file_map_iterator p = lst.begin (); | |
1769 p != lst.end (); | |
1770 p++) | |
1771 { | |
1772 std::string nm = p->first; | |
1773 | |
1774 int types = p->second; | |
1775 | |
1776 if (types & load_path::OCT_FILE) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1777 nm += ".oct"; |
7336 | 1778 else if (types & load_path::MEX_FILE) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1779 nm += ".mex"; |
7336 | 1780 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1781 nm += ".m"; |
7336 | 1782 |
1783 retval[count++] = nm; | |
1784 } | |
1785 | |
1786 return retval; | |
1787 } | |
1788 | |
1789 void | |
5832 | 1790 load_path::do_display (std::ostream& os) const |
1791 { | |
1792 for (const_dir_info_list_iterator i = dir_info_list.begin (); | |
1793 i != dir_info_list.end (); | |
1794 i++) | |
1795 { | |
1796 string_vector fcn_files = i->fcn_files; | |
1797 | |
1798 if (! fcn_files.empty ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1799 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1800 os << "\n*** function files in " << i->dir_name << ":\n\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1801 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1802 fcn_files.list_in_columns (os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1803 } |
5832 | 1804 |
7336 | 1805 const dir_info::method_file_map_type& method_file_map |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1806 = i->method_file_map; |
5832 | 1807 |
7336 | 1808 if (! method_file_map.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1809 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1810 for (dir_info::const_method_file_map_iterator |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1811 p = method_file_map.begin (); p != method_file_map.end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1812 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1813 os << "\n*** methods in " << i->dir_name |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1814 << "/@" << p->first << ":\n\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1815 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1816 const dir_info::class_info& ci = p->second; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1817 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1818 string_vector method_files = get_file_list (ci.method_file_map); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1819 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1820 method_files.list_in_columns (os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1821 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1822 } |
7336 | 1823 } |
5864 | 1824 |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1825 default_loader.display (os); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1826 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1827 for (const_loader_map_iterator l = loader_map.begin (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1828 l != loader_map.end (); ++l) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1829 l->second.display (os); |
5832 | 1830 } |
1831 | |
10334
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1832 // True if a path is contained in a path list separated by path_sep_char |
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1833 static bool |
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1834 in_path_list (const std::string& path_list, const std::string& path) |
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1835 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1836 size_t ps = path.size (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1837 size_t pls = path_list.size (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1838 size_t pos = path_list.find (path); |
10334
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1839 char psc = dir_path::path_sep_char (); |
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1840 while (pos != std::string::npos) |
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1841 { |
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1842 if ((pos == 0 || path_list[pos-1] == psc) |
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1843 && (pos + ps == pls || path_list[pos + ps] == psc)) |
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1844 return true; |
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1845 else |
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1846 pos = path_list.find (path, pos + 1); |
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1847 } |
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1848 |
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1849 return false; |
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1850 } |
db540cb0e959
improve shadowed function checking
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
1851 |
5832 | 1852 void |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1853 load_path::add (const dir_info& di, bool at_end, |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1854 const std::string& pname) const |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1855 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1856 loader& l = get_loader (pname); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1857 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1858 l.add (di, at_end); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1859 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1860 dir_info::package_dir_map_type package_dir_map = di.package_dir_map; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1861 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1862 for (dir_info::const_package_dir_map_iterator p = package_dir_map.begin (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1863 p != package_dir_map.end (); ++p) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1864 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1865 std::string full_name = p->first; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1866 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1867 if (! pname.empty ()) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1868 full_name = pname + "." + full_name; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1869 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1870 add (p->second, at_end, full_name); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1871 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1872 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1873 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1874 void |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1875 load_path::loader::add_to_fcn_map (const dir_info& di, bool at_end) |
5832 | 1876 { |
1877 std::string dir_name = di.dir_name; | |
1878 | |
1879 string_vector fcn_files = di.fcn_files; | |
1880 | |
1881 octave_idx_type len = fcn_files.length (); | |
1882 | |
1883 for (octave_idx_type i = 0; i < len; i++) | |
1884 { | |
1885 std::string fname = fcn_files[i]; | |
1886 | |
1887 std::string ext; | |
1888 std::string base = fname; | |
1889 | |
1890 size_t pos = fname.rfind ('.'); | |
1891 | |
8021 | 1892 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1893 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1894 base = fname.substr (0, pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1895 ext = fname.substr (pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1896 } |
5832 | 1897 |
7336 | 1898 file_info_list_type& file_info_list = fcn_map[base]; |
5832 | 1899 |
1900 file_info_list_iterator p = file_info_list.begin (); | |
1901 | |
1902 while (p != file_info_list.end ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1903 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1904 if (p->dir_name == dir_name) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1905 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1906 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1907 p++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1908 } |
5832 | 1909 |
1910 int t = 0; | |
1911 if (ext == ".m") | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1912 t = load_path::M_FILE; |
5832 | 1913 else if (ext == ".oct") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1914 t = load_path::OCT_FILE; |
5864 | 1915 else if (ext == ".mex") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1916 t = load_path::MEX_FILE; |
5832 | 1917 |
1918 if (p == file_info_list.end ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1919 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1920 file_info fi (dir_name, t); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1921 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1922 if (at_end) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1923 file_info_list.push_back (fi); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1924 else |
10242
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1925 { |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1926 // Warn if a built-in or library function is being shadowed. |
10446
ba932ad87a04
load_path::add_to_fcn_map: style fixes
John W. Eaton <jwe@octave.org>
parents:
10334
diff
changeset
|
1927 |
10242
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1928 if (! file_info_list.empty ()) |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1929 { |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1930 file_info& old = file_info_list.front (); |
10446
ba932ad87a04
load_path::add_to_fcn_map: style fixes
John W. Eaton <jwe@octave.org>
parents:
10334
diff
changeset
|
1931 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1932 // FIXME: do we need to be more careful about the |
10446
ba932ad87a04
load_path::add_to_fcn_map: style fixes
John W. Eaton <jwe@octave.org>
parents:
10334
diff
changeset
|
1933 // way we look for old.dir_name in sys_path to avoid |
ba932ad87a04
load_path::add_to_fcn_map: style fixes
John W. Eaton <jwe@octave.org>
parents:
10334
diff
changeset
|
1934 // partial matches? |
ba932ad87a04
load_path::add_to_fcn_map: style fixes
John W. Eaton <jwe@octave.org>
parents:
10334
diff
changeset
|
1935 |
14884
f10cddda37c5
omit warning for multiple Contents.m files in the load path
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
1936 // Don't warn about Contents.m files since we expect |
f10cddda37c5
omit warning for multiple Contents.m files in the load path
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
1937 // more than one to exist in the load path. |
f10cddda37c5
omit warning for multiple Contents.m files in the load path
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
1938 |
f10cddda37c5
omit warning for multiple Contents.m files in the load path
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
1939 if (fname != "Contents.m" |
f10cddda37c5
omit warning for multiple Contents.m files in the load path
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
1940 && sys_path.find (old.dir_name) != std::string::npos |
10446
ba932ad87a04
load_path::add_to_fcn_map: style fixes
John W. Eaton <jwe@octave.org>
parents:
10334
diff
changeset
|
1941 && in_path_list (sys_path, old.dir_name)) |
10242
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1942 { |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1943 std::string fcn_path = file_ops::concat (dir_name, fname); |
10446
ba932ad87a04
load_path::add_to_fcn_map: style fixes
John W. Eaton <jwe@octave.org>
parents:
10334
diff
changeset
|
1944 |
10242
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1945 warning_with_id ("Octave:shadowed-function", |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11578
diff
changeset
|
1946 "function %s shadows a core library function", |
10242
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1947 fcn_path.c_str ()); |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1948 } |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1949 } |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1950 else if (symbol_table::is_built_in_function_name (base)) |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1951 { |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1952 std::string fcn_path = file_ops::concat (dir_name, fname); |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1953 warning_with_id ("Octave:shadowed-function", |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11578
diff
changeset
|
1954 "function %s shadows a built-in function", |
10242
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1955 fcn_path.c_str ()); |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1956 } |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1957 |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1958 file_info_list.push_front (fi); |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1959 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1960 } |
5832 | 1961 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1962 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1963 file_info& fi = *p; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1964 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1965 fi.types |= t; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1966 } |
5832 | 1967 } |
1968 } | |
1969 | |
7336 | 1970 void |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1971 load_path::loader::add_to_private_fcn_map (const dir_info& di) |
7336 | 1972 { |
1973 dir_info::fcn_file_map_type private_file_map = di.private_file_map; | |
1974 | |
1975 if (! private_file_map.empty ()) | |
1976 private_fcn_map[di.dir_name] = private_file_map; | |
1977 } | |
1978 | |
1979 void | |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
1980 load_path::loader::add_to_method_map (const dir_info& di, bool at_end) |
7336 | 1981 { |
1982 std::string dir_name = di.dir_name; | |
1983 | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1984 // <CLASS_NAME, CLASS_INFO> |
7336 | 1985 dir_info::method_file_map_type method_file_map = di.method_file_map; |
1986 | |
1987 for (dir_info::const_method_file_map_iterator q = method_file_map.begin (); | |
1988 q != method_file_map.end (); | |
1989 q++) | |
1990 { | |
1991 std::string class_name = q->first; | |
1992 | |
1993 fcn_map_type& fm = method_map[class_name]; | |
1994 | |
1995 std::string full_dir_name | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1996 = file_ops::concat (dir_name, "@" + class_name); |
7336 | 1997 |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1998 const dir_info::class_info& ci = q->second; |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1999 |
7336 | 2000 // <FCN_NAME, TYPES> |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
2001 const dir_info::fcn_file_map_type& m = ci.method_file_map; |
7336 | 2002 |
2003 for (dir_info::const_fcn_file_map_iterator p = m.begin (); | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2004 p != m.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2005 p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2006 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2007 std::string base = p->first; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2008 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2009 int types = p->second; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2010 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2011 file_info_list_type& file_info_list = fm[base]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2012 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2013 file_info_list_iterator p2 = file_info_list.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2014 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2015 while (p2 != file_info_list.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2016 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2017 if (p2->dir_name == full_dir_name) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2018 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2019 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2020 p2++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2021 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2022 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2023 if (p2 == file_info_list.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2024 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2025 file_info fi (full_dir_name, types); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2026 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2027 if (at_end) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2028 file_info_list.push_back (fi); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2029 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2030 file_info_list.push_front (fi); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2031 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2032 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2033 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2034 // FIXME: is this possible? |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2035 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2036 file_info& fi = *p2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2037 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2038 fi.types = types; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2039 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2040 } |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
2041 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
2042 // <FCN_NAME, TYPES> |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
2043 dir_info::fcn_file_map_type private_file_map = ci.private_file_map; |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
2044 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
2045 if (! private_file_map.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2046 private_fcn_map[full_dir_name] = private_file_map; |
7336 | 2047 } |
2048 } | |
2049 | |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2050 void |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2051 load_path::loader::display (std::ostream& os) const |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2052 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2053 os << "*** loader: " << (prefix.empty () ? "<top-level>" : prefix) << "\n\n"; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2054 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2055 for (std::list<std::string>::const_iterator s = dir_list.begin (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2056 s != dir_list.end (); ++s) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2057 os << *s << "\n"; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2058 os << "\n"; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2059 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2060 for (const_private_fcn_map_iterator i = private_fcn_map.begin (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2061 i != private_fcn_map.end (); i++) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2062 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2063 os << "\n*** private functions in " |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2064 << file_ops::concat (i->first, "private") << ":\n\n"; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2065 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2066 print_fcn_list (os, i->second); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2067 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2068 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2069 #if defined (DEBUG_LOAD_PATH) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2070 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2071 for (const_fcn_map_iterator i = fcn_map.begin (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2072 i != fcn_map.end (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2073 i++) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2074 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2075 os << i->first << ":\n"; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2076 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2077 const file_info_list_type& file_info_list = i->second; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2078 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2079 for (const_file_info_list_iterator p = file_info_list.begin (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2080 p != file_info_list.end (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2081 p++) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2082 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2083 os << " " << p->dir_name << " ("; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2084 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2085 print_types (os, p->types); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2086 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2087 os << ")\n"; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2088 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2089 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2090 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2091 for (const_method_map_iterator i = method_map.begin (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2092 i != method_map.end (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2093 i++) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2094 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2095 os << "CLASS " << i->first << ":\n"; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2096 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2097 const fcn_map_type& fm = i->second; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2098 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2099 for (const_fcn_map_iterator q = fm.begin (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2100 q != fm.end (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2101 q++) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2102 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2103 os << " " << q->first << ":\n"; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2104 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2105 const file_info_list_type& file_info_list = q->second; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2106 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2107 for (const_file_info_list_iterator p = file_info_list.begin (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2108 p != file_info_list.end (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2109 p++) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2110 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2111 os << " " << p->dir_name << " ("; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2112 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2113 print_types (os, p->types); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2114 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2115 os << ")\n"; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2116 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2117 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2118 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2119 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2120 os << "\n"; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2121 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2122 #endif |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2123 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2124 |
5832 | 2125 std::string |
2126 genpath (const std::string& dirname, const string_vector& skip) | |
2127 { | |
2128 std::string retval; | |
2129 | |
5871 | 2130 dir_entry dir (dirname); |
5832 | 2131 |
2132 if (dir) | |
2133 { | |
2134 retval = dirname; | |
2135 | |
18136
181bbce78595
Sort result of genpath() for matlab compatibility (bug #40903).
Rik <rik@octave.org>
parents:
17856
diff
changeset
|
2136 string_vector dirlist = dir.read ().sort (false); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11578
diff
changeset
|
2137 |
5832 | 2138 octave_idx_type len = dirlist.length (); |
2139 | |
2140 for (octave_idx_type i = 0; i < len; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2141 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2142 std::string elt = dirlist[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2143 |
17414
20d1b911b4e7
* libinterp/corefcn/load-path.cc (genpath): Ignore package dirs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16896
diff
changeset
|
2144 bool skip_p = (elt == "." || elt == ".." || elt[0] == '@' |
20d1b911b4e7
* libinterp/corefcn/load-path.cc (genpath): Ignore package dirs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16896
diff
changeset
|
2145 || elt[0] == '+'); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2146 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2147 if (! skip_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2148 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2149 for (octave_idx_type j = 0; j < skip.length (); j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2150 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2151 skip_p = (elt == skip[j]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2152 if (skip_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2153 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2154 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2155 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2156 if (! skip_p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2157 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2158 std::string nm = file_ops::concat (dirname, elt); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2159 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2160 file_stat fs (nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2161 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2162 if (fs && fs.is_dir ()) |
10971
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2163 retval += dir_path::path_sep_str () + genpath (nm, skip); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2164 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2165 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2166 } |
5832 | 2167 } |
2168 | |
2169 return retval; | |
2170 } | |
2171 | |
16690
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
2172 std::list<std::string> |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
2173 load_path::do_get_all_package_names (bool only_top_level) const |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
2174 { |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
2175 std::list<std::string> retval; |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
2176 |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
2177 for (const_loader_map_iterator l = loader_map.begin (); |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
2178 l != loader_map.end (); ++l) |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
2179 { |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
2180 if (! only_top_level || l->first.find ('.') == std::string::npos) |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
2181 retval.push_back (l->first); |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
2182 } |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
2183 |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
2184 return retval; |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
2185 } |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
2186 |
5832 | 2187 static void |
2188 execute_pkg_add_or_del (const std::string& dir, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2189 const std::string& script_file) |
5832 | 2190 { |
2191 if (! octave_interpreter_ready) | |
2192 return; | |
2193 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9807
diff
changeset
|
2194 unwind_protect frame; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9807
diff
changeset
|
2195 |
7272 | 2196 std::string file = file_ops::concat (dir, script_file); |
5832 | 2197 |
5978 | 2198 file_stat fs (file); |
5832 | 2199 |
2200 if (fs.exists ()) | |
5975 | 2201 source_file (file, "base"); |
5832 | 2202 } |
2203 | |
2204 void | |
2205 execute_pkg_add (const std::string& dir) | |
2206 { | |
2207 execute_pkg_add_or_del (dir, "PKG_ADD"); | |
2208 } | |
2209 | |
2210 void | |
2211 execute_pkg_del (const std::string& dir) | |
2212 { | |
2213 execute_pkg_add_or_del (dir, "PKG_DEL"); | |
2214 } | |
2215 | |
2216 DEFUN (genpath, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2217 "-*- texinfo -*-\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
2218 @deftypefn {Built-in Function} {} genpath (@var{dir})\n\ |
10971
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2219 @deftypefnx {Built-in Function} {} genpath (@var{dir}, @var{skip}, @dots{})\n\ |
8325
b93ac0586e4b
spelling corrections
Brian Gough<bjg@network-theory.co.uk>
parents:
8141
diff
changeset
|
2220 Return a path constructed from @var{dir} and all its subdirectories.\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
2221 If additional string parameters are given, the resulting path will\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
2222 exclude directories with those names.\n\ |
5832 | 2223 @end deftypefn") |
2224 { | |
2225 octave_value retval; | |
2226 | |
10971
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2227 octave_idx_type nargin = args.length (); |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2228 |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2229 if (nargin == 1) |
5832 | 2230 { |
2231 std::string dirname = args(0).string_value (); | |
2232 | |
2233 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2234 retval = genpath (dirname); |
5832 | 2235 else |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19066
diff
changeset
|
2236 error ("genpath: DIR must be a string"); |
5832 | 2237 } |
10971
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2238 else if (nargin > 1) |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2239 { |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2240 std::string dirname = args(0).string_value (); |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2241 |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2242 string_vector skip (nargin - 1); |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2243 |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2244 for (octave_idx_type i = 1; i < nargin; i++) |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2245 { |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2246 skip[i-1] = args(i).string_value (); |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2247 |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2248 if (error_state) |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2249 break; |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2250 } |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2251 |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2252 if (! error_state) |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2253 retval = genpath (dirname, skip); |
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2254 else |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19066
diff
changeset
|
2255 error ("genpath: all arguments must be strings"); |
10971
386aa01ca84c
genpath: accept additional arguments as names of directories to skip
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10957
diff
changeset
|
2256 } |
5832 | 2257 else |
2258 print_usage (); | |
2259 | |
2260 return retval; | |
2261 } | |
2262 | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2263 static void |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2264 rehash_internal (void) |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2265 { |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2266 load_path::update (); |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2267 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2268 // FIXME: maybe we should rename this variable since it is being |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2269 // used for more than keeping track of the prompt time. |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2270 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2271 // This will force updated functions to be found. |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2272 Vlast_prompt_time.stamp (); |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2273 } |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2274 |
5832 | 2275 DEFUN (rehash, , , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2276 "-*- texinfo -*-\n\ |
5832 | 2277 @deftypefn {Built-in Function} {} rehash ()\n\ |
6644 | 2278 Reinitialize Octave's load path directory cache.\n\ |
5832 | 2279 @end deftypefn") |
2280 { | |
2281 octave_value_list retval; | |
2282 | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2283 rehash_internal (); |
5832 | 2284 |
2285 return retval; | |
2286 } | |
2287 | |
8609
fcf762ba66cf
load-path.cc (Fcommand_line_path): rename from Fcommandlinepath
John W. Eaton <jwe@octave.org>
parents:
8593
diff
changeset
|
2288 DEFUN (command_line_path, , , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2289 "-*- texinfo -*-\n\ |
8609
fcf762ba66cf
load-path.cc (Fcommand_line_path): rename from Fcommandlinepath
John W. Eaton <jwe@octave.org>
parents:
8593
diff
changeset
|
2290 @deftypefn {Built-in Function} {} command_line_path (@dots{})\n\ |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
2291 Return the command line path variable.\n\ |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
2292 \n\ |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
2293 @seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
2294 @end deftypefn") |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
2295 { |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
2296 return octave_value (load_path::get_command_line_path ()); |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
2297 } |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
2298 |
7391 | 2299 DEFUN (restoredefaultpath, , , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2300 "-*- texinfo -*-\n\ |
7391 | 2301 @deftypefn {Built-in Function} {} restoredefaultpath (@dots{})\n\ |
12601
99babbf683ff
doc: Correct use of it's -> its in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
2302 Restore Octave's path to its initial state at startup.\n\ |
7391 | 2303 \n\ |
2304 @seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ | |
2305 @end deftypefn") | |
2306 { | |
2307 load_path::initialize (true); | |
2308 | |
2309 return octave_value (load_path::system_path ()); | |
2310 } | |
2311 | |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
2312 // Return Octave's original default list of directories in which to |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
2313 // search for function files. This corresponds to the path that |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
2314 // exists prior to running the system's octaverc file or the user's |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
2315 // ~/.octaverc file |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
2316 |
7391 | 2317 DEFUN (__pathorig__, , , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2318 "-*- texinfo -*-\n\ |
7391 | 2319 @deftypefn {Built-in Function} {@var{val} =} __pathorig__ ()\n\ |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
2320 Undocumented internal function.\n\ |
5832 | 2321 @end deftypefn") |
2322 { | |
6630 | 2323 return octave_value (load_path::system_path ()); |
5832 | 2324 } |
2325 | |
2326 DEFUN (path, args, nargout, | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2327 "-*- texinfo -*-\n\ |
6678 | 2328 @deftypefn {Built-in Function} {} path (@dots{})\n\ |
6644 | 2329 Modify or display Octave's load path.\n\ |
5832 | 2330 \n\ |
2331 If @var{nargin} and @var{nargout} are zero, display the elements of\n\ | |
6644 | 2332 Octave's load path in an easy to read format.\n\ |
5832 | 2333 \n\ |
2334 If @var{nargin} is zero and nargout is greater than zero, return the\n\ | |
6644 | 2335 current load path.\n\ |
5832 | 2336 \n\ |
2337 If @var{nargin} is greater than zero, concatenate the arguments,\n\ | |
10980
1cbfb15892c9
addpath, rmpath: document path arguments
John W. Eaton <jwe@octave.org>
parents:
10971
diff
changeset
|
2338 separating them with @code{pathsep}. Set the internal search path\n\ |
5832 | 2339 to the result and return it.\n\ |
2340 \n\ | |
2341 No checks are made for duplicate elements.\n\ | |
2342 @seealso{addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ | |
2343 @end deftypefn") | |
2344 { | |
2345 octave_value retval; | |
2346 | |
2347 int argc = args.length () + 1; | |
2348 | |
2349 string_vector argv = args.make_argv ("path"); | |
2350 | |
2351 if (! error_state) | |
2352 { | |
2353 if (argc > 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2354 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2355 std::string path = argv[1]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2356 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2357 for (int i = 2; i < argc; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2358 path += dir_path::path_sep_str () + argv[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2359 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2360 load_path::set (path, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2361 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2362 rehash_internal (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2363 } |
5832 | 2364 |
2365 if (nargout > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2366 retval = load_path::path (); |
5832 | 2367 else if (argc == 1 && nargout == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2368 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2369 octave_stdout << |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2370 "\nOctave's search path contains the following directories:\n\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2371 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2372 string_vector dirs = load_path::dirs (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2373 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2374 dirs.list_in_columns (octave_stdout); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2375 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2376 octave_stdout << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2377 } |
5832 | 2378 } |
2379 | |
2380 return retval; | |
2381 } | |
2382 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8704
diff
changeset
|
2383 DEFUN (addpath, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2384 "-*- texinfo -*-\n\ |
10840 | 2385 @deftypefn {Built-in Function} {} addpath (@var{dir1}, @dots{})\n\ |
6678 | 2386 @deftypefnx {Built-in Function} {} addpath (@var{dir1}, @dots{}, @var{option})\n\ |
16567
68176102fe07
* load-path.cc (Faddpath): Doc fix.
John W. Eaton <jwe@octave.org>
parents:
16547
diff
changeset
|
2387 Add named directories to the function search path. If\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
2388 @var{option} is @qcode{\"-begin\"} or 0 (the default), prepend the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
2389 directory name to the current path. If @var{option} is @qcode{\"-end\"}\n\ |
5832 | 2390 or 1, append the directory name to the current path.\n\ |
2391 Directories added to the path must exist.\n\ | |
10980
1cbfb15892c9
addpath, rmpath: document path arguments
John W. Eaton <jwe@octave.org>
parents:
10971
diff
changeset
|
2392 \n\ |
1cbfb15892c9
addpath, rmpath: document path arguments
John W. Eaton <jwe@octave.org>
parents:
10971
diff
changeset
|
2393 In addition to accepting individual directory arguments, lists of\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
2394 directory names separated by @code{pathsep} are also accepted. For example:\n\ |
10980
1cbfb15892c9
addpath, rmpath: document path arguments
John W. Eaton <jwe@octave.org>
parents:
10971
diff
changeset
|
2395 \n\ |
1cbfb15892c9
addpath, rmpath: document path arguments
John W. Eaton <jwe@octave.org>
parents:
10971
diff
changeset
|
2396 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2397 addpath (\"dir1:/dir2:~/dir3\")\n\ |
10980
1cbfb15892c9
addpath, rmpath: document path arguments
John W. Eaton <jwe@octave.org>
parents:
10971
diff
changeset
|
2398 @end example\n\ |
5832 | 2399 @seealso{path, rmpath, genpath, pathdef, savepath, pathsep}\n\ |
2400 @end deftypefn") | |
2401 { | |
2402 octave_value retval; | |
2403 | |
2404 // Originally written by Bill Denney and Etienne Grossman. Heavily | |
2405 // modified and translated to C++ by jwe. | |
2406 | |
2407 if (nargout > 0) | |
2408 retval = load_path::path (); | |
2409 | |
2410 int nargin = args.length (); | |
2411 | |
2412 if (nargin > 0) | |
2413 { | |
2414 bool append = false; | |
2415 | |
2416 octave_value option_arg = args(nargin-1); | |
2417 | |
2418 if (option_arg.is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2419 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2420 std::string option = option_arg.string_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2421 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2422 if (option == "-end") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2423 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2424 append = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2425 nargin--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2426 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2427 else if (option == "-begin") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2428 nargin--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2429 } |
5832 | 2430 else if (option_arg.is_numeric_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2431 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2432 int val = option_arg.int_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2433 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2434 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2435 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2436 if (val == 0) |
10957
27efbc0733f2
addpath: accept numeric option arguments as documented
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
2437 nargin--; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2438 else if (val == 1) |
10957
27efbc0733f2
addpath: accept numeric option arguments as documented
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
2439 { |
27efbc0733f2
addpath: accept numeric option arguments as documented
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
2440 append = true; |
27efbc0733f2
addpath: accept numeric option arguments as documented
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
2441 nargin--; |
27efbc0733f2
addpath: accept numeric option arguments as documented
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
2442 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2443 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2444 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2445 error ("addpath: expecting final argument to be 1 or 0"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2446 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2447 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2448 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2449 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2450 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2451 error ("addpath: expecting final argument to be 1 or 0"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2452 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2453 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2454 } |
5832 | 2455 |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2456 bool need_to_update = false; |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2457 |
5832 | 2458 for (int i = 0; i < nargin; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2459 { |
19438
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
2460 if (args(i).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2461 { |
19438
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
2462 std::string arg = args(i).string_value (); |
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
2463 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2464 std::list<std::string> dir_elts = split_path (arg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2465 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2466 if (! append) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2467 std::reverse (dir_elts.begin (), dir_elts.end ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2468 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2469 for (std::list<std::string>::const_iterator p = dir_elts.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2470 p != dir_elts.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2471 p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2472 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2473 std::string dir = *p; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2474 |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
10982
diff
changeset
|
2475 //dir = regexprep (dir_elts{j}, '//+', "/"); |
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
10982
diff
changeset
|
2476 //dir = regexprep (dir, '/$', ""); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2477 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2478 if (append) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2479 load_path::append (dir, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2480 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2481 load_path::prepend (dir, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2482 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2483 need_to_update = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2484 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2485 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2486 else |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19066
diff
changeset
|
2487 error ("addpath: all arguments must be strings"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2488 } |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2489 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2490 if (need_to_update) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2491 rehash_internal (); |
5832 | 2492 } |
2493 else | |
2494 print_usage (); | |
2495 | |
2496 return retval; | |
2497 } | |
2498 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8704
diff
changeset
|
2499 DEFUN (rmpath, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2500 "-*- texinfo -*-\n\ |
6678 | 2501 @deftypefn {Built-in Function} {} rmpath (@var{dir1}, @dots{})\n\ |
5832 | 2502 Remove @var{dir1}, @dots{} from the current function search path.\n\ |
2503 \n\ | |
10980
1cbfb15892c9
addpath, rmpath: document path arguments
John W. Eaton <jwe@octave.org>
parents:
10971
diff
changeset
|
2504 In addition to accepting individual directory arguments, lists of\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
2505 directory names separated by @code{pathsep} are also accepted. For example:\n\ |
10980
1cbfb15892c9
addpath, rmpath: document path arguments
John W. Eaton <jwe@octave.org>
parents:
10971
diff
changeset
|
2506 \n\ |
1cbfb15892c9
addpath, rmpath: document path arguments
John W. Eaton <jwe@octave.org>
parents:
10971
diff
changeset
|
2507 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2508 rmpath (\"dir1:/dir2:~/dir3\")\n\ |
10980
1cbfb15892c9
addpath, rmpath: document path arguments
John W. Eaton <jwe@octave.org>
parents:
10971
diff
changeset
|
2509 @end example\n\ |
5832 | 2510 @seealso{path, addpath, genpath, pathdef, savepath, pathsep}\n\ |
2511 @end deftypefn") | |
2512 { | |
2513 // Originally by Etienne Grossmann. Heavily modified and translated | |
2514 // to C++ by jwe. | |
2515 | |
2516 octave_value retval; | |
2517 | |
2518 if (nargout > 0) | |
2519 retval = load_path::path (); | |
2520 | |
2521 int nargin = args.length (); | |
2522 | |
2523 if (nargin > 0) | |
2524 { | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2525 bool need_to_update = false; |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2526 |
5832 | 2527 for (int i = 0; i < nargin; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2528 { |
19438
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
2529 if (args(i).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2530 { |
19438
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
2531 std::string arg = args(i).string_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2532 std::list<std::string> dir_elts = split_path (arg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2533 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2534 for (std::list<std::string>::const_iterator p = dir_elts.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2535 p != dir_elts.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2536 p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2537 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2538 std::string dir = *p; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2539 |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
10982
diff
changeset
|
2540 //dir = regexprep (dir_elts{j}, '//+', "/"); |
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
10982
diff
changeset
|
2541 //dir = regexprep (dir, '/$', ""); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2542 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2543 if (! load_path::remove (dir)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2544 warning ("rmpath: %s: not found", dir.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2545 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2546 need_to_update = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2547 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2548 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2549 else |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19066
diff
changeset
|
2550 error ("addpath: all arguments must be strings"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2551 } |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2552 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2553 if (need_to_update) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2554 rehash_internal (); |
5832 | 2555 } |
2556 else | |
2557 print_usage (); | |
2558 | |
2559 return retval; | |
2560 } | |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2561 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2562 DEFUN (__dump_load_path__, , , "") |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2563 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2564 load_path::display (octave_stdout); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2565 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2566 return octave_value_list (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16567
diff
changeset
|
2567 } |