Mercurial > hg > octave-lyh
annotate libinterp/corefcn/load-path.h @ 17335:fe6518a1d87c
Move TeX symbol decoding into the lexer (bug #39831).
* libinterp/Makefile.am (BUILT_SOURCES): Add corefcn/oct-tex-symbols.cc.
(BUILT_DISTFILES): Add corefcn/oct-tex-lexer.ll and
corefcn/oct-tex-symbols.cc.
(EXTRA_DIST): Add corefcn/oct-tex-lexer.in.ll and
corefcn/oct-tex-symbols.in.
(ULT_DIST_SRC): Filter out corefcn/oct-tex-lexer.ll from DIST_SRC and
add corefcn/oct-tex-lexer.in.ll instead.
(CLEAN_FILES): Add corefcn/oct-tex-parser.output.
* libinterp/corefcn/modules.mk (corefcn/oct-tex-lexer.ll,
corefcn/oct-tex-symbols.cc): New rules to build the TeX lexer.
(corefcn/txt-eng.cc): Add dependency on corefcn/oct-tex-symbols.cc.
* libinterp/corefcn/oct-tex-lexer.in.ll: Renamed from oct-tex.lexer.ll.
Remove COMMAND state. Remove ID regex. Replace rules for symbols with
tag @SYMBOL_RULES@.
* libinterp/corefcn/oct-tex-parser.yy (ID, CMD, identifier): Remove
tokens.
(SYM, sym): New token and value.
(symbol_element): Build from SYM.
* libinterp/corefcn/oct-tex-symbols.in: New file with supported TeX
symbols and corresponding codes (unicode and MS symbols).
* libinterp/corefcn/txt-eng.h (class text_element_symbol): Make it
inherit from text_element.
(text_element_symbol::code): Removed member.
(text_element_symbol::symbol): New member.
(text_element_symbol::text_element_symbol): Adapt constructor.
(text_element_symbol::get_symbol): New method.
(text_element_symbol::get_symbol_code): Make const.
* libinterp/corefcn/txt-eng.cc (symbol_names, symbol_codes): Remove
static variables, now auto-generated from oct-tex-symbols.in.
(oct-tex-symbols.cc): New include.
(text_element_symbol::get_symbol_code): Change implementation to simply
index into auto-generated symbol_codes array.
* libinterp/corefcn/txt-eng-ft.cc
(ft_render::visit(text_element_symbol)): Don't use
text_element_symbol::string_value(), use
text_element_symbol::get_symbol() instead.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Sat, 24 Aug 2013 14:27:09 -0400 |
parents | 68fc671a9339 |
children | 498b2dd1bd56 |
rev | line source |
---|---|
5832 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
3 Copyright (C) 2006-2012 John W. Eaton |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
4 Copyright (C) 2010 VZLU Prague |
5832 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
5832 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
5832 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_load_path_h) | |
25 #define octave_load_path_h 1 | |
26 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
27 #include <iosfwd> |
5832 | 28 #include <list> |
29 #include <map> | |
30 #include <string> | |
31 | |
5835 | 32 #include "pathsearch.h" |
5832 | 33 #include "str-vec.h" |
34 | |
35 class | |
6241 | 36 OCTINTERP_API |
5832 | 37 load_path |
38 { | |
39 protected: | |
40 | |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8950
diff
changeset
|
41 load_path (void) |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
42 : dir_info_list (), fcn_map (), private_fcn_map (), method_map (), |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
43 init_dirs () { } |
5832 | 44 |
45 public: | |
46 | |
7336 | 47 typedef void (*hook_fcn_ptr) (const std::string& dir); |
5832 | 48 |
49 ~load_path (void) { } | |
50 | |
6365 | 51 static void initialize (bool set_initial_path = false) |
5832 | 52 { |
53 if (instance_ok ()) | |
6365 | 54 instance->do_initialize (set_initial_path); |
5832 | 55 } |
56 | |
57 static void clear (void) | |
58 { | |
59 if (instance_ok ()) | |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
60 instance->do_clear (); |
5832 | 61 } |
62 | |
5867 | 63 static void set (const std::string& p, bool warn = false) |
5832 | 64 { |
65 if (instance_ok ()) | |
5867 | 66 instance->do_set (p, warn); |
5832 | 67 } |
68 | |
5867 | 69 static void append (const std::string& dir, bool warn = false) |
5832 | 70 { |
71 if (instance_ok ()) | |
5867 | 72 instance->do_append (dir, warn); |
5832 | 73 } |
74 | |
5867 | 75 static void prepend (const std::string& dir, bool warn = false) |
5832 | 76 { |
77 if (instance_ok ()) | |
5867 | 78 instance->do_prepend (dir, warn); |
5832 | 79 } |
80 | |
81 static bool remove (const std::string& dir) | |
82 { | |
83 return instance_ok () ? instance->do_remove (dir) : false; | |
84 } | |
85 | |
86 static void update (void) | |
87 { | |
88 if (instance_ok ()) | |
89 instance->do_update (); | |
90 } | |
91 | |
16547
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
92 static bool contains_canonical (const std::string& dir_name) |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
93 { |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
94 return instance_ok () ? instance->do_contains_canonical (dir_name) : false; |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
95 } |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
96 |
7336 | 97 static std::string find_method (const std::string& class_name, |
10313 | 98 const std::string& meth, |
99 std::string& dir_name) | |
7336 | 100 { |
101 return instance_ok () | |
102 ? instance->do_find_method (class_name, meth, dir_name) : std::string (); | |
103 } | |
104 | |
105 static std::string find_method (const std::string& class_name, | |
10313 | 106 const std::string& meth) |
7336 | 107 { |
108 std::string dir_name; | |
109 return find_method (class_name, meth, dir_name); | |
110 } | |
111 | |
112 static std::list<std::string> methods (const std::string& class_name) | |
113 { | |
114 return instance_ok () | |
115 ? instance->do_methods (class_name) : std::list<std::string> (); | |
116 } | |
117 | |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
118 static std::list<std::string> overloads (const std::string& meth) |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9261
diff
changeset
|
119 { |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9261
diff
changeset
|
120 return instance_ok () |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
121 ? instance->do_overloads (meth) : std::list<std::string> (); |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9261
diff
changeset
|
122 } |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9261
diff
changeset
|
123 |
7336 | 124 static std::string find_fcn (const std::string& fcn, std::string& dir_name) |
125 { | |
126 return instance_ok () | |
127 ? instance->do_find_fcn (fcn, dir_name) : std::string (); | |
128 } | |
129 | |
5832 | 130 static std::string find_fcn (const std::string& fcn) |
131 { | |
7336 | 132 std::string dir_name; |
133 return find_fcn (fcn, dir_name); | |
134 } | |
135 | |
136 static std::string find_private_fcn (const std::string& dir, | |
10313 | 137 const std::string& fcn) |
7336 | 138 { |
5832 | 139 return instance_ok () |
7336 | 140 ? instance->do_find_private_fcn (dir, fcn) : std::string (); |
5832 | 141 } |
142 | |
143 static std::string find_fcn_file (const std::string& fcn) | |
144 { | |
7336 | 145 std::string dir_name; |
146 | |
5832 | 147 return instance_ok () ? |
7336 | 148 instance->do_find_fcn (fcn, dir_name, M_FILE) : std::string (); |
5832 | 149 } |
150 | |
151 static std::string find_oct_file (const std::string& fcn) | |
152 { | |
7336 | 153 std::string dir_name; |
154 | |
5832 | 155 return instance_ok () ? |
7336 | 156 instance->do_find_fcn (fcn, dir_name, OCT_FILE) : std::string (); |
5832 | 157 } |
158 | |
5864 | 159 static std::string find_mex_file (const std::string& fcn) |
160 { | |
7336 | 161 std::string dir_name; |
162 | |
5864 | 163 return instance_ok () ? |
7336 | 164 instance->do_find_fcn (fcn, dir_name, MEX_FILE) : std::string (); |
5864 | 165 } |
166 | |
5832 | 167 static std::string find_file (const std::string& file) |
168 { | |
169 return instance_ok () | |
170 ? instance->do_find_file (file) : std::string (); | |
171 } | |
172 | |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8008
diff
changeset
|
173 static std::string find_dir (const std::string& dir) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8008
diff
changeset
|
174 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8008
diff
changeset
|
175 return instance_ok () |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8008
diff
changeset
|
176 ? instance->do_find_dir (dir) : std::string (); |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8008
diff
changeset
|
177 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8008
diff
changeset
|
178 |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
179 static string_vector find_matching_dirs (const std::string& dir) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
180 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
181 return instance_ok () |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
182 ? instance->do_find_matching_dirs (dir) : string_vector (); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
183 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
184 |
5832 | 185 static std::string find_first_of (const string_vector& files) |
186 { | |
187 return instance_ok () ? | |
188 instance->do_find_first_of (files) : std::string (); | |
189 } | |
190 | |
191 static string_vector find_all_first_of (const string_vector& files) | |
192 { | |
193 return instance_ok () ? | |
194 instance->do_find_all_first_of (files) : string_vector (); | |
195 } | |
196 | |
197 static string_vector dirs (void) | |
198 { | |
199 return instance_ok () ? instance->do_dirs () : string_vector (); | |
200 } | |
201 | |
202 static std::list<std::string> dir_list (void) | |
203 { | |
204 return instance_ok () | |
205 ? instance->do_dir_list () : std::list<std::string> (); | |
206 } | |
207 | |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
208 static string_vector files (const std::string& dir, bool omit_exts = false) |
5832 | 209 { |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
210 return instance_ok () |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
211 ? instance->do_files (dir, omit_exts) : string_vector (); |
5832 | 212 } |
213 | |
214 static string_vector fcn_names (void) | |
215 { | |
216 return instance_ok () ? instance->do_fcn_names () : string_vector (); | |
217 } | |
218 | |
219 static std::string path (void) | |
220 { | |
221 return instance_ok () ? instance->do_path () : std::string (); | |
222 } | |
223 | |
224 static void display (std::ostream& os) | |
225 { | |
226 if (instance_ok ()) | |
227 instance->do_display (os); | |
228 } | |
229 | |
7336 | 230 static void set_add_hook (hook_fcn_ptr f) { add_hook = f; } |
5832 | 231 |
7336 | 232 static void set_remove_hook (hook_fcn_ptr f) { remove_hook = f; } |
5832 | 233 |
234 static void set_command_line_path (const std::string& p) | |
235 { | |
5835 | 236 if (command_line_path.empty ()) |
237 command_line_path = p; | |
238 else | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7971
diff
changeset
|
239 command_line_path += dir_path::path_sep_str () + p; |
5832 | 240 } |
241 | |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8329
diff
changeset
|
242 static std::string get_command_line_path (void) |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8329
diff
changeset
|
243 { |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8329
diff
changeset
|
244 return instance_ok () ? instance->do_get_command_line_path () : std::string (); |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8329
diff
changeset
|
245 } |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8329
diff
changeset
|
246 |
6626 | 247 static std::string system_path (void) |
248 { | |
6630 | 249 return instance_ok () ? instance->do_system_path () : std::string (); |
6626 | 250 } |
251 | |
5832 | 252 private: |
253 | |
254 static const int M_FILE = 1; | |
255 static const int OCT_FILE = 2; | |
5864 | 256 static const int MEX_FILE = 4; |
5832 | 257 |
258 class dir_info | |
259 { | |
260 public: | |
261 | |
7336 | 262 // <FCN_NAME, TYPE> |
263 typedef std::map<std::string, int> fcn_file_map_type; | |
264 | |
265 typedef fcn_file_map_type::const_iterator const_fcn_file_map_iterator; | |
266 typedef fcn_file_map_type::iterator fcn_file_map_iterator; | |
267 | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
268 struct class_info |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
269 { |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
270 class_info (void) : method_file_map (), private_file_map () { } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
271 |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
272 class_info (const class_info& ci) |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
273 : method_file_map (ci.method_file_map), |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
274 private_file_map (ci.private_file_map) { } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
275 |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
276 class_info& operator = (const class_info& ci) |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
277 { |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
278 if (this != &ci) |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
279 { |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
280 method_file_map = ci.method_file_map; |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
281 private_file_map = ci.private_file_map; |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
282 } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
283 return *this; |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
284 } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
285 |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
286 ~class_info (void) { } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
287 |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
288 fcn_file_map_type method_file_map; |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
289 fcn_file_map_type private_file_map; |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
290 }; |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
291 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
292 // <CLASS_NAME, CLASS_INFO> |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
293 typedef std::map<std::string, class_info> method_file_map_type; |
7336 | 294 |
295 typedef method_file_map_type::const_iterator const_method_file_map_iterator; | |
296 typedef method_file_map_type::iterator method_file_map_iterator; | |
297 | |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
298 // This default constructor is only provided so we can create a |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
299 // std::map of dir_info objects. You should not use this |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
300 // constructor for any other purpose. |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
301 dir_info (void) |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
302 : dir_name (), abs_dir_name (), is_relative (false), |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
303 dir_mtime (), dir_time_last_checked (), |
14376
7dd6ac033e69
Warn when the default path is overwritten
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
304 all_files (), fcn_files (), private_file_map (), method_file_map () |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
305 { } |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
306 |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
307 dir_info (const std::string& d) |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
308 : dir_name (d), abs_dir_name (), is_relative (false), |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
309 dir_mtime (), dir_time_last_checked (), |
14376
7dd6ac033e69
Warn when the default path is overwritten
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
310 all_files (), fcn_files (), private_file_map (), method_file_map () |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
311 { |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
312 initialize (); |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
313 } |
5832 | 314 |
315 dir_info (const dir_info& di) | |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
316 : dir_name (di.dir_name), abs_dir_name (di.abs_dir_name), |
10313 | 317 is_relative (di.is_relative), |
318 dir_mtime (di.dir_mtime), | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
319 dir_time_last_checked (di.dir_time_last_checked), |
10313 | 320 all_files (di.all_files), fcn_files (di.fcn_files), |
321 private_file_map (di.private_file_map), | |
322 method_file_map (di.method_file_map) { } | |
5832 | 323 |
324 ~dir_info (void) { } | |
325 | |
326 dir_info& operator = (const dir_info& di) | |
327 { | |
328 if (&di != this) | |
10313 | 329 { |
330 dir_name = di.dir_name; | |
331 abs_dir_name = di.abs_dir_name; | |
332 is_relative = di.is_relative; | |
333 dir_mtime = di.dir_mtime; | |
334 dir_time_last_checked = di.dir_time_last_checked; | |
335 all_files = di.all_files; | |
336 fcn_files = di.fcn_files; | |
337 private_file_map = di.private_file_map; | |
338 method_file_map = di.method_file_map; | |
339 } | |
5832 | 340 |
341 return *this; | |
342 } | |
343 | |
344 void update (void); | |
345 | |
346 std::string dir_name; | |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
347 std::string abs_dir_name; |
5832 | 348 bool is_relative; |
349 octave_time dir_mtime; | |
9748
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
9581
diff
changeset
|
350 octave_time dir_time_last_checked; |
5832 | 351 string_vector all_files; |
352 string_vector fcn_files; | |
7336 | 353 fcn_file_map_type private_file_map; |
354 method_file_map_type method_file_map; | |
5832 | 355 |
356 private: | |
357 | |
358 void initialize (void); | |
359 | |
7336 | 360 void get_file_list (const std::string& d); |
361 | |
362 void get_private_file_map (const std::string& d); | |
5832 | 363 |
7336 | 364 void get_method_file_map (const std::string& d, |
10313 | 365 const std::string& class_name); |
7336 | 366 |
367 friend fcn_file_map_type get_fcn_files (const std::string& d); | |
5832 | 368 }; |
369 | |
370 class file_info | |
371 { | |
372 public: | |
373 | |
374 file_info (const std::string& d, int t) : dir_name (d), types (t) { } | |
375 | |
376 file_info (const file_info& fi) | |
377 : dir_name (fi.dir_name), types (fi.types) { } | |
378 | |
379 ~file_info (void) { } | |
380 | |
381 file_info& operator = (const file_info& fi) | |
382 { | |
383 if (&fi != this) | |
10313 | 384 { |
385 dir_name = fi.dir_name; | |
386 types = fi.types; | |
387 } | |
5832 | 388 |
389 return *this; | |
390 } | |
391 | |
392 std::string dir_name; | |
393 int types; | |
394 }; | |
395 | |
396 // We maintain two ways of looking at the same information. | |
397 // | |
398 // First, a list of directories and the set of "public" files and | |
399 // private files (those found in the special "private" subdirectory) | |
400 // in each directory. | |
401 // | |
402 // Second, a map from file names (the union of all "public" files for all | |
7336 | 403 // directories, but without filename extensions) to a list of |
5832 | 404 // corresponding information (directory name and file types). This |
405 // way, we can quickly find shadowed file names and look up all | |
406 // overloaded functions (in the "@" directories used to implement | |
407 // classes). | |
408 | |
7336 | 409 typedef std::list<dir_info> dir_info_list_type; |
410 | |
411 typedef dir_info_list_type::const_iterator const_dir_info_list_iterator; | |
412 typedef dir_info_list_type::iterator dir_info_list_iterator; | |
413 | |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
414 typedef std::map<std::string, dir_info> abs_dir_cache_type; |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
415 |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
416 typedef abs_dir_cache_type::const_iterator const_abs_dir_cache_iterator; |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
417 typedef abs_dir_cache_type::iterator abs_dir_cache_iterator; |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
418 |
7336 | 419 typedef std::list<file_info> file_info_list_type; |
420 | |
421 typedef file_info_list_type::const_iterator const_file_info_list_iterator; | |
422 typedef file_info_list_type::iterator file_info_list_iterator; | |
423 | |
424 // <FCN_NAME, FILE_INFO_LIST> | |
425 typedef std::map<std::string, file_info_list_type> fcn_map_type; | |
426 | |
427 typedef fcn_map_type::const_iterator const_fcn_map_iterator; | |
428 typedef fcn_map_type::iterator fcn_map_iterator; | |
5832 | 429 |
7336 | 430 // <DIR_NAME, <FCN_NAME, TYPE>> |
431 typedef std::map<std::string, dir_info::fcn_file_map_type> private_fcn_map_type; | |
432 | |
433 typedef private_fcn_map_type::const_iterator const_private_fcn_map_iterator; | |
434 typedef private_fcn_map_type::iterator private_fcn_map_iterator; | |
435 | |
436 // <CLASS_NAME, <FCN_NAME, FILE_INFO_LIST>> | |
437 typedef std::map<std::string, fcn_map_type> method_map_type; | |
438 | |
439 typedef method_map_type::const_iterator const_method_map_iterator; | |
440 typedef method_map_type::iterator method_map_iterator; | |
10907
6105ed2db9d7
load_path::dir_info::initialize: clear method_file_map before updating file list
John W. Eaton <jwe@octave.org>
parents:
10521
diff
changeset
|
441 |
7336 | 442 mutable dir_info_list_type dir_info_list; |
443 | |
444 mutable fcn_map_type fcn_map; | |
445 | |
446 mutable private_fcn_map_type private_fcn_map; | |
447 | |
448 mutable method_map_type method_map; | |
5832 | 449 |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
450 mutable std::set<std::string> init_dirs; |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
451 |
5832 | 452 static load_path *instance; |
453 | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
454 static void cleanup_instance (void) { delete instance; instance = 0; } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
455 |
7336 | 456 static hook_fcn_ptr add_hook; |
5832 | 457 |
7336 | 458 static hook_fcn_ptr remove_hook; |
5832 | 459 |
460 static std::string command_line_path; | |
461 | |
6626 | 462 static std::string sys_path; |
463 | |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
464 static abs_dir_cache_type abs_dir_cache; |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
465 |
5832 | 466 static bool instance_ok (void); |
467 | |
468 const_dir_info_list_iterator find_dir_info (const std::string& dir) const; | |
469 dir_info_list_iterator find_dir_info (const std::string& dir); | |
470 | |
471 bool contains (const std::string& dir) const; | |
472 | |
16547
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
473 bool do_contains_canonical (const std::string& dir) const; |
3cd80afc3509
improve debugging with the GUI
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
474 |
7336 | 475 void move_fcn_map (const std::string& dir, |
10313 | 476 const string_vector& fcn_files, bool at_end); |
7336 | 477 |
478 void move_method_map (const std::string& dir, bool at_end); | |
479 | |
5832 | 480 void move (std::list<dir_info>::iterator i, bool at_end); |
481 | |
6365 | 482 void do_initialize (bool set_initial_path); |
5832 | 483 |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
484 void do_clear (void); |
5832 | 485 |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
486 void do_set (const std::string& p, bool warn, bool is_init = false); |
5867 | 487 |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
488 void do_append (const std::string& dir, bool warn); |
5832 | 489 |
5867 | 490 void do_prepend (const std::string& dir, bool warn); |
5832 | 491 |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
492 void do_add (const std::string& dir, bool at_end, bool warn); |
5832 | 493 |
7336 | 494 void remove_fcn_map (const std::string& dir, const string_vector& fcn_files); |
495 | |
496 void remove_private_fcn_map (const std::string& dir); | |
497 | |
498 void remove_method_map (const std::string& dir); | |
499 | |
5832 | 500 bool do_remove (const std::string& dir); |
501 | |
502 void do_update (void) const; | |
503 | |
7336 | 504 static bool |
505 check_file_type (std::string& fname, int type, int possible_types, | |
10313 | 506 const std::string& fcn, const char *who); |
7336 | 507 |
5832 | 508 std::string do_find_fcn (const std::string& fcn, |
10313 | 509 std::string& dir_name, |
510 int type = M_FILE | OCT_FILE | MEX_FILE) const; | |
5832 | 511 |
7336 | 512 std::string do_find_private_fcn (const std::string& dir, |
10313 | 513 const std::string& fcn, |
514 int type = M_FILE | OCT_FILE | MEX_FILE) const; | |
7336 | 515 |
516 std::string do_find_method (const std::string& class_name, | |
10313 | 517 const std::string& meth, |
518 std::string& dir_name, | |
519 int type = M_FILE | OCT_FILE | MEX_FILE) const; | |
7336 | 520 |
521 std::list<std::string> do_methods (const std::string& class_name) const; | |
522 | |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
523 std::list<std::string> do_overloads (const std::string& meth) const; |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9261
diff
changeset
|
524 |
5832 | 525 std::string do_find_file (const std::string& file) const; |
526 | |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8008
diff
changeset
|
527 std::string 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:
8008
diff
changeset
|
528 |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
529 string_vector do_find_matching_dirs (const std::string& dir) const; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
530 |
5832 | 531 std::string do_find_first_of (const string_vector& files) const; |
532 | |
533 string_vector do_find_all_first_of (const string_vector& files) const; | |
534 | |
535 string_vector do_dirs (void) const; | |
536 | |
537 std::list<std::string> do_dir_list (void) const; | |
538 | |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
539 string_vector do_files (const std::string& dir, bool omit_exts) const; |
5832 | 540 |
541 string_vector do_fcn_names (void) const; | |
542 | |
543 std::string do_path (void) const; | |
544 | |
7336 | 545 friend void print_types (std::ostream& os, int types); |
546 | |
547 friend string_vector get_file_list (const dir_info::fcn_file_map_type& lst); | |
548 | |
549 friend void | |
550 print_fcn_list (std::ostream& os, const dir_info::fcn_file_map_type& lst); | |
551 | |
5832 | 552 void do_display (std::ostream& os) const; |
553 | |
6629 | 554 std::string do_system_path (void) const { return sys_path; } |
6626 | 555 |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8329
diff
changeset
|
556 std::string do_get_command_line_path (void) const { return command_line_path; } |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8329
diff
changeset
|
557 |
5832 | 558 void add_to_fcn_map (const dir_info& di, bool at_end) const; |
7336 | 559 |
560 void add_to_private_fcn_map (const dir_info& di) const; | |
561 | |
562 void add_to_method_map (const dir_info& di, bool at_end) const; | |
563 | |
564 friend dir_info::fcn_file_map_type get_fcn_files (const std::string& d); | |
5832 | 565 }; |
566 | |
567 extern std::string | |
568 genpath (const std::string& dir, const string_vector& skip = "private"); | |
569 | |
570 extern void execute_pkg_add (const std::string& dir); | |
571 extern void execute_pkg_del (const std::string& dir); | |
572 | |
573 #endif |