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