Mercurial > hg > octave-lyh
annotate src/load-path.cc @ 9807:645c478aa89d
load-path.cc (load_path::do_find_all_first_of): take advantage of string_vector (std::list<std:string>) constructor
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Nov 2009 15:18:28 -0500 |
parents | 8e345f2fe4d6 |
children | 2cd940306a06 |
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 | |
9807
645c478aa89d
load-path.cc (load_path::do_find_all_first_of): take advantage of string_vector (std::list<std:string>) constructor
John W. Eaton <jwe@octave.org>
parents:
9806
diff
changeset
|
1352 return retlist; |
5832 | 1353 } |
1354 | |
1355 string_vector | |
1356 load_path::do_dirs (void) const | |
1357 { | |
1358 size_t len = dir_info_list.size (); | |
1359 | |
1360 string_vector retval (len); | |
1361 | |
1362 octave_idx_type k = 0; | |
1363 | |
1364 for (const_dir_info_list_iterator i = dir_info_list.begin (); | |
1365 i != dir_info_list.end (); | |
1366 i++) | |
1367 retval[k++] = i->dir_name; | |
1368 | |
1369 return retval; | |
1370 } | |
1371 | |
1372 std::list<std::string> | |
1373 load_path::do_dir_list (void) const | |
1374 { | |
1375 std::list<std::string> retval; | |
1376 | |
1377 for (const_dir_info_list_iterator i = dir_info_list.begin (); | |
1378 i != dir_info_list.end (); | |
1379 i++) | |
1380 retval.push_back (i->dir_name); | |
1381 | |
1382 return retval; | |
1383 } | |
1384 | |
1385 string_vector | |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1386 load_path::do_files (const std::string& dir, bool omit_exts) const |
5832 | 1387 { |
1388 string_vector retval; | |
1389 | |
9282
2ed8d2d92507
load_path::do_files: avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
9261
diff
changeset
|
1390 const_dir_info_list_iterator p = find_dir_info (dir); |
5832 | 1391 |
9282
2ed8d2d92507
load_path::do_files: avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
9261
diff
changeset
|
1392 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
|
1393 retval = p->fcn_files; |
5832 | 1394 |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1395 if (omit_exts) |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1396 { |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1397 octave_idx_type len = retval.length (); |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1398 |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1399 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
|
1400 { |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1401 std::string fname = retval[i]; |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1402 |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1403 size_t pos = fname.rfind ('.'); |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1404 |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1405 if (pos != std::string::npos) |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1406 retval[i] = fname.substr (0, pos); |
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 } |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1409 |
5832 | 1410 return retval; |
1411 } | |
1412 | |
1413 string_vector | |
1414 load_path::do_fcn_names (void) const | |
1415 { | |
1416 size_t len = fcn_map.size (); | |
1417 | |
1418 string_vector retval (len); | |
1419 | |
1420 octave_idx_type count = 0; | |
1421 | |
1422 for (const_fcn_map_iterator p = fcn_map.begin (); | |
1423 p != fcn_map.end (); | |
1424 p++) | |
1425 retval[count++] = p->first; | |
1426 | |
1427 return retval; | |
1428 } | |
1429 | |
1430 std::string | |
1431 load_path::do_path (void) const | |
1432 { | |
1433 std::string xpath; | |
1434 | |
1435 string_vector xdirs = load_path::dirs (); | |
1436 | |
1437 octave_idx_type len = xdirs.length (); | |
1438 | |
1439 if (len > 0) | |
1440 xpath = xdirs[0]; | |
1441 | |
1442 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
|
1443 xpath += dir_path::path_sep_str () + xdirs[i]; |
5832 | 1444 |
1445 return xpath; | |
1446 } | |
1447 | |
1448 void | |
7336 | 1449 print_types (std::ostream& os, int types) |
1450 { | |
1451 bool printed_type = false; | |
1452 | |
1453 if (types & load_path::OCT_FILE) | |
1454 { | |
1455 os << "oct"; | |
1456 printed_type = true; | |
1457 } | |
1458 | |
1459 if (types & load_path::MEX_FILE) | |
1460 { | |
1461 if (printed_type) | |
1462 os << "|"; | |
1463 os << "mex"; | |
1464 printed_type = true; | |
1465 } | |
1466 | |
1467 if (types & load_path::M_FILE) | |
1468 { | |
1469 if (printed_type) | |
1470 os << "|"; | |
1471 os << "m"; | |
1472 printed_type = true; | |
1473 } | |
1474 } | |
1475 | |
1476 void | |
1477 print_fcn_list (std::ostream& os, | |
1478 const load_path::dir_info::fcn_file_map_type& lst) | |
1479 { | |
1480 for (load_path::dir_info::const_fcn_file_map_iterator p = lst.begin (); | |
1481 p != lst.end (); | |
1482 p++) | |
1483 { | |
1484 os << " " << p->first << " ("; | |
1485 | |
1486 print_types (os, p->second); | |
1487 | |
1488 os << ")\n"; | |
1489 } | |
1490 } | |
1491 | |
1492 string_vector | |
1493 get_file_list (const load_path::dir_info::fcn_file_map_type& lst) | |
1494 { | |
1495 octave_idx_type n = lst.size (); | |
1496 | |
1497 string_vector retval (n); | |
1498 | |
1499 octave_idx_type count = 0; | |
1500 | |
1501 for (load_path::dir_info::const_fcn_file_map_iterator p = lst.begin (); | |
1502 p != lst.end (); | |
1503 p++) | |
1504 { | |
1505 std::string nm = p->first; | |
1506 | |
1507 int types = p->second; | |
1508 | |
1509 if (types & load_path::OCT_FILE) | |
1510 nm += ".oct"; | |
1511 else if (types & load_path::MEX_FILE) | |
1512 nm += ".mex"; | |
1513 else | |
1514 nm += ".m"; | |
1515 | |
1516 retval[count++] = nm; | |
1517 } | |
1518 | |
1519 return retval; | |
1520 } | |
1521 | |
1522 void | |
5832 | 1523 load_path::do_display (std::ostream& os) const |
1524 { | |
1525 for (const_dir_info_list_iterator i = dir_info_list.begin (); | |
1526 i != dir_info_list.end (); | |
1527 i++) | |
1528 { | |
1529 string_vector fcn_files = i->fcn_files; | |
1530 | |
1531 if (! fcn_files.empty ()) | |
1532 { | |
1533 os << "\n*** function files in " << i->dir_name << ":\n\n"; | |
1534 | |
1535 fcn_files.list_in_columns (os); | |
1536 } | |
1537 | |
7336 | 1538 const dir_info::method_file_map_type& method_file_map |
1539 = i->method_file_map; | |
5832 | 1540 |
7336 | 1541 if (! method_file_map.empty ()) |
5832 | 1542 { |
7336 | 1543 for (dir_info::const_method_file_map_iterator p = method_file_map.begin (); |
1544 p != method_file_map.end (); | |
5832 | 1545 p++) |
1546 { | |
7336 | 1547 os << "\n*** methods in " << i->dir_name |
1548 << "/@" << p->first << ":\n\n"; | |
5832 | 1549 |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1550 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
|
1551 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1552 string_vector method_files = get_file_list (ci.method_file_map); |
5832 | 1553 |
7336 | 1554 method_files.list_in_columns (os); |
1555 } | |
1556 } | |
1557 } | |
5864 | 1558 |
7336 | 1559 for (const_private_fcn_map_iterator i = private_fcn_map.begin (); |
1560 i != private_fcn_map.end (); i++) | |
1561 { | |
1562 os << "\n*** private functions in " | |
1563 << file_ops::concat (i->first, "private") << ":\n\n"; | |
5832 | 1564 |
7336 | 1565 print_fcn_list (os, i->second); |
5832 | 1566 } |
1567 | |
1568 #if defined (DEBUG_LOAD_PATH) | |
1569 | |
1570 for (const_fcn_map_iterator i = fcn_map.begin (); | |
1571 i != fcn_map.end (); | |
1572 i++) | |
1573 { | |
1574 os << i->first << ":\n"; | |
1575 | |
7336 | 1576 const file_info_list_type& file_info_list = i->second; |
5832 | 1577 |
1578 for (const_file_info_list_iterator p = file_info_list.begin (); | |
1579 p != file_info_list.end (); | |
1580 p++) | |
1581 { | |
1582 os << " " << p->dir_name << " ("; | |
1583 | |
7336 | 1584 print_types (os, p->types); |
5832 | 1585 |
1586 os << ")\n"; | |
1587 } | |
1588 } | |
1589 | |
7336 | 1590 for (const_method_map_iterator i = method_map.begin (); |
1591 i != method_map.end (); | |
1592 i++) | |
1593 { | |
1594 os << "CLASS " << i->first << ":\n"; | |
1595 | |
1596 const fcn_map_type& fm = i->second; | |
1597 | |
1598 for (const_fcn_map_iterator q = fm.begin (); | |
1599 q != fm.end (); | |
1600 q++) | |
1601 { | |
1602 os << " " << q->first << ":\n"; | |
1603 | |
1604 const file_info_list_type& file_info_list = q->second; | |
1605 | |
1606 for (const_file_info_list_iterator p = file_info_list.begin (); | |
1607 p != file_info_list.end (); | |
1608 p++) | |
1609 { | |
1610 os << " " << p->dir_name << " ("; | |
1611 | |
1612 print_types (os, p->types); | |
1613 | |
1614 os << ")\n"; | |
1615 } | |
1616 } | |
1617 } | |
1618 | |
5832 | 1619 os << "\n"; |
1620 | |
1621 #endif | |
1622 } | |
1623 | |
1624 void | |
1625 load_path::add_to_fcn_map (const dir_info& di, bool at_end) const | |
1626 { | |
1627 std::string dir_name = di.dir_name; | |
1628 | |
1629 string_vector fcn_files = di.fcn_files; | |
1630 | |
1631 octave_idx_type len = fcn_files.length (); | |
1632 | |
1633 for (octave_idx_type i = 0; i < len; i++) | |
1634 { | |
1635 std::string fname = fcn_files[i]; | |
1636 | |
1637 std::string ext; | |
1638 std::string base = fname; | |
1639 | |
1640 size_t pos = fname.rfind ('.'); | |
1641 | |
8021 | 1642 if (pos != std::string::npos) |
5832 | 1643 { |
1644 base = fname.substr (0, pos); | |
1645 ext = fname.substr (pos); | |
1646 } | |
1647 | |
7336 | 1648 file_info_list_type& file_info_list = fcn_map[base]; |
5832 | 1649 |
1650 file_info_list_iterator p = file_info_list.begin (); | |
1651 | |
1652 while (p != file_info_list.end ()) | |
1653 { | |
1654 if (p->dir_name == dir_name) | |
1655 break; | |
1656 | |
1657 p++; | |
1658 } | |
1659 | |
1660 int t = 0; | |
1661 if (ext == ".m") | |
1662 t = load_path::M_FILE; | |
1663 else if (ext == ".oct") | |
1664 t = load_path::OCT_FILE; | |
5864 | 1665 else if (ext == ".mex") |
1666 t = load_path::MEX_FILE; | |
5832 | 1667 |
1668 if (p == file_info_list.end ()) | |
1669 { | |
1670 file_info fi (dir_name, t); | |
1671 | |
1672 if (at_end) | |
1673 file_info_list.push_back (fi); | |
1674 else | |
1675 file_info_list.push_front (fi); | |
1676 } | |
1677 else | |
1678 { | |
1679 file_info& fi = *p; | |
1680 | |
1681 fi.types |= t; | |
1682 } | |
1683 } | |
1684 } | |
1685 | |
7336 | 1686 void |
1687 load_path::add_to_private_fcn_map (const dir_info& di) const | |
1688 { | |
1689 dir_info::fcn_file_map_type private_file_map = di.private_file_map; | |
1690 | |
1691 if (! private_file_map.empty ()) | |
1692 private_fcn_map[di.dir_name] = private_file_map; | |
1693 } | |
1694 | |
1695 void | |
1696 load_path::add_to_method_map (const dir_info& di, bool at_end) const | |
1697 { | |
1698 std::string dir_name = di.dir_name; | |
1699 | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1700 // <CLASS_NAME, CLASS_INFO> |
7336 | 1701 dir_info::method_file_map_type method_file_map = di.method_file_map; |
1702 | |
1703 for (dir_info::const_method_file_map_iterator q = method_file_map.begin (); | |
1704 q != method_file_map.end (); | |
1705 q++) | |
1706 { | |
1707 std::string class_name = q->first; | |
1708 | |
1709 fcn_map_type& fm = method_map[class_name]; | |
1710 | |
1711 std::string full_dir_name | |
1712 = file_ops::concat (dir_name, "@" + class_name); | |
1713 | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1714 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
|
1715 |
7336 | 1716 // <FCN_NAME, TYPES> |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1717 const dir_info::fcn_file_map_type& m = ci.method_file_map; |
7336 | 1718 |
1719 for (dir_info::const_fcn_file_map_iterator p = m.begin (); | |
1720 p != m.end (); | |
1721 p++) | |
1722 { | |
1723 std::string base = p->first; | |
1724 | |
1725 int types = p->second; | |
1726 | |
1727 file_info_list_type& file_info_list = fm[base]; | |
1728 | |
1729 file_info_list_iterator p2 = file_info_list.begin (); | |
1730 | |
1731 while (p2 != file_info_list.end ()) | |
1732 { | |
1733 if (p2->dir_name == full_dir_name) | |
1734 break; | |
1735 | |
1736 p2++; | |
1737 } | |
1738 | |
1739 if (p2 == file_info_list.end ()) | |
1740 { | |
1741 file_info fi (full_dir_name, types); | |
1742 | |
1743 if (at_end) | |
1744 file_info_list.push_back (fi); | |
1745 else | |
1746 file_info_list.push_front (fi); | |
1747 } | |
1748 else | |
1749 { | |
1750 // FIXME -- is this possible? | |
1751 | |
1752 file_info& fi = *p2; | |
1753 | |
1754 fi.types = types; | |
1755 } | |
1756 } | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1757 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1758 // <FCN_NAME, TYPES> |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1759 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
|
1760 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1761 if (! private_file_map.empty ()) |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1762 private_fcn_map[full_dir_name] = private_file_map; |
7336 | 1763 } |
1764 } | |
1765 | |
5832 | 1766 std::string |
1767 genpath (const std::string& dirname, const string_vector& skip) | |
1768 { | |
1769 std::string retval; | |
1770 | |
5871 | 1771 dir_entry dir (dirname); |
5832 | 1772 |
1773 if (dir) | |
1774 { | |
1775 retval = dirname; | |
1776 | |
1777 string_vector dirlist = dir.read (); | |
1778 | |
1779 octave_idx_type len = dirlist.length (); | |
1780 | |
1781 for (octave_idx_type i = 0; i < len; i++) | |
1782 { | |
1783 std::string elt = dirlist[i]; | |
1784 | |
1785 // FIXME -- the caller should be able to specify the list of | |
7336 | 1786 // directories to skip in addition to ".", "..", and |
1787 // directories beginning with "@". | |
5832 | 1788 |
7336 | 1789 bool skip_p = (elt == "." || elt == ".." || elt[0] == '@'); |
5832 | 1790 |
1791 if (! skip_p) | |
1792 { | |
1793 for (octave_idx_type j = 0; j < skip.length (); j++) | |
1794 { | |
1795 skip_p = (elt == skip[j]); | |
1796 if (skip_p) | |
1797 break; | |
1798 } | |
1799 | |
1800 if (! skip_p) | |
1801 { | |
7272 | 1802 std::string nm = file_ops::concat (dirname, elt); |
5832 | 1803 |
1804 file_stat fs (nm); | |
1805 | |
1806 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
|
1807 retval += dir_path::path_sep_str () + genpath (nm); |
5832 | 1808 } |
1809 } | |
1810 } | |
1811 } | |
1812 | |
1813 return retval; | |
1814 } | |
1815 | |
1816 static void | |
1817 execute_pkg_add_or_del (const std::string& dir, | |
1818 const std::string& script_file) | |
1819 { | |
1820 if (! octave_interpreter_ready) | |
1821 return; | |
1822 | |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9282
diff
changeset
|
1823 unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); |
5832 | 1824 |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9282
diff
changeset
|
1825 unwind_protect::protect_var (input_from_startup_file); |
5832 | 1826 |
1827 input_from_startup_file = true; | |
1828 | |
7272 | 1829 std::string file = file_ops::concat (dir, script_file); |
5832 | 1830 |
5978 | 1831 file_stat fs (file); |
5832 | 1832 |
1833 if (fs.exists ()) | |
5975 | 1834 source_file (file, "base"); |
5832 | 1835 |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9282
diff
changeset
|
1836 unwind_protect::run_frame (uwp_frame); |
5832 | 1837 } |
1838 | |
1839 void | |
1840 execute_pkg_add (const std::string& dir) | |
1841 { | |
1842 execute_pkg_add_or_del (dir, "PKG_ADD"); | |
1843 } | |
1844 | |
1845 void | |
1846 execute_pkg_del (const std::string& dir) | |
1847 { | |
1848 execute_pkg_add_or_del (dir, "PKG_DEL"); | |
1849 } | |
1850 | |
1851 DEFUN (genpath, args, , | |
1852 "-*- texinfo -*-\n\ | |
1853 @deftypefn {Built-in Function} {} genpath (@var{dir})\n\ | |
8325
b93ac0586e4b
spelling corrections
Brian Gough<bjg@network-theory.co.uk>
parents:
8141
diff
changeset
|
1854 Return a path constructed from @var{dir} and all its subdirectories.\n\ |
5832 | 1855 @end deftypefn") |
1856 { | |
1857 octave_value retval; | |
1858 | |
1859 if (args.length () == 1) | |
1860 { | |
1861 std::string dirname = args(0).string_value (); | |
1862 | |
1863 if (! error_state) | |
1864 retval = genpath (dirname); | |
1865 else | |
1866 error ("genpath: expecting argument to be a character string"); | |
1867 } | |
1868 else | |
1869 print_usage (); | |
1870 | |
1871 return retval; | |
1872 } | |
1873 | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1874 static void |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1875 rehash_internal (void) |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1876 { |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1877 load_path::update (); |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1878 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1879 // 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
|
1880 // 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
|
1881 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1882 // 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
|
1883 Vlast_prompt_time.stamp (); |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1884 } |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1885 |
5832 | 1886 DEFUN (rehash, , , |
1887 "-*- texinfo -*-\n\ | |
1888 @deftypefn {Built-in Function} {} rehash ()\n\ | |
6644 | 1889 Reinitialize Octave's load path directory cache.\n\ |
5832 | 1890 @end deftypefn") |
1891 { | |
1892 octave_value_list retval; | |
1893 | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1894 rehash_internal (); |
5832 | 1895 |
1896 return retval; | |
1897 } | |
1898 | |
8609
fcf762ba66cf
load-path.cc (Fcommand_line_path): rename from Fcommandlinepath
John W. Eaton <jwe@octave.org>
parents:
8593
diff
changeset
|
1899 DEFUN (command_line_path, , , |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1900 "-*- texinfo -*-\n\ |
8609
fcf762ba66cf
load-path.cc (Fcommand_line_path): rename from Fcommandlinepath
John W. Eaton <jwe@octave.org>
parents:
8593
diff
changeset
|
1901 @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
|
1902 Return the command line path variable.\n\ |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1903 \n\ |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1904 @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
|
1905 @end deftypefn") |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1906 { |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1907 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
|
1908 } |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1909 |
7391 | 1910 DEFUN (restoredefaultpath, , , |
1911 "-*- texinfo -*-\n\ | |
1912 @deftypefn {Built-in Function} {} restoredefaultpath (@dots{})\n\ | |
1913 Restore Octave's path to it's initial state at startup.\n\ | |
1914 \n\ | |
1915 @seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ | |
1916 @end deftypefn") | |
1917 { | |
1918 load_path::initialize (true); | |
1919 | |
1920 return octave_value (load_path::system_path ()); | |
1921 } | |
1922 | |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
1923 // 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
|
1924 // 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
|
1925 // 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
|
1926 // ~/.octaverc file |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
1927 |
7391 | 1928 DEFUN (__pathorig__, , , |
5832 | 1929 "-*- texinfo -*-\n\ |
7391 | 1930 @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
|
1931 Undocumented internal function.\n\ |
5832 | 1932 @end deftypefn") |
1933 { | |
6630 | 1934 return octave_value (load_path::system_path ()); |
5832 | 1935 } |
1936 | |
1937 DEFUN (path, args, nargout, | |
1938 "-*- texinfo -*-\n\ | |
6678 | 1939 @deftypefn {Built-in Function} {} path (@dots{})\n\ |
6644 | 1940 Modify or display Octave's load path.\n\ |
5832 | 1941 \n\ |
1942 If @var{nargin} and @var{nargout} are zero, display the elements of\n\ | |
6644 | 1943 Octave's load path in an easy to read format.\n\ |
5832 | 1944 \n\ |
1945 If @var{nargin} is zero and nargout is greater than zero, return the\n\ | |
6644 | 1946 current load path.\n\ |
5832 | 1947 \n\ |
1948 If @var{nargin} is greater than zero, concatenate the arguments,\n\ | |
1949 separating them with @code{pathsep()}. Set the internal search path\n\ | |
1950 to the result and return it.\n\ | |
1951 \n\ | |
1952 No checks are made for duplicate elements.\n\ | |
1953 @seealso{addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ | |
1954 @end deftypefn") | |
1955 { | |
1956 octave_value retval; | |
1957 | |
1958 int argc = args.length () + 1; | |
1959 | |
1960 string_vector argv = args.make_argv ("path"); | |
1961 | |
1962 if (! error_state) | |
1963 { | |
1964 if (argc > 1) | |
1965 { | |
1966 std::string path = argv[1]; | |
1967 | |
1968 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
|
1969 path += dir_path::path_sep_str () + argv[i]; |
5832 | 1970 |
5867 | 1971 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
|
1972 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1973 rehash_internal (); |
5832 | 1974 } |
1975 | |
1976 if (nargout > 0) | |
1977 retval = load_path::path (); | |
1978 else if (argc == 1 && nargout == 0) | |
1979 { | |
1980 octave_stdout << "\nOctave's search path contains the following directories:\n\n"; | |
1981 | |
1982 string_vector dirs = load_path::dirs (); | |
1983 | |
1984 dirs.list_in_columns (octave_stdout); | |
1985 | |
1986 octave_stdout << "\n"; | |
1987 } | |
1988 } | |
1989 | |
1990 return retval; | |
1991 } | |
1992 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8704
diff
changeset
|
1993 DEFUN (addpath, args, nargout, |
5832 | 1994 "-*- texinfo -*-\n\ |
6678 | 1995 @deftypefn {Built-in Function} {} addpath (@var{dir1}, @dots{})\n\ |
1996 @deftypefnx {Built-in Function} {} addpath (@var{dir1}, @dots{}, @var{option})\n\ | |
5832 | 1997 Add @var{dir1}, @dots{} to the current function search path. If\n\ |
1998 @var{option} is @samp{\"-begin\"} or 0 (the default), prepend the\n\ | |
1999 directory name to the current path. If @var{option} is @samp{\"-end\"}\n\ | |
2000 or 1, append the directory name to the current path.\n\ | |
2001 Directories added to the path must exist.\n\ | |
2002 @seealso{path, rmpath, genpath, pathdef, savepath, pathsep}\n\ | |
2003 @end deftypefn") | |
2004 { | |
2005 octave_value retval; | |
2006 | |
2007 // Originally written by Bill Denney and Etienne Grossman. Heavily | |
2008 // modified and translated to C++ by jwe. | |
2009 | |
2010 if (nargout > 0) | |
2011 retval = load_path::path (); | |
2012 | |
2013 int nargin = args.length (); | |
2014 | |
2015 if (nargin > 0) | |
2016 { | |
2017 bool append = false; | |
2018 | |
2019 octave_value option_arg = args(nargin-1); | |
2020 | |
2021 if (option_arg.is_string ()) | |
2022 { | |
2023 std::string option = option_arg.string_value (); | |
2024 | |
2025 if (option == "-end") | |
2026 { | |
2027 append = true; | |
2028 nargin--; | |
2029 } | |
2030 else if (option == "-begin") | |
2031 nargin--; | |
2032 } | |
2033 else if (option_arg.is_numeric_type ()) | |
2034 { | |
2035 int val = option_arg.int_value (); | |
2036 | |
2037 if (! error_state) | |
2038 { | |
2039 if (val == 0) | |
2040 append = false; | |
2041 else if (val == 1) | |
2042 append = true; | |
2043 else | |
2044 { | |
2045 error ("addpath: expecting final argument to be 1 or 0"); | |
2046 return retval; | |
2047 } | |
2048 } | |
2049 else | |
2050 { | |
2051 error ("addpath: expecting final argument to be 1 or 0"); | |
2052 return retval; | |
2053 } | |
2054 } | |
2055 | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2056 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
|
2057 |
5832 | 2058 for (int i = 0; i < nargin; i++) |
2059 { | |
2060 std::string arg = args(i).string_value (); | |
2061 | |
2062 if (! error_state) | |
2063 { | |
2064 std::list<std::string> dir_elts = split_path (arg); | |
2065 | |
9401
6c421f2355b5
load-path.cc (Faddpath): preserve order of prepended elements
John W. Eaton <jwe@octave.org>
parents:
9377
diff
changeset
|
2066 if (! append) |
6c421f2355b5
load-path.cc (Faddpath): preserve order of prepended elements
John W. Eaton <jwe@octave.org>
parents:
9377
diff
changeset
|
2067 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
|
2068 |
5832 | 2069 for (std::list<std::string>::const_iterator p = dir_elts.begin (); |
2070 p != dir_elts.end (); | |
2071 p++) | |
2072 { | |
2073 std::string dir = *p; | |
2074 | |
2075 //dir = regexprep (dir_elts{j}, "//+", "/"); | |
2076 //dir = regexprep (dir, "/$", ""); | |
2077 | |
5867 | 2078 if (append) |
2079 load_path::append (dir, true); | |
5832 | 2080 else |
5867 | 2081 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
|
2082 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2083 need_to_update = true; |
5832 | 2084 } |
2085 } | |
2086 else | |
2087 error ("addpath: expecting all args to be character strings"); | |
2088 } | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2089 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2090 if (need_to_update) |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2091 rehash_internal (); |
5832 | 2092 } |
2093 else | |
2094 print_usage (); | |
2095 | |
2096 return retval; | |
2097 } | |
2098 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8704
diff
changeset
|
2099 DEFUN (rmpath, args, nargout, |
5832 | 2100 "-*- texinfo -*-\n\ |
6678 | 2101 @deftypefn {Built-in Function} {} rmpath (@var{dir1}, @dots{})\n\ |
5832 | 2102 Remove @var{dir1}, @dots{} from the current function search path.\n\ |
2103 \n\ | |
2104 @seealso{path, addpath, genpath, pathdef, savepath, pathsep}\n\ | |
2105 @end deftypefn") | |
2106 { | |
2107 // Originally by Etienne Grossmann. Heavily modified and translated | |
2108 // to C++ by jwe. | |
2109 | |
2110 octave_value retval; | |
2111 | |
2112 if (nargout > 0) | |
2113 retval = load_path::path (); | |
2114 | |
2115 int nargin = args.length (); | |
2116 | |
2117 if (nargin > 0) | |
2118 { | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2119 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
|
2120 |
5832 | 2121 for (int i = 0; i < nargin; i++) |
2122 { | |
2123 std::string arg = args(i).string_value (); | |
2124 | |
2125 if (! error_state) | |
2126 { | |
2127 std::list<std::string> dir_elts = split_path (arg); | |
2128 | |
2129 for (std::list<std::string>::const_iterator p = dir_elts.begin (); | |
2130 p != dir_elts.end (); | |
2131 p++) | |
2132 { | |
2133 std::string dir = *p; | |
2134 | |
2135 //dir = regexprep (dir_elts{j}, "//+", "/"); | |
2136 //dir = regexprep (dir, "/$", ""); | |
2137 | |
2138 if (! load_path::remove (dir)) | |
2139 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
|
2140 else |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2141 need_to_update = true; |
5832 | 2142 } |
2143 } | |
2144 else | |
2145 error ("addpath: expecting all args to be character strings"); | |
2146 } | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2147 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2148 if (need_to_update) |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2149 rehash_internal (); |
5832 | 2150 } |
2151 else | |
2152 print_usage (); | |
2153 | |
2154 return retval; | |
2155 } | |
2156 | |
2157 /* | |
2158 ;;; Local Variables: *** | |
2159 ;;; mode: C++ *** | |
2160 ;;; End: *** | |
2161 */ |