1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
1
|
26 #endif |
|
27 |
1468
|
28 #include <cstdio> |
1343
|
29 #include <cstring> |
605
|
30 |
4207
|
31 #include <set> |
1728
|
32 #include <string> |
|
33 |
2926
|
34 #include "file-stat.h" |
|
35 #include "oct-env.h" |
4604
|
36 #include "file-ops.h" |
2926
|
37 #include "glob-match.h" |
1755
|
38 #include "str-vec.h" |
|
39 |
2492
|
40 #include <defaults.h> |
4435
|
41 #include "Cell.h" |
1352
|
42 #include "defun.h" |
|
43 #include "dirfns.h" |
|
44 #include "error.h" |
2205
|
45 #include "gripes.h" |
1352
|
46 #include "help.h" |
3165
|
47 #include "input.h" |
1352
|
48 #include "lex.h" |
5832
|
49 #include "load-path.h" |
2926
|
50 #include "oct-map.h" |
|
51 #include "oct-obj.h" |
|
52 #include "ov.h" |
3933
|
53 #include "ov-usr-fcn.h" |
605
|
54 #include "pager.h" |
1352
|
55 #include "parse.h" |
2926
|
56 #include "symtab.h" |
2205
|
57 #include "toplev.h" |
1352
|
58 #include "unwind-prot.h" |
1
|
59 #include "utils.h" |
1352
|
60 #include "variables.h" |
2205
|
61 |
|
62 // Should Octave always check to see if function files have changed |
|
63 // since they were last compiled? |
5794
|
64 static int Vignore_function_time_stamp = 1; |
2205
|
65 |
1
|
66 // Symbol table for symbols at the top level. |
581
|
67 symbol_table *top_level_sym_tab = 0; |
1
|
68 |
|
69 // Symbol table for the current scope. |
581
|
70 symbol_table *curr_sym_tab = 0; |
1
|
71 |
4245
|
72 // Symbol table for the current caller scope. |
|
73 symbol_table *curr_caller_sym_tab = 0; |
|
74 |
1
|
75 // Symbol table for global symbols. |
581
|
76 symbol_table *global_sym_tab = 0; |
1
|
77 |
4009
|
78 // Symbol table for functions and built-in symbols. |
|
79 symbol_table *fbi_sym_tab = 0; |
|
80 |
4700
|
81 bool |
4208
|
82 at_top_level (void) |
|
83 { |
|
84 return (curr_sym_tab == top_level_sym_tab); |
|
85 } |
|
86 |
593
|
87 // Initialization. |
|
88 |
|
89 // Create the initial symbol tables and set the current scope at the |
|
90 // top level. |
|
91 |
195
|
92 void |
|
93 initialize_symbol_tables (void) |
|
94 { |
4009
|
95 if (! fbi_sym_tab) |
4238
|
96 fbi_sym_tab = new symbol_table (2048, "FBI"); |
4009
|
97 |
581
|
98 if (! global_sym_tab) |
4238
|
99 global_sym_tab = new symbol_table (2048, "GLOBAL"); |
195
|
100 |
581
|
101 if (! top_level_sym_tab) |
4238
|
102 top_level_sym_tab = new symbol_table (4096, "TOP"); |
195
|
103 |
4245
|
104 curr_caller_sym_tab = curr_sym_tab = top_level_sym_tab; |
195
|
105 } |
|
106 |
6068
|
107 void |
6072
|
108 clear_mex_functions (void) |
6068
|
109 { |
6072
|
110 fbi_sym_tab->clear_mex_functions (); |
6068
|
111 } |
|
112 |
593
|
113 // Attributes of variables and functions. |
|
114 |
4208
|
115 // Is this a command-style function? |
593
|
116 |
4208
|
117 static std::set <std::string> command_set; |
4207
|
118 |
|
119 static inline bool |
4208
|
120 is_marked_as_command (const std::string& s) |
4207
|
121 { |
4208
|
122 return command_set.find (s) != command_set.end (); |
4207
|
123 } |
|
124 |
|
125 static inline void |
4208
|
126 mark_as_command (const std::string& s) |
4207
|
127 { |
4208
|
128 command_set.insert (s); |
4207
|
129 } |
|
130 |
|
131 static inline void |
4208
|
132 unmark_command (const std::string& s) |
4207
|
133 { |
4208
|
134 command_set.erase (s); |
4207
|
135 |
|
136 symbol_record *sr = fbi_sym_tab->lookup (s); |
|
137 |
|
138 if (sr) |
4208
|
139 sr->unmark_command (); |
4207
|
140 } |
|
141 |
4208
|
142 DEFCMD (mark_as_command, args, , |
4207
|
143 "-*- texinfo -*-\n\ |
4208
|
144 @deftypefn {Built-in Function} {} mark_as_command (@var{name})\n\ |
|
145 Enter @var{name} into the list of commands.\n\ |
5642
|
146 @seealso{unmark_command, iscommand}\n\ |
|
147 @end deftypefn") |
4207
|
148 { |
|
149 octave_value_list retval; |
|
150 |
4208
|
151 if (at_top_level ()) |
|
152 { |
|
153 int nargin = args.length (); |
4207
|
154 |
4208
|
155 if (nargin > 0) |
|
156 { |
|
157 int argc = nargin + 1; |
4207
|
158 |
4208
|
159 string_vector argv = args.make_argv ("mark_as_command"); |
4207
|
160 |
4208
|
161 if (! error_state) |
|
162 { |
|
163 for (int i = 1; i < argc; i++) |
|
164 mark_as_command (argv[i]); |
|
165 } |
4207
|
166 } |
4208
|
167 else |
5823
|
168 print_usage (); |
4207
|
169 } |
|
170 else |
4208
|
171 warning ("mark_as_command: invalid use inside function body"); |
4207
|
172 |
|
173 return retval; |
|
174 } |
|
175 |
4208
|
176 DEFCMD (unmark_command, args, , |
4207
|
177 "-*- texinfo -*-\n\ |
5102
|
178 @deftypefn {Built-in Function} {} unmark_command (@var{name})\n\ |
4208
|
179 Remove @var{name} from the list of commands.\n\ |
5642
|
180 @seealso{mark_as_command, iscommand}\n\ |
|
181 @end deftypefn") |
4207
|
182 { |
|
183 octave_value_list retval; |
|
184 |
4208
|
185 if (at_top_level ()) |
|
186 { |
|
187 int nargin = args.length (); |
4207
|
188 |
4208
|
189 if (nargin > 0) |
|
190 { |
|
191 int argc = nargin + 1; |
4207
|
192 |
4208
|
193 string_vector argv = args.make_argv ("unmark_command"); |
4207
|
194 |
4208
|
195 if (! error_state) |
|
196 { |
|
197 for (int i = 1; i < argc; i++) |
|
198 unmark_command (argv[i]); |
|
199 } |
4207
|
200 } |
4208
|
201 else |
5823
|
202 print_usage (); |
4207
|
203 } |
|
204 else |
4208
|
205 warning ("mark_as_command: invalid use inside function body"); |
4207
|
206 |
|
207 return retval; |
|
208 } |
|
209 |
1827
|
210 bool |
4208
|
211 is_command_name (const std::string& s) |
593
|
212 { |
4207
|
213 bool retval = false; |
|
214 |
4009
|
215 symbol_record *sr = fbi_sym_tab->lookup (s); |
4207
|
216 |
|
217 if (sr) |
|
218 { |
4208
|
219 if (sr->is_command ()) |
4207
|
220 retval = true; |
4208
|
221 else if (is_marked_as_command (s)) |
4207
|
222 { |
4208
|
223 sr->mark_as_command (); |
4207
|
224 retval = true; |
|
225 } |
|
226 } |
|
227 else |
4208
|
228 retval = is_marked_as_command (s); |
4207
|
229 |
|
230 return retval; |
593
|
231 } |
|
232 |
5102
|
233 DEFCMD (iscommand, args, , |
|
234 "-*- texinfo -*-\n\ |
|
235 @deftypefn {Built-in Function} {} iscommand (@var{name})\n\ |
|
236 Return true if @var{name} is a command style function. If @var{name}\n\ |
|
237 is omitted, return a list of identifiers which are marked as commands with\n\ |
|
238 mark_as_command.\n\ |
5642
|
239 @seealso{mark_as_command, unmark_command}\n\ |
|
240 @end deftypefn") |
5102
|
241 { |
|
242 octave_value retval; |
|
243 |
|
244 int nargin = args.length (); |
|
245 |
|
246 if (nargin == 0) |
|
247 { |
|
248 string_vector lst (command_set.size ()); |
|
249 |
|
250 int i = 0; |
|
251 for (std::set<std::string>::const_iterator p = command_set.begin (); |
|
252 p != command_set.end (); p++) |
|
253 lst[i++] = *p; |
|
254 |
|
255 retval = Cell (lst.qsort ()); |
|
256 } |
|
257 else if (nargin == 1) |
|
258 { |
|
259 string_vector argv = args.make_argv ("iscommand"); |
|
260 |
|
261 if (! error_state) |
|
262 { |
|
263 std::string s = argv[1]; |
|
264 retval = is_command_name(s); |
|
265 } |
|
266 } |
|
267 else |
5823
|
268 print_usage (); |
5102
|
269 |
|
270 return retval; |
|
271 } |
|
272 |
|
273 // Is this a raw input command? |
|
274 |
|
275 static std::set <std::string> rawcommand_set; |
|
276 |
5685
|
277 bool |
5102
|
278 is_marked_as_rawcommand (const std::string& s) |
|
279 { |
|
280 return rawcommand_set.find (s) != rawcommand_set.end (); |
|
281 } |
|
282 |
5685
|
283 void |
5102
|
284 mark_as_rawcommand (const std::string& s) |
|
285 { |
|
286 command_set.insert (s); |
|
287 rawcommand_set.insert (s); |
|
288 } |
|
289 |
5685
|
290 void |
5102
|
291 unmark_rawcommand (const std::string& s) |
|
292 { |
|
293 rawcommand_set.erase (s); |
|
294 |
|
295 symbol_record *sr = fbi_sym_tab->lookup (s); |
|
296 |
|
297 if (sr) |
|
298 sr->unmark_rawcommand (); |
|
299 } |
|
300 |
|
301 DEFCMD (mark_as_rawcommand, args, , |
|
302 "-*- texinfo -*-\n\ |
|
303 @deftypefn {Built-in Function} {} mark_as_rawcommand (@var{name})\n\ |
|
304 Enter @var{name} into the list of raw input commands and to the list of\n\ |
|
305 command style functions.\n\ |
|
306 Raw input commands are like normal command style functions, but they\n\ |
|
307 receive their input unprocessed (ie. strings still contain the quotes\n\ |
|
308 and escapes they had when input). However, comments and continuations\n\ |
|
309 are handled as usual, you cannot pass a token starting with a comment\n\ |
|
310 character ('#' or '%') to your function, and the last token cannot be\n\ |
|
311 a continuation token ('\\' or '...').\n\ |
5642
|
312 @seealso{unmark_rawcommand, israwcommand, iscommand, mark_as_command}\n\ |
|
313 @end deftypefn") |
5102
|
314 { |
|
315 octave_value_list retval; |
|
316 |
|
317 if (at_top_level ()) |
|
318 { |
|
319 int nargin = args.length (); |
|
320 |
|
321 if (nargin > 0) |
|
322 { |
|
323 int argc = nargin + 1; |
|
324 |
|
325 string_vector argv = args.make_argv ("mark_as_rawcommand"); |
|
326 |
|
327 if (! error_state) |
|
328 { |
|
329 for (int i = 1; i < argc; i++) |
|
330 mark_as_rawcommand (argv[i]); |
|
331 } |
|
332 } |
|
333 else |
5823
|
334 print_usage (); |
5102
|
335 } |
|
336 else |
|
337 warning ("mark_as_rawcommand: invalid use inside function body"); |
|
338 |
|
339 return retval; |
|
340 } |
|
341 |
|
342 DEFCMD (unmark_rawcommand, args, , |
|
343 "-*- texinfo -*-\n\ |
|
344 @deftypefn {Built-in Function} {} unmark_rawcommand (@var{name})\n\ |
|
345 Remove @var{name} from the list of raw input commands.\n\ |
|
346 Note that this does not remove @var{name} from the list of command style\n\ |
|
347 functions.\n\ |
5642
|
348 @seealso{mark_as_rawcommand, israwcommand, iscommand, unmark_command}\n\ |
|
349 @end deftypefn") |
5102
|
350 { |
|
351 octave_value_list retval; |
|
352 |
|
353 if (at_top_level ()) |
|
354 { |
|
355 int nargin = args.length (); |
|
356 |
|
357 if (nargin > 0) |
|
358 { |
|
359 int argc = nargin + 1; |
|
360 |
|
361 string_vector argv = args.make_argv ("unmark_rawcommand"); |
|
362 |
|
363 if (! error_state) |
|
364 { |
|
365 for (int i = 1; i < argc; i++) |
|
366 unmark_rawcommand (argv[i]); |
|
367 } |
|
368 } |
|
369 else |
5823
|
370 print_usage (); |
5102
|
371 } |
|
372 else |
|
373 warning ("unmark_rawcommand: invalid use inside function body"); |
|
374 |
|
375 return retval; |
|
376 } |
|
377 |
|
378 bool |
|
379 is_rawcommand_name (const std::string& s) |
|
380 { |
|
381 bool retval = false; |
|
382 |
|
383 symbol_record *sr = fbi_sym_tab->lookup (s); |
|
384 |
|
385 if (sr) |
|
386 { |
|
387 if (sr->is_rawcommand ()) |
|
388 retval = true; |
|
389 else if (is_marked_as_rawcommand (s)) |
|
390 { |
|
391 sr->mark_as_rawcommand (); |
|
392 retval = true; |
|
393 } |
|
394 } |
|
395 else |
|
396 retval = is_marked_as_rawcommand (s); |
|
397 |
|
398 return retval; |
|
399 } |
|
400 |
|
401 DEFCMD (israwcommand, args, , |
|
402 "-*- texinfo -*-\n\ |
|
403 @deftypefn {Built-in Function} {} israwcommand (@var{name})\n\ |
|
404 Return true if @var{name} is a raw input command function.\n\ |
|
405 If @var{name} is omitted, return a list of identifiers which are marked as\n\ |
|
406 raw input commands with mark_as_rawcommand.\n\ |
5642
|
407 @seealso{mark_as_rawcommand, unmark_rawcommand}\n\ |
|
408 @end deftypefn") |
5102
|
409 { |
|
410 octave_value retval; |
|
411 |
|
412 int nargin = args.length (); |
|
413 |
|
414 if (nargin == 0) |
|
415 { |
|
416 string_vector lst (rawcommand_set.size()); |
|
417 |
|
418 int i = 0; |
|
419 for (std::set<std::string>::const_iterator p = rawcommand_set.begin (); |
|
420 p != rawcommand_set.end (); |
|
421 p++) |
|
422 lst[i++] = *p; |
|
423 |
|
424 retval = Cell (lst.qsort ()); |
|
425 } |
|
426 else if (nargin == 1) |
|
427 { |
|
428 string_vector argv = args.make_argv ("israwcommand"); |
|
429 |
|
430 if (! error_state) |
|
431 { |
|
432 std::string s = argv[1]; |
|
433 retval = is_rawcommand_name(s); |
|
434 } |
|
435 } |
|
436 else |
5823
|
437 print_usage (); |
5102
|
438 |
|
439 return retval; |
|
440 } |
|
441 |
3355
|
442 // Is this a built-in function? |
2294
|
443 |
|
444 bool |
3523
|
445 is_builtin_function_name (const std::string& s) |
2294
|
446 { |
4009
|
447 symbol_record *sr = fbi_sym_tab->lookup (s); |
2294
|
448 return (sr && sr->is_builtin_function ()); |
|
449 } |
|
450 |
|
451 // Is this a mapper function? |
|
452 |
|
453 bool |
3523
|
454 is_mapper_function_name (const std::string& s) |
2294
|
455 { |
4009
|
456 symbol_record *sr = fbi_sym_tab->lookup (s); |
2294
|
457 return (sr && sr->is_mapper_function ()); |
|
458 } |
|
459 |
593
|
460 // Is this function globally in this scope? |
|
461 |
1827
|
462 bool |
3523
|
463 is_globally_visible (const std::string& name) |
593
|
464 { |
2856
|
465 symbol_record *sr = curr_sym_tab->lookup (name); |
593
|
466 return (sr && sr->is_linked_to_global ()); |
|
467 } |
|
468 |
2086
|
469 // Is this octave_value a valid function? |
593
|
470 |
2975
|
471 octave_function * |
4345
|
472 is_valid_function (const std::string& fcn_name, |
|
473 const std::string& warn_for, bool warn) |
593
|
474 { |
2975
|
475 octave_function *ans = 0; |
593
|
476 |
|
477 symbol_record *sr = 0; |
1755
|
478 |
|
479 if (! fcn_name.empty ()) |
3618
|
480 { |
4009
|
481 sr = fbi_sym_tab->lookup (fcn_name, true); |
3618
|
482 |
|
483 lookup (sr, false); |
|
484 } |
593
|
485 |
|
486 if (sr) |
2975
|
487 { |
|
488 octave_value tmp = sr->def (); |
|
489 ans = tmp.function_value (true); |
|
490 } |
593
|
491 |
|
492 if (! sr || ! ans || ! sr->is_function ()) |
|
493 { |
|
494 if (warn) |
|
495 error ("%s: the symbol `%s' is not valid as a function", |
1755
|
496 warn_for.c_str (), fcn_name.c_str ()); |
593
|
497 ans = 0; |
|
498 } |
|
499 |
|
500 return ans; |
|
501 } |
|
502 |
2975
|
503 octave_function * |
4345
|
504 is_valid_function (const octave_value& arg, |
|
505 const std::string& warn_for, bool warn) |
3178
|
506 { |
|
507 octave_function *ans = 0; |
|
508 |
3523
|
509 std::string fcn_name; |
3178
|
510 |
|
511 if (arg.is_string ()) |
4700
|
512 { |
|
513 fcn_name = arg.string_value (); |
3178
|
514 |
4700
|
515 if (! error_state) |
|
516 ans = is_valid_function (fcn_name, warn_for, warn); |
|
517 else if (warn) |
|
518 error ("%s: expecting function name as argument", warn_for.c_str ()); |
|
519 } |
3178
|
520 else if (warn) |
|
521 error ("%s: expecting function name as argument", warn_for.c_str ()); |
|
522 |
|
523 return ans; |
|
524 } |
|
525 |
|
526 octave_function * |
3523
|
527 extract_function (const octave_value& arg, const std::string& warn_for, |
|
528 const std::string& fname, const std::string& header, |
|
529 const std::string& trailer) |
2796
|
530 { |
2975
|
531 octave_function *retval = 0; |
2796
|
532 |
|
533 retval = is_valid_function (arg, warn_for, 0); |
|
534 |
|
535 if (! retval) |
|
536 { |
3523
|
537 std::string s = arg.string_value (); |
2796
|
538 |
3523
|
539 std::string cmd = header; |
2796
|
540 cmd.append (s); |
|
541 cmd.append (trailer); |
|
542 |
|
543 if (! error_state) |
|
544 { |
|
545 int parse_status; |
|
546 |
2898
|
547 eval_string (cmd, true, parse_status); |
2796
|
548 |
|
549 if (parse_status == 0) |
|
550 { |
|
551 retval = is_valid_function (fname, warn_for, 0); |
|
552 |
|
553 if (! retval) |
|
554 { |
|
555 error ("%s: `%s' is not valid as a function", |
|
556 warn_for.c_str (), fname.c_str ()); |
|
557 return retval; |
|
558 } |
|
559 } |
|
560 else |
|
561 error ("%s: `%s' is not valid as a function", |
|
562 warn_for.c_str (), fname.c_str ()); |
|
563 } |
|
564 else |
|
565 error ("%s: expecting first argument to be a string", |
|
566 warn_for.c_str ()); |
|
567 } |
|
568 |
|
569 return retval; |
|
570 } |
|
571 |
2921
|
572 string_vector |
3523
|
573 get_struct_elts (const std::string& text) |
2921
|
574 { |
|
575 int n = 1; |
|
576 |
|
577 size_t pos = 0; |
|
578 |
|
579 size_t len = text.length (); |
|
580 |
|
581 while ((pos = text.find ('.', pos)) != NPOS) |
|
582 { |
|
583 if (++pos == len) |
|
584 break; |
|
585 |
|
586 n++; |
|
587 } |
|
588 |
|
589 string_vector retval (n); |
|
590 |
|
591 pos = 0; |
|
592 |
|
593 for (int i = 0; i < n; i++) |
|
594 { |
4587
|
595 len = text.find ('.', pos); |
2921
|
596 |
|
597 if (len != NPOS) |
|
598 len -= pos; |
|
599 |
|
600 retval[i] = text.substr (pos, len); |
|
601 |
|
602 if (len != NPOS) |
|
603 pos += len + 1; |
|
604 } |
|
605 |
|
606 return retval; |
|
607 } |
|
608 |
4179
|
609 static inline bool |
|
610 is_variable (const std::string& name) |
|
611 { |
|
612 bool retval = false; |
|
613 |
|
614 if (! name.empty ()) |
|
615 { |
|
616 symbol_record *sr = curr_sym_tab->lookup (name); |
|
617 |
|
618 if (! sr) |
|
619 sr = fbi_sym_tab->lookup (name); |
|
620 |
|
621 retval = (sr && sr->is_variable ()); |
|
622 } |
|
623 |
|
624 return retval; |
|
625 } |
|
626 |
2921
|
627 string_vector |
3933
|
628 generate_struct_completions (const std::string& text, |
|
629 std::string& prefix, std::string& hint) |
2921
|
630 { |
|
631 string_vector names; |
|
632 |
|
633 size_t pos = text.rfind ('.'); |
|
634 |
3933
|
635 if (pos != NPOS) |
2921
|
636 { |
|
637 if (pos == text.length ()) |
|
638 hint = ""; |
|
639 else |
|
640 hint = text.substr (pos+1); |
|
641 |
|
642 prefix = text.substr (0, pos); |
|
643 |
4179
|
644 std::string base_name = prefix; |
|
645 |
|
646 pos = base_name.find_first_of ("{(."); |
2921
|
647 |
4179
|
648 if (pos != NPOS) |
|
649 base_name = base_name.substr (0, pos); |
4143
|
650 |
4179
|
651 if (is_variable (base_name)) |
|
652 { |
|
653 int parse_status; |
|
654 |
|
655 unwind_protect::begin_frame ("generate_struct_completions"); |
3935
|
656 |
4452
|
657 unwind_protect_int (error_state); |
|
658 unwind_protect_int (warning_state); |
|
659 |
4179
|
660 unwind_protect_bool (discard_error_messages); |
4452
|
661 unwind_protect_bool (discard_warning_messages); |
3935
|
662 |
4179
|
663 discard_error_messages = true; |
4452
|
664 discard_warning_messages = true; |
2921
|
665 |
4179
|
666 octave_value tmp = eval_string (prefix, true, parse_status); |
|
667 |
|
668 unwind_protect::run_frame ("generate_struct_completions"); |
3935
|
669 |
4179
|
670 if (tmp.is_defined () && tmp.is_map ()) |
|
671 names = tmp.map_keys (); |
|
672 } |
|
673 } |
2921
|
674 |
|
675 return names; |
|
676 } |
|
677 |
5775
|
678 // FIXME -- this will have to be much smarter to work |
4179
|
679 // "correctly". |
|
680 |
2921
|
681 bool |
3523
|
682 looks_like_struct (const std::string& text) |
2921
|
683 { |
4604
|
684 bool retval = (! text.empty () |
|
685 && text != "." |
|
686 && text.find_first_of (file_ops::dir_sep_chars) == NPOS |
|
687 && text.find ("..") == NPOS |
|
688 && text.rfind ('.') != NPOS); |
3968
|
689 |
4179
|
690 #if 0 |
3968
|
691 symbol_record *sr = curr_sym_tab->lookup (text); |
2963
|
692 |
3968
|
693 if (sr && ! sr->is_function ()) |
|
694 { |
|
695 int parse_status; |
2921
|
696 |
4143
|
697 unwind_protect::begin_frame ("looks_like_struct"); |
|
698 |
|
699 unwind_protect_bool (discard_error_messages); |
|
700 unwind_protect_int (error_state); |
|
701 |
|
702 discard_error_messages = true; |
|
703 |
3968
|
704 octave_value tmp = eval_string (text, true, parse_status); |
|
705 |
4143
|
706 unwind_protect::run_frame ("looks_like_struct"); |
|
707 |
3968
|
708 retval = (tmp.is_defined () && tmp.is_map ()); |
|
709 } |
4179
|
710 #endif |
3968
|
711 |
|
712 return retval; |
2921
|
713 } |
2796
|
714 |
5930
|
715 static octave_value |
|
716 do_isglobal (const octave_value_list& args) |
593
|
717 { |
4233
|
718 octave_value retval = false; |
593
|
719 |
712
|
720 int nargin = args.length (); |
|
721 |
|
722 if (nargin != 1) |
593
|
723 { |
5823
|
724 print_usage (); |
593
|
725 return retval; |
|
726 } |
|
727 |
3523
|
728 std::string name = args(0).string_value (); |
593
|
729 |
636
|
730 if (error_state) |
|
731 { |
4028
|
732 error ("isglobal: expecting std::string argument"); |
636
|
733 return retval; |
|
734 } |
|
735 |
2856
|
736 symbol_record *sr = curr_sym_tab->lookup (name); |
593
|
737 |
4233
|
738 retval = (sr && sr->is_linked_to_global ()); |
593
|
739 |
|
740 return retval; |
|
741 } |
|
742 |
5930
|
743 DEFUN (isglobal, args, , |
|
744 "-*- texinfo -*-\n\ |
|
745 @deftypefn {Built-in Function} {} isglobal (@var{name})\n\ |
|
746 Return 1 if @var{name} is globally visible. Otherwise, return 0. For\n\ |
|
747 example,\n\ |
|
748 \n\ |
|
749 @example\n\ |
|
750 @group\n\ |
|
751 global x\n\ |
|
752 isglobal (\"x\")\n\ |
|
753 @result{} 1\n\ |
|
754 @end group\n\ |
|
755 @end example\n\ |
|
756 @end deftypefn") |
|
757 { |
|
758 return do_isglobal (args); |
|
759 } |
|
760 |
|
761 DEFUN (is_global, args, , |
|
762 "-*- texinfo -*-\n\ |
|
763 @deftypefn {Built-in Function} {} isglobal (@var{name})\n\ |
|
764 This function has been deprecated. Use isglobal instead.\n\ |
|
765 @end deftypefn") |
|
766 { |
|
767 return do_isglobal (args); |
|
768 } |
|
769 |
4016
|
770 int |
|
771 symbol_exist (const std::string& name, const std::string& type) |
593
|
772 { |
4016
|
773 int retval = 0; |
636
|
774 |
3523
|
775 std::string struct_elts; |
|
776 std::string symbol_name = name; |
1755
|
777 |
|
778 size_t pos = name.find ('.'); |
|
779 |
2790
|
780 if (pos != NPOS && pos > 0) |
1277
|
781 { |
1755
|
782 struct_elts = name.substr (pos+1); |
2790
|
783 symbol_name = name.substr (0, pos); |
1277
|
784 } |
|
785 |
4009
|
786 // We shouldn't need to look in the global symbol table, since any |
|
787 // name that is visible in the current scope will be in the local |
|
788 // symbol table. |
|
789 |
2856
|
790 symbol_record *sr = curr_sym_tab->lookup (symbol_name); |
593
|
791 |
4009
|
792 if (! (sr && sr->is_defined ())) |
|
793 sr = fbi_sym_tab->lookup (symbol_name); |
593
|
794 |
4009
|
795 if (sr && sr->is_defined ()) |
1277
|
796 { |
4357
|
797 bool not_a_struct = struct_elts.empty (); |
|
798 bool var_ok = not_a_struct || sr->is_map_element (struct_elts); |
|
799 |
4016
|
800 if (! retval |
4357
|
801 && var_ok |
4016
|
802 && (type == "any" || type == "var") |
4357
|
803 && sr->is_user_variable ()) |
4009
|
804 { |
4016
|
805 retval = 1; |
4009
|
806 } |
4016
|
807 |
|
808 if (! retval |
|
809 && (type == "any" || type == "builtin")) |
4009
|
810 { |
4357
|
811 if (not_a_struct && sr->is_builtin_function ()) |
4016
|
812 { |
|
813 retval = 5; |
|
814 } |
4009
|
815 } |
4016
|
816 |
|
817 if (! retval |
4357
|
818 && not_a_struct |
4016
|
819 && (type == "any" || type == "file") |
|
820 && (sr->is_user_function () || sr->is_dld_function ())) |
4009
|
821 { |
4261
|
822 octave_value t = sr->def (); |
4016
|
823 octave_function *f = t.function_value (true); |
|
824 std::string s = f ? f->fcn_file_name () : std::string (); |
|
825 |
4438
|
826 retval = s.empty () ? 103 : (sr->is_user_function () ? 2 : 3); |
4009
|
827 } |
1421
|
828 } |
4016
|
829 |
5140
|
830 if (! (type == "var" || type == "builtin")) |
593
|
831 { |
5140
|
832 if (! retval) |
593
|
833 { |
5484
|
834 std::string file_name = lookup_autoload (name); |
|
835 |
|
836 if (file_name.empty ()) |
5832
|
837 file_name = load_path::find_fcn (name); |
5140
|
838 |
|
839 size_t len = file_name.length (); |
|
840 |
5832
|
841 if (len > 0) |
4437
|
842 { |
5140
|
843 if (type == "any" || type == "file") |
|
844 { |
5864
|
845 if (len > 4 && (file_name.substr (len-4) == ".oct" |
|
846 || file_name.substr (len-4) == ".mex")) |
5140
|
847 retval = 3; |
|
848 else |
|
849 retval = 2; |
|
850 } |
4437
|
851 } |
593
|
852 } |
5140
|
853 |
|
854 if (! retval) |
593
|
855 { |
5140
|
856 std::string file_name = file_in_path (name, ""); |
|
857 |
|
858 if (file_name.empty ()) |
|
859 file_name = name; |
|
860 |
|
861 file_stat fs (file_name); |
|
862 |
|
863 if (fs) |
1421
|
864 { |
5140
|
865 if ((type == "any" || type == "file") |
|
866 && fs.is_reg ()) |
|
867 { |
|
868 retval = 2; |
|
869 } |
|
870 else if ((type == "any" || type == "dir") |
|
871 && fs.is_dir ()) |
|
872 { |
|
873 retval = 7; |
|
874 } |
1421
|
875 } |
593
|
876 } |
|
877 } |
|
878 |
|
879 return retval; |
|
880 } |
|
881 |
4962
|
882 #define GET_IDX(LEN) \ |
|
883 static_cast<int> ((LEN-1) * static_cast<double> (rand ()) / RAND_MAX) |
|
884 |
4954
|
885 std::string |
|
886 unique_symbol_name (const std::string& basename) |
|
887 { |
4962
|
888 static const std::string alpha |
|
889 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|
890 |
|
891 static size_t len = alpha.length (); |
|
892 |
|
893 std::string nm = basename + alpha[GET_IDX (len)]; |
|
894 |
|
895 size_t pos = nm.length (); |
|
896 |
|
897 if (nm.substr (0, 2) == "__") |
|
898 nm.append ("__"); |
|
899 |
|
900 while (symbol_exist (nm, "any")) |
|
901 nm.insert (pos++, 1, alpha[GET_IDX (len)]); |
|
902 |
|
903 return nm; |
4954
|
904 } |
|
905 |
4016
|
906 DEFUN (exist, args, , |
|
907 "-*- texinfo -*-\n\ |
|
908 @deftypefn {Built-in Function} {} exist (@var{name}, @var{type})\n\ |
|
909 Return 1 if the name exists as a variable, 2 if the name (after\n\ |
5814
|
910 appending @samp{.m}) is a function file in Octave's @code{path}, 3 if the\n\ |
5864
|
911 name is a @samp{.oct} or @samp{.mex} file in Octave's @code{path},\n\ |
|
912 5 if the name is a built-in function, 7 if the name is a directory, or 103\n\ |
4016
|
913 if the name is a function not associated with a file (entered on\n\ |
|
914 the command line).\n\ |
|
915 \n\ |
|
916 Otherwise, return 0.\n\ |
|
917 \n\ |
|
918 This function also returns 2 if a regular file called @var{name}\n\ |
5814
|
919 exists in Octave's search path. If you want information about\n\ |
4016
|
920 other types of files, you should use some combination of the functions\n\ |
|
921 @code{file_in_path} and @code{stat} instead.\n\ |
|
922 \n\ |
|
923 If the optional argument @var{type} is supplied, check only for\n\ |
|
924 symbols of the specified type. Valid types are\n\ |
|
925 \n\ |
|
926 @table @samp\n\ |
|
927 @item \"var\"\n\ |
|
928 Check only for variables.\n\ |
|
929 @item \"builtin\"\n\ |
|
930 Check only for built-in functions.\n\ |
|
931 @item \"file\"\n\ |
|
932 Check only for files.\n\ |
|
933 @item \"dir\"\n\ |
|
934 Check only for directories.\n\ |
|
935 @end table\n\ |
|
936 @end deftypefn") |
|
937 { |
4233
|
938 octave_value retval = false; |
4016
|
939 |
|
940 int nargin = args.length (); |
|
941 |
|
942 if (nargin == 1 || nargin == 2) |
|
943 { |
|
944 std::string name = args(0).string_value (); |
|
945 |
|
946 if (! error_state) |
|
947 { |
|
948 std::string type |
|
949 = (nargin == 2) ? args(1).string_value () : std::string ("any"); |
|
950 |
|
951 if (! error_state) |
4233
|
952 retval = symbol_exist (name, type); |
4016
|
953 else |
|
954 error ("exist: expecting second argument to be a string"); |
|
955 } |
|
956 else |
|
957 error ("exist: expecting first argument to be a string"); |
|
958 } |
|
959 else |
5823
|
960 print_usage (); |
4016
|
961 |
|
962 return retval; |
|
963 } |
|
964 |
5138
|
965 // Return TRUE if F and G are both names for the same file. |
|
966 |
|
967 static bool |
|
968 same_file (const std::string& f, const std::string& g) |
|
969 { |
|
970 std::string c_f = file_ops::canonicalize_file_name (f); |
|
971 std::string c_g = file_ops::canonicalize_file_name (g); |
|
972 |
|
973 file_stat f_fs (c_f); |
|
974 file_stat g_fs (c_g); |
|
975 |
|
976 return (f_fs.ino () == g_fs.ino () && f_fs.dev () == g_fs.dev ()); |
|
977 } |
|
978 |
5663
|
979 bool |
5397
|
980 fcn_out_of_date (octave_function *fcn, const std::string& ff, time_t tp) |
5312
|
981 { |
|
982 bool retval = false; |
|
983 |
5397
|
984 fcn->mark_fcn_file_up_to_date (octave_time ()); |
|
985 |
|
986 if (! (Vignore_function_time_stamp == 2 |
|
987 || (Vignore_function_time_stamp && fcn->is_system_fcn_file ()))) |
5312
|
988 { |
5397
|
989 file_stat fs (ff); |
|
990 |
|
991 if (fs && fs.is_newer (tp)) |
|
992 retval = true; |
5312
|
993 } |
|
994 |
|
995 return retval; |
|
996 } |
|
997 |
5397
|
998 // Is there a corresponding function file that is newer than the |
|
999 // symbol definition? |
|
1000 |
5312
|
1001 static bool |
1
|
1002 symbol_out_of_date (symbol_record *sr) |
|
1003 { |
2926
|
1004 bool retval = false; |
195
|
1005 |
5397
|
1006 if (sr) |
1
|
1007 { |
2975
|
1008 octave_value ans = sr->def (); |
|
1009 |
5397
|
1010 octave_function *fcn = ans.function_value (true); |
|
1011 |
5436
|
1012 // No need to check nested functions. They can only be executed |
5437
|
1013 // from within the parent function that contains them. Parent |
5436
|
1014 // and nested functions will be updated simultaneously when we |
|
1015 // check the parent. |
|
1016 |
|
1017 if (fcn && ! fcn->is_nested_function ()) |
5397
|
1018 { |
|
1019 std::string ff = fcn->fcn_file_name (); |
|
1020 |
|
1021 if (! ff.empty ()) |
|
1022 { |
|
1023 if (fcn->time_checked () < Vlast_prompt_time) |
|
1024 { |
|
1025 time_t tp = fcn->time_parsed (); |
|
1026 |
|
1027 std::string nm = fcn->name (); |
|
1028 |
5775
|
1029 // FIXME -- the following code is repeated |
5534
|
1030 // in load_fcn_from_file in parse.y. |
|
1031 |
5397
|
1032 string_vector names (2); |
|
1033 |
5534
|
1034 int nm_len = nm.length (); |
|
1035 |
|
1036 std::string file; |
|
1037 |
|
1038 if (octave_env::absolute_pathname (nm) |
5864
|
1039 && ((nm_len > 4 && (nm.substr (nm_len-4) == ".oct" |
|
1040 || nm.substr (nm_len-4) == ".mex")) |
5534
|
1041 || (nm_len > 2 && nm.substr (nm_len-4) == ".m"))) |
|
1042 { |
|
1043 file = nm; |
|
1044 } |
|
1045 else |
|
1046 { |
|
1047 file = lookup_autoload (nm); |
|
1048 |
|
1049 if (file.empty ()) |
|
1050 { |
|
1051 file = octave_env::make_absolute |
5832
|
1052 (load_path::find_fcn (nm), octave_env::getcwd ()); |
5534
|
1053 } |
|
1054 } |
5397
|
1055 |
|
1056 if (same_file (file, ff)) |
|
1057 { |
|
1058 retval = fcn_out_of_date (fcn, ff, tp); |
|
1059 } |
|
1060 else |
|
1061 { |
|
1062 // Check the full function name. Maybe we alrady |
|
1063 // parsed it. |
|
1064 |
|
1065 symbol_record *full_sr = fbi_sym_tab->lookup (file); |
|
1066 |
|
1067 if (full_sr) |
|
1068 { |
|
1069 octave_value v = full_sr->def (); |
|
1070 |
|
1071 if (v.is_function ()) |
|
1072 { |
|
1073 // OK, swap the aliases around. |
|
1074 |
5775
|
1075 // FIXME -- this is a bit |
5397
|
1076 // tricky, so maybe some refactoring is |
|
1077 // in order here too... |
|
1078 |
|
1079 symbol_record *short_sr = fbi_sym_tab->lookup (nm); |
|
1080 |
|
1081 if (short_sr) |
|
1082 short_sr->alias (full_sr); |
|
1083 |
|
1084 // Make local symbol table entry point |
|
1085 // to correct global function too. |
|
1086 |
|
1087 sr->alias (full_sr); |
|
1088 |
|
1089 fcn = v.function_value (); |
|
1090 |
|
1091 retval = fcn_out_of_date (fcn, file, tp); |
|
1092 } |
|
1093 else |
|
1094 retval = true; |
|
1095 } |
|
1096 else |
|
1097 retval = true; |
|
1098 } |
|
1099 } |
|
1100 } |
|
1101 } |
1
|
1102 } |
2926
|
1103 |
|
1104 return retval; |
1
|
1105 } |
|
1106 |
1827
|
1107 bool |
2856
|
1108 lookup (symbol_record *sym_rec, bool exec_script) |
581
|
1109 { |
1827
|
1110 bool script_executed = false; |
581
|
1111 |
|
1112 if (! sym_rec->is_linked_to_global ()) |
|
1113 { |
|
1114 if (sym_rec->is_defined ()) |
|
1115 { |
|
1116 if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) |
1271
|
1117 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
1118 } |
|
1119 else if (! sym_rec->is_formal_parameter ()) |
|
1120 { |
|
1121 link_to_builtin_or_function (sym_rec); |
1271
|
1122 |
581
|
1123 if (! sym_rec->is_defined ()) |
1271
|
1124 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
1125 else if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) |
1271
|
1126 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
1127 } |
|
1128 } |
|
1129 |
1271
|
1130 return script_executed; |
581
|
1131 } |
|
1132 |
|
1133 // Get the symbol record for the given name that is visible in the |
|
1134 // current scope. Reread any function definitions that appear to be |
|
1135 // out of date. If a function is available in a file but is not |
|
1136 // currently loaded, this will load it and insert the name in the |
|
1137 // current symbol table. |
|
1138 |
|
1139 symbol_record * |
3523
|
1140 lookup_by_name (const std::string& nm, bool exec_script) |
581
|
1141 { |
2856
|
1142 symbol_record *sym_rec = curr_sym_tab->lookup (nm, true); |
581
|
1143 |
|
1144 lookup (sym_rec, exec_script); |
|
1145 |
|
1146 return sym_rec; |
|
1147 } |
|
1148 |
4930
|
1149 octave_value |
4342
|
1150 lookup_function (const std::string& nm) |
|
1151 { |
4930
|
1152 octave_value retval; |
4342
|
1153 |
|
1154 symbol_record *sr = 0; |
|
1155 |
|
1156 if (curr_parent_function) |
|
1157 { |
4748
|
1158 std::string parent = curr_parent_function->name (); |
4342
|
1159 |
|
1160 sr = fbi_sym_tab->lookup (parent + ":" + nm); |
|
1161 } |
|
1162 |
|
1163 if (! sr || ! sr->is_function ()) |
|
1164 { |
|
1165 sr = fbi_sym_tab->lookup (nm, true); |
|
1166 |
|
1167 if (sr && ! sr->is_function ()) |
|
1168 load_fcn_from_file (sr, false); |
|
1169 } |
|
1170 |
|
1171 if (sr) |
|
1172 { |
|
1173 octave_value v = sr->def (); |
|
1174 |
|
1175 if (v.is_function ()) |
4930
|
1176 retval = v; |
4342
|
1177 } |
|
1178 |
|
1179 return retval; |
|
1180 } |
|
1181 |
4930
|
1182 octave_value |
4700
|
1183 lookup_user_function (const std::string& nm) |
|
1184 { |
4930
|
1185 octave_value retval; |
4700
|
1186 |
|
1187 symbol_record *sr = 0; |
|
1188 |
|
1189 if (curr_parent_function) |
|
1190 { |
4748
|
1191 std::string parent = curr_parent_function->name (); |
4700
|
1192 |
|
1193 sr = fbi_sym_tab->lookup (parent + ":" + nm); |
|
1194 } |
|
1195 |
|
1196 if (! sr || ! sr->is_user_function ()) |
|
1197 { |
|
1198 sr = fbi_sym_tab->lookup (nm, true); |
|
1199 |
|
1200 if (sr && ! sr->is_user_function ()) |
|
1201 load_fcn_from_file (sr, false); |
|
1202 } |
|
1203 |
|
1204 if (sr) |
4930
|
1205 retval = sr->def (); |
4700
|
1206 |
|
1207 return retval; |
|
1208 } |
|
1209 |
2849
|
1210 octave_value |
4988
|
1211 lookup_function_handle (const std::string& nm) |
|
1212 { |
|
1213 octave_value retval; |
|
1214 |
|
1215 symbol_record *sr = curr_sym_tab->lookup (nm, true); |
|
1216 |
|
1217 if (sr && sr->def ().is_function_handle ()) |
|
1218 retval = sr->def (); |
|
1219 |
|
1220 return retval; |
|
1221 } |
|
1222 |
|
1223 octave_value |
5027
|
1224 get_global_value (const std::string& nm, bool silent) |
2849
|
1225 { |
|
1226 octave_value retval; |
|
1227 |
|
1228 symbol_record *sr = global_sym_tab->lookup (nm); |
|
1229 |
|
1230 if (sr) |
|
1231 { |
2975
|
1232 octave_value sr_def = sr->def (); |
2849
|
1233 |
5027
|
1234 if (sr_def.is_defined ()) |
|
1235 retval = sr_def; |
|
1236 else if (! silent) |
2849
|
1237 error ("get_global_by_name: undefined symbol `%s'", nm.c_str ()); |
|
1238 } |
5027
|
1239 else if (! silent) |
2849
|
1240 error ("get_global_by_name: unknown symbol `%s'", nm.c_str ()); |
|
1241 |
|
1242 return retval; |
|
1243 } |
|
1244 |
|
1245 void |
3523
|
1246 set_global_value (const std::string& nm, const octave_value& val) |
2849
|
1247 { |
2856
|
1248 symbol_record *sr = global_sym_tab->lookup (nm, true); |
2849
|
1249 |
|
1250 if (sr) |
|
1251 sr->define (val); |
|
1252 else |
|
1253 panic_impossible (); |
|
1254 } |
|
1255 |
593
|
1256 // Variable values. |
195
|
1257 |
5791
|
1258 octave_value |
|
1259 set_internal_variable (bool& var, const octave_value_list& args, |
5794
|
1260 int nargout, const char *nm) |
5791
|
1261 { |
5794
|
1262 octave_value retval; |
|
1263 |
5800
|
1264 int nargin = args.length (); |
|
1265 |
|
1266 if (nargout > 0 || nargin == 0) |
5794
|
1267 retval = var; |
5791
|
1268 |
|
1269 if (nargin == 1) |
|
1270 { |
|
1271 bool bval = args(0).bool_value (); |
|
1272 |
|
1273 if (! error_state) |
|
1274 var = bval; |
|
1275 else |
|
1276 error ("%s: expecting arg to be a logical value", nm); |
|
1277 } |
|
1278 else if (nargin > 1) |
5823
|
1279 print_usage (); |
5791
|
1280 |
|
1281 return retval; |
|
1282 } |
|
1283 |
|
1284 octave_value |
5794
|
1285 set_internal_variable (char& var, const octave_value_list& args, |
|
1286 int nargout, const char *nm) |
5791
|
1287 { |
5794
|
1288 octave_value retval; |
|
1289 |
5800
|
1290 int nargin = args.length (); |
|
1291 |
|
1292 if (nargout > 0 || nargin == 0) |
5794
|
1293 retval = var; |
5791
|
1294 |
|
1295 if (nargin == 1) |
|
1296 { |
|
1297 std::string sval = args(0).string_value (); |
|
1298 |
|
1299 if (! error_state) |
5794
|
1300 { |
|
1301 switch (sval.length ()) |
|
1302 { |
|
1303 case 1: |
|
1304 var = sval[0]; |
|
1305 break; |
|
1306 |
|
1307 case 0: |
|
1308 var = '\0'; |
|
1309 break; |
|
1310 |
|
1311 default: |
|
1312 error ("%s: argument must be a single character", nm); |
|
1313 break; |
|
1314 } |
|
1315 } |
|
1316 else |
|
1317 error ("%s: argument must be a single character", nm); |
|
1318 } |
|
1319 else if (nargin > 1) |
5823
|
1320 print_usage (); |
5794
|
1321 |
|
1322 return retval; |
|
1323 } |
|
1324 |
|
1325 octave_value |
|
1326 set_internal_variable (int& var, const octave_value_list& args, |
|
1327 int nargout, const char *nm, |
|
1328 int minval, int maxval) |
|
1329 { |
|
1330 octave_value retval; |
|
1331 |
5800
|
1332 int nargin = args.length (); |
|
1333 |
|
1334 if (nargout > 0 || nargin == 0) |
5794
|
1335 retval = var; |
|
1336 |
|
1337 if (nargin == 1) |
|
1338 { |
|
1339 int ival = args(0).int_value (); |
|
1340 |
|
1341 if (! error_state) |
|
1342 { |
|
1343 if (ival < minval) |
|
1344 error ("%s: expecting arg to be greater than %d", minval); |
|
1345 else if (ival > maxval) |
|
1346 error ("%s: expecting arg to be less than or equal to %d", maxval); |
|
1347 else |
|
1348 var = ival; |
|
1349 } |
|
1350 else |
|
1351 error ("%s: expecting arg to be an integer value", nm); |
|
1352 } |
|
1353 else if (nargin > 1) |
5823
|
1354 print_usage (); |
5794
|
1355 |
|
1356 return retval; |
|
1357 } |
|
1358 |
|
1359 octave_value |
|
1360 set_internal_variable (double& var, const octave_value_list& args, |
|
1361 int nargout, const char *nm, |
|
1362 double minval, double maxval) |
|
1363 { |
|
1364 octave_value retval; |
|
1365 |
5800
|
1366 int nargin = args.length (); |
|
1367 |
|
1368 if (nargout > 0 || nargin == 0) |
5794
|
1369 retval = var; |
|
1370 |
|
1371 if (nargin == 1) |
|
1372 { |
|
1373 double dval = args(0).scalar_value (); |
|
1374 |
|
1375 if (! error_state) |
|
1376 { |
|
1377 if (dval < minval) |
|
1378 error ("%s: expecting arg to be greater than %g", minval); |
|
1379 else if (dval > maxval) |
|
1380 error ("%s: expecting arg to be less than or equal to %g", maxval); |
|
1381 else |
|
1382 var = dval; |
|
1383 } |
|
1384 else |
|
1385 error ("%s: expecting arg to be a scalar value", nm); |
|
1386 } |
|
1387 else if (nargin > 1) |
5823
|
1388 print_usage (); |
5794
|
1389 |
|
1390 return retval; |
|
1391 } |
|
1392 |
|
1393 octave_value |
|
1394 set_internal_variable (std::string& var, const octave_value_list& args, |
|
1395 int nargout, const char *nm, bool empty_ok) |
|
1396 { |
|
1397 octave_value retval; |
|
1398 |
5800
|
1399 int nargin = args.length (); |
|
1400 |
|
1401 if (nargout > 0 || nargin == 0) |
5794
|
1402 retval = var; |
|
1403 |
|
1404 if (nargin == 1) |
|
1405 { |
|
1406 std::string sval = args(0).string_value (); |
|
1407 |
|
1408 if (! error_state) |
|
1409 { |
|
1410 if (empty_ok || ! sval.empty ()) |
|
1411 var = sval; |
|
1412 else |
|
1413 error ("%s: value must not be empty", nm); |
|
1414 } |
5791
|
1415 else |
|
1416 error ("%s: expecting arg to be a character string", nm); |
|
1417 } |
|
1418 else if (nargin > 1) |
5823
|
1419 print_usage (); |
1
|
1420 |
|
1421 return retval; |
|
1422 } |
|
1423 |
593
|
1424 // Global stuff and links to builtin variables and functions. |
|
1425 |
581
|
1426 // Make the definition of the symbol record sr be the same as the |
|
1427 // definition of the global variable of the same name, creating it if |
1418
|
1428 // it doesn't already exist. |
581
|
1429 |
195
|
1430 void |
|
1431 link_to_global_variable (symbol_record *sr) |
|
1432 { |
2975
|
1433 if (! sr->is_linked_to_global ()) |
195
|
1434 { |
2975
|
1435 sr->mark_as_linked_to_global (); |
195
|
1436 |
2975
|
1437 if (! error_state) |
|
1438 { |
3523
|
1439 std::string nm = sr->name (); |
2846
|
1440 |
2975
|
1441 symbol_record *gsr = global_sym_tab->lookup (nm, true); |
|
1442 |
|
1443 // Make sure this symbol is a variable. |
2900
|
1444 |
4009
|
1445 if (! gsr->is_user_variable ()) |
2975
|
1446 gsr->define (octave_value ()); |
2900
|
1447 |
4009
|
1448 sr->alias (gsr); |
2975
|
1449 } |
195
|
1450 } |
|
1451 } |
|
1452 |
581
|
1453 // Make the definition of the symbol record sr be the same as the |
|
1454 // definition of the builtin variable of the same name. |
|
1455 |
|
1456 // Make the definition of the symbol record sr be the same as the |
5794
|
1457 // definition of the builtin function, or user function of the same |
|
1458 // name, provided that the name has not been used as a formal parameter. |
581
|
1459 |
195
|
1460 void |
|
1461 link_to_builtin_or_function (symbol_record *sr) |
|
1462 { |
4238
|
1463 std::string nm = sr->name (); |
|
1464 |
|
1465 symbol_record *tmp_sym = 0; |
|
1466 |
|
1467 if (curr_parent_function) |
|
1468 { |
4748
|
1469 std::string parent = curr_parent_function->name (); |
4238
|
1470 |
|
1471 tmp_sym = fbi_sym_tab->lookup (parent + ":" + nm); |
|
1472 } |
|
1473 |
|
1474 if (! tmp_sym) |
|
1475 tmp_sym = fbi_sym_tab->lookup (nm); |
195
|
1476 |
529
|
1477 if (tmp_sym |
5794
|
1478 && tmp_sym->is_function () |
529
|
1479 && ! tmp_sym->is_formal_parameter ()) |
|
1480 sr->alias (tmp_sym); |
195
|
1481 } |
|
1482 |
581
|
1483 // Force a link to a function in the current symbol table. This is |
|
1484 // used just after defining a function to avoid different behavior |
|
1485 // depending on whether or not the function has been evaluated after |
|
1486 // being defined. |
|
1487 // |
|
1488 // Return without doing anything if there isn't a function with the |
|
1489 // given name defined in the global symbol table. |
|
1490 |
195
|
1491 void |
3523
|
1492 force_link_to_function (const std::string& id_name) |
195
|
1493 { |
4009
|
1494 symbol_record *fsr = fbi_sym_tab->lookup (id_name, true); |
|
1495 if (fsr->is_function ()) |
195
|
1496 { |
|
1497 curr_sym_tab->clear (id_name); |
2856
|
1498 symbol_record *csr = curr_sym_tab->lookup (id_name, true); |
4009
|
1499 csr->alias (fsr); |
195
|
1500 } |
|
1501 } |
|
1502 |
2294
|
1503 DEFUN (document, args, , |
3361
|
1504 "-*- texinfo -*-\n\ |
|
1505 @deftypefn {Built-in Function} {} document (@var{symbol}, @var{text})\n\ |
|
1506 Set the documentation string for @var{symbol} to @var{text}.\n\ |
|
1507 @end deftypefn") |
593
|
1508 { |
2294
|
1509 octave_value retval; |
1755
|
1510 |
2294
|
1511 int nargin = args.length (); |
1755
|
1512 |
2294
|
1513 if (nargin == 2) |
593
|
1514 { |
3523
|
1515 std::string name = args(0).string_value (); |
593
|
1516 |
2294
|
1517 if (! error_state) |
593
|
1518 { |
3523
|
1519 std::string help = args(1).string_value (); |
593
|
1520 |
2294
|
1521 if (! error_state) |
|
1522 { |
5794
|
1523 if (is_command_name (name) |
2294
|
1524 || is_mapper_function_name (name) |
|
1525 || is_builtin_function_name (name)) |
5794
|
1526 error ("document: can't redefine help for built-in functions"); |
2294
|
1527 else |
|
1528 { |
2856
|
1529 symbol_record *sym_rec = curr_sym_tab->lookup (name); |
2294
|
1530 |
|
1531 if (sym_rec) |
|
1532 sym_rec->document (help); |
|
1533 else |
|
1534 error ("document: no such symbol `%s'", name.c_str ()); |
|
1535 } |
|
1536 } |
593
|
1537 } |
|
1538 } |
|
1539 else |
5823
|
1540 print_usage (); |
593
|
1541 |
|
1542 return retval; |
|
1543 } |
|
1544 |
5775
|
1545 // FIXME -- this function is duplicated in symtab.cc with the |
5659
|
1546 // name maybe_list_cmp_fcn. |
|
1547 |
|
1548 static int |
|
1549 symbol_record_name_compare (const void *a_arg, const void *b_arg) |
|
1550 { |
5929
|
1551 const symbol_record *a = *(static_cast<symbol_record *const*> (a_arg)); |
|
1552 const symbol_record *b = *(static_cast<symbol_record *const*> (b_arg)); |
5659
|
1553 |
|
1554 std::string a_nm = a->name (); |
|
1555 std::string b_nm = b->name (); |
|
1556 |
|
1557 return a_nm.compare (b_nm); |
|
1558 } |
|
1559 |
4435
|
1560 static octave_value |
|
1561 do_who (int argc, const string_vector& argv, int return_list) |
529
|
1562 { |
4435
|
1563 octave_value retval; |
529
|
1564 |
2856
|
1565 bool show_builtins = false; |
3248
|
1566 bool show_functions = false; |
|
1567 bool show_variables = false; |
2856
|
1568 bool show_verbose = false; |
529
|
1569 |
3523
|
1570 std::string my_name = argv[0]; |
584
|
1571 |
1857
|
1572 int i; |
|
1573 for (i = 1; i < argc; i++) |
529
|
1574 { |
1755
|
1575 if (argv[i] == "-all" || argv[i] == "-a") |
529
|
1576 { |
2856
|
1577 show_builtins = true; |
|
1578 show_functions = true; |
|
1579 show_variables = true; |
529
|
1580 } |
1755
|
1581 else if (argv[i] == "-builtins" || argv[i] == "-b") |
2856
|
1582 show_builtins = true; |
1755
|
1583 else if (argv[i] == "-functions" || argv[i] == "-f") |
2856
|
1584 show_functions = true; |
1755
|
1585 else if (argv[i] == "-long" || argv[i] == "-l") |
2856
|
1586 show_verbose = true; |
1755
|
1587 else if (argv[i] == "-variables" || argv[i] == "-v") |
2856
|
1588 show_variables = true; |
1755
|
1589 else if (argv[i][0] == '-') |
|
1590 warning ("%s: unrecognized option `%s'", my_name.c_str (), |
|
1591 argv[i].c_str ()); |
529
|
1592 else |
867
|
1593 break; |
529
|
1594 } |
|
1595 |
3248
|
1596 // If no options were specified to select the type of symbol to |
|
1597 // display, then set defaults. |
|
1598 |
|
1599 if (! (show_builtins || show_functions || show_variables)) |
|
1600 { |
4208
|
1601 show_functions = at_top_level (); |
3248
|
1602 show_variables = true; |
|
1603 } |
|
1604 |
1857
|
1605 int npats = argc - i; |
|
1606 string_vector pats (npats); |
|
1607 for (int j = 0; j < npats; j++) |
|
1608 pats[j] = argv[i+j]; |
|
1609 |
1271
|
1610 // If the user specified -l and nothing else, show variables. If |
|
1611 // evaluating this at the top level, also show functions. |
529
|
1612 |
|
1613 if (show_verbose && ! (show_builtins || show_functions || show_variables)) |
|
1614 { |
4208
|
1615 show_functions = at_top_level (); |
529
|
1616 show_variables = 1; |
|
1617 } |
|
1618 |
4435
|
1619 if (return_list) |
529
|
1620 { |
5775
|
1621 // FIXME -- maybe symbol_list should return a std::list |
5659
|
1622 // object instead of an Array. |
|
1623 |
|
1624 dim_vector dv (0, 0); |
|
1625 |
|
1626 Array<symbol_record *> s3 (dv); |
|
1627 Array<symbol_record *> s4 (dv); |
|
1628 Array<symbol_record *> s5 (dv); |
|
1629 Array<symbol_record *> s6 (dv); |
|
1630 Array<symbol_record *> s7 (dv); |
5864
|
1631 Array<symbol_record *> s8 (dv); |
4435
|
1632 |
|
1633 if (show_builtins) |
|
1634 { |
5659
|
1635 s3 = fbi_sym_tab->symbol_list (pats, symbol_record::BUILTIN_FUNCTION, |
|
1636 SYMTAB_ALL_SCOPES); |
4435
|
1637 } |
|
1638 |
|
1639 if (show_functions) |
|
1640 { |
5659
|
1641 s4 = fbi_sym_tab->symbol_list (pats, symbol_record::DLD_FUNCTION, |
|
1642 SYMTAB_ALL_SCOPES); |
|
1643 |
|
1644 s5 = fbi_sym_tab->symbol_list (pats, symbol_record::USER_FUNCTION, |
|
1645 SYMTAB_ALL_SCOPES); |
5864
|
1646 |
|
1647 s6 = fbi_sym_tab->symbol_list (pats, symbol_record::MEX_FUNCTION, |
|
1648 SYMTAB_ALL_SCOPES); |
4435
|
1649 } |
|
1650 |
|
1651 if (show_variables) |
|
1652 { |
5864
|
1653 s7 = curr_sym_tab->symbol_list (pats, symbol_record::USER_VARIABLE, |
5659
|
1654 SYMTAB_LOCAL_SCOPE); |
|
1655 |
5864
|
1656 s8 = curr_sym_tab->symbol_list (pats, symbol_record::USER_VARIABLE, |
5659
|
1657 SYMTAB_GLOBAL_SCOPE); |
4435
|
1658 } |
|
1659 |
5659
|
1660 octave_idx_type s3_len = s3.length (); |
|
1661 octave_idx_type s4_len = s4.length (); |
|
1662 octave_idx_type s5_len = s5.length (); |
|
1663 octave_idx_type s6_len = s6.length (); |
|
1664 octave_idx_type s7_len = s7.length (); |
5864
|
1665 octave_idx_type s8_len = s8.length (); |
|
1666 |
|
1667 octave_idx_type symbols_len |
|
1668 = s3_len + s4_len + s5_len + s6_len + s7_len + s8_len; |
5659
|
1669 |
|
1670 Array<symbol_record *> symbols (dim_vector (symbols_len, 1)); |
|
1671 |
|
1672 octave_idx_type k = 0; |
|
1673 |
|
1674 symbols.insert (s3, k, 0); |
|
1675 k += s3_len; |
|
1676 symbols.insert (s4, k, 0); |
|
1677 k += s4_len; |
|
1678 symbols.insert (s5, k, 0); |
|
1679 k += s5_len; |
|
1680 symbols.insert (s6, k, 0); |
|
1681 k += s6_len; |
|
1682 symbols.insert (s7, k, 0); |
5864
|
1683 k += s7_len; |
|
1684 symbols.insert (s8, k, 0); |
5659
|
1685 |
|
1686 symbols.qsort (symbol_record_name_compare); |
|
1687 |
4435
|
1688 if (show_verbose) |
|
1689 { |
5659
|
1690 Array<octave_value> name_info (symbols_len, 1); |
|
1691 Array<octave_value> size_info (symbols_len, 1); |
|
1692 Array<octave_value> bytes_info (symbols_len, 1); |
|
1693 Array<octave_value> class_info (symbols_len, 1); |
|
1694 Array<octave_value> global_info (symbols_len, 1); |
|
1695 Array<octave_value> sparse_info (symbols_len, 1); |
|
1696 Array<octave_value> complex_info (symbols_len, 1); |
|
1697 Array<octave_value> nesting_info (symbols_len, 1); |
|
1698 |
|
1699 for (octave_idx_type j = 0; j < symbols_len; j++) |
|
1700 { |
|
1701 symbol_record *sr = symbols(j); |
|
1702 |
|
1703 Octave_map ni; |
|
1704 |
|
1705 std::string caller_function_name; |
5743
|
1706 |
|
1707 octave_function *caller = octave_call_stack::caller (); |
|
1708 if (caller) |
|
1709 caller_function_name = caller->name (); |
5659
|
1710 |
|
1711 ni.assign ("function", caller_function_name); |
|
1712 ni.assign ("level", 1); |
|
1713 |
|
1714 name_info(j) = sr->name (); |
|
1715 size_info(j) = sr->size (); |
|
1716 bytes_info(j) = sr->byte_size (); |
|
1717 class_info(j) = sr->class_name (); |
|
1718 global_info(j) = sr->is_linked_to_global (); |
|
1719 sparse_info(j) = sr->is_sparse_type (); |
|
1720 complex_info(j) = sr->is_complex_type (); |
|
1721 nesting_info(j) = ni; |
|
1722 } |
|
1723 |
|
1724 Octave_map info; |
|
1725 |
|
1726 info.assign ("name", name_info); |
|
1727 info.assign ("size", size_info); |
|
1728 info.assign ("bytes", bytes_info); |
|
1729 info.assign ("class", class_info); |
|
1730 info.assign ("global", global_info); |
|
1731 info.assign ("sparse", sparse_info); |
|
1732 info.assign ("complex", complex_info); |
|
1733 info.assign ("nesting", nesting_info); |
|
1734 |
|
1735 retval = info; |
4435
|
1736 } |
|
1737 else |
5659
|
1738 { |
|
1739 string_vector names; |
|
1740 |
|
1741 if (symbols_len > 0) |
|
1742 { |
|
1743 names.resize (symbols_len); |
|
1744 |
|
1745 for (octave_idx_type j = 0; j < symbols_len; j++) |
|
1746 names[j] = symbols(j)->name (); |
|
1747 } |
|
1748 |
|
1749 retval = Cell (names); |
|
1750 } |
529
|
1751 } |
4435
|
1752 else |
529
|
1753 { |
4435
|
1754 int pad_after = 0; |
|
1755 |
|
1756 if (show_builtins) |
|
1757 { |
|
1758 pad_after += fbi_sym_tab->maybe_list |
|
1759 ("*** built-in functions:", pats, octave_stdout, |
|
1760 show_verbose, symbol_record::BUILTIN_FUNCTION, SYMTAB_ALL_SCOPES); |
|
1761 } |
529
|
1762 |
4435
|
1763 if (show_functions) |
|
1764 { |
|
1765 pad_after += fbi_sym_tab->maybe_list |
|
1766 ("*** dynamically linked functions:", pats, |
|
1767 octave_stdout, show_verbose, symbol_record::DLD_FUNCTION, |
|
1768 SYMTAB_ALL_SCOPES); |
|
1769 |
|
1770 pad_after += fbi_sym_tab->maybe_list |
|
1771 ("*** currently compiled functions:", pats, |
|
1772 octave_stdout, show_verbose, symbol_record::USER_FUNCTION, |
|
1773 SYMTAB_ALL_SCOPES); |
5864
|
1774 |
|
1775 pad_after += fbi_sym_tab->maybe_list |
|
1776 ("*** mex functions:", pats, |
|
1777 octave_stdout, show_verbose, symbol_record::MEX_FUNCTION, |
|
1778 SYMTAB_ALL_SCOPES); |
4435
|
1779 } |
|
1780 |
|
1781 if (show_variables) |
|
1782 { |
|
1783 pad_after += curr_sym_tab->maybe_list |
|
1784 ("*** local user variables:", pats, octave_stdout, |
|
1785 show_verbose, symbol_record::USER_VARIABLE, SYMTAB_LOCAL_SCOPE); |
|
1786 |
|
1787 pad_after += curr_sym_tab->maybe_list |
|
1788 ("*** globally visible user variables:", pats, |
|
1789 octave_stdout, show_verbose, symbol_record::USER_VARIABLE, |
|
1790 SYMTAB_GLOBAL_SCOPE); |
|
1791 } |
|
1792 |
|
1793 if (pad_after) |
|
1794 octave_stdout << "\n"; |
529
|
1795 } |
|
1796 |
581
|
1797 return retval; |
|
1798 } |
|
1799 |
4435
|
1800 DEFCMD (who, args, nargout, |
3361
|
1801 "-*- texinfo -*-\n\ |
|
1802 @deffn {Command} who options pattern @dots{}\n\ |
|
1803 @deffnx {Command} whos options pattern @dots{}\n\ |
|
1804 List currently defined symbols matching the given patterns. The\n\ |
|
1805 following are valid options. They may be shortened to one character but\n\ |
|
1806 may not be combined.\n\ |
|
1807 \n\ |
|
1808 @table @code\n\ |
|
1809 @item -all\n\ |
|
1810 List all currently defined symbols.\n\ |
|
1811 \n\ |
|
1812 @item -builtins\n\ |
5794
|
1813 List built-in functions. This includes all currently\n\ |
3361
|
1814 compiled function files, but does not include all function files that\n\ |
5814
|
1815 are in the search path.\n\ |
581
|
1816 \n\ |
3361
|
1817 @item -functions\n\ |
|
1818 List user-defined functions.\n\ |
|
1819 \n\ |
|
1820 @item -long\n\ |
|
1821 Print a long listing including the type and dimensions of any symbols.\n\ |
|
1822 The symbols in the first column of output indicate whether it is\n\ |
|
1823 possible to redefine the symbol, and whether it is possible for it to be\n\ |
|
1824 cleared.\n\ |
|
1825 \n\ |
|
1826 @item -variables\n\ |
|
1827 List user-defined variables.\n\ |
|
1828 @end table\n\ |
|
1829 \n\ |
|
1830 Valid patterns are the same as described for the @code{clear} command\n\ |
|
1831 above. If no patterns are supplied, all symbols from the given category\n\ |
|
1832 are listed. By default, only user defined functions and variables\n\ |
|
1833 visible in the local scope are displayed.\n\ |
|
1834 \n\ |
|
1835 The command @kbd{whos} is equivalent to @kbd{who -long}.\n\ |
|
1836 @end deffn") |
581
|
1837 { |
4435
|
1838 octave_value retval; |
581
|
1839 |
4435
|
1840 if (nargout < 2) |
|
1841 { |
|
1842 int argc = args.length () + 1; |
|
1843 |
|
1844 string_vector argv = args.make_argv ("who"); |
1755
|
1845 |
4435
|
1846 if (error_state) |
|
1847 return retval; |
1755
|
1848 |
4435
|
1849 retval = do_who (argc, argv, nargout == 1); |
|
1850 } |
|
1851 else |
5823
|
1852 print_usage (); |
581
|
1853 |
529
|
1854 return retval; |
|
1855 } |
|
1856 |
4435
|
1857 DEFCMD (whos, args, nargout, |
3458
|
1858 "-*- texinfo -*-\n\ |
|
1859 @deffn {Command} whos options pattern @dots{}\n\ |
|
1860 See who.\n\ |
|
1861 @end deffn") |
581
|
1862 { |
4435
|
1863 octave_value retval; |
712
|
1864 |
4435
|
1865 if (nargout < 2) |
|
1866 { |
|
1867 int nargin = args.length (); |
|
1868 |
|
1869 octave_value_list tmp_args; |
|
1870 |
|
1871 for (int i = nargin; i > 0; i--) |
|
1872 tmp_args(i) = args(i-1); |
581
|
1873 |
4435
|
1874 tmp_args(0) = "-long"; |
1755
|
1875 |
4435
|
1876 int argc = tmp_args.length () + 1; |
|
1877 |
|
1878 string_vector argv = tmp_args.make_argv ("whos"); |
581
|
1879 |
4435
|
1880 if (error_state) |
|
1881 return retval; |
581
|
1882 |
4435
|
1883 retval = do_who (argc, argv, nargout == 1); |
|
1884 } |
|
1885 else |
5823
|
1886 print_usage (); |
581
|
1887 |
|
1888 return retval; |
|
1889 } |
|
1890 |
593
|
1891 // Defining variables. |
|
1892 |
1162
|
1893 void |
2856
|
1894 bind_ans (const octave_value& val, bool print) |
1162
|
1895 { |
5794
|
1896 symbol_record *sr = curr_sym_tab->lookup ("ans", true); |
1162
|
1897 |
2978
|
1898 if (val.is_defined ()) |
|
1899 { |
|
1900 sr->define (val); |
1162
|
1901 |
2978
|
1902 if (print) |
|
1903 val.print_with_name (octave_stdout, "ans"); |
|
1904 } |
1162
|
1905 } |
|
1906 |
593
|
1907 void |
5794
|
1908 bind_internal_variable (const std::string& fname, const octave_value& val) |
593
|
1909 { |
5794
|
1910 octave_value_list args; |
|
1911 |
|
1912 args(0) = val; |
|
1913 |
|
1914 feval (fname, args, 0); |
529
|
1915 } |
|
1916 |
4319
|
1917 void |
|
1918 mlock (const std::string& nm) |
|
1919 { |
|
1920 symbol_record *sr = fbi_sym_tab->lookup (nm, true); |
|
1921 |
|
1922 if (sr) |
|
1923 sr->mark_as_static (); |
|
1924 } |
|
1925 |
|
1926 void |
|
1927 munlock (const std::string& nm) |
|
1928 { |
|
1929 symbol_record *sr = fbi_sym_tab->lookup (nm); |
|
1930 |
|
1931 if (sr && sr->is_static ()) |
|
1932 sr->unmark_static (); |
|
1933 else |
|
1934 error ("munlock: %s is not locked", nm.c_str ()); |
|
1935 } |
|
1936 |
|
1937 bool |
|
1938 mislocked (const std::string& nm) |
|
1939 { |
|
1940 symbol_record *sr = fbi_sym_tab->lookup (nm); |
|
1941 |
|
1942 return (sr && sr->is_static ()); |
|
1943 } |
|
1944 |
|
1945 DEFCMD (mlock, args, , |
|
1946 "-*- texinfo -*-\n\ |
4526
|
1947 @deftypefn {Built-in Function} {} mlock (@var{name})\n\ |
4319
|
1948 Lock the named function into memory. If no function is named\n\ |
|
1949 then lock in the current function.\n\ |
5642
|
1950 @seealso{munlock, mislocked, persistent}\n\ |
|
1951 @end deftypefn") |
4319
|
1952 { |
|
1953 octave_value_list retval; |
|
1954 |
|
1955 if (args.length () == 1) |
|
1956 { |
|
1957 std::string name = args(0).string_value (); |
|
1958 |
|
1959 if (! error_state) |
|
1960 mlock (name); |
|
1961 else |
|
1962 error ("mlock: expecting argument to be a function name"); |
|
1963 } |
|
1964 else if (args.length () == 0) |
|
1965 { |
5744
|
1966 octave_user_function *fcn = octave_call_stack::caller_user_function (); |
5743
|
1967 |
|
1968 if (fcn) |
|
1969 mlock (fcn->name ()); |
4319
|
1970 else |
|
1971 error ("mlock: invalid use outside a function"); |
|
1972 } |
|
1973 else |
5823
|
1974 print_usage (); |
4319
|
1975 |
|
1976 return retval; |
|
1977 } |
|
1978 |
|
1979 DEFCMD (munlock, args, , |
|
1980 "-*- texinfo -*-\n\ |
|
1981 @deftypefn {Built-in Function} {} munlock (@var{fcn})\n\ |
|
1982 Unlock the named function. If no function is named\n\ |
|
1983 then unlock the current function.\n\ |
5642
|
1984 @seealso{mlock, mislocked, persistent}\n\ |
|
1985 @end deftypefn") |
4319
|
1986 { |
|
1987 octave_value_list retval; |
|
1988 |
|
1989 if (args.length() == 1) |
|
1990 { |
|
1991 std::string name = args(0).string_value (); |
|
1992 |
|
1993 if (! error_state) |
|
1994 munlock (name); |
|
1995 else |
|
1996 error ("munlock: expecting argument to be a function name"); |
|
1997 } |
|
1998 else if (args.length () == 0) |
|
1999 { |
5744
|
2000 octave_user_function *fcn = octave_call_stack::caller_user_function (); |
5743
|
2001 |
|
2002 if (fcn) |
|
2003 mlock (fcn->name ()); |
4319
|
2004 else |
|
2005 error ("munlock: invalid use outside a function"); |
|
2006 } |
|
2007 else |
5823
|
2008 print_usage (); |
4319
|
2009 |
|
2010 return retval; |
|
2011 } |
|
2012 |
|
2013 |
|
2014 DEFCMD (mislocked, args, , |
|
2015 "-*- texinfo -*-\n\ |
|
2016 @deftypefn {Built-in Function} {} mislocked (@var{fcn})\n\ |
|
2017 Return true if the named function is locked. If no function is named\n\ |
|
2018 then return true if the current function is locked.\n\ |
5642
|
2019 @seealso{mlock, munlock, persistent}\n\ |
|
2020 @end deftypefn") |
4319
|
2021 { |
|
2022 octave_value retval; |
|
2023 |
|
2024 if (args.length() == 1) |
|
2025 { |
|
2026 std::string name = args(0).string_value (); |
|
2027 |
|
2028 if (! error_state) |
|
2029 retval = mislocked (name); |
|
2030 else |
|
2031 error ("mislocked: expecting argument to be a function name"); |
|
2032 } |
|
2033 else if (args.length () == 0) |
|
2034 { |
5744
|
2035 octave_user_function *fcn = octave_call_stack::caller_user_function (); |
5743
|
2036 |
|
2037 if (fcn) |
|
2038 retval = mislocked (fcn->name ()); |
4319
|
2039 else |
|
2040 error ("mislocked: invalid use outside a function"); |
|
2041 } |
|
2042 else |
5823
|
2043 print_usage (); |
4319
|
2044 |
|
2045 return retval; |
|
2046 } |
|
2047 |
593
|
2048 // Deleting names from the symbol tables. |
|
2049 |
3681
|
2050 static inline bool |
4009
|
2051 name_matches_any_pattern (const std::string& nm, |
|
2052 const string_vector& argv, int argc, int idx) |
3681
|
2053 { |
|
2054 bool retval = false; |
|
2055 |
|
2056 for (int k = idx; k < argc; k++) |
|
2057 { |
|
2058 std::string patstr = argv[k]; |
|
2059 |
|
2060 if (! patstr.empty ()) |
|
2061 { |
|
2062 glob_match pattern (patstr); |
|
2063 |
|
2064 if (pattern.match (nm)) |
|
2065 { |
|
2066 retval = true; |
|
2067 break; |
|
2068 } |
|
2069 } |
|
2070 } |
|
2071 |
|
2072 return retval; |
|
2073 } |
|
2074 |
4009
|
2075 static inline bool |
|
2076 is_local_variable (const std::string& nm) |
|
2077 { |
|
2078 symbol_record *sr = curr_sym_tab->lookup (nm); |
|
2079 |
|
2080 return (sr && sr->is_variable ()); |
|
2081 } |
|
2082 |
|
2083 static inline void |
|
2084 maybe_warn_exclusive (bool exclusive) |
|
2085 { |
|
2086 if (exclusive) |
|
2087 warning ("clear: ignoring --exclusive option"); |
|
2088 } |
|
2089 |
|
2090 static inline void |
|
2091 do_clear_all (void) |
|
2092 { |
|
2093 curr_sym_tab->clear (); |
|
2094 fbi_sym_tab->clear_functions (); |
|
2095 global_sym_tab->clear (); |
|
2096 } |
|
2097 |
|
2098 static inline void |
|
2099 do_clear_functions (void) |
|
2100 { |
|
2101 curr_sym_tab->clear_functions (); |
|
2102 fbi_sym_tab->clear_functions (); |
|
2103 } |
|
2104 |
|
2105 static inline void |
|
2106 do_clear_globals (void) |
|
2107 { |
|
2108 curr_sym_tab->clear_globals (); |
|
2109 global_sym_tab->clear (); |
|
2110 } |
|
2111 |
|
2112 static inline void |
|
2113 do_clear_variables (void) |
|
2114 { |
|
2115 curr_sym_tab->clear (); |
|
2116 } |
|
2117 |
|
2118 static inline bool |
|
2119 do_clear_function (const std::string& nm) |
|
2120 { |
|
2121 bool b1 = curr_sym_tab->clear_function (nm); |
|
2122 |
|
2123 bool b2 = fbi_sym_tab->clear_function (nm); |
|
2124 |
|
2125 return b1 || b2; |
|
2126 } |
|
2127 |
|
2128 static inline bool |
|
2129 do_clear_global (const std::string& nm) |
|
2130 { |
|
2131 bool b1 = curr_sym_tab->clear_global (nm); |
|
2132 |
|
2133 bool b2 = global_sym_tab->clear_variable (nm); |
|
2134 |
|
2135 return b1 || b2; |
|
2136 } |
|
2137 |
|
2138 static inline bool |
|
2139 do_clear_variable (const std::string& nm) |
|
2140 { |
|
2141 return curr_sym_tab->clear_variable (nm); |
|
2142 } |
|
2143 |
|
2144 static inline bool |
|
2145 do_clear_symbol (const std::string& nm) |
|
2146 { |
|
2147 bool cleared = curr_sym_tab->clear_variable (nm); |
|
2148 |
|
2149 if (! cleared) |
|
2150 cleared = do_clear_function (nm); |
|
2151 |
|
2152 return cleared; |
|
2153 } |
|
2154 |
|
2155 static inline bool |
|
2156 do_clear_function_pattern (const std::string& pat) |
|
2157 { |
|
2158 bool b1 = curr_sym_tab->clear_function_pattern (pat); |
|
2159 |
|
2160 bool b2 = fbi_sym_tab->clear_function_pattern (pat); |
|
2161 |
|
2162 return b1 || b2; |
|
2163 } |
|
2164 |
|
2165 static inline bool |
|
2166 do_clear_global_pattern (const std::string& pat) |
|
2167 { |
|
2168 bool b1 = curr_sym_tab->clear_global_pattern (pat); |
|
2169 |
|
2170 bool b2 = global_sym_tab->clear_variable_pattern (pat); |
|
2171 |
|
2172 return b1 || b2; |
|
2173 } |
|
2174 |
|
2175 static inline bool |
|
2176 do_clear_variable_pattern (const std::string& pat) |
|
2177 { |
|
2178 return curr_sym_tab->clear_variable_pattern (pat); |
|
2179 } |
|
2180 |
|
2181 static inline bool |
|
2182 do_clear_symbol_pattern (const std::string& pat) |
|
2183 { |
5775
|
2184 // FIXME -- if we have a variable v1 and a function v2 and |
4009
|
2185 // someone says clear v*, we will clear the variable but not the |
|
2186 // function. Is that really what should happen? (I think it is |
|
2187 // what Matlab does.) |
|
2188 |
|
2189 bool cleared = curr_sym_tab->clear_variable_pattern (pat); |
|
2190 |
|
2191 if (! cleared) |
|
2192 cleared = do_clear_function_pattern (pat); |
|
2193 |
|
2194 return cleared; |
|
2195 } |
|
2196 |
|
2197 static inline void |
|
2198 do_clear_functions (const string_vector& argv, int argc, int idx, |
|
2199 bool exclusive = false) |
|
2200 { |
|
2201 if (idx == argc) |
|
2202 do_clear_functions (); |
|
2203 else |
|
2204 { |
|
2205 if (exclusive) |
|
2206 { |
|
2207 string_vector lfcns = curr_sym_tab->user_function_name_list (); |
|
2208 |
|
2209 int lcount = lfcns.length (); |
|
2210 |
|
2211 for (int i = 0; i < lcount; i++) |
|
2212 { |
|
2213 std::string nm = lfcns[i]; |
|
2214 |
|
2215 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2216 do_clear_function (nm); |
|
2217 } |
|
2218 |
|
2219 string_vector fcns = fbi_sym_tab->user_function_name_list (); |
|
2220 |
|
2221 int fcount = fcns.length (); |
|
2222 |
|
2223 for (int i = 0; i < fcount; i++) |
|
2224 { |
|
2225 std::string nm = fcns[i]; |
|
2226 |
|
2227 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2228 do_clear_function (nm); |
|
2229 } |
|
2230 } |
|
2231 else |
|
2232 { |
|
2233 while (idx < argc) |
|
2234 do_clear_function_pattern (argv[idx++]); |
|
2235 } |
|
2236 } |
|
2237 } |
|
2238 |
|
2239 static inline void |
|
2240 do_clear_globals (const string_vector& argv, int argc, int idx, |
|
2241 bool exclusive = false) |
|
2242 { |
|
2243 if (idx == argc) |
|
2244 do_clear_globals (); |
|
2245 else |
|
2246 { |
|
2247 if (exclusive) |
|
2248 { |
|
2249 string_vector lvars = curr_sym_tab->global_variable_name_list (); |
|
2250 |
|
2251 int lcount = lvars.length (); |
|
2252 |
|
2253 for (int i = 0; i < lcount; i++) |
|
2254 { |
|
2255 std::string nm = lvars[i]; |
|
2256 |
|
2257 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2258 do_clear_global (nm); |
|
2259 } |
|
2260 |
|
2261 string_vector gvars = global_sym_tab->global_variable_name_list (); |
|
2262 |
|
2263 int gcount = gvars.length (); |
|
2264 |
|
2265 for (int i = 0; i < gcount; i++) |
|
2266 { |
|
2267 std::string nm = gvars[i]; |
|
2268 |
|
2269 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2270 do_clear_global (nm); |
|
2271 } |
|
2272 } |
|
2273 else |
|
2274 { |
|
2275 while (idx < argc) |
|
2276 do_clear_global_pattern (argv[idx++]); |
|
2277 } |
|
2278 } |
|
2279 } |
|
2280 |
|
2281 static inline void |
|
2282 do_clear_variables (const string_vector& argv, int argc, int idx, |
|
2283 bool exclusive = false) |
|
2284 { |
|
2285 if (idx == argc) |
|
2286 do_clear_variables (); |
|
2287 else |
|
2288 { |
|
2289 if (exclusive) |
|
2290 { |
|
2291 string_vector lvars = curr_sym_tab->variable_name_list (); |
|
2292 |
|
2293 int lcount = lvars.length (); |
|
2294 |
|
2295 for (int i = 0; i < lcount; i++) |
|
2296 { |
|
2297 std::string nm = lvars[i]; |
|
2298 |
|
2299 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2300 do_clear_variable (nm); |
|
2301 } |
|
2302 } |
|
2303 else |
|
2304 { |
|
2305 while (idx < argc) |
|
2306 do_clear_variable_pattern (argv[idx++]); |
|
2307 } |
|
2308 } |
|
2309 } |
|
2310 |
|
2311 static inline void |
|
2312 do_clear_symbols (const string_vector& argv, int argc, int idx, |
|
2313 bool exclusive = false) |
|
2314 { |
|
2315 if (idx == argc) |
|
2316 do_clear_variables (); |
|
2317 else |
|
2318 { |
|
2319 if (exclusive) |
|
2320 { |
5775
|
2321 // FIXME -- is this really what we want, or do we |
4009
|
2322 // somehow want to only clear the functions that are not |
|
2323 // shadowed by local variables? It seems that would be a |
|
2324 // bit harder to do. |
|
2325 |
|
2326 do_clear_variables (argv, argc, idx, exclusive); |
|
2327 do_clear_functions (argv, argc, idx, exclusive); |
|
2328 } |
|
2329 else |
|
2330 { |
|
2331 while (idx < argc) |
|
2332 do_clear_symbol_pattern (argv[idx++]); |
|
2333 } |
|
2334 } |
|
2335 } |
|
2336 |
|
2337 static void |
|
2338 do_matlab_compatible_clear (const string_vector& argv, int argc, int idx) |
|
2339 { |
|
2340 // This is supposed to be mostly Matlab compatible. |
|
2341 |
|
2342 for (; idx < argc; idx++) |
|
2343 { |
|
2344 if (argv[idx] == "all" && ! is_local_variable ("all")) |
|
2345 { |
|
2346 do_clear_all (); |
|
2347 } |
|
2348 else if (argv[idx] == "functions" && ! is_local_variable ("functions")) |
|
2349 { |
|
2350 do_clear_functions (argv, argc, ++idx); |
|
2351 } |
|
2352 else if (argv[idx] == "global" && ! is_local_variable ("global")) |
|
2353 { |
|
2354 do_clear_globals (argv, argc, ++idx); |
|
2355 } |
|
2356 else if (argv[idx] == "variables" && ! is_local_variable ("variables")) |
|
2357 { |
|
2358 do_clear_variables (); |
|
2359 } |
|
2360 else |
|
2361 { |
|
2362 do_clear_symbol_pattern (argv[idx]); |
|
2363 } |
|
2364 } |
|
2365 } |
|
2366 |
|
2367 #define CLEAR_OPTION_ERROR(cond) \ |
|
2368 do \ |
|
2369 { \ |
|
2370 if (cond) \ |
|
2371 { \ |
5823
|
2372 print_usage (); \ |
4009
|
2373 return retval; \ |
|
2374 } \ |
|
2375 } \ |
|
2376 while (0) |
|
2377 |
4954
|
2378 bool |
|
2379 clear_function (const std::string& nm) |
|
2380 { |
|
2381 return do_clear_function (nm); |
|
2382 } |
|
2383 |
4988
|
2384 bool |
|
2385 clear_variable (const std::string& nm) |
|
2386 { |
|
2387 return do_clear_variable (nm); |
|
2388 } |
|
2389 |
|
2390 bool |
|
2391 clear_symbol (const std::string& nm) |
|
2392 { |
|
2393 return do_clear_symbol (nm); |
|
2394 } |
|
2395 |
4208
|
2396 DEFCMD (clear, args, , |
3361
|
2397 "-*- texinfo -*-\n\ |
|
2398 @deffn {Command} clear [-x] pattern @dots{}\n\ |
|
2399 Delete the names matching the given patterns from the symbol table. The\n\ |
|
2400 pattern may contain the following special characters:\n\ |
4016
|
2401 \n\ |
3361
|
2402 @table @code\n\ |
|
2403 @item ?\n\ |
|
2404 Match any single character.\n\ |
668
|
2405 \n\ |
3361
|
2406 @item *\n\ |
|
2407 Match zero or more characters.\n\ |
|
2408 \n\ |
|
2409 @item [ @var{list} ]\n\ |
|
2410 Match the list of characters specified by @var{list}. If the first\n\ |
|
2411 character is @code{!} or @code{^}, match all characters except those\n\ |
|
2412 specified by @var{list}. For example, the pattern @samp{[a-zA-Z]} will\n\ |
|
2413 match all lower and upper case alphabetic characters.\n\ |
|
2414 @end table\n\ |
|
2415 \n\ |
|
2416 For example, the command\n\ |
593
|
2417 \n\ |
3361
|
2418 @example\n\ |
|
2419 clear foo b*r\n\ |
|
2420 @end example\n\ |
|
2421 \n\ |
|
2422 @noindent\n\ |
|
2423 clears the name @code{foo} and all names that begin with the letter\n\ |
|
2424 @code{b} and end with the letter @code{r}.\n\ |
668
|
2425 \n\ |
3361
|
2426 If @code{clear} is called without any arguments, all user-defined\n\ |
|
2427 variables (local and global) are cleared from the symbol table. If\n\ |
|
2428 @code{clear} is called with at least one argument, only the visible\n\ |
|
2429 names matching the arguments are cleared. For example, suppose you have\n\ |
|
2430 defined a function @code{foo}, and then hidden it by performing the\n\ |
|
2431 assignment @code{foo = 2}. Executing the command @kbd{clear foo} once\n\ |
|
2432 will clear the variable definition and restore the definition of\n\ |
|
2433 @code{foo} as a function. Executing @kbd{clear foo} a second time will\n\ |
|
2434 clear the function definition.\n\ |
|
2435 \n\ |
|
2436 With -x, clear the variables that don't match the patterns.\n\ |
|
2437 \n\ |
|
2438 This command may not be used within a function body.\n\ |
|
2439 @end deffn") |
529
|
2440 { |
2086
|
2441 octave_value_list retval; |
593
|
2442 |
1755
|
2443 int argc = args.length () + 1; |
593
|
2444 |
1968
|
2445 string_vector argv = args.make_argv ("clear"); |
1755
|
2446 |
4009
|
2447 if (! error_state) |
529
|
2448 { |
4009
|
2449 if (argc == 1) |
593
|
2450 { |
4009
|
2451 do_clear_variables (); |
3681
|
2452 } |
|
2453 else |
|
2454 { |
4009
|
2455 int idx = 0; |
|
2456 |
|
2457 bool clear_all = false; |
|
2458 bool clear_functions = false; |
|
2459 bool clear_globals = false; |
|
2460 bool clear_variables = false; |
|
2461 bool exclusive = false; |
|
2462 bool have_dash_option = false; |
3681
|
2463 |
4009
|
2464 while (++idx < argc) |
|
2465 { |
4010
|
2466 if (argv[idx] == "-all" || argv[idx] == "-a") |
593
|
2467 { |
4009
|
2468 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681
|
2469 |
4009
|
2470 have_dash_option = true; |
|
2471 clear_all = true; |
|
2472 } |
4010
|
2473 else if (argv[idx] == "-exclusive" || argv[idx] == "-x") |
4009
|
2474 { |
|
2475 have_dash_option = true; |
|
2476 exclusive = true; |
|
2477 } |
4010
|
2478 else if (argv[idx] == "-functions" || argv[idx] == "-f") |
4009
|
2479 { |
|
2480 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681
|
2481 |
4009
|
2482 have_dash_option = true; |
|
2483 clear_functions = true; |
|
2484 } |
4010
|
2485 else if (argv[idx] == "-global" || argv[idx] == "-g") |
4009
|
2486 { |
|
2487 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
|
2488 |
|
2489 have_dash_option = true; |
|
2490 clear_globals = true; |
|
2491 } |
4010
|
2492 else if (argv[idx] == "-variables" || argv[idx] == "-v") |
4009
|
2493 { |
|
2494 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681
|
2495 |
4009
|
2496 have_dash_option = true; |
|
2497 clear_variables = true; |
|
2498 } |
|
2499 else |
|
2500 break; |
|
2501 } |
3681
|
2502 |
4224
|
2503 if (idx <= argc) |
4009
|
2504 { |
|
2505 if (! have_dash_option) |
|
2506 { |
|
2507 do_matlab_compatible_clear (argv, argc, idx); |
|
2508 } |
|
2509 else |
|
2510 { |
|
2511 if (clear_all) |
3681
|
2512 { |
4009
|
2513 maybe_warn_exclusive (exclusive); |
3681
|
2514 |
4009
|
2515 if (++idx < argc) |
|
2516 warning |
4010
|
2517 ("clear: ignoring extra arguments after -all"); |
3681
|
2518 |
4009
|
2519 curr_sym_tab->clear (); |
|
2520 fbi_sym_tab->clear_functions (); |
|
2521 global_sym_tab->clear (); |
|
2522 } |
|
2523 else if (clear_functions) |
|
2524 { |
|
2525 do_clear_functions (argv, argc, idx, exclusive); |
|
2526 } |
|
2527 else if (clear_globals) |
593
|
2528 { |
4009
|
2529 do_clear_globals (argv, argc, idx, exclusive); |
|
2530 } |
|
2531 else if (clear_variables) |
|
2532 { |
|
2533 do_clear_variables (argv, argc, idx, exclusive); |
|
2534 } |
|
2535 else |
|
2536 { |
|
2537 do_clear_symbols (argv, argc, idx, exclusive); |
593
|
2538 } |
|
2539 } |
|
2540 } |
|
2541 } |
|
2542 } |
|
2543 |
|
2544 return retval; |
529
|
2545 } |
|
2546 |
3933
|
2547 DEFUN (__print_symtab_info__, args, , |
3446
|
2548 "-*- texinfo -*-\n\ |
3933
|
2549 @deftypefn {Built-in Function} {} __print_symtab_info__ ()\n\ |
3446
|
2550 Print raw symbol table statistices.\n\ |
|
2551 @end deftypefn") |
3005
|
2552 { |
|
2553 octave_value_list retval; |
|
2554 |
|
2555 int nargin = args.length (); |
|
2556 |
|
2557 if (nargin == 1) |
|
2558 { |
3523
|
2559 std::string arg = args(0).string_value (); |
3005
|
2560 |
4009
|
2561 if (arg == "fbi") |
|
2562 fbi_sym_tab->print_info (octave_stdout); |
|
2563 else if (arg == "global") |
3933
|
2564 global_sym_tab->print_info (octave_stdout); |
|
2565 else if (arg == "top-level") |
|
2566 top_level_sym_tab->print_info (octave_stdout); |
3005
|
2567 else |
3933
|
2568 { |
4009
|
2569 symbol_record *fsr = fbi_sym_tab->lookup (arg, true); |
3933
|
2570 |
4009
|
2571 if (fsr && fsr->is_user_function ()) |
3933
|
2572 { |
4009
|
2573 octave_value tmp = fsr->def (); |
5759
|
2574 const octave_base_value& rep = tmp.get_rep (); |
3933
|
2575 |
|
2576 const octave_user_function& fcn |
5759
|
2577 = dynamic_cast<const octave_user_function&> (rep); |
3933
|
2578 |
|
2579 fcn.print_symtab_info (octave_stdout); |
|
2580 } |
|
2581 else |
|
2582 error ("no user-defined function named %s", arg.c_str ()); |
|
2583 } |
3005
|
2584 } |
|
2585 else if (nargin == 0) |
3933
|
2586 curr_sym_tab->print_info (octave_stdout); |
3005
|
2587 else |
5823
|
2588 print_usage (); |
3005
|
2589 |
|
2590 return retval; |
|
2591 } |
|
2592 |
3933
|
2593 DEFUN (__print_symbol_info__, args, , |
3446
|
2594 "-*- texinfo -*-\n\ |
|
2595 @deftypefn {Built-in Function} {} __dump_symbol_info__ (@var{name})\n\ |
3548
|
2596 Print symbol table information for the symbol @var{name}.\n\ |
3446
|
2597 @end deftypefn") |
3239
|
2598 { |
|
2599 octave_value_list retval; |
|
2600 |
|
2601 int nargin = args.length (); |
|
2602 |
|
2603 if (nargin == 1) |
|
2604 { |
3523
|
2605 std::string symbol_name = args(0).string_value (); |
3239
|
2606 |
|
2607 if (! error_state) |
|
2608 { |
|
2609 symbol_record *sr = curr_sym_tab->lookup (symbol_name); |
|
2610 |
|
2611 if (sr) |
3933
|
2612 sr->print_info (octave_stdout); |
3239
|
2613 else |
3933
|
2614 error ("__print_symbol_info__: symbol %s not found", |
3239
|
2615 symbol_name.c_str ()); |
|
2616 } |
|
2617 else |
5823
|
2618 print_usage (); |
3239
|
2619 } |
|
2620 else |
5823
|
2621 print_usage (); |
3239
|
2622 |
|
2623 return retval; |
|
2624 } |
|
2625 |
5794
|
2626 DEFUN (ignore_function_time_stamp, args, nargout, |
3372
|
2627 "-*- texinfo -*-\n\ |
5794
|
2628 @deftypefn {Built-in Function} {@var{val} =} ignore_function_time_stamp ()\n\ |
|
2629 @deftypefnx {Built-in Function} {@var{old_val} =} ignore_function_time_stamp (@var{new_val})\n\ |
|
2630 Query or set the internal variable that controls whether Octave checks\n\ |
|
2631 the time stamp on files each time it looks up functions defined in\n\ |
|
2632 function files. If the internal variable is set to @code{\"system\"},\n\ |
|
2633 Octave will not automatically recompile function files in subdirectories of\n\ |
3371
|
2634 @file{@var{octave-home}/lib/@var{version}} if they have changed since\n\ |
|
2635 they were last compiled, but will recompile other function files in the\n\ |
5814
|
2636 search path if they change. If set to @code{\"all\"}, Octave will not\n\ |
3371
|
2637 recompile any function files unless their definitions are removed with\n\ |
5794
|
2638 @code{clear}. If set to \"none\", Octave will always check time stamps\n\ |
|
2639 on files to determine whether functions defined in function files\n\ |
|
2640 need to recompiled.\n\ |
|
2641 @end deftypefn") |
|
2642 { |
|
2643 octave_value retval; |
|
2644 |
|
2645 if (nargout > 0) |
|
2646 { |
|
2647 switch (Vignore_function_time_stamp) |
|
2648 { |
|
2649 case 1: |
|
2650 retval = "system"; |
|
2651 break; |
|
2652 |
|
2653 case 2: |
|
2654 retval = "all"; |
|
2655 break; |
|
2656 |
|
2657 default: |
|
2658 retval = "none"; |
|
2659 break; |
|
2660 } |
|
2661 } |
|
2662 |
|
2663 int nargin = args.length (); |
|
2664 |
|
2665 if (nargin == 1) |
|
2666 { |
|
2667 std::string sval = args(0).string_value (); |
|
2668 |
|
2669 if (! error_state) |
|
2670 { |
|
2671 if (sval == "all") |
|
2672 Vignore_function_time_stamp = 2; |
|
2673 else if (sval == "system") |
|
2674 Vignore_function_time_stamp = 1; |
|
2675 else if (sval == "none") |
|
2676 Vignore_function_time_stamp = 0; |
|
2677 else |
|
2678 error ("ignore_function_time_stamp: expecting argument to be \"all\", \"system\", or \"none\""); |
|
2679 } |
|
2680 else |
|
2681 error ("ignore_function_time_stamp: expecting argument to be character string"); |
|
2682 } |
|
2683 else if (nargin > 1) |
5823
|
2684 print_usage (); |
5794
|
2685 |
|
2686 return retval; |
3016
|
2687 } |
|
2688 |
1
|
2689 /* |
|
2690 ;;; Local Variables: *** |
|
2691 ;;; mode: C++ *** |
|
2692 ;;; End: *** |
|
2693 */ |