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