Mercurial > hg > octave-lyh
annotate src/load-path.cc @ 9806:8e345f2fe4d6
improved support for Contents.m files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Nov 2009 15:11:14 -0500 |
parents | 7922a24f78c0 |
children | 645c478aa89d |
rev | line source |
---|---|
5832 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2006, 2007, 2008, 2009 John W. Eaton |
5832 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
5832 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
5832 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <algorithm> | |
28 | |
29 #include "dir-ops.h" | |
30 #include "file-ops.h" | |
31 #include "file-stat.h" | |
32 #include "oct-env.h" | |
33 #include "pathsearch.h" | |
34 | |
35 #include "defaults.h" | |
36 #include "defun.h" | |
37 #include "input.h" | |
38 #include "load-path.h" | |
39 #include "pager.h" | |
40 #include "parse.h" | |
41 #include "toplev.h" | |
42 #include "unwind-prot.h" | |
43 #include "utils.h" | |
44 | |
45 load_path *load_path::instance = 0; | |
7336 | 46 load_path::hook_fcn_ptr load_path::add_hook = execute_pkg_add; |
47 load_path::hook_fcn_ptr load_path::remove_hook = execute_pkg_del; | |
5832 | 48 std::string load_path::command_line_path; |
6630 | 49 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
|
50 load_path::abs_dir_cache_type load_path::abs_dir_cache; |
5832 | 51 |
52 void | |
53 load_path::dir_info::update (void) | |
54 { | |
8330
8303f0e912bc
load-path.cc (load_path::dir_info::update): simplify previous change
John W. Eaton <jwe@octave.org>
parents:
8329
diff
changeset
|
55 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
|
56 |
8303f0e912bc
load-path.cc (load_path::dir_info::update): simplify previous change
John W. Eaton <jwe@octave.org>
parents:
8329
diff
changeset
|
57 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
|
58 { |
8330
8303f0e912bc
load-path.cc (load_path::dir_info::update): simplify previous change
John W. Eaton <jwe@octave.org>
parents:
8329
diff
changeset
|
59 if (is_relative) |
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
|
60 { |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
61 try |
8330
8303f0e912bc
load-path.cc (load_path::dir_info::update): simplify previous change
John W. Eaton <jwe@octave.org>
parents:
8329
diff
changeset
|
62 { |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
63 std::string abs_name |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
64 = octave_env::make_absolute (dir_name, octave_env::getcwd ()); |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
65 |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
66 abs_dir_cache_iterator p = abs_dir_cache.find (abs_name); |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
67 |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
68 if (p != abs_dir_cache.end ()) |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
69 { |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
70 // The directory is in the cache of all directories |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
71 // we have visited (indexed by its absolute name). |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
72 // If it is out of date, initialize it. Otherwise, |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
73 // copy the info from the cache. By doing that, we |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
74 // avoid unnecessary calls to stat that can slow |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
75 // things down tremendously for large directories. |
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
|
76 |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
77 const dir_info& di = p->second; |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
78 |
9748
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
9581
diff
changeset
|
79 if (fs.mtime () + fs.time_resolution () > di.dir_time_last_checked) |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
80 initialize (); |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
81 else |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
82 *this = di; |
9764
7922a24f78c0
fix relative directory caching
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
83 } |
7922a24f78c0
fix relative directory caching
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
84 else |
7922a24f78c0
fix relative directory caching
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
85 { |
7922a24f78c0
fix relative directory caching
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
86 // We haven't seen this directory before. |
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
|
87 |
9764
7922a24f78c0
fix relative directory caching
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
88 initialize (); |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
89 } |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
90 } |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
91 catch (octave_execution_exception) |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
92 { |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
93 // Skip updating if we don't know where we are, but |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
94 // don't treat it as an error. |
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
|
95 |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
96 error_state = 0; |
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
|
97 } |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
98 } |
9764
7922a24f78c0
fix relative directory caching
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
99 else if (fs.mtime () + fs.time_resolution () > dir_time_last_checked) |
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
|
100 initialize (); |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
101 } |
5832 | 102 else |
103 { | |
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 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
|
105 warning ("load_path: %s: %s", dir_name.c_str (), msg.c_str ()); |
5832 | 106 } |
107 } | |
108 | |
109 void | |
110 load_path::dir_info::initialize (void) | |
111 { | |
112 is_relative = ! octave_env::absolute_pathname (dir_name); | |
113 | |
9748
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
9581
diff
changeset
|
114 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
|
115 |
5832 | 116 file_stat fs (dir_name); |
117 | |
118 if (fs) | |
119 { | |
120 dir_mtime = fs.mtime (); | |
9748
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
9581
diff
changeset
|
121 dir_time_last_checked = octave_time (); |
5832 | 122 |
7336 | 123 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
|
124 |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
125 try |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
126 { |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
127 std::string abs_name |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
128 = octave_env::make_absolute (dir_name, octave_env::getcwd ()); |
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
|
129 |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
130 // FIXME -- nothing is ever removed from this cache of |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
131 // directory information, so there could be some resource |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
132 // problems. Perhaps it should be pruned from time to time. |
8331 | 133 |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
134 abs_dir_cache[abs_name] = *this; |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
135 } |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
136 catch (octave_execution_exception) |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
137 { |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
138 // Skip updating if we don't know where we are. |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
139 } |
5832 | 140 } |
141 else | |
142 { | |
143 std::string msg = fs.error (); | |
144 warning ("load_path: %s: %s", dir_name.c_str (), msg.c_str ()); | |
145 } | |
146 } | |
147 | |
7336 | 148 void |
5832 | 149 load_path::dir_info::get_file_list (const std::string& d) |
150 { | |
151 dir_entry dir (d); | |
152 | |
153 if (dir) | |
154 { | |
155 string_vector flist = dir.read (); | |
156 | |
157 octave_idx_type len = flist.length (); | |
158 | |
159 all_files.resize (len); | |
160 fcn_files.resize (len); | |
161 | |
162 octave_idx_type all_files_count = 0; | |
163 octave_idx_type fcn_files_count = 0; | |
164 | |
165 for (octave_idx_type i = 0; i < len; i++) | |
166 { | |
167 std::string fname = flist[i]; | |
168 | |
7272 | 169 std::string full_name = file_ops::concat (d, fname); |
5832 | 170 |
171 file_stat fs (full_name); | |
172 | |
173 if (fs) | |
174 { | |
175 if (fs.is_dir ()) | |
176 { | |
7336 | 177 if (fname == "private") |
178 get_private_file_map (full_name); | |
179 else if (fname[0] == '@') | |
180 get_method_file_map (full_name, fname.substr (1)); | |
5832 | 181 } |
182 else | |
183 { | |
184 all_files[all_files_count++] = fname; | |
185 | |
186 size_t pos = fname.rfind ('.'); | |
187 | |
8021 | 188 if (pos != std::string::npos) |
5832 | 189 { |
190 std::string ext = fname.substr (pos); | |
191 | |
5864 | 192 if (ext == ".m" || ext == ".oct" || ext == ".mex") |
5832 | 193 { |
194 std::string base = fname.substr (0, pos); | |
195 | |
196 if (valid_identifier (base)) | |
197 fcn_files[fcn_files_count++] = fname; | |
198 } | |
199 } | |
200 } | |
201 } | |
202 } | |
203 | |
204 all_files.resize (all_files_count); | |
205 fcn_files.resize (fcn_files_count); | |
206 } | |
207 else | |
208 { | |
209 std::string msg = dir.error (); | |
210 warning ("load_path: %s: %s", d.c_str (), msg.c_str ()); | |
211 } | |
212 } | |
213 | |
7336 | 214 load_path::dir_info::fcn_file_map_type |
215 get_fcn_files (const std::string& d) | |
5832 | 216 { |
7336 | 217 load_path::dir_info::fcn_file_map_type retval; |
218 | |
5832 | 219 dir_entry dir (d); |
220 | |
221 if (dir) | |
222 { | |
223 string_vector flist = dir.read (); | |
224 | |
225 octave_idx_type len = flist.length (); | |
226 | |
227 for (octave_idx_type i = 0; i < len; i++) | |
228 { | |
229 std::string fname = flist[i]; | |
230 | |
231 std::string ext; | |
232 std::string base = fname; | |
233 | |
234 size_t pos = fname.rfind ('.'); | |
235 | |
8021 | 236 if (pos != std::string::npos) |
5832 | 237 { |
238 base = fname.substr (0, pos); | |
239 ext = fname.substr (pos); | |
240 | |
241 if (valid_identifier (base)) | |
242 { | |
243 int t = 0; | |
244 | |
245 if (ext == ".m") | |
246 t = load_path::M_FILE; | |
247 else if (ext == ".oct") | |
248 t = load_path::OCT_FILE; | |
5864 | 249 else if (ext == ".mex") |
250 t = load_path::MEX_FILE; | |
5832 | 251 |
7336 | 252 retval[base] |= t; |
5832 | 253 } |
254 } | |
255 } | |
256 } | |
257 else | |
258 { | |
259 std::string msg = dir.error (); | |
260 warning ("load_path: %s: %s", d.c_str (), msg.c_str ()); | |
261 } | |
7336 | 262 |
263 return retval; | |
264 } | |
265 | |
266 void | |
267 load_path::dir_info::get_private_file_map (const std::string& d) | |
268 { | |
269 private_file_map = get_fcn_files (d); | |
270 } | |
271 | |
272 void | |
273 load_path::dir_info::get_method_file_map (const std::string& d, | |
274 const std::string& class_name) | |
275 { | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
276 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
|
277 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
278 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
|
279 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
280 file_stat fs (pd); |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
281 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
282 if (fs && fs.is_dir ()) |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
283 method_file_map[class_name].private_file_map = get_fcn_files (pd); |
5832 | 284 } |
285 | |
286 bool | |
287 load_path::instance_ok (void) | |
288 { | |
289 bool retval = true; | |
290 | |
291 if (! instance) | |
292 instance = new load_path (); | |
293 | |
294 if (! instance) | |
295 { | |
296 ::error ("unable to create load path object!"); | |
297 | |
298 retval = false; | |
299 } | |
300 | |
301 return retval; | |
302 } | |
303 | |
7336 | 304 // FIXME -- maybe we should also maintain a map to speed up this |
305 // method of access. | |
306 | |
5832 | 307 load_path::const_dir_info_list_iterator |
5919 | 308 load_path::find_dir_info (const std::string& dir_arg) const |
5832 | 309 { |
5919 | 310 std::string dir = file_ops::tilde_expand (dir_arg); |
311 | |
5832 | 312 const_dir_info_list_iterator retval = dir_info_list.begin (); |
313 | |
314 while (retval != dir_info_list.end ()) | |
315 { | |
316 if (retval->dir_name == dir) | |
317 break; | |
318 | |
319 retval++; | |
320 } | |
321 | |
322 return retval; | |
323 } | |
324 | |
325 load_path::dir_info_list_iterator | |
5919 | 326 load_path::find_dir_info (const std::string& dir_arg) |
5832 | 327 { |
5919 | 328 std::string dir = file_ops::tilde_expand (dir_arg); |
329 | |
5832 | 330 dir_info_list_iterator retval = dir_info_list.begin (); |
331 | |
332 while (retval != dir_info_list.end ()) | |
333 { | |
334 if (retval->dir_name == dir) | |
335 break; | |
336 | |
337 retval++; | |
338 } | |
339 | |
340 return retval; | |
341 } | |
342 | |
343 bool | |
344 load_path::contains (const std::string& dir) const | |
345 { | |
346 return find_dir_info (dir) != dir_info_list.end (); | |
347 } | |
348 | |
349 void | |
7336 | 350 load_path::move_fcn_map (const std::string& dir_name, |
351 const string_vector& fcn_files, bool at_end) | |
5832 | 352 { |
7336 | 353 octave_idx_type len = fcn_files.length (); |
354 | |
355 for (octave_idx_type k = 0; k < len; k++) | |
5832 | 356 { |
7336 | 357 std::string fname = fcn_files[k]; |
5832 | 358 |
7336 | 359 std::string ext; |
360 std::string base = fname; | |
361 | |
362 size_t pos = fname.rfind ('.'); | |
5832 | 363 |
8021 | 364 if (pos != std::string::npos) |
7336 | 365 { |
366 base = fname.substr (0, pos); | |
367 ext = fname.substr (pos); | |
368 } | |
5832 | 369 |
7336 | 370 file_info_list_type& file_info_list = fcn_map[base]; |
5832 | 371 |
7336 | 372 if (file_info_list.size () == 1) |
373 continue; | |
374 else | |
5832 | 375 { |
7336 | 376 for (file_info_list_iterator p = file_info_list.begin (); |
377 p != file_info_list.end (); | |
378 p++) | |
379 { | |
380 if (p->dir_name == dir_name) | |
381 { | |
382 file_info fi = *p; | |
5832 | 383 |
7336 | 384 file_info_list.erase (p); |
385 | |
386 if (at_end) | |
387 file_info_list.push_back (fi); | |
388 else | |
389 file_info_list.push_front (fi); | |
5832 | 390 |
7336 | 391 break; |
392 } | |
393 } | |
394 } | |
395 } | |
396 } | |
5832 | 397 |
7336 | 398 void |
399 load_path::move_method_map (const std::string& dir_name, bool at_end) | |
400 { | |
401 for (method_map_iterator i = method_map.begin (); | |
402 i != method_map.end (); | |
403 i++) | |
404 { | |
405 std::string class_name = i->first; | |
5832 | 406 |
7336 | 407 fcn_map_type& fm = i->second; |
408 | |
409 std::string full_dir_name | |
410 = file_ops::concat (dir_name, "@" + class_name); | |
411 | |
412 for (fcn_map_iterator q = fm.begin (); q != fm.end (); q++) | |
413 { | |
414 file_info_list_type& file_info_list = q->second; | |
5832 | 415 |
416 if (file_info_list.size () == 1) | |
417 continue; | |
418 else | |
419 { | |
7336 | 420 for (file_info_list_iterator p = file_info_list.begin (); |
421 p != file_info_list.end (); | |
422 p++) | |
5832 | 423 { |
7336 | 424 if (p->dir_name == full_dir_name) |
5832 | 425 { |
6149 | 426 file_info fi = *p; |
5832 | 427 |
428 file_info_list.erase (p); | |
429 | |
430 if (at_end) | |
431 file_info_list.push_back (fi); | |
432 else | |
433 file_info_list.push_front (fi); | |
434 | |
435 break; | |
436 } | |
437 } | |
438 } | |
439 } | |
440 } | |
441 } | |
442 | |
7336 | 443 void |
444 load_path::move (dir_info_list_iterator i, bool at_end) | |
445 { | |
446 if (dir_info_list.size () > 1) | |
447 { | |
448 dir_info di = *i; | |
449 | |
450 dir_info_list.erase (i); | |
451 | |
452 if (at_end) | |
453 dir_info_list.push_back (di); | |
454 else | |
455 dir_info_list.push_front (di); | |
456 | |
457 std::string dir_name = di.dir_name; | |
458 | |
459 move_fcn_map (dir_name, di.fcn_files, at_end); | |
460 | |
461 // No need to move elements of private function map. | |
462 | |
463 move_method_map (dir_name, at_end); | |
464 } | |
465 } | |
466 | |
5832 | 467 static void |
468 maybe_add_path_elts (std::string& path, const std::string& dir) | |
469 { | |
470 std::string tpath = genpath (dir); | |
471 | |
472 if (! tpath.empty ()) | |
7374 | 473 { |
474 if (path.empty ()) | |
475 path = tpath; | |
476 else | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
477 path += dir_path::path_sep_str () + tpath; |
7374 | 478 } |
5832 | 479 } |
480 | |
481 void | |
6365 | 482 load_path::do_initialize (bool set_initial_path) |
5832 | 483 { |
7374 | 484 sys_path = ""; |
5832 | 485 |
6365 | 486 if (set_initial_path) |
487 { | |
6626 | 488 maybe_add_path_elts (sys_path, Vlocal_ver_oct_file_dir); |
489 maybe_add_path_elts (sys_path, Vlocal_api_oct_file_dir); | |
490 maybe_add_path_elts (sys_path, Vlocal_oct_file_dir); | |
491 maybe_add_path_elts (sys_path, Vlocal_ver_fcn_file_dir); | |
492 maybe_add_path_elts (sys_path, Vlocal_api_fcn_file_dir); | |
493 maybe_add_path_elts (sys_path, Vlocal_fcn_file_dir); | |
494 maybe_add_path_elts (sys_path, Voct_file_dir); | |
495 maybe_add_path_elts (sys_path, Vfcn_file_dir); | |
6365 | 496 } |
5832 | 497 |
498 std::string tpath = load_path::command_line_path; | |
499 | |
500 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
|
501 tpath = octave_env::getenv ("OCTAVE_PATH"); |
5832 | 502 |
503 std::string xpath = "."; | |
504 | |
505 if (! tpath.empty ()) | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
506 xpath += dir_path::path_sep_str () + tpath; |
5832 | 507 |
7374 | 508 if (! sys_path.empty ()) |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
509 xpath += dir_path::path_sep_str () + sys_path; |
5832 | 510 |
6119 | 511 do_set (xpath, false); |
5832 | 512 } |
513 | |
514 void | |
515 load_path::do_clear (void) | |
516 { | |
517 dir_info_list.clear (); | |
518 fcn_map.clear (); | |
7336 | 519 private_fcn_map.clear (); |
520 method_map.clear (); | |
5867 | 521 |
522 do_append (".", false); | |
5832 | 523 } |
524 | |
525 static std::list<std::string> | |
526 split_path (const std::string& p) | |
527 { | |
528 std::list<std::string> retval; | |
529 | |
530 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
|
531 size_t end = p.find (dir_path::path_sep_char ()); |
5832 | 532 |
533 size_t len = p.length (); | |
534 | |
8021 | 535 while (end != std::string::npos) |
5832 | 536 { |
537 std::string elt = p.substr (beg, end-beg); | |
538 | |
539 if (! elt.empty ()) | |
540 retval.push_back (elt); | |
541 | |
542 beg = end + 1; | |
543 | |
544 if (beg == len) | |
545 break; | |
546 | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
547 end = p.find (dir_path::path_sep_char (), beg); |
5832 | 548 } |
549 | |
550 std::string elt = p.substr (beg); | |
551 | |
552 if (! elt.empty ()) | |
553 retval.push_back (elt); | |
554 | |
555 return retval; | |
556 } | |
557 | |
558 void | |
5867 | 559 load_path::do_set (const std::string& p, bool warn) |
5832 | 560 { |
561 std::list<std::string> elts = split_path (p); | |
562 | |
563 // Temporarily disable add hook. | |
564 | |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9282
diff
changeset
|
565 unwind_protect::protect_var (add_hook); |
5832 | 566 |
567 add_hook = 0; | |
568 | |
8511
a835406e02dd
load_path::do_set: call clear after disabling add_hook
John W. Eaton <jwe@octave.org>
parents:
8331
diff
changeset
|
569 do_clear (); |
a835406e02dd
load_path::do_set: call clear after disabling add_hook
John W. Eaton <jwe@octave.org>
parents:
8331
diff
changeset
|
570 |
5832 | 571 for (std::list<std::string>::const_iterator i = elts.begin (); |
572 i != elts.end (); | |
573 i++) | |
5867 | 574 do_append (*i, warn); |
5832 | 575 |
576 // Restore add hook and execute for all newly added directories. | |
577 | |
578 unwind_protect::run (); | |
579 | |
580 for (dir_info_list_iterator i = dir_info_list.begin (); | |
581 i != dir_info_list.end (); | |
582 i++) | |
583 { | |
584 if (add_hook) | |
585 add_hook (i->dir_name); | |
586 } | |
587 } | |
588 | |
589 void | |
5867 | 590 load_path::do_append (const std::string& dir, bool warn) |
5832 | 591 { |
592 if (! dir.empty ()) | |
5867 | 593 do_add (dir, true, warn); |
594 } | |
5832 | 595 |
5867 | 596 void |
597 load_path::do_prepend (const std::string& dir, bool warn) | |
598 { | |
599 if (! dir.empty ()) | |
600 do_add (dir, false, warn); | |
5832 | 601 } |
602 | |
603 void | |
5919 | 604 load_path::do_add (const std::string& dir_arg, bool at_end, bool warn) |
5832 | 605 { |
5919 | 606 size_t len = dir_arg.length (); |
5911 | 607 |
5919 | 608 if (len > 1 && dir_arg.substr (len-2) == "//") |
5911 | 609 warning_with_id ("Octave:recursive-path-search", |
610 "trailing `//' is no longer special in search path elements"); | |
611 | |
5919 | 612 std::string dir = file_ops::tilde_expand (dir_arg); |
613 | |
5867 | 614 dir_info_list_iterator i = find_dir_info (dir); |
615 | |
616 if (i != dir_info_list.end ()) | |
617 move (i, at_end); | |
618 else | |
5832 | 619 { |
5867 | 620 file_stat fs (dir); |
5832 | 621 |
5867 | 622 if (fs) |
5832 | 623 { |
5867 | 624 if (fs.is_dir ()) |
625 { | |
626 dir_info di (dir); | |
5832 | 627 |
5867 | 628 if (! error_state) |
629 { | |
630 if (at_end) | |
631 dir_info_list.push_back (di); | |
632 else | |
633 dir_info_list.push_front (di); | |
634 | |
635 add_to_fcn_map (di, true); | |
5832 | 636 |
7336 | 637 add_to_private_fcn_map (di); |
638 | |
639 add_to_method_map (di, true); | |
640 | |
5867 | 641 if (add_hook) |
642 add_hook (dir); | |
643 } | |
5832 | 644 } |
5867 | 645 else if (warn) |
5919 | 646 warning ("addpath: %s: not a directory", dir_arg.c_str ()); |
5832 | 647 } |
5867 | 648 else if (warn) |
649 { | |
650 std::string msg = fs.error (); | |
5919 | 651 warning ("addpath: %s: %s", dir_arg.c_str (), msg.c_str ()); |
5867 | 652 } |
653 } | |
5832 | 654 |
5867 | 655 // FIXME -- is there a better way to do this? |
5832 | 656 |
5867 | 657 i = find_dir_info ("."); |
5832 | 658 |
5867 | 659 if (i != dir_info_list.end ()) |
5871 | 660 move (i, false); |
5867 | 661 else |
662 panic_impossible (); | |
5832 | 663 } |
664 | |
7336 | 665 void |
666 load_path::remove_fcn_map (const std::string& dir, | |
667 const string_vector& fcn_files) | |
668 { | |
669 octave_idx_type len = fcn_files.length (); | |
670 | |
671 for (octave_idx_type k = 0; k < len; k++) | |
672 { | |
673 std::string fname = fcn_files[k]; | |
674 | |
675 std::string ext; | |
676 std::string base = fname; | |
677 | |
678 size_t pos = fname.rfind ('.'); | |
679 | |
8021 | 680 if (pos != std::string::npos) |
7336 | 681 { |
682 base = fname.substr (0, pos); | |
683 ext = fname.substr (pos); | |
684 } | |
685 | |
686 file_info_list_type& file_info_list = fcn_map[base]; | |
687 | |
688 for (file_info_list_iterator p = file_info_list.begin (); | |
689 p != file_info_list.end (); | |
690 p++) | |
691 { | |
692 if (p->dir_name == dir) | |
693 { | |
694 file_info_list.erase (p); | |
695 | |
696 if (file_info_list.empty ()) | |
697 fcn_map.erase (fname); | |
698 | |
699 break; | |
700 } | |
701 } | |
702 } | |
703 } | |
704 | |
705 void | |
706 load_path::remove_private_fcn_map (const std::string& dir) | |
707 { | |
708 private_fcn_map_iterator p = private_fcn_map.find (dir); | |
709 | |
710 if (p != private_fcn_map.end ()) | |
711 private_fcn_map.erase (p); | |
712 } | |
713 | |
714 void | |
715 load_path::remove_method_map (const std::string& dir) | |
716 { | |
717 for (method_map_iterator i = method_map.begin (); | |
718 i != method_map.end (); | |
719 i++) | |
720 { | |
721 std::string class_name = i->first; | |
722 | |
723 fcn_map_type& fm = i->second; | |
724 | |
725 std::string full_dir_name = file_ops::concat (dir, "@" + class_name); | |
726 | |
727 for (fcn_map_iterator q = fm.begin (); q != fm.end (); q++) | |
728 { | |
729 file_info_list_type& file_info_list = q->second; | |
730 | |
731 if (file_info_list.size () == 1) | |
732 continue; | |
733 else | |
734 { | |
735 for (file_info_list_iterator p = file_info_list.begin (); | |
736 p != file_info_list.end (); | |
737 p++) | |
738 { | |
739 if (p->dir_name == full_dir_name) | |
740 { | |
741 file_info_list.erase (p); | |
742 | |
743 // FIXME -- if there are no other elements, we | |
744 // should remove this element of fm but calling | |
745 // erase here would invalidate the iterator q. | |
746 | |
747 break; | |
748 } | |
749 } | |
750 } | |
751 } | |
752 } | |
753 } | |
754 | |
5832 | 755 bool |
5919 | 756 load_path::do_remove (const std::string& dir_arg) |
5832 | 757 { |
758 bool retval = false; | |
759 | |
5919 | 760 if (! dir_arg.empty ()) |
5832 | 761 { |
5919 | 762 if (dir_arg == ".") |
5867 | 763 { |
764 warning ("rmpath: can't remove \".\" from path"); | |
5832 | 765 |
5867 | 766 // Avoid additional warnings. |
5832 | 767 retval = true; |
5867 | 768 } |
769 else | |
770 { | |
5919 | 771 std::string dir = file_ops::tilde_expand (dir_arg); |
772 | |
5867 | 773 dir_info_list_iterator i = find_dir_info (dir); |
5832 | 774 |
5867 | 775 if (i != dir_info_list.end ()) |
776 { | |
777 retval = true; | |
5832 | 778 |
6825 | 779 if (remove_hook) |
780 remove_hook (dir); | |
781 | |
5867 | 782 string_vector fcn_files = i->fcn_files; |
783 | |
784 dir_info_list.erase (i); | |
5832 | 785 |
7336 | 786 remove_fcn_map (dir, fcn_files); |
5867 | 787 |
7336 | 788 remove_private_fcn_map (dir); |
5832 | 789 |
7336 | 790 remove_method_map (dir); |
5832 | 791 } |
792 } | |
793 } | |
794 | |
795 return retval; | |
796 } | |
797 | |
798 void | |
799 load_path::do_update (void) const | |
800 { | |
801 // I don't see a better way to do this because we need to | |
802 // preserve the correct directory ordering for new files that | |
803 // have appeared. | |
804 | |
805 fcn_map.clear (); | |
806 | |
7336 | 807 private_fcn_map.clear (); |
808 | |
809 method_map.clear (); | |
810 | |
5832 | 811 for (dir_info_list_iterator p = dir_info_list.begin (); |
812 p != dir_info_list.end (); | |
813 p++) | |
814 { | |
815 dir_info& di = *p; | |
816 | |
817 di.update (); | |
818 | |
819 add_to_fcn_map (di, true); | |
7336 | 820 |
821 add_to_private_fcn_map (di); | |
822 | |
823 add_to_method_map (di, true); | |
5832 | 824 } |
825 } | |
826 | |
7336 | 827 bool |
828 load_path::check_file_type (std::string& fname, int type, int possible_types, | |
829 const std::string& fcn, const char *who) | |
830 { | |
831 bool retval = false; | |
832 | |
833 if (type == load_path::OCT_FILE) | |
834 { | |
835 if ((type & possible_types) == load_path::OCT_FILE) | |
836 { | |
837 fname += ".oct"; | |
838 retval = true; | |
839 } | |
840 } | |
841 else if (type == load_path::M_FILE) | |
842 { | |
843 if ((type & possible_types) == load_path::M_FILE) | |
844 { | |
845 fname += ".m"; | |
846 retval = true; | |
847 } | |
848 } | |
849 else if (type == load_path::MEX_FILE) | |
850 { | |
851 if ((type & possible_types) == load_path::MEX_FILE) | |
852 { | |
853 fname += ".mex"; | |
854 retval = true; | |
855 } | |
856 } | |
857 else if (type == (load_path::M_FILE | load_path::OCT_FILE)) | |
858 { | |
859 if (possible_types & load_path::OCT_FILE) | |
860 { | |
861 fname += ".oct"; | |
862 retval = true; | |
863 } | |
864 else if (possible_types & load_path::M_FILE) | |
865 { | |
866 fname += ".m"; | |
867 retval = true; | |
868 } | |
869 } | |
870 else if (type == (load_path::M_FILE | load_path::MEX_FILE)) | |
871 { | |
872 if (possible_types & load_path::MEX_FILE) | |
873 { | |
874 fname += ".mex"; | |
875 retval = true; | |
876 } | |
877 else if (possible_types & load_path::M_FILE) | |
878 { | |
879 fname += ".m"; | |
880 retval = true; | |
881 } | |
882 } | |
883 else if (type == (load_path::OCT_FILE | load_path::MEX_FILE)) | |
884 { | |
885 if (possible_types & load_path::OCT_FILE) | |
886 { | |
887 fname += ".oct"; | |
888 retval = true; | |
889 } | |
890 else if (possible_types & load_path::MEX_FILE) | |
891 { | |
892 fname += ".mex"; | |
893 retval = true; | |
894 } | |
895 } | |
896 else if (type == (load_path::M_FILE | load_path::OCT_FILE | |
897 | load_path::MEX_FILE)) | |
898 { | |
899 if (possible_types & load_path::OCT_FILE) | |
900 { | |
901 fname += ".oct"; | |
902 retval = true; | |
903 } | |
904 else if (possible_types & load_path::MEX_FILE) | |
905 { | |
906 fname += ".mex"; | |
907 retval = true; | |
908 } | |
909 else if (possible_types & load_path::M_FILE) | |
910 { | |
911 fname += ".m"; | |
912 retval = true; | |
913 } | |
914 } | |
915 else | |
916 error ("%s: %s: invalid type code = %d", who, fcn.c_str (), type); | |
917 | |
918 return retval; | |
919 } | |
920 | |
5832 | 921 std::string |
7336 | 922 load_path::do_find_fcn (const std::string& fcn, std::string& dir_name, |
923 int type) const | |
5832 | 924 { |
925 std::string retval; | |
7336 | 926 |
927 // update (); | |
5832 | 928 |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
929 if (fcn.length () > 0 && fcn[0] == '@') |
5832 | 930 { |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
931 size_t pos = fcn.find ('/'); |
5832 | 932 |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
933 if (pos != std::string::npos) |
5832 | 934 { |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
935 std::string class_name = fcn.substr (1, pos-1); |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
936 std::string meth = fcn.substr (pos+1); |
5832 | 937 |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
938 retval = do_find_method (class_name, meth, dir_name); |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
939 } |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
940 else |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
941 retval = std::string (); |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
942 } |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
943 else |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
944 { |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
945 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
|
946 |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
947 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
|
948 |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
949 if (p != fcn_map.end ()) |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
950 { |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
951 const file_info_list_type& file_info_list = p->second; |
5832 | 952 |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
953 for (const_file_info_list_iterator i = file_info_list.begin (); |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
954 i != file_info_list.end (); |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
955 i++) |
5832 | 956 { |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
957 const file_info& fi = *i; |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
958 |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
959 retval = file_ops::concat (fi.dir_name, fcn); |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
960 |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
961 if (check_file_type (retval, type, fi.types, |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
962 fcn, "load_path::do_find_fcn")) |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
963 { |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
964 dir_name = fi.dir_name; |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
965 break; |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
966 } |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
967 else |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
968 retval = std::string (); |
5832 | 969 } |
7336 | 970 } |
971 } | |
972 | |
973 return retval; | |
974 } | |
975 | |
976 std::string | |
977 load_path::do_find_private_fcn (const std::string& dir, | |
978 const std::string& fcn, int type) const | |
979 { | |
980 std::string retval; | |
981 | |
982 // update (); | |
983 | |
984 const_private_fcn_map_iterator q = private_fcn_map.find (dir); | |
985 | |
986 if (q != private_fcn_map.end ()) | |
987 { | |
988 const dir_info::fcn_file_map_type& m = q->second; | |
989 | |
990 dir_info::const_fcn_file_map_iterator p = m.find (fcn); | |
991 | |
992 if (p != m.end ()) | |
993 { | |
994 std::string fname | |
995 = file_ops::concat (file_ops::concat (dir, "private"), fcn); | |
996 | |
997 if (check_file_type (fname, type, p->second, fcn, | |
998 "load_path::find_private_fcn")) | |
999 retval = fname; | |
1000 } | |
1001 } | |
1002 | |
1003 return retval; | |
1004 } | |
1005 | |
1006 std::string | |
1007 load_path::do_find_method (const std::string& class_name, | |
1008 const std::string& meth, | |
1009 std::string& dir_name, int type) const | |
1010 { | |
1011 std::string retval; | |
1012 | |
1013 // update (); | |
1014 | |
1015 dir_name = std::string (); | |
1016 | |
1017 const_method_map_iterator q = method_map.find (class_name); | |
1018 | |
1019 if (q != method_map.end ()) | |
1020 { | |
1021 const fcn_map_type& m = q->second; | |
1022 | |
1023 const_fcn_map_iterator p = m.find (meth); | |
1024 | |
9581
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1025 if (p != m.end ()) |
7336 | 1026 { |
1027 const file_info_list_type& file_info_list = p->second; | |
1028 | |
1029 for (const_file_info_list_iterator i = file_info_list.begin (); | |
1030 i != file_info_list.end (); | |
1031 i++) | |
5864 | 1032 { |
7336 | 1033 const file_info& fi = *i; |
1034 | |
1035 retval = file_ops::concat (fi.dir_name, meth); | |
1036 | |
1037 bool found = check_file_type (retval, type, fi.types, | |
1038 meth, "load_path::do_find_method"); | |
1039 | |
1040 if (found) | |
5864 | 1041 { |
7336 | 1042 dir_name = fi.dir_name; |
5832 | 1043 break; |
1044 } | |
7336 | 1045 else |
1046 retval = std::string (); | |
5864 | 1047 } |
5832 | 1048 } |
1049 } | |
1050 | |
1051 return retval; | |
1052 } | |
1053 | |
7336 | 1054 std::list<std::string> |
1055 load_path::do_methods (const std::string& class_name) const | |
1056 { | |
1057 std::list<std::string> retval; | |
1058 | |
1059 // update (); | |
1060 | |
1061 const_method_map_iterator q = method_map.find (class_name); | |
1062 | |
1063 if (q != method_map.end ()) | |
1064 { | |
1065 const fcn_map_type& m = q->second; | |
1066 | |
1067 for (const_fcn_map_iterator p = m.begin (); p != m.end (); p++) | |
1068 retval.push_back (p->first); | |
1069 } | |
1070 | |
1071 if (! retval.empty ()) | |
1072 retval.sort (); | |
1073 | |
1074 return retval; | |
1075 } | |
1076 | |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1077 bool |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1078 load_path::do_any_class_method (const std::string& meth) const |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1079 { |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1080 bool retval = false; |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1081 |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1082 // update (); |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1083 |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1084 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
|
1085 q != method_map.end (); q++) |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1086 { |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1087 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
|
1088 |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1089 if (m.find (meth) != m.end ()) |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1090 { |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1091 retval = true; |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1092 break; |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1093 } |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1094 } |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1095 |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1096 return retval; |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1097 } |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1098 |
5832 | 1099 std::string |
1100 load_path::do_find_file (const std::string& file) const | |
1101 { | |
1102 std::string retval; | |
1103 | |
8021 | 1104 if (file.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos) |
5832 | 1105 { |
6838 | 1106 if (octave_env::absolute_pathname (file) |
1107 || octave_env::rooted_relative_pathname (file)) | |
1108 { | |
1109 file_stat fs (file); | |
5832 | 1110 |
6838 | 1111 if (fs.exists ()) |
1112 return file; | |
1113 } | |
1114 else | |
1115 { | |
1116 for (const_dir_info_list_iterator p = dir_info_list.begin (); | |
1117 p != dir_info_list.end (); | |
1118 p++) | |
1119 { | |
7272 | 1120 std::string tfile = file_ops::concat (p->dir_name, file); |
5832 | 1121 |
6838 | 1122 file_stat fs (tfile); |
6159 | 1123 |
6838 | 1124 if (fs.exists ()) |
1125 return tfile; | |
5832 | 1126 } |
1127 } | |
1128 } | |
6838 | 1129 else |
1130 { | |
1131 for (const_dir_info_list_iterator p = dir_info_list.begin (); | |
1132 p != dir_info_list.end (); | |
1133 p++) | |
1134 { | |
1135 string_vector all_files = p->all_files; | |
6159 | 1136 |
6838 | 1137 octave_idx_type len = all_files.length (); |
1138 | |
1139 for (octave_idx_type i = 0; i < len; i++) | |
1140 { | |
1141 if (all_files[i] == file) | |
7272 | 1142 return file_ops::concat (p->dir_name, file); |
6838 | 1143 } |
1144 } | |
1145 } | |
5832 | 1146 |
1147 return retval; | |
1148 } | |
1149 | |
1150 std::string | |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1151 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
|
1152 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1153 std::string retval; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1154 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1155 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
|
1156 && (octave_env::absolute_pathname (dir) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1157 || octave_env::rooted_relative_pathname (dir))) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1158 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1159 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
|
1160 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1161 if (fs.exists () && fs.is_dir ()) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1162 return dir; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1163 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1164 else |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1165 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1166 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1167 p != dir_info_list.end (); |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1168 p++) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1169 { |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1170 std::string dname |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1171 = octave_env::make_absolute (p->dir_name, octave_env::getcwd ()); |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1172 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1173 size_t dname_len = dname.length (); |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1174 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1175 if (dname.substr (dname_len - 1) == file_ops::dir_sep_str ()) |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1176 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1177 dname = dname.substr (0, dname_len - 1); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1178 dname_len--; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1179 } |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1180 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1181 size_t dir_len = dir.length (); |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1182 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1183 if (dname_len >= dir_len |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1184 && file_ops::is_dir_sep (dname[dname_len - dir_len - 1]) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1185 && dir.compare (dname.substr (dname_len - dir_len)) == 0) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1186 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1187 file_stat fs (p->dir_name); |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1188 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1189 if (fs.exists () && fs.is_dir ()) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1190 return p->dir_name; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1191 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1192 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1193 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1194 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1195 return retval; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1196 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1197 |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1198 string_vector |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1199 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
|
1200 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1201 std::list<std::string> retlist; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1202 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1203 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
|
1204 && (octave_env::absolute_pathname (dir) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1205 || octave_env::rooted_relative_pathname (dir))) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1206 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1207 file_stat fs (dir); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1208 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1209 if (fs.exists () && fs.is_dir ()) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1210 retlist.push_back (dir); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1211 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1212 else |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1213 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1214 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1215 p != dir_info_list.end (); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1216 p++) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1217 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1218 std::string dname |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1219 = octave_env::make_absolute (p->dir_name, octave_env::getcwd ()); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1220 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1221 size_t dname_len = dname.length (); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1222 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1223 if (dname.substr (dname_len - 1) == file_ops::dir_sep_str ()) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1224 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1225 dname = dname.substr (0, dname_len - 1); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1226 dname_len--; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1227 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1228 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1229 size_t dir_len = dir.length (); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1230 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1231 if (dname_len >= dir_len |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1232 && file_ops::is_dir_sep (dname[dname_len - dir_len - 1]) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1233 && dir.compare (dname.substr (dname_len - dir_len)) == 0) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1234 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1235 file_stat fs (p->dir_name); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1236 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1237 if (fs.exists () && fs.is_dir ()) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1238 retlist.push_back (p->dir_name); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1239 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1240 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1241 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1242 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1243 return retlist; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1244 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1245 |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1246 std::string |
5832 | 1247 load_path::do_find_first_of (const string_vector& flist) const |
1248 { | |
1249 std::string retval; | |
1250 | |
1251 std::string dir_name; | |
1252 std::string file_name; | |
1253 | |
1254 octave_idx_type flen = flist.length (); | |
1255 octave_idx_type rel_flen = 0; | |
1256 | |
1257 string_vector rel_flist (flen); | |
1258 | |
1259 for (octave_idx_type i = 0; i < flen; i++) | |
1260 { | |
1261 if (octave_env::absolute_pathname (flist[i])) | |
1262 { | |
1263 file_stat fs (flist[i]); | |
1264 | |
1265 if (fs.exists ()) | |
1266 return flist[i]; | |
1267 } | |
1268 else | |
1269 rel_flist[rel_flen++] = flist[i]; | |
1270 } | |
1271 | |
1272 rel_flist.resize (rel_flen); | |
1273 | |
1274 for (const_dir_info_list_iterator p = dir_info_list.begin (); | |
1275 p != dir_info_list.end (); | |
1276 p++) | |
1277 { | |
1278 string_vector all_files = p->all_files; | |
1279 | |
1280 octave_idx_type len = all_files.length (); | |
1281 | |
1282 for (octave_idx_type i = 0; i < len; i++) | |
1283 { | |
1284 for (octave_idx_type j = 0; j < rel_flen; j++) | |
1285 { | |
1286 if (all_files[i] == rel_flist[j]) | |
1287 { | |
1288 dir_name = p->dir_name; | |
1289 file_name = rel_flist[j]; | |
6159 | 1290 |
1291 goto done; | |
5832 | 1292 } |
1293 } | |
1294 } | |
1295 } | |
1296 | |
6159 | 1297 done: |
1298 | |
5832 | 1299 if (! dir_name.empty ()) |
7272 | 1300 retval = file_ops::concat (dir_name, file_name); |
5832 | 1301 |
1302 return retval; | |
1303 } | |
1304 | |
1305 string_vector | |
1306 load_path::do_find_all_first_of (const string_vector& flist) const | |
1307 { | |
1308 std::list<std::string> retlist; | |
1309 | |
1310 std::string dir_name; | |
1311 std::string file_name; | |
1312 | |
1313 octave_idx_type flen = flist.length (); | |
1314 octave_idx_type rel_flen = 0; | |
1315 | |
1316 string_vector rel_flist (flen); | |
1317 | |
1318 for (octave_idx_type i = 0; i < flen; i++) | |
1319 { | |
1320 if (octave_env::absolute_pathname (flist[i])) | |
1321 { | |
1322 file_stat fs (flist[i]); | |
1323 | |
1324 if (fs.exists ()) | |
1325 retlist.push_back (flist[i]); | |
1326 } | |
1327 else | |
1328 rel_flist[rel_flen++] = flist[i]; | |
1329 } | |
1330 | |
1331 rel_flist.resize (rel_flen); | |
1332 | |
1333 for (const_dir_info_list_iterator p = dir_info_list.begin (); | |
1334 p != dir_info_list.end (); | |
1335 p++) | |
1336 { | |
1337 string_vector all_files = p->all_files; | |
1338 | |
1339 octave_idx_type len = all_files.length (); | |
1340 | |
1341 for (octave_idx_type i = 0; i < len; i++) | |
1342 { | |
1343 for (octave_idx_type j = 0; j < rel_flen; j++) | |
1344 { | |
1345 if (all_files[i] == rel_flist[j]) | |
1346 retlist.push_back | |
7272 | 1347 (file_ops::concat (p->dir_name, rel_flist[j])); |
5832 | 1348 } |
1349 } | |
1350 } | |
1351 | |
1352 size_t retsize = retlist.size (); | |
1353 | |
1354 string_vector retval (retsize); | |
1355 | |
1356 for (size_t i = 0; i < retsize; i++) | |
1357 { | |
1358 retval[i] = retlist.front (); | |
1359 | |
1360 retlist.pop_front (); | |
1361 } | |
1362 | |
1363 return retval; | |
1364 } | |
1365 | |
1366 string_vector | |
1367 load_path::do_dirs (void) const | |
1368 { | |
1369 size_t len = dir_info_list.size (); | |
1370 | |
1371 string_vector retval (len); | |
1372 | |
1373 octave_idx_type k = 0; | |
1374 | |
1375 for (const_dir_info_list_iterator i = dir_info_list.begin (); | |
1376 i != dir_info_list.end (); | |
1377 i++) | |
1378 retval[k++] = i->dir_name; | |
1379 | |
1380 return retval; | |
1381 } | |
1382 | |
1383 std::list<std::string> | |
1384 load_path::do_dir_list (void) const | |
1385 { | |
1386 std::list<std::string> retval; | |
1387 | |
1388 for (const_dir_info_list_iterator i = dir_info_list.begin (); | |
1389 i != dir_info_list.end (); | |
1390 i++) | |
1391 retval.push_back (i->dir_name); | |
1392 | |
1393 return retval; | |
1394 } | |
1395 | |
1396 string_vector | |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1397 load_path::do_files (const std::string& dir, bool omit_exts) const |
5832 | 1398 { |
1399 string_vector retval; | |
1400 | |
9282
2ed8d2d92507
load_path::do_files: avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
9261
diff
changeset
|
1401 const_dir_info_list_iterator p = find_dir_info (dir); |
5832 | 1402 |
9282
2ed8d2d92507
load_path::do_files: avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
9261
diff
changeset
|
1403 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
|
1404 retval = p->fcn_files; |
5832 | 1405 |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1406 if (omit_exts) |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1407 { |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1408 octave_idx_type len = retval.length (); |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1409 |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1410 for (octave_idx_type i = 0; i < len; i++) |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1411 { |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1412 std::string fname = retval[i]; |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1413 |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1414 size_t pos = fname.rfind ('.'); |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1415 |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1416 if (pos != std::string::npos) |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1417 retval[i] = fname.substr (0, pos); |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1418 } |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1419 } |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1420 |
5832 | 1421 return retval; |
1422 } | |
1423 | |
1424 string_vector | |
1425 load_path::do_fcn_names (void) const | |
1426 { | |
1427 size_t len = fcn_map.size (); | |
1428 | |
1429 string_vector retval (len); | |
1430 | |
1431 octave_idx_type count = 0; | |
1432 | |
1433 for (const_fcn_map_iterator p = fcn_map.begin (); | |
1434 p != fcn_map.end (); | |
1435 p++) | |
1436 retval[count++] = p->first; | |
1437 | |
1438 return retval; | |
1439 } | |
1440 | |
1441 std::string | |
1442 load_path::do_path (void) const | |
1443 { | |
1444 std::string xpath; | |
1445 | |
1446 string_vector xdirs = load_path::dirs (); | |
1447 | |
1448 octave_idx_type len = xdirs.length (); | |
1449 | |
1450 if (len > 0) | |
1451 xpath = xdirs[0]; | |
1452 | |
1453 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
|
1454 xpath += dir_path::path_sep_str () + xdirs[i]; |
5832 | 1455 |
1456 return xpath; | |
1457 } | |
1458 | |
1459 void | |
7336 | 1460 print_types (std::ostream& os, int types) |
1461 { | |
1462 bool printed_type = false; | |
1463 | |
1464 if (types & load_path::OCT_FILE) | |
1465 { | |
1466 os << "oct"; | |
1467 printed_type = true; | |
1468 } | |
1469 | |
1470 if (types & load_path::MEX_FILE) | |
1471 { | |
1472 if (printed_type) | |
1473 os << "|"; | |
1474 os << "mex"; | |
1475 printed_type = true; | |
1476 } | |
1477 | |
1478 if (types & load_path::M_FILE) | |
1479 { | |
1480 if (printed_type) | |
1481 os << "|"; | |
1482 os << "m"; | |
1483 printed_type = true; | |
1484 } | |
1485 } | |
1486 | |
1487 void | |
1488 print_fcn_list (std::ostream& os, | |
1489 const load_path::dir_info::fcn_file_map_type& lst) | |
1490 { | |
1491 for (load_path::dir_info::const_fcn_file_map_iterator p = lst.begin (); | |
1492 p != lst.end (); | |
1493 p++) | |
1494 { | |
1495 os << " " << p->first << " ("; | |
1496 | |
1497 print_types (os, p->second); | |
1498 | |
1499 os << ")\n"; | |
1500 } | |
1501 } | |
1502 | |
1503 string_vector | |
1504 get_file_list (const load_path::dir_info::fcn_file_map_type& lst) | |
1505 { | |
1506 octave_idx_type n = lst.size (); | |
1507 | |
1508 string_vector retval (n); | |
1509 | |
1510 octave_idx_type count = 0; | |
1511 | |
1512 for (load_path::dir_info::const_fcn_file_map_iterator p = lst.begin (); | |
1513 p != lst.end (); | |
1514 p++) | |
1515 { | |
1516 std::string nm = p->first; | |
1517 | |
1518 int types = p->second; | |
1519 | |
1520 if (types & load_path::OCT_FILE) | |
1521 nm += ".oct"; | |
1522 else if (types & load_path::MEX_FILE) | |
1523 nm += ".mex"; | |
1524 else | |
1525 nm += ".m"; | |
1526 | |
1527 retval[count++] = nm; | |
1528 } | |
1529 | |
1530 return retval; | |
1531 } | |
1532 | |
1533 void | |
5832 | 1534 load_path::do_display (std::ostream& os) const |
1535 { | |
1536 for (const_dir_info_list_iterator i = dir_info_list.begin (); | |
1537 i != dir_info_list.end (); | |
1538 i++) | |
1539 { | |
1540 string_vector fcn_files = i->fcn_files; | |
1541 | |
1542 if (! fcn_files.empty ()) | |
1543 { | |
1544 os << "\n*** function files in " << i->dir_name << ":\n\n"; | |
1545 | |
1546 fcn_files.list_in_columns (os); | |
1547 } | |
1548 | |
7336 | 1549 const dir_info::method_file_map_type& method_file_map |
1550 = i->method_file_map; | |
5832 | 1551 |
7336 | 1552 if (! method_file_map.empty ()) |
5832 | 1553 { |
7336 | 1554 for (dir_info::const_method_file_map_iterator p = method_file_map.begin (); |
1555 p != method_file_map.end (); | |
5832 | 1556 p++) |
1557 { | |
7336 | 1558 os << "\n*** methods in " << i->dir_name |
1559 << "/@" << p->first << ":\n\n"; | |
5832 | 1560 |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1561 const dir_info::class_info& ci = p->second; |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1562 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1563 string_vector method_files = get_file_list (ci.method_file_map); |
5832 | 1564 |
7336 | 1565 method_files.list_in_columns (os); |
1566 } | |
1567 } | |
1568 } | |
5864 | 1569 |
7336 | 1570 for (const_private_fcn_map_iterator i = private_fcn_map.begin (); |
1571 i != private_fcn_map.end (); i++) | |
1572 { | |
1573 os << "\n*** private functions in " | |
1574 << file_ops::concat (i->first, "private") << ":\n\n"; | |
5832 | 1575 |
7336 | 1576 print_fcn_list (os, i->second); |
5832 | 1577 } |
1578 | |
1579 #if defined (DEBUG_LOAD_PATH) | |
1580 | |
1581 for (const_fcn_map_iterator i = fcn_map.begin (); | |
1582 i != fcn_map.end (); | |
1583 i++) | |
1584 { | |
1585 os << i->first << ":\n"; | |
1586 | |
7336 | 1587 const file_info_list_type& file_info_list = i->second; |
5832 | 1588 |
1589 for (const_file_info_list_iterator p = file_info_list.begin (); | |
1590 p != file_info_list.end (); | |
1591 p++) | |
1592 { | |
1593 os << " " << p->dir_name << " ("; | |
1594 | |
7336 | 1595 print_types (os, p->types); |
5832 | 1596 |
1597 os << ")\n"; | |
1598 } | |
1599 } | |
1600 | |
7336 | 1601 for (const_method_map_iterator i = method_map.begin (); |
1602 i != method_map.end (); | |
1603 i++) | |
1604 { | |
1605 os << "CLASS " << i->first << ":\n"; | |
1606 | |
1607 const fcn_map_type& fm = i->second; | |
1608 | |
1609 for (const_fcn_map_iterator q = fm.begin (); | |
1610 q != fm.end (); | |
1611 q++) | |
1612 { | |
1613 os << " " << q->first << ":\n"; | |
1614 | |
1615 const file_info_list_type& file_info_list = q->second; | |
1616 | |
1617 for (const_file_info_list_iterator p = file_info_list.begin (); | |
1618 p != file_info_list.end (); | |
1619 p++) | |
1620 { | |
1621 os << " " << p->dir_name << " ("; | |
1622 | |
1623 print_types (os, p->types); | |
1624 | |
1625 os << ")\n"; | |
1626 } | |
1627 } | |
1628 } | |
1629 | |
5832 | 1630 os << "\n"; |
1631 | |
1632 #endif | |
1633 } | |
1634 | |
1635 void | |
1636 load_path::add_to_fcn_map (const dir_info& di, bool at_end) const | |
1637 { | |
1638 std::string dir_name = di.dir_name; | |
1639 | |
1640 string_vector fcn_files = di.fcn_files; | |
1641 | |
1642 octave_idx_type len = fcn_files.length (); | |
1643 | |
1644 for (octave_idx_type i = 0; i < len; i++) | |
1645 { | |
1646 std::string fname = fcn_files[i]; | |
1647 | |
1648 std::string ext; | |
1649 std::string base = fname; | |
1650 | |
1651 size_t pos = fname.rfind ('.'); | |
1652 | |
8021 | 1653 if (pos != std::string::npos) |
5832 | 1654 { |
1655 base = fname.substr (0, pos); | |
1656 ext = fname.substr (pos); | |
1657 } | |
1658 | |
7336 | 1659 file_info_list_type& file_info_list = fcn_map[base]; |
5832 | 1660 |
1661 file_info_list_iterator p = file_info_list.begin (); | |
1662 | |
1663 while (p != file_info_list.end ()) | |
1664 { | |
1665 if (p->dir_name == dir_name) | |
1666 break; | |
1667 | |
1668 p++; | |
1669 } | |
1670 | |
1671 int t = 0; | |
1672 if (ext == ".m") | |
1673 t = load_path::M_FILE; | |
1674 else if (ext == ".oct") | |
1675 t = load_path::OCT_FILE; | |
5864 | 1676 else if (ext == ".mex") |
1677 t = load_path::MEX_FILE; | |
5832 | 1678 |
1679 if (p == file_info_list.end ()) | |
1680 { | |
1681 file_info fi (dir_name, t); | |
1682 | |
1683 if (at_end) | |
1684 file_info_list.push_back (fi); | |
1685 else | |
1686 file_info_list.push_front (fi); | |
1687 } | |
1688 else | |
1689 { | |
1690 file_info& fi = *p; | |
1691 | |
1692 fi.types |= t; | |
1693 } | |
1694 } | |
1695 } | |
1696 | |
7336 | 1697 void |
1698 load_path::add_to_private_fcn_map (const dir_info& di) const | |
1699 { | |
1700 dir_info::fcn_file_map_type private_file_map = di.private_file_map; | |
1701 | |
1702 if (! private_file_map.empty ()) | |
1703 private_fcn_map[di.dir_name] = private_file_map; | |
1704 } | |
1705 | |
1706 void | |
1707 load_path::add_to_method_map (const dir_info& di, bool at_end) const | |
1708 { | |
1709 std::string dir_name = di.dir_name; | |
1710 | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1711 // <CLASS_NAME, CLASS_INFO> |
7336 | 1712 dir_info::method_file_map_type method_file_map = di.method_file_map; |
1713 | |
1714 for (dir_info::const_method_file_map_iterator q = method_file_map.begin (); | |
1715 q != method_file_map.end (); | |
1716 q++) | |
1717 { | |
1718 std::string class_name = q->first; | |
1719 | |
1720 fcn_map_type& fm = method_map[class_name]; | |
1721 | |
1722 std::string full_dir_name | |
1723 = file_ops::concat (dir_name, "@" + class_name); | |
1724 | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1725 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
|
1726 |
7336 | 1727 // <FCN_NAME, TYPES> |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1728 const dir_info::fcn_file_map_type& m = ci.method_file_map; |
7336 | 1729 |
1730 for (dir_info::const_fcn_file_map_iterator p = m.begin (); | |
1731 p != m.end (); | |
1732 p++) | |
1733 { | |
1734 std::string base = p->first; | |
1735 | |
1736 int types = p->second; | |
1737 | |
1738 file_info_list_type& file_info_list = fm[base]; | |
1739 | |
1740 file_info_list_iterator p2 = file_info_list.begin (); | |
1741 | |
1742 while (p2 != file_info_list.end ()) | |
1743 { | |
1744 if (p2->dir_name == full_dir_name) | |
1745 break; | |
1746 | |
1747 p2++; | |
1748 } | |
1749 | |
1750 if (p2 == file_info_list.end ()) | |
1751 { | |
1752 file_info fi (full_dir_name, types); | |
1753 | |
1754 if (at_end) | |
1755 file_info_list.push_back (fi); | |
1756 else | |
1757 file_info_list.push_front (fi); | |
1758 } | |
1759 else | |
1760 { | |
1761 // FIXME -- is this possible? | |
1762 | |
1763 file_info& fi = *p2; | |
1764 | |
1765 fi.types = types; | |
1766 } | |
1767 } | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1768 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1769 // <FCN_NAME, TYPES> |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1770 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
|
1771 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1772 if (! private_file_map.empty ()) |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1773 private_fcn_map[full_dir_name] = private_file_map; |
7336 | 1774 } |
1775 } | |
1776 | |
5832 | 1777 std::string |
1778 genpath (const std::string& dirname, const string_vector& skip) | |
1779 { | |
1780 std::string retval; | |
1781 | |
5871 | 1782 dir_entry dir (dirname); |
5832 | 1783 |
1784 if (dir) | |
1785 { | |
1786 retval = dirname; | |
1787 | |
1788 string_vector dirlist = dir.read (); | |
1789 | |
1790 octave_idx_type len = dirlist.length (); | |
1791 | |
1792 for (octave_idx_type i = 0; i < len; i++) | |
1793 { | |
1794 std::string elt = dirlist[i]; | |
1795 | |
1796 // FIXME -- the caller should be able to specify the list of | |
7336 | 1797 // directories to skip in addition to ".", "..", and |
1798 // directories beginning with "@". | |
5832 | 1799 |
7336 | 1800 bool skip_p = (elt == "." || elt == ".." || elt[0] == '@'); |
5832 | 1801 |
1802 if (! skip_p) | |
1803 { | |
1804 for (octave_idx_type j = 0; j < skip.length (); j++) | |
1805 { | |
1806 skip_p = (elt == skip[j]); | |
1807 if (skip_p) | |
1808 break; | |
1809 } | |
1810 | |
1811 if (! skip_p) | |
1812 { | |
7272 | 1813 std::string nm = file_ops::concat (dirname, elt); |
5832 | 1814 |
1815 file_stat fs (nm); | |
1816 | |
1817 if (fs && fs.is_dir ()) | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
1818 retval += dir_path::path_sep_str () + genpath (nm); |
5832 | 1819 } |
1820 } | |
1821 } | |
1822 } | |
1823 | |
1824 return retval; | |
1825 } | |
1826 | |
1827 static void | |
1828 execute_pkg_add_or_del (const std::string& dir, | |
1829 const std::string& script_file) | |
1830 { | |
1831 if (! octave_interpreter_ready) | |
1832 return; | |
1833 | |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9282
diff
changeset
|
1834 unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); |
5832 | 1835 |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9282
diff
changeset
|
1836 unwind_protect::protect_var (input_from_startup_file); |
5832 | 1837 |
1838 input_from_startup_file = true; | |
1839 | |
7272 | 1840 std::string file = file_ops::concat (dir, script_file); |
5832 | 1841 |
5978 | 1842 file_stat fs (file); |
5832 | 1843 |
1844 if (fs.exists ()) | |
5975 | 1845 source_file (file, "base"); |
5832 | 1846 |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9282
diff
changeset
|
1847 unwind_protect::run_frame (uwp_frame); |
5832 | 1848 } |
1849 | |
1850 void | |
1851 execute_pkg_add (const std::string& dir) | |
1852 { | |
1853 execute_pkg_add_or_del (dir, "PKG_ADD"); | |
1854 } | |
1855 | |
1856 void | |
1857 execute_pkg_del (const std::string& dir) | |
1858 { | |
1859 execute_pkg_add_or_del (dir, "PKG_DEL"); | |
1860 } | |
1861 | |
1862 DEFUN (genpath, args, , | |
1863 "-*- texinfo -*-\n\ | |
1864 @deftypefn {Built-in Function} {} genpath (@var{dir})\n\ | |
8325
b93ac0586e4b
spelling corrections
Brian Gough<bjg@network-theory.co.uk>
parents:
8141
diff
changeset
|
1865 Return a path constructed from @var{dir} and all its subdirectories.\n\ |
5832 | 1866 @end deftypefn") |
1867 { | |
1868 octave_value retval; | |
1869 | |
1870 if (args.length () == 1) | |
1871 { | |
1872 std::string dirname = args(0).string_value (); | |
1873 | |
1874 if (! error_state) | |
1875 retval = genpath (dirname); | |
1876 else | |
1877 error ("genpath: expecting argument to be a character string"); | |
1878 } | |
1879 else | |
1880 print_usage (); | |
1881 | |
1882 return retval; | |
1883 } | |
1884 | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1885 static void |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1886 rehash_internal (void) |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1887 { |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1888 load_path::update (); |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1889 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1890 // FIXME -- maybe we should rename this variable since it is being |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1891 // 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
|
1892 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1893 // 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
|
1894 Vlast_prompt_time.stamp (); |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1895 } |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1896 |
5832 | 1897 DEFUN (rehash, , , |
1898 "-*- texinfo -*-\n\ | |
1899 @deftypefn {Built-in Function} {} rehash ()\n\ | |
6644 | 1900 Reinitialize Octave's load path directory cache.\n\ |
5832 | 1901 @end deftypefn") |
1902 { | |
1903 octave_value_list retval; | |
1904 | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1905 rehash_internal (); |
5832 | 1906 |
1907 return retval; | |
1908 } | |
1909 | |
8609
fcf762ba66cf
load-path.cc (Fcommand_line_path): rename from Fcommandlinepath
John W. Eaton <jwe@octave.org>
parents:
8593
diff
changeset
|
1910 DEFUN (command_line_path, , , |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1911 "-*- texinfo -*-\n\ |
8609
fcf762ba66cf
load-path.cc (Fcommand_line_path): rename from Fcommandlinepath
John W. Eaton <jwe@octave.org>
parents:
8593
diff
changeset
|
1912 @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
|
1913 Return the command line path variable.\n\ |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1914 \n\ |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1915 @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
|
1916 @end deftypefn") |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1917 { |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1918 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
|
1919 } |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1920 |
7391 | 1921 DEFUN (restoredefaultpath, , , |
1922 "-*- texinfo -*-\n\ | |
1923 @deftypefn {Built-in Function} {} restoredefaultpath (@dots{})\n\ | |
1924 Restore Octave's path to it's initial state at startup.\n\ | |
1925 \n\ | |
1926 @seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ | |
1927 @end deftypefn") | |
1928 { | |
1929 load_path::initialize (true); | |
1930 | |
1931 return octave_value (load_path::system_path ()); | |
1932 } | |
1933 | |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
1934 // 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
|
1935 // 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
|
1936 // 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
|
1937 // ~/.octaverc file |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
1938 |
7391 | 1939 DEFUN (__pathorig__, , , |
5832 | 1940 "-*- texinfo -*-\n\ |
7391 | 1941 @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
|
1942 Undocumented internal function.\n\ |
5832 | 1943 @end deftypefn") |
1944 { | |
6630 | 1945 return octave_value (load_path::system_path ()); |
5832 | 1946 } |
1947 | |
1948 DEFUN (path, args, nargout, | |
1949 "-*- texinfo -*-\n\ | |
6678 | 1950 @deftypefn {Built-in Function} {} path (@dots{})\n\ |
6644 | 1951 Modify or display Octave's load path.\n\ |
5832 | 1952 \n\ |
1953 If @var{nargin} and @var{nargout} are zero, display the elements of\n\ | |
6644 | 1954 Octave's load path in an easy to read format.\n\ |
5832 | 1955 \n\ |
1956 If @var{nargin} is zero and nargout is greater than zero, return the\n\ | |
6644 | 1957 current load path.\n\ |
5832 | 1958 \n\ |
1959 If @var{nargin} is greater than zero, concatenate the arguments,\n\ | |
1960 separating them with @code{pathsep()}. Set the internal search path\n\ | |
1961 to the result and return it.\n\ | |
1962 \n\ | |
1963 No checks are made for duplicate elements.\n\ | |
1964 @seealso{addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ | |
1965 @end deftypefn") | |
1966 { | |
1967 octave_value retval; | |
1968 | |
1969 int argc = args.length () + 1; | |
1970 | |
1971 string_vector argv = args.make_argv ("path"); | |
1972 | |
1973 if (! error_state) | |
1974 { | |
1975 if (argc > 1) | |
1976 { | |
1977 std::string path = argv[1]; | |
1978 | |
1979 for (int i = 2; i < argc; i++) | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
1980 path += dir_path::path_sep_str () + argv[i]; |
5832 | 1981 |
5867 | 1982 load_path::set (path, true); |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1983 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1984 rehash_internal (); |
5832 | 1985 } |
1986 | |
1987 if (nargout > 0) | |
1988 retval = load_path::path (); | |
1989 else if (argc == 1 && nargout == 0) | |
1990 { | |
1991 octave_stdout << "\nOctave's search path contains the following directories:\n\n"; | |
1992 | |
1993 string_vector dirs = load_path::dirs (); | |
1994 | |
1995 dirs.list_in_columns (octave_stdout); | |
1996 | |
1997 octave_stdout << "\n"; | |
1998 } | |
1999 } | |
2000 | |
2001 return retval; | |
2002 } | |
2003 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8704
diff
changeset
|
2004 DEFUN (addpath, args, nargout, |
5832 | 2005 "-*- texinfo -*-\n\ |
6678 | 2006 @deftypefn {Built-in Function} {} addpath (@var{dir1}, @dots{})\n\ |
2007 @deftypefnx {Built-in Function} {} addpath (@var{dir1}, @dots{}, @var{option})\n\ | |
5832 | 2008 Add @var{dir1}, @dots{} to the current function search path. If\n\ |
2009 @var{option} is @samp{\"-begin\"} or 0 (the default), prepend the\n\ | |
2010 directory name to the current path. If @var{option} is @samp{\"-end\"}\n\ | |
2011 or 1, append the directory name to the current path.\n\ | |
2012 Directories added to the path must exist.\n\ | |
2013 @seealso{path, rmpath, genpath, pathdef, savepath, pathsep}\n\ | |
2014 @end deftypefn") | |
2015 { | |
2016 octave_value retval; | |
2017 | |
2018 // Originally written by Bill Denney and Etienne Grossman. Heavily | |
2019 // modified and translated to C++ by jwe. | |
2020 | |
2021 if (nargout > 0) | |
2022 retval = load_path::path (); | |
2023 | |
2024 int nargin = args.length (); | |
2025 | |
2026 if (nargin > 0) | |
2027 { | |
2028 bool append = false; | |
2029 | |
2030 octave_value option_arg = args(nargin-1); | |
2031 | |
2032 if (option_arg.is_string ()) | |
2033 { | |
2034 std::string option = option_arg.string_value (); | |
2035 | |
2036 if (option == "-end") | |
2037 { | |
2038 append = true; | |
2039 nargin--; | |
2040 } | |
2041 else if (option == "-begin") | |
2042 nargin--; | |
2043 } | |
2044 else if (option_arg.is_numeric_type ()) | |
2045 { | |
2046 int val = option_arg.int_value (); | |
2047 | |
2048 if (! error_state) | |
2049 { | |
2050 if (val == 0) | |
2051 append = false; | |
2052 else if (val == 1) | |
2053 append = true; | |
2054 else | |
2055 { | |
2056 error ("addpath: expecting final argument to be 1 or 0"); | |
2057 return retval; | |
2058 } | |
2059 } | |
2060 else | |
2061 { | |
2062 error ("addpath: expecting final argument to be 1 or 0"); | |
2063 return retval; | |
2064 } | |
2065 } | |
2066 | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2067 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
|
2068 |
5832 | 2069 for (int i = 0; i < nargin; i++) |
2070 { | |
2071 std::string arg = args(i).string_value (); | |
2072 | |
2073 if (! error_state) | |
2074 { | |
2075 std::list<std::string> dir_elts = split_path (arg); | |
2076 | |
9401
6c421f2355b5
load-path.cc (Faddpath): preserve order of prepended elements
John W. Eaton <jwe@octave.org>
parents:
9377
diff
changeset
|
2077 if (! append) |
6c421f2355b5
load-path.cc (Faddpath): preserve order of prepended elements
John W. Eaton <jwe@octave.org>
parents:
9377
diff
changeset
|
2078 std::reverse (dir_elts.begin (), dir_elts.end ()); |
6c421f2355b5
load-path.cc (Faddpath): preserve order of prepended elements
John W. Eaton <jwe@octave.org>
parents:
9377
diff
changeset
|
2079 |
5832 | 2080 for (std::list<std::string>::const_iterator p = dir_elts.begin (); |
2081 p != dir_elts.end (); | |
2082 p++) | |
2083 { | |
2084 std::string dir = *p; | |
2085 | |
2086 //dir = regexprep (dir_elts{j}, "//+", "/"); | |
2087 //dir = regexprep (dir, "/$", ""); | |
2088 | |
5867 | 2089 if (append) |
2090 load_path::append (dir, true); | |
5832 | 2091 else |
5867 | 2092 load_path::prepend (dir, true); |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2093 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2094 need_to_update = true; |
5832 | 2095 } |
2096 } | |
2097 else | |
2098 error ("addpath: expecting all args to be character strings"); | |
2099 } | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2100 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2101 if (need_to_update) |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2102 rehash_internal (); |
5832 | 2103 } |
2104 else | |
2105 print_usage (); | |
2106 | |
2107 return retval; | |
2108 } | |
2109 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8704
diff
changeset
|
2110 DEFUN (rmpath, args, nargout, |
5832 | 2111 "-*- texinfo -*-\n\ |
6678 | 2112 @deftypefn {Built-in Function} {} rmpath (@var{dir1}, @dots{})\n\ |
5832 | 2113 Remove @var{dir1}, @dots{} from the current function search path.\n\ |
2114 \n\ | |
2115 @seealso{path, addpath, genpath, pathdef, savepath, pathsep}\n\ | |
2116 @end deftypefn") | |
2117 { | |
2118 // Originally by Etienne Grossmann. Heavily modified and translated | |
2119 // to C++ by jwe. | |
2120 | |
2121 octave_value retval; | |
2122 | |
2123 if (nargout > 0) | |
2124 retval = load_path::path (); | |
2125 | |
2126 int nargin = args.length (); | |
2127 | |
2128 if (nargin > 0) | |
2129 { | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2130 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
|
2131 |
5832 | 2132 for (int i = 0; i < nargin; i++) |
2133 { | |
2134 std::string arg = args(i).string_value (); | |
2135 | |
2136 if (! error_state) | |
2137 { | |
2138 std::list<std::string> dir_elts = split_path (arg); | |
2139 | |
2140 for (std::list<std::string>::const_iterator p = dir_elts.begin (); | |
2141 p != dir_elts.end (); | |
2142 p++) | |
2143 { | |
2144 std::string dir = *p; | |
2145 | |
2146 //dir = regexprep (dir_elts{j}, "//+", "/"); | |
2147 //dir = regexprep (dir, "/$", ""); | |
2148 | |
2149 if (! load_path::remove (dir)) | |
2150 warning ("rmpath: %s: not found", dir.c_str ()); | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2151 else |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2152 need_to_update = true; |
5832 | 2153 } |
2154 } | |
2155 else | |
2156 error ("addpath: expecting all args to be character strings"); | |
2157 } | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2158 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2159 if (need_to_update) |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2160 rehash_internal (); |
5832 | 2161 } |
2162 else | |
2163 print_usage (); | |
2164 | |
2165 return retval; | |
2166 } | |
2167 | |
2168 /* | |
2169 ;;; Local Variables: *** | |
2170 ;;; mode: C++ *** | |
2171 ;;; End: *** | |
2172 */ |