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\ |
6637
|
238 @code{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 |
5663
|
965 bool |
5397
|
966 fcn_out_of_date (octave_function *fcn, const std::string& ff, time_t tp) |
5312
|
967 { |
|
968 bool retval = false; |
|
969 |
5397
|
970 fcn->mark_fcn_file_up_to_date (octave_time ()); |
|
971 |
|
972 if (! (Vignore_function_time_stamp == 2 |
|
973 || (Vignore_function_time_stamp && fcn->is_system_fcn_file ()))) |
5312
|
974 { |
5397
|
975 file_stat fs (ff); |
|
976 |
|
977 if (fs && fs.is_newer (tp)) |
|
978 retval = true; |
5312
|
979 } |
|
980 |
|
981 return retval; |
|
982 } |
|
983 |
5397
|
984 // Is there a corresponding function file that is newer than the |
|
985 // symbol definition? |
|
986 |
5312
|
987 static bool |
1
|
988 symbol_out_of_date (symbol_record *sr) |
|
989 { |
2926
|
990 bool retval = false; |
195
|
991 |
5397
|
992 if (sr) |
1
|
993 { |
2975
|
994 octave_value ans = sr->def (); |
|
995 |
5397
|
996 octave_function *fcn = ans.function_value (true); |
|
997 |
6325
|
998 if (fcn) |
5397
|
999 { |
|
1000 std::string ff = fcn->fcn_file_name (); |
|
1001 |
|
1002 if (! ff.empty ()) |
|
1003 { |
6323
|
1004 octave_time tc = fcn->time_checked (); |
|
1005 |
|
1006 bool relative = fcn->is_relative (); |
|
1007 |
|
1008 if (tc < Vlast_prompt_time |
|
1009 || (relative && tc < Vlast_chdir_time)) |
5397
|
1010 { |
|
1011 time_t tp = fcn->time_parsed (); |
|
1012 |
6346
|
1013 std::string nm = fcn->is_nested_function () |
|
1014 ? fcn->parent_fcn_name () : fcn->name (); |
5397
|
1015 |
5775
|
1016 // FIXME -- the following code is repeated |
5534
|
1017 // in load_fcn_from_file in parse.y. |
|
1018 |
|
1019 int nm_len = nm.length (); |
|
1020 |
|
1021 std::string file; |
|
1022 |
|
1023 if (octave_env::absolute_pathname (nm) |
5864
|
1024 && ((nm_len > 4 && (nm.substr (nm_len-4) == ".oct" |
|
1025 || nm.substr (nm_len-4) == ".mex")) |
5534
|
1026 || (nm_len > 2 && nm.substr (nm_len-4) == ".m"))) |
|
1027 { |
|
1028 file = nm; |
|
1029 } |
|
1030 else |
|
1031 { |
|
1032 file = lookup_autoload (nm); |
|
1033 |
|
1034 if (file.empty ()) |
6323
|
1035 file = load_path::find_fcn (nm); |
|
1036 |
|
1037 file = octave_env::make_absolute (file, octave_env::getcwd ()); |
5534
|
1038 } |
5397
|
1039 |
6613
|
1040 if (file.empty ()) |
6323
|
1041 { |
6613
|
1042 // Can't see this function now, so we should |
|
1043 // clear it. |
6323
|
1044 |
|
1045 sr->clear (); |
|
1046 |
|
1047 retval = true; |
|
1048 } |
|
1049 else if (same_file (file, ff)) |
5397
|
1050 { |
|
1051 retval = fcn_out_of_date (fcn, ff, tp); |
|
1052 } |
|
1053 else |
|
1054 { |
6323
|
1055 // Check the full function name. Maybe we already |
5397
|
1056 // parsed it. |
|
1057 |
|
1058 symbol_record *full_sr = fbi_sym_tab->lookup (file); |
|
1059 |
|
1060 if (full_sr) |
|
1061 { |
|
1062 octave_value v = full_sr->def (); |
|
1063 |
|
1064 if (v.is_function ()) |
|
1065 { |
|
1066 // OK, swap the aliases around. |
|
1067 |
5775
|
1068 // FIXME -- this is a bit |
5397
|
1069 // tricky, so maybe some refactoring is |
|
1070 // in order here too... |
|
1071 |
|
1072 symbol_record *short_sr = fbi_sym_tab->lookup (nm); |
|
1073 |
|
1074 if (short_sr) |
|
1075 short_sr->alias (full_sr); |
|
1076 |
|
1077 // Make local symbol table entry point |
|
1078 // to correct global function too. |
|
1079 |
|
1080 sr->alias (full_sr); |
|
1081 |
|
1082 fcn = v.function_value (); |
|
1083 |
|
1084 retval = fcn_out_of_date (fcn, file, tp); |
|
1085 } |
|
1086 else |
|
1087 retval = true; |
|
1088 } |
|
1089 else |
|
1090 retval = true; |
|
1091 } |
|
1092 } |
|
1093 } |
|
1094 } |
1
|
1095 } |
2926
|
1096 |
|
1097 return retval; |
1
|
1098 } |
|
1099 |
1827
|
1100 bool |
2856
|
1101 lookup (symbol_record *sym_rec, bool exec_script) |
581
|
1102 { |
1827
|
1103 bool script_executed = false; |
581
|
1104 |
|
1105 if (! sym_rec->is_linked_to_global ()) |
|
1106 { |
|
1107 if (sym_rec->is_defined ()) |
|
1108 { |
|
1109 if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) |
1271
|
1110 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
1111 } |
|
1112 else if (! sym_rec->is_formal_parameter ()) |
|
1113 { |
|
1114 link_to_builtin_or_function (sym_rec); |
1271
|
1115 |
581
|
1116 if (! sym_rec->is_defined ()) |
1271
|
1117 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
1118 else if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) |
1271
|
1119 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
1120 } |
|
1121 } |
|
1122 |
1271
|
1123 return script_executed; |
581
|
1124 } |
|
1125 |
|
1126 // Get the symbol record for the given name that is visible in the |
|
1127 // current scope. Reread any function definitions that appear to be |
|
1128 // out of date. If a function is available in a file but is not |
|
1129 // currently loaded, this will load it and insert the name in the |
|
1130 // current symbol table. |
|
1131 |
|
1132 symbol_record * |
3523
|
1133 lookup_by_name (const std::string& nm, bool exec_script) |
581
|
1134 { |
2856
|
1135 symbol_record *sym_rec = curr_sym_tab->lookup (nm, true); |
581
|
1136 |
|
1137 lookup (sym_rec, exec_script); |
|
1138 |
|
1139 return sym_rec; |
|
1140 } |
|
1141 |
4930
|
1142 octave_value |
6323
|
1143 lookup_function (const std::string& nm, const std::string& parent) |
4342
|
1144 { |
4930
|
1145 octave_value retval; |
4342
|
1146 |
|
1147 symbol_record *sr = 0; |
|
1148 |
6323
|
1149 if (! parent.empty ()) |
|
1150 sr = fbi_sym_tab->lookup (parent + ":" + nm); |
|
1151 |
4342
|
1152 if (! sr || ! sr->is_function ()) |
|
1153 { |
6351
|
1154 if (curr_parent_function) |
|
1155 sr = fbi_sym_tab->lookup (curr_parent_function->name () + ":" + nm); |
|
1156 |
|
1157 if (! sr || ! sr->is_function ()) |
|
1158 sr = fbi_sym_tab->lookup (nm, true); |
4342
|
1159 |
|
1160 if (sr && ! sr->is_function ()) |
|
1161 load_fcn_from_file (sr, false); |
|
1162 } |
|
1163 |
|
1164 if (sr) |
|
1165 { |
|
1166 octave_value v = sr->def (); |
|
1167 |
|
1168 if (v.is_function ()) |
4930
|
1169 retval = v; |
4342
|
1170 } |
|
1171 |
|
1172 return retval; |
|
1173 } |
|
1174 |
4930
|
1175 octave_value |
4700
|
1176 lookup_user_function (const std::string& nm) |
|
1177 { |
4930
|
1178 octave_value retval; |
4700
|
1179 |
|
1180 symbol_record *sr = 0; |
|
1181 |
|
1182 if (curr_parent_function) |
|
1183 { |
4748
|
1184 std::string parent = curr_parent_function->name (); |
4700
|
1185 |
|
1186 sr = fbi_sym_tab->lookup (parent + ":" + nm); |
|
1187 } |
|
1188 |
|
1189 if (! sr || ! sr->is_user_function ()) |
|
1190 { |
|
1191 sr = fbi_sym_tab->lookup (nm, true); |
|
1192 |
|
1193 if (sr && ! sr->is_user_function ()) |
|
1194 load_fcn_from_file (sr, false); |
|
1195 } |
|
1196 |
|
1197 if (sr) |
4930
|
1198 retval = sr->def (); |
4700
|
1199 |
|
1200 return retval; |
|
1201 } |
|
1202 |
2849
|
1203 octave_value |
4988
|
1204 lookup_function_handle (const std::string& nm) |
|
1205 { |
|
1206 octave_value retval; |
|
1207 |
|
1208 symbol_record *sr = curr_sym_tab->lookup (nm, true); |
|
1209 |
|
1210 if (sr && sr->def ().is_function_handle ()) |
|
1211 retval = sr->def (); |
|
1212 |
|
1213 return retval; |
|
1214 } |
|
1215 |
|
1216 octave_value |
5027
|
1217 get_global_value (const std::string& nm, bool silent) |
2849
|
1218 { |
|
1219 octave_value retval; |
|
1220 |
|
1221 symbol_record *sr = global_sym_tab->lookup (nm); |
|
1222 |
|
1223 if (sr) |
|
1224 { |
2975
|
1225 octave_value sr_def = sr->def (); |
2849
|
1226 |
5027
|
1227 if (sr_def.is_defined ()) |
|
1228 retval = sr_def; |
|
1229 else if (! silent) |
2849
|
1230 error ("get_global_by_name: undefined symbol `%s'", nm.c_str ()); |
|
1231 } |
5027
|
1232 else if (! silent) |
2849
|
1233 error ("get_global_by_name: unknown symbol `%s'", nm.c_str ()); |
|
1234 |
|
1235 return retval; |
|
1236 } |
|
1237 |
|
1238 void |
3523
|
1239 set_global_value (const std::string& nm, const octave_value& val) |
2849
|
1240 { |
2856
|
1241 symbol_record *sr = global_sym_tab->lookup (nm, true); |
2849
|
1242 |
|
1243 if (sr) |
|
1244 sr->define (val); |
|
1245 else |
|
1246 panic_impossible (); |
|
1247 } |
|
1248 |
593
|
1249 // Variable values. |
195
|
1250 |
5791
|
1251 octave_value |
|
1252 set_internal_variable (bool& var, const octave_value_list& args, |
5794
|
1253 int nargout, const char *nm) |
5791
|
1254 { |
5794
|
1255 octave_value retval; |
|
1256 |
5800
|
1257 int nargin = args.length (); |
|
1258 |
|
1259 if (nargout > 0 || nargin == 0) |
5794
|
1260 retval = var; |
5791
|
1261 |
|
1262 if (nargin == 1) |
|
1263 { |
|
1264 bool bval = args(0).bool_value (); |
|
1265 |
|
1266 if (! error_state) |
|
1267 var = bval; |
|
1268 else |
|
1269 error ("%s: expecting arg to be a logical value", nm); |
|
1270 } |
|
1271 else if (nargin > 1) |
5823
|
1272 print_usage (); |
5791
|
1273 |
|
1274 return retval; |
|
1275 } |
|
1276 |
|
1277 octave_value |
5794
|
1278 set_internal_variable (char& var, const octave_value_list& args, |
|
1279 int nargout, const char *nm) |
5791
|
1280 { |
5794
|
1281 octave_value retval; |
|
1282 |
5800
|
1283 int nargin = args.length (); |
|
1284 |
|
1285 if (nargout > 0 || nargin == 0) |
5794
|
1286 retval = var; |
5791
|
1287 |
|
1288 if (nargin == 1) |
|
1289 { |
|
1290 std::string sval = args(0).string_value (); |
|
1291 |
|
1292 if (! error_state) |
5794
|
1293 { |
|
1294 switch (sval.length ()) |
|
1295 { |
|
1296 case 1: |
|
1297 var = sval[0]; |
|
1298 break; |
|
1299 |
|
1300 case 0: |
|
1301 var = '\0'; |
|
1302 break; |
|
1303 |
|
1304 default: |
|
1305 error ("%s: argument must be a single character", nm); |
|
1306 break; |
|
1307 } |
|
1308 } |
|
1309 else |
|
1310 error ("%s: argument must be a single character", nm); |
|
1311 } |
|
1312 else if (nargin > 1) |
5823
|
1313 print_usage (); |
5794
|
1314 |
|
1315 return retval; |
|
1316 } |
|
1317 |
|
1318 octave_value |
|
1319 set_internal_variable (int& var, const octave_value_list& args, |
|
1320 int nargout, const char *nm, |
|
1321 int minval, int maxval) |
|
1322 { |
|
1323 octave_value retval; |
|
1324 |
5800
|
1325 int nargin = args.length (); |
|
1326 |
|
1327 if (nargout > 0 || nargin == 0) |
5794
|
1328 retval = var; |
|
1329 |
|
1330 if (nargin == 1) |
|
1331 { |
|
1332 int ival = args(0).int_value (); |
|
1333 |
|
1334 if (! error_state) |
|
1335 { |
|
1336 if (ival < minval) |
|
1337 error ("%s: expecting arg to be greater than %d", minval); |
|
1338 else if (ival > maxval) |
|
1339 error ("%s: expecting arg to be less than or equal to %d", maxval); |
|
1340 else |
|
1341 var = ival; |
|
1342 } |
|
1343 else |
|
1344 error ("%s: expecting arg to be an integer value", nm); |
|
1345 } |
|
1346 else if (nargin > 1) |
5823
|
1347 print_usage (); |
5794
|
1348 |
|
1349 return retval; |
|
1350 } |
|
1351 |
|
1352 octave_value |
|
1353 set_internal_variable (double& var, const octave_value_list& args, |
|
1354 int nargout, const char *nm, |
|
1355 double minval, double maxval) |
|
1356 { |
|
1357 octave_value retval; |
|
1358 |
5800
|
1359 int nargin = args.length (); |
|
1360 |
|
1361 if (nargout > 0 || nargin == 0) |
5794
|
1362 retval = var; |
|
1363 |
|
1364 if (nargin == 1) |
|
1365 { |
|
1366 double dval = args(0).scalar_value (); |
|
1367 |
|
1368 if (! error_state) |
|
1369 { |
|
1370 if (dval < minval) |
|
1371 error ("%s: expecting arg to be greater than %g", minval); |
|
1372 else if (dval > maxval) |
|
1373 error ("%s: expecting arg to be less than or equal to %g", maxval); |
|
1374 else |
|
1375 var = dval; |
|
1376 } |
|
1377 else |
|
1378 error ("%s: expecting arg to be a scalar value", nm); |
|
1379 } |
|
1380 else if (nargin > 1) |
5823
|
1381 print_usage (); |
5794
|
1382 |
|
1383 return retval; |
|
1384 } |
|
1385 |
|
1386 octave_value |
|
1387 set_internal_variable (std::string& var, const octave_value_list& args, |
|
1388 int nargout, const char *nm, bool empty_ok) |
|
1389 { |
|
1390 octave_value retval; |
|
1391 |
5800
|
1392 int nargin = args.length (); |
|
1393 |
|
1394 if (nargout > 0 || nargin == 0) |
5794
|
1395 retval = var; |
|
1396 |
|
1397 if (nargin == 1) |
|
1398 { |
|
1399 std::string sval = args(0).string_value (); |
|
1400 |
|
1401 if (! error_state) |
|
1402 { |
|
1403 if (empty_ok || ! sval.empty ()) |
|
1404 var = sval; |
|
1405 else |
|
1406 error ("%s: value must not be empty", nm); |
|
1407 } |
5791
|
1408 else |
|
1409 error ("%s: expecting arg to be a character string", nm); |
|
1410 } |
|
1411 else if (nargin > 1) |
5823
|
1412 print_usage (); |
1
|
1413 |
|
1414 return retval; |
|
1415 } |
|
1416 |
593
|
1417 // Global stuff and links to builtin variables and functions. |
|
1418 |
581
|
1419 // Make the definition of the symbol record sr be the same as the |
|
1420 // definition of the global variable of the same name, creating it if |
1418
|
1421 // it doesn't already exist. |
581
|
1422 |
195
|
1423 void |
|
1424 link_to_global_variable (symbol_record *sr) |
|
1425 { |
2975
|
1426 if (! sr->is_linked_to_global ()) |
195
|
1427 { |
2975
|
1428 sr->mark_as_linked_to_global (); |
195
|
1429 |
2975
|
1430 if (! error_state) |
|
1431 { |
3523
|
1432 std::string nm = sr->name (); |
2846
|
1433 |
2975
|
1434 symbol_record *gsr = global_sym_tab->lookup (nm, true); |
|
1435 |
|
1436 // Make sure this symbol is a variable. |
2900
|
1437 |
4009
|
1438 if (! gsr->is_user_variable ()) |
2975
|
1439 gsr->define (octave_value ()); |
2900
|
1440 |
4009
|
1441 sr->alias (gsr); |
2975
|
1442 } |
195
|
1443 } |
|
1444 } |
|
1445 |
581
|
1446 // Make the definition of the symbol record sr be the same as the |
|
1447 // definition of the builtin variable of the same name. |
|
1448 |
|
1449 // Make the definition of the symbol record sr be the same as the |
5794
|
1450 // definition of the builtin function, or user function of the same |
|
1451 // name, provided that the name has not been used as a formal parameter. |
581
|
1452 |
195
|
1453 void |
|
1454 link_to_builtin_or_function (symbol_record *sr) |
|
1455 { |
4238
|
1456 std::string nm = sr->name (); |
|
1457 |
|
1458 symbol_record *tmp_sym = 0; |
|
1459 |
6323
|
1460 octave_function *fcn = octave_call_stack::current (); |
|
1461 |
|
1462 std::string parent = fcn ? fcn->parent_fcn_name () : std::string (); |
|
1463 |
|
1464 if (! parent.empty ()) |
|
1465 tmp_sym = fbi_sym_tab->lookup (parent + ":" + nm); |
|
1466 |
|
1467 if (! tmp_sym && curr_parent_function) |
|
1468 tmp_sym = fbi_sym_tab->lookup (curr_parent_function->name () + ":" + nm); |
4238
|
1469 |
|
1470 if (! tmp_sym) |
|
1471 tmp_sym = fbi_sym_tab->lookup (nm); |
195
|
1472 |
529
|
1473 if (tmp_sym |
5794
|
1474 && tmp_sym->is_function () |
529
|
1475 && ! tmp_sym->is_formal_parameter ()) |
|
1476 sr->alias (tmp_sym); |
195
|
1477 } |
|
1478 |
581
|
1479 // Force a link to a function in the current symbol table. This is |
|
1480 // used just after defining a function to avoid different behavior |
|
1481 // depending on whether or not the function has been evaluated after |
|
1482 // being defined. |
|
1483 // |
|
1484 // Return without doing anything if there isn't a function with the |
|
1485 // given name defined in the global symbol table. |
|
1486 |
195
|
1487 void |
3523
|
1488 force_link_to_function (const std::string& id_name) |
195
|
1489 { |
4009
|
1490 symbol_record *fsr = fbi_sym_tab->lookup (id_name, true); |
|
1491 if (fsr->is_function ()) |
195
|
1492 { |
|
1493 curr_sym_tab->clear (id_name); |
2856
|
1494 symbol_record *csr = curr_sym_tab->lookup (id_name, true); |
4009
|
1495 csr->alias (fsr); |
195
|
1496 } |
|
1497 } |
|
1498 |
2294
|
1499 DEFUN (document, args, , |
3361
|
1500 "-*- texinfo -*-\n\ |
|
1501 @deftypefn {Built-in Function} {} document (@var{symbol}, @var{text})\n\ |
|
1502 Set the documentation string for @var{symbol} to @var{text}.\n\ |
|
1503 @end deftypefn") |
593
|
1504 { |
2294
|
1505 octave_value retval; |
1755
|
1506 |
2294
|
1507 int nargin = args.length (); |
1755
|
1508 |
2294
|
1509 if (nargin == 2) |
593
|
1510 { |
3523
|
1511 std::string name = args(0).string_value (); |
593
|
1512 |
2294
|
1513 if (! error_state) |
593
|
1514 { |
3523
|
1515 std::string help = args(1).string_value (); |
593
|
1516 |
2294
|
1517 if (! error_state) |
|
1518 { |
5794
|
1519 if (is_command_name (name) |
2294
|
1520 || is_mapper_function_name (name) |
|
1521 || is_builtin_function_name (name)) |
5794
|
1522 error ("document: can't redefine help for built-in functions"); |
2294
|
1523 else |
|
1524 { |
2856
|
1525 symbol_record *sym_rec = curr_sym_tab->lookup (name); |
2294
|
1526 |
|
1527 if (sym_rec) |
|
1528 sym_rec->document (help); |
|
1529 else |
|
1530 error ("document: no such symbol `%s'", name.c_str ()); |
|
1531 } |
|
1532 } |
593
|
1533 } |
|
1534 } |
|
1535 else |
5823
|
1536 print_usage (); |
593
|
1537 |
|
1538 return retval; |
|
1539 } |
|
1540 |
5775
|
1541 // FIXME -- this function is duplicated in symtab.cc with the |
5659
|
1542 // name maybe_list_cmp_fcn. |
|
1543 |
|
1544 static int |
|
1545 symbol_record_name_compare (const void *a_arg, const void *b_arg) |
|
1546 { |
5929
|
1547 const symbol_record *a = *(static_cast<symbol_record *const*> (a_arg)); |
|
1548 const symbol_record *b = *(static_cast<symbol_record *const*> (b_arg)); |
5659
|
1549 |
|
1550 std::string a_nm = a->name (); |
|
1551 std::string b_nm = b->name (); |
|
1552 |
|
1553 return a_nm.compare (b_nm); |
|
1554 } |
|
1555 |
4435
|
1556 static octave_value |
|
1557 do_who (int argc, const string_vector& argv, int return_list) |
529
|
1558 { |
4435
|
1559 octave_value retval; |
529
|
1560 |
2856
|
1561 bool show_builtins = false; |
3248
|
1562 bool show_functions = false; |
|
1563 bool show_variables = false; |
2856
|
1564 bool show_verbose = false; |
529
|
1565 |
3523
|
1566 std::string my_name = argv[0]; |
584
|
1567 |
1857
|
1568 int i; |
|
1569 for (i = 1; i < argc; i++) |
529
|
1570 { |
1755
|
1571 if (argv[i] == "-all" || argv[i] == "-a") |
529
|
1572 { |
2856
|
1573 show_builtins = true; |
|
1574 show_functions = true; |
|
1575 show_variables = true; |
529
|
1576 } |
1755
|
1577 else if (argv[i] == "-builtins" || argv[i] == "-b") |
2856
|
1578 show_builtins = true; |
1755
|
1579 else if (argv[i] == "-functions" || argv[i] == "-f") |
2856
|
1580 show_functions = true; |
1755
|
1581 else if (argv[i] == "-long" || argv[i] == "-l") |
2856
|
1582 show_verbose = true; |
1755
|
1583 else if (argv[i] == "-variables" || argv[i] == "-v") |
2856
|
1584 show_variables = true; |
1755
|
1585 else if (argv[i][0] == '-') |
|
1586 warning ("%s: unrecognized option `%s'", my_name.c_str (), |
|
1587 argv[i].c_str ()); |
529
|
1588 else |
867
|
1589 break; |
529
|
1590 } |
|
1591 |
3248
|
1592 // If no options were specified to select the type of symbol to |
|
1593 // display, then set defaults. |
|
1594 |
|
1595 if (! (show_builtins || show_functions || show_variables)) |
|
1596 { |
4208
|
1597 show_functions = at_top_level (); |
3248
|
1598 show_variables = true; |
|
1599 } |
|
1600 |
1857
|
1601 int npats = argc - i; |
|
1602 string_vector pats (npats); |
|
1603 for (int j = 0; j < npats; j++) |
|
1604 pats[j] = argv[i+j]; |
|
1605 |
1271
|
1606 // If the user specified -l and nothing else, show variables. If |
|
1607 // evaluating this at the top level, also show functions. |
529
|
1608 |
|
1609 if (show_verbose && ! (show_builtins || show_functions || show_variables)) |
|
1610 { |
4208
|
1611 show_functions = at_top_level (); |
529
|
1612 show_variables = 1; |
|
1613 } |
|
1614 |
4435
|
1615 if (return_list) |
529
|
1616 { |
5775
|
1617 // FIXME -- maybe symbol_list should return a std::list |
5659
|
1618 // object instead of an Array. |
|
1619 |
|
1620 dim_vector dv (0, 0); |
|
1621 |
|
1622 Array<symbol_record *> s3 (dv); |
|
1623 Array<symbol_record *> s4 (dv); |
|
1624 Array<symbol_record *> s5 (dv); |
|
1625 Array<symbol_record *> s6 (dv); |
|
1626 Array<symbol_record *> s7 (dv); |
5864
|
1627 Array<symbol_record *> s8 (dv); |
4435
|
1628 |
|
1629 if (show_builtins) |
|
1630 { |
5659
|
1631 s3 = fbi_sym_tab->symbol_list (pats, symbol_record::BUILTIN_FUNCTION, |
|
1632 SYMTAB_ALL_SCOPES); |
4435
|
1633 } |
|
1634 |
|
1635 if (show_functions) |
|
1636 { |
5659
|
1637 s4 = fbi_sym_tab->symbol_list (pats, symbol_record::DLD_FUNCTION, |
|
1638 SYMTAB_ALL_SCOPES); |
|
1639 |
|
1640 s5 = fbi_sym_tab->symbol_list (pats, symbol_record::USER_FUNCTION, |
|
1641 SYMTAB_ALL_SCOPES); |
5864
|
1642 |
|
1643 s6 = fbi_sym_tab->symbol_list (pats, symbol_record::MEX_FUNCTION, |
|
1644 SYMTAB_ALL_SCOPES); |
4435
|
1645 } |
|
1646 |
|
1647 if (show_variables) |
|
1648 { |
5864
|
1649 s7 = curr_sym_tab->symbol_list (pats, symbol_record::USER_VARIABLE, |
5659
|
1650 SYMTAB_LOCAL_SCOPE); |
|
1651 |
5864
|
1652 s8 = curr_sym_tab->symbol_list (pats, symbol_record::USER_VARIABLE, |
5659
|
1653 SYMTAB_GLOBAL_SCOPE); |
4435
|
1654 } |
|
1655 |
5659
|
1656 octave_idx_type s3_len = s3.length (); |
|
1657 octave_idx_type s4_len = s4.length (); |
|
1658 octave_idx_type s5_len = s5.length (); |
|
1659 octave_idx_type s6_len = s6.length (); |
|
1660 octave_idx_type s7_len = s7.length (); |
5864
|
1661 octave_idx_type s8_len = s8.length (); |
|
1662 |
|
1663 octave_idx_type symbols_len |
|
1664 = s3_len + s4_len + s5_len + s6_len + s7_len + s8_len; |
5659
|
1665 |
|
1666 Array<symbol_record *> symbols (dim_vector (symbols_len, 1)); |
|
1667 |
|
1668 octave_idx_type k = 0; |
|
1669 |
|
1670 symbols.insert (s3, k, 0); |
|
1671 k += s3_len; |
|
1672 symbols.insert (s4, k, 0); |
|
1673 k += s4_len; |
|
1674 symbols.insert (s5, k, 0); |
|
1675 k += s5_len; |
|
1676 symbols.insert (s6, k, 0); |
|
1677 k += s6_len; |
|
1678 symbols.insert (s7, k, 0); |
5864
|
1679 k += s7_len; |
|
1680 symbols.insert (s8, k, 0); |
5659
|
1681 |
|
1682 symbols.qsort (symbol_record_name_compare); |
|
1683 |
4435
|
1684 if (show_verbose) |
|
1685 { |
5659
|
1686 Array<octave_value> name_info (symbols_len, 1); |
|
1687 Array<octave_value> size_info (symbols_len, 1); |
|
1688 Array<octave_value> bytes_info (symbols_len, 1); |
|
1689 Array<octave_value> class_info (symbols_len, 1); |
|
1690 Array<octave_value> global_info (symbols_len, 1); |
|
1691 Array<octave_value> sparse_info (symbols_len, 1); |
|
1692 Array<octave_value> complex_info (symbols_len, 1); |
|
1693 Array<octave_value> nesting_info (symbols_len, 1); |
|
1694 |
|
1695 for (octave_idx_type j = 0; j < symbols_len; j++) |
|
1696 { |
|
1697 symbol_record *sr = symbols(j); |
|
1698 |
|
1699 Octave_map ni; |
|
1700 |
|
1701 std::string caller_function_name; |
5743
|
1702 |
|
1703 octave_function *caller = octave_call_stack::caller (); |
|
1704 if (caller) |
|
1705 caller_function_name = caller->name (); |
5659
|
1706 |
|
1707 ni.assign ("function", caller_function_name); |
|
1708 ni.assign ("level", 1); |
|
1709 |
|
1710 name_info(j) = sr->name (); |
|
1711 size_info(j) = sr->size (); |
|
1712 bytes_info(j) = sr->byte_size (); |
|
1713 class_info(j) = sr->class_name (); |
|
1714 global_info(j) = sr->is_linked_to_global (); |
|
1715 sparse_info(j) = sr->is_sparse_type (); |
|
1716 complex_info(j) = sr->is_complex_type (); |
|
1717 nesting_info(j) = ni; |
|
1718 } |
|
1719 |
|
1720 Octave_map info; |
|
1721 |
|
1722 info.assign ("name", name_info); |
|
1723 info.assign ("size", size_info); |
|
1724 info.assign ("bytes", bytes_info); |
|
1725 info.assign ("class", class_info); |
|
1726 info.assign ("global", global_info); |
|
1727 info.assign ("sparse", sparse_info); |
|
1728 info.assign ("complex", complex_info); |
|
1729 info.assign ("nesting", nesting_info); |
|
1730 |
|
1731 retval = info; |
4435
|
1732 } |
|
1733 else |
5659
|
1734 { |
|
1735 string_vector names; |
|
1736 |
|
1737 if (symbols_len > 0) |
|
1738 { |
|
1739 names.resize (symbols_len); |
|
1740 |
|
1741 for (octave_idx_type j = 0; j < symbols_len; j++) |
|
1742 names[j] = symbols(j)->name (); |
|
1743 } |
|
1744 |
|
1745 retval = Cell (names); |
|
1746 } |
529
|
1747 } |
4435
|
1748 else |
529
|
1749 { |
4435
|
1750 int pad_after = 0; |
|
1751 |
|
1752 if (show_builtins) |
|
1753 { |
|
1754 pad_after += fbi_sym_tab->maybe_list |
|
1755 ("*** built-in functions:", pats, octave_stdout, |
|
1756 show_verbose, symbol_record::BUILTIN_FUNCTION, SYMTAB_ALL_SCOPES); |
|
1757 } |
529
|
1758 |
4435
|
1759 if (show_functions) |
|
1760 { |
|
1761 pad_after += fbi_sym_tab->maybe_list |
|
1762 ("*** dynamically linked functions:", pats, |
|
1763 octave_stdout, show_verbose, symbol_record::DLD_FUNCTION, |
|
1764 SYMTAB_ALL_SCOPES); |
|
1765 |
|
1766 pad_after += fbi_sym_tab->maybe_list |
|
1767 ("*** currently compiled functions:", pats, |
|
1768 octave_stdout, show_verbose, symbol_record::USER_FUNCTION, |
|
1769 SYMTAB_ALL_SCOPES); |
5864
|
1770 |
|
1771 pad_after += fbi_sym_tab->maybe_list |
|
1772 ("*** mex functions:", pats, |
|
1773 octave_stdout, show_verbose, symbol_record::MEX_FUNCTION, |
|
1774 SYMTAB_ALL_SCOPES); |
4435
|
1775 } |
|
1776 |
|
1777 if (show_variables) |
|
1778 { |
|
1779 pad_after += curr_sym_tab->maybe_list |
|
1780 ("*** local user variables:", pats, octave_stdout, |
|
1781 show_verbose, symbol_record::USER_VARIABLE, SYMTAB_LOCAL_SCOPE); |
|
1782 |
|
1783 pad_after += curr_sym_tab->maybe_list |
|
1784 ("*** globally visible user variables:", pats, |
|
1785 octave_stdout, show_verbose, symbol_record::USER_VARIABLE, |
|
1786 SYMTAB_GLOBAL_SCOPE); |
|
1787 } |
|
1788 |
|
1789 if (pad_after) |
|
1790 octave_stdout << "\n"; |
529
|
1791 } |
|
1792 |
581
|
1793 return retval; |
|
1794 } |
|
1795 |
4435
|
1796 DEFCMD (who, args, nargout, |
3361
|
1797 "-*- texinfo -*-\n\ |
|
1798 @deffn {Command} who options pattern @dots{}\n\ |
|
1799 @deffnx {Command} whos options pattern @dots{}\n\ |
|
1800 List currently defined symbols matching the given patterns. The\n\ |
|
1801 following are valid options. They may be shortened to one character but\n\ |
|
1802 may not be combined.\n\ |
|
1803 \n\ |
|
1804 @table @code\n\ |
|
1805 @item -all\n\ |
|
1806 List all currently defined symbols.\n\ |
|
1807 \n\ |
|
1808 @item -builtins\n\ |
5794
|
1809 List built-in functions. This includes all currently\n\ |
3361
|
1810 compiled function files, but does not include all function files that\n\ |
5814
|
1811 are in the search path.\n\ |
581
|
1812 \n\ |
3361
|
1813 @item -functions\n\ |
|
1814 List user-defined functions.\n\ |
|
1815 \n\ |
|
1816 @item -long\n\ |
|
1817 Print a long listing including the type and dimensions of any symbols.\n\ |
|
1818 The symbols in the first column of output indicate whether it is\n\ |
|
1819 possible to redefine the symbol, and whether it is possible for it to be\n\ |
|
1820 cleared.\n\ |
|
1821 \n\ |
|
1822 @item -variables\n\ |
|
1823 List user-defined variables.\n\ |
|
1824 @end table\n\ |
|
1825 \n\ |
|
1826 Valid patterns are the same as described for the @code{clear} command\n\ |
|
1827 above. If no patterns are supplied, all symbols from the given category\n\ |
|
1828 are listed. By default, only user defined functions and variables\n\ |
|
1829 visible in the local scope are displayed.\n\ |
|
1830 \n\ |
|
1831 The command @kbd{whos} is equivalent to @kbd{who -long}.\n\ |
|
1832 @end deffn") |
581
|
1833 { |
4435
|
1834 octave_value retval; |
581
|
1835 |
4435
|
1836 if (nargout < 2) |
|
1837 { |
|
1838 int argc = args.length () + 1; |
|
1839 |
|
1840 string_vector argv = args.make_argv ("who"); |
1755
|
1841 |
4435
|
1842 if (error_state) |
|
1843 return retval; |
1755
|
1844 |
4435
|
1845 retval = do_who (argc, argv, nargout == 1); |
|
1846 } |
|
1847 else |
5823
|
1848 print_usage (); |
581
|
1849 |
529
|
1850 return retval; |
|
1851 } |
|
1852 |
4435
|
1853 DEFCMD (whos, args, nargout, |
3458
|
1854 "-*- texinfo -*-\n\ |
|
1855 @deffn {Command} whos options pattern @dots{}\n\ |
|
1856 See who.\n\ |
|
1857 @end deffn") |
581
|
1858 { |
4435
|
1859 octave_value retval; |
712
|
1860 |
4435
|
1861 if (nargout < 2) |
|
1862 { |
|
1863 int nargin = args.length (); |
|
1864 |
|
1865 octave_value_list tmp_args; |
|
1866 |
|
1867 for (int i = nargin; i > 0; i--) |
|
1868 tmp_args(i) = args(i-1); |
581
|
1869 |
4435
|
1870 tmp_args(0) = "-long"; |
1755
|
1871 |
4435
|
1872 int argc = tmp_args.length () + 1; |
|
1873 |
|
1874 string_vector argv = tmp_args.make_argv ("whos"); |
581
|
1875 |
4435
|
1876 if (error_state) |
|
1877 return retval; |
581
|
1878 |
4435
|
1879 retval = do_who (argc, argv, nargout == 1); |
|
1880 } |
|
1881 else |
5823
|
1882 print_usage (); |
581
|
1883 |
|
1884 return retval; |
|
1885 } |
|
1886 |
593
|
1887 // Defining variables. |
|
1888 |
1162
|
1889 void |
2856
|
1890 bind_ans (const octave_value& val, bool print) |
1162
|
1891 { |
5794
|
1892 symbol_record *sr = curr_sym_tab->lookup ("ans", true); |
1162
|
1893 |
2978
|
1894 if (val.is_defined ()) |
|
1895 { |
|
1896 sr->define (val); |
1162
|
1897 |
2978
|
1898 if (print) |
|
1899 val.print_with_name (octave_stdout, "ans"); |
|
1900 } |
1162
|
1901 } |
|
1902 |
593
|
1903 void |
5794
|
1904 bind_internal_variable (const std::string& fname, const octave_value& val) |
593
|
1905 { |
5794
|
1906 octave_value_list args; |
|
1907 |
|
1908 args(0) = val; |
|
1909 |
|
1910 feval (fname, args, 0); |
529
|
1911 } |
|
1912 |
4319
|
1913 void |
|
1914 mlock (const std::string& nm) |
|
1915 { |
|
1916 symbol_record *sr = fbi_sym_tab->lookup (nm, true); |
|
1917 |
|
1918 if (sr) |
|
1919 sr->mark_as_static (); |
|
1920 } |
|
1921 |
|
1922 void |
|
1923 munlock (const std::string& nm) |
|
1924 { |
|
1925 symbol_record *sr = fbi_sym_tab->lookup (nm); |
|
1926 |
|
1927 if (sr && sr->is_static ()) |
|
1928 sr->unmark_static (); |
|
1929 else |
|
1930 error ("munlock: %s is not locked", nm.c_str ()); |
|
1931 } |
|
1932 |
|
1933 bool |
|
1934 mislocked (const std::string& nm) |
|
1935 { |
|
1936 symbol_record *sr = fbi_sym_tab->lookup (nm); |
|
1937 |
|
1938 return (sr && sr->is_static ()); |
|
1939 } |
|
1940 |
|
1941 DEFCMD (mlock, args, , |
|
1942 "-*- texinfo -*-\n\ |
4526
|
1943 @deftypefn {Built-in Function} {} mlock (@var{name})\n\ |
4319
|
1944 Lock the named function into memory. If no function is named\n\ |
|
1945 then lock in the current function.\n\ |
5642
|
1946 @seealso{munlock, mislocked, persistent}\n\ |
|
1947 @end deftypefn") |
4319
|
1948 { |
|
1949 octave_value_list retval; |
|
1950 |
|
1951 if (args.length () == 1) |
|
1952 { |
|
1953 std::string name = args(0).string_value (); |
|
1954 |
|
1955 if (! error_state) |
|
1956 mlock (name); |
|
1957 else |
|
1958 error ("mlock: expecting argument to be a function name"); |
|
1959 } |
|
1960 else if (args.length () == 0) |
|
1961 { |
5744
|
1962 octave_user_function *fcn = octave_call_stack::caller_user_function (); |
5743
|
1963 |
|
1964 if (fcn) |
|
1965 mlock (fcn->name ()); |
4319
|
1966 else |
|
1967 error ("mlock: invalid use outside a function"); |
|
1968 } |
|
1969 else |
5823
|
1970 print_usage (); |
4319
|
1971 |
|
1972 return retval; |
|
1973 } |
|
1974 |
|
1975 DEFCMD (munlock, args, , |
|
1976 "-*- texinfo -*-\n\ |
|
1977 @deftypefn {Built-in Function} {} munlock (@var{fcn})\n\ |
|
1978 Unlock the named function. If no function is named\n\ |
|
1979 then unlock the current function.\n\ |
5642
|
1980 @seealso{mlock, mislocked, persistent}\n\ |
|
1981 @end deftypefn") |
4319
|
1982 { |
|
1983 octave_value_list retval; |
|
1984 |
|
1985 if (args.length() == 1) |
|
1986 { |
|
1987 std::string name = args(0).string_value (); |
|
1988 |
|
1989 if (! error_state) |
|
1990 munlock (name); |
|
1991 else |
|
1992 error ("munlock: expecting argument to be a function name"); |
|
1993 } |
|
1994 else if (args.length () == 0) |
|
1995 { |
5744
|
1996 octave_user_function *fcn = octave_call_stack::caller_user_function (); |
5743
|
1997 |
|
1998 if (fcn) |
|
1999 mlock (fcn->name ()); |
4319
|
2000 else |
|
2001 error ("munlock: invalid use outside a function"); |
|
2002 } |
|
2003 else |
5823
|
2004 print_usage (); |
4319
|
2005 |
|
2006 return retval; |
|
2007 } |
|
2008 |
|
2009 |
|
2010 DEFCMD (mislocked, args, , |
|
2011 "-*- texinfo -*-\n\ |
|
2012 @deftypefn {Built-in Function} {} mislocked (@var{fcn})\n\ |
|
2013 Return true if the named function is locked. If no function is named\n\ |
|
2014 then return true if the current function is locked.\n\ |
5642
|
2015 @seealso{mlock, munlock, persistent}\n\ |
|
2016 @end deftypefn") |
4319
|
2017 { |
|
2018 octave_value retval; |
|
2019 |
|
2020 if (args.length() == 1) |
|
2021 { |
|
2022 std::string name = args(0).string_value (); |
|
2023 |
|
2024 if (! error_state) |
|
2025 retval = mislocked (name); |
|
2026 else |
|
2027 error ("mislocked: expecting argument to be a function name"); |
|
2028 } |
|
2029 else if (args.length () == 0) |
|
2030 { |
5744
|
2031 octave_user_function *fcn = octave_call_stack::caller_user_function (); |
5743
|
2032 |
|
2033 if (fcn) |
|
2034 retval = mislocked (fcn->name ()); |
4319
|
2035 else |
|
2036 error ("mislocked: invalid use outside a function"); |
|
2037 } |
|
2038 else |
5823
|
2039 print_usage (); |
4319
|
2040 |
|
2041 return retval; |
|
2042 } |
|
2043 |
593
|
2044 // Deleting names from the symbol tables. |
|
2045 |
3681
|
2046 static inline bool |
4009
|
2047 name_matches_any_pattern (const std::string& nm, |
|
2048 const string_vector& argv, int argc, int idx) |
3681
|
2049 { |
|
2050 bool retval = false; |
|
2051 |
|
2052 for (int k = idx; k < argc; k++) |
|
2053 { |
|
2054 std::string patstr = argv[k]; |
|
2055 |
|
2056 if (! patstr.empty ()) |
|
2057 { |
|
2058 glob_match pattern (patstr); |
|
2059 |
|
2060 if (pattern.match (nm)) |
|
2061 { |
|
2062 retval = true; |
|
2063 break; |
|
2064 } |
|
2065 } |
|
2066 } |
|
2067 |
|
2068 return retval; |
|
2069 } |
|
2070 |
4009
|
2071 static inline bool |
|
2072 is_local_variable (const std::string& nm) |
|
2073 { |
|
2074 symbol_record *sr = curr_sym_tab->lookup (nm); |
|
2075 |
|
2076 return (sr && sr->is_variable ()); |
|
2077 } |
|
2078 |
|
2079 static inline void |
|
2080 maybe_warn_exclusive (bool exclusive) |
|
2081 { |
|
2082 if (exclusive) |
|
2083 warning ("clear: ignoring --exclusive option"); |
|
2084 } |
|
2085 |
|
2086 static inline void |
|
2087 do_clear_all (void) |
|
2088 { |
|
2089 curr_sym_tab->clear (); |
|
2090 fbi_sym_tab->clear_functions (); |
|
2091 global_sym_tab->clear (); |
|
2092 } |
|
2093 |
|
2094 static inline void |
|
2095 do_clear_functions (void) |
|
2096 { |
|
2097 curr_sym_tab->clear_functions (); |
|
2098 fbi_sym_tab->clear_functions (); |
|
2099 } |
|
2100 |
|
2101 static inline void |
|
2102 do_clear_globals (void) |
|
2103 { |
|
2104 curr_sym_tab->clear_globals (); |
|
2105 global_sym_tab->clear (); |
|
2106 } |
|
2107 |
|
2108 static inline void |
|
2109 do_clear_variables (void) |
|
2110 { |
|
2111 curr_sym_tab->clear (); |
|
2112 } |
|
2113 |
|
2114 static inline bool |
|
2115 do_clear_function (const std::string& nm) |
|
2116 { |
|
2117 bool b1 = curr_sym_tab->clear_function (nm); |
|
2118 |
|
2119 bool b2 = fbi_sym_tab->clear_function (nm); |
|
2120 |
|
2121 return b1 || b2; |
|
2122 } |
|
2123 |
|
2124 static inline bool |
|
2125 do_clear_global (const std::string& nm) |
|
2126 { |
|
2127 bool b1 = curr_sym_tab->clear_global (nm); |
|
2128 |
|
2129 bool b2 = global_sym_tab->clear_variable (nm); |
|
2130 |
|
2131 return b1 || b2; |
|
2132 } |
|
2133 |
|
2134 static inline bool |
|
2135 do_clear_variable (const std::string& nm) |
|
2136 { |
|
2137 return curr_sym_tab->clear_variable (nm); |
|
2138 } |
|
2139 |
|
2140 static inline bool |
|
2141 do_clear_symbol (const std::string& nm) |
|
2142 { |
|
2143 bool cleared = curr_sym_tab->clear_variable (nm); |
|
2144 |
|
2145 if (! cleared) |
|
2146 cleared = do_clear_function (nm); |
|
2147 |
|
2148 return cleared; |
|
2149 } |
|
2150 |
|
2151 static inline bool |
|
2152 do_clear_function_pattern (const std::string& pat) |
|
2153 { |
|
2154 bool b1 = curr_sym_tab->clear_function_pattern (pat); |
|
2155 |
|
2156 bool b2 = fbi_sym_tab->clear_function_pattern (pat); |
|
2157 |
|
2158 return b1 || b2; |
|
2159 } |
|
2160 |
|
2161 static inline bool |
|
2162 do_clear_global_pattern (const std::string& pat) |
|
2163 { |
|
2164 bool b1 = curr_sym_tab->clear_global_pattern (pat); |
|
2165 |
|
2166 bool b2 = global_sym_tab->clear_variable_pattern (pat); |
|
2167 |
|
2168 return b1 || b2; |
|
2169 } |
|
2170 |
|
2171 static inline bool |
|
2172 do_clear_variable_pattern (const std::string& pat) |
|
2173 { |
|
2174 return curr_sym_tab->clear_variable_pattern (pat); |
|
2175 } |
|
2176 |
|
2177 static inline bool |
|
2178 do_clear_symbol_pattern (const std::string& pat) |
|
2179 { |
5775
|
2180 // FIXME -- if we have a variable v1 and a function v2 and |
4009
|
2181 // someone says clear v*, we will clear the variable but not the |
|
2182 // function. Is that really what should happen? (I think it is |
|
2183 // what Matlab does.) |
|
2184 |
|
2185 bool cleared = curr_sym_tab->clear_variable_pattern (pat); |
|
2186 |
|
2187 if (! cleared) |
|
2188 cleared = do_clear_function_pattern (pat); |
|
2189 |
|
2190 return cleared; |
|
2191 } |
|
2192 |
|
2193 static inline void |
|
2194 do_clear_functions (const string_vector& argv, int argc, int idx, |
|
2195 bool exclusive = false) |
|
2196 { |
|
2197 if (idx == argc) |
|
2198 do_clear_functions (); |
|
2199 else |
|
2200 { |
|
2201 if (exclusive) |
|
2202 { |
|
2203 string_vector lfcns = curr_sym_tab->user_function_name_list (); |
|
2204 |
|
2205 int lcount = lfcns.length (); |
|
2206 |
|
2207 for (int i = 0; i < lcount; i++) |
|
2208 { |
|
2209 std::string nm = lfcns[i]; |
|
2210 |
|
2211 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2212 do_clear_function (nm); |
|
2213 } |
|
2214 |
|
2215 string_vector fcns = fbi_sym_tab->user_function_name_list (); |
|
2216 |
|
2217 int fcount = fcns.length (); |
|
2218 |
|
2219 for (int i = 0; i < fcount; i++) |
|
2220 { |
|
2221 std::string nm = fcns[i]; |
|
2222 |
|
2223 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2224 do_clear_function (nm); |
|
2225 } |
|
2226 } |
|
2227 else |
|
2228 { |
|
2229 while (idx < argc) |
|
2230 do_clear_function_pattern (argv[idx++]); |
|
2231 } |
|
2232 } |
|
2233 } |
|
2234 |
|
2235 static inline void |
|
2236 do_clear_globals (const string_vector& argv, int argc, int idx, |
|
2237 bool exclusive = false) |
|
2238 { |
|
2239 if (idx == argc) |
|
2240 do_clear_globals (); |
|
2241 else |
|
2242 { |
|
2243 if (exclusive) |
|
2244 { |
|
2245 string_vector lvars = curr_sym_tab->global_variable_name_list (); |
|
2246 |
|
2247 int lcount = lvars.length (); |
|
2248 |
|
2249 for (int i = 0; i < lcount; i++) |
|
2250 { |
|
2251 std::string nm = lvars[i]; |
|
2252 |
|
2253 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2254 do_clear_global (nm); |
|
2255 } |
|
2256 |
|
2257 string_vector gvars = global_sym_tab->global_variable_name_list (); |
|
2258 |
|
2259 int gcount = gvars.length (); |
|
2260 |
|
2261 for (int i = 0; i < gcount; i++) |
|
2262 { |
|
2263 std::string nm = gvars[i]; |
|
2264 |
|
2265 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2266 do_clear_global (nm); |
|
2267 } |
|
2268 } |
|
2269 else |
|
2270 { |
|
2271 while (idx < argc) |
|
2272 do_clear_global_pattern (argv[idx++]); |
|
2273 } |
|
2274 } |
|
2275 } |
|
2276 |
|
2277 static inline void |
|
2278 do_clear_variables (const string_vector& argv, int argc, int idx, |
|
2279 bool exclusive = false) |
|
2280 { |
|
2281 if (idx == argc) |
|
2282 do_clear_variables (); |
|
2283 else |
|
2284 { |
|
2285 if (exclusive) |
|
2286 { |
|
2287 string_vector lvars = curr_sym_tab->variable_name_list (); |
|
2288 |
|
2289 int lcount = lvars.length (); |
|
2290 |
|
2291 for (int i = 0; i < lcount; i++) |
|
2292 { |
|
2293 std::string nm = lvars[i]; |
|
2294 |
|
2295 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2296 do_clear_variable (nm); |
|
2297 } |
|
2298 } |
|
2299 else |
|
2300 { |
|
2301 while (idx < argc) |
|
2302 do_clear_variable_pattern (argv[idx++]); |
|
2303 } |
|
2304 } |
|
2305 } |
|
2306 |
|
2307 static inline void |
|
2308 do_clear_symbols (const string_vector& argv, int argc, int idx, |
|
2309 bool exclusive = false) |
|
2310 { |
|
2311 if (idx == argc) |
|
2312 do_clear_variables (); |
|
2313 else |
|
2314 { |
|
2315 if (exclusive) |
|
2316 { |
5775
|
2317 // FIXME -- is this really what we want, or do we |
4009
|
2318 // somehow want to only clear the functions that are not |
|
2319 // shadowed by local variables? It seems that would be a |
|
2320 // bit harder to do. |
|
2321 |
|
2322 do_clear_variables (argv, argc, idx, exclusive); |
|
2323 do_clear_functions (argv, argc, idx, exclusive); |
|
2324 } |
|
2325 else |
|
2326 { |
|
2327 while (idx < argc) |
|
2328 do_clear_symbol_pattern (argv[idx++]); |
|
2329 } |
|
2330 } |
|
2331 } |
|
2332 |
|
2333 static void |
|
2334 do_matlab_compatible_clear (const string_vector& argv, int argc, int idx) |
|
2335 { |
|
2336 // This is supposed to be mostly Matlab compatible. |
|
2337 |
|
2338 for (; idx < argc; idx++) |
|
2339 { |
|
2340 if (argv[idx] == "all" && ! is_local_variable ("all")) |
|
2341 { |
|
2342 do_clear_all (); |
|
2343 } |
|
2344 else if (argv[idx] == "functions" && ! is_local_variable ("functions")) |
|
2345 { |
|
2346 do_clear_functions (argv, argc, ++idx); |
|
2347 } |
|
2348 else if (argv[idx] == "global" && ! is_local_variable ("global")) |
|
2349 { |
|
2350 do_clear_globals (argv, argc, ++idx); |
|
2351 } |
|
2352 else if (argv[idx] == "variables" && ! is_local_variable ("variables")) |
|
2353 { |
|
2354 do_clear_variables (); |
|
2355 } |
|
2356 else |
|
2357 { |
|
2358 do_clear_symbol_pattern (argv[idx]); |
|
2359 } |
|
2360 } |
|
2361 } |
|
2362 |
|
2363 #define CLEAR_OPTION_ERROR(cond) \ |
|
2364 do \ |
|
2365 { \ |
|
2366 if (cond) \ |
|
2367 { \ |
5823
|
2368 print_usage (); \ |
4009
|
2369 return retval; \ |
|
2370 } \ |
|
2371 } \ |
|
2372 while (0) |
|
2373 |
4954
|
2374 bool |
|
2375 clear_function (const std::string& nm) |
|
2376 { |
|
2377 return do_clear_function (nm); |
|
2378 } |
|
2379 |
4988
|
2380 bool |
|
2381 clear_variable (const std::string& nm) |
|
2382 { |
|
2383 return do_clear_variable (nm); |
|
2384 } |
|
2385 |
|
2386 bool |
|
2387 clear_symbol (const std::string& nm) |
|
2388 { |
|
2389 return do_clear_symbol (nm); |
|
2390 } |
|
2391 |
4208
|
2392 DEFCMD (clear, args, , |
3361
|
2393 "-*- texinfo -*-\n\ |
|
2394 @deffn {Command} clear [-x] pattern @dots{}\n\ |
|
2395 Delete the names matching the given patterns from the symbol table. The\n\ |
|
2396 pattern may contain the following special characters:\n\ |
4016
|
2397 \n\ |
3361
|
2398 @table @code\n\ |
|
2399 @item ?\n\ |
|
2400 Match any single character.\n\ |
668
|
2401 \n\ |
3361
|
2402 @item *\n\ |
|
2403 Match zero or more characters.\n\ |
|
2404 \n\ |
|
2405 @item [ @var{list} ]\n\ |
|
2406 Match the list of characters specified by @var{list}. If the first\n\ |
|
2407 character is @code{!} or @code{^}, match all characters except those\n\ |
|
2408 specified by @var{list}. For example, the pattern @samp{[a-zA-Z]} will\n\ |
|
2409 match all lower and upper case alphabetic characters.\n\ |
|
2410 @end table\n\ |
|
2411 \n\ |
|
2412 For example, the command\n\ |
593
|
2413 \n\ |
3361
|
2414 @example\n\ |
|
2415 clear foo b*r\n\ |
|
2416 @end example\n\ |
|
2417 \n\ |
|
2418 @noindent\n\ |
|
2419 clears the name @code{foo} and all names that begin with the letter\n\ |
|
2420 @code{b} and end with the letter @code{r}.\n\ |
668
|
2421 \n\ |
3361
|
2422 If @code{clear} is called without any arguments, all user-defined\n\ |
|
2423 variables (local and global) are cleared from the symbol table. If\n\ |
|
2424 @code{clear} is called with at least one argument, only the visible\n\ |
|
2425 names matching the arguments are cleared. For example, suppose you have\n\ |
|
2426 defined a function @code{foo}, and then hidden it by performing the\n\ |
|
2427 assignment @code{foo = 2}. Executing the command @kbd{clear foo} once\n\ |
|
2428 will clear the variable definition and restore the definition of\n\ |
|
2429 @code{foo} as a function. Executing @kbd{clear foo} a second time will\n\ |
|
2430 clear the function definition.\n\ |
|
2431 \n\ |
|
2432 With -x, clear the variables that don't match the patterns.\n\ |
|
2433 @end deffn") |
529
|
2434 { |
2086
|
2435 octave_value_list retval; |
593
|
2436 |
1755
|
2437 int argc = args.length () + 1; |
593
|
2438 |
1968
|
2439 string_vector argv = args.make_argv ("clear"); |
1755
|
2440 |
4009
|
2441 if (! error_state) |
529
|
2442 { |
4009
|
2443 if (argc == 1) |
593
|
2444 { |
4009
|
2445 do_clear_variables (); |
3681
|
2446 } |
|
2447 else |
|
2448 { |
4009
|
2449 int idx = 0; |
|
2450 |
|
2451 bool clear_all = false; |
|
2452 bool clear_functions = false; |
|
2453 bool clear_globals = false; |
|
2454 bool clear_variables = false; |
|
2455 bool exclusive = false; |
|
2456 bool have_dash_option = false; |
3681
|
2457 |
4009
|
2458 while (++idx < argc) |
|
2459 { |
4010
|
2460 if (argv[idx] == "-all" || argv[idx] == "-a") |
593
|
2461 { |
4009
|
2462 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681
|
2463 |
4009
|
2464 have_dash_option = true; |
|
2465 clear_all = true; |
|
2466 } |
4010
|
2467 else if (argv[idx] == "-exclusive" || argv[idx] == "-x") |
4009
|
2468 { |
|
2469 have_dash_option = true; |
|
2470 exclusive = true; |
|
2471 } |
4010
|
2472 else if (argv[idx] == "-functions" || argv[idx] == "-f") |
4009
|
2473 { |
|
2474 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681
|
2475 |
4009
|
2476 have_dash_option = true; |
|
2477 clear_functions = true; |
|
2478 } |
4010
|
2479 else if (argv[idx] == "-global" || argv[idx] == "-g") |
4009
|
2480 { |
|
2481 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
|
2482 |
|
2483 have_dash_option = true; |
|
2484 clear_globals = true; |
|
2485 } |
4010
|
2486 else if (argv[idx] == "-variables" || argv[idx] == "-v") |
4009
|
2487 { |
|
2488 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681
|
2489 |
4009
|
2490 have_dash_option = true; |
|
2491 clear_variables = true; |
|
2492 } |
|
2493 else |
|
2494 break; |
|
2495 } |
3681
|
2496 |
4224
|
2497 if (idx <= argc) |
4009
|
2498 { |
|
2499 if (! have_dash_option) |
|
2500 { |
|
2501 do_matlab_compatible_clear (argv, argc, idx); |
|
2502 } |
|
2503 else |
|
2504 { |
|
2505 if (clear_all) |
3681
|
2506 { |
4009
|
2507 maybe_warn_exclusive (exclusive); |
3681
|
2508 |
4009
|
2509 if (++idx < argc) |
|
2510 warning |
4010
|
2511 ("clear: ignoring extra arguments after -all"); |
3681
|
2512 |
4009
|
2513 curr_sym_tab->clear (); |
|
2514 fbi_sym_tab->clear_functions (); |
|
2515 global_sym_tab->clear (); |
|
2516 } |
|
2517 else if (clear_functions) |
|
2518 { |
|
2519 do_clear_functions (argv, argc, idx, exclusive); |
|
2520 } |
|
2521 else if (clear_globals) |
593
|
2522 { |
4009
|
2523 do_clear_globals (argv, argc, idx, exclusive); |
|
2524 } |
|
2525 else if (clear_variables) |
|
2526 { |
|
2527 do_clear_variables (argv, argc, idx, exclusive); |
|
2528 } |
|
2529 else |
|
2530 { |
|
2531 do_clear_symbols (argv, argc, idx, exclusive); |
593
|
2532 } |
|
2533 } |
|
2534 } |
|
2535 } |
|
2536 } |
|
2537 |
|
2538 return retval; |
529
|
2539 } |
|
2540 |
3933
|
2541 DEFUN (__print_symtab_info__, args, , |
3446
|
2542 "-*- texinfo -*-\n\ |
3933
|
2543 @deftypefn {Built-in Function} {} __print_symtab_info__ ()\n\ |
3446
|
2544 Print raw symbol table statistices.\n\ |
|
2545 @end deftypefn") |
3005
|
2546 { |
|
2547 octave_value_list retval; |
|
2548 |
|
2549 int nargin = args.length (); |
|
2550 |
|
2551 if (nargin == 1) |
|
2552 { |
3523
|
2553 std::string arg = args(0).string_value (); |
3005
|
2554 |
4009
|
2555 if (arg == "fbi") |
|
2556 fbi_sym_tab->print_info (octave_stdout); |
|
2557 else if (arg == "global") |
3933
|
2558 global_sym_tab->print_info (octave_stdout); |
|
2559 else if (arg == "top-level") |
|
2560 top_level_sym_tab->print_info (octave_stdout); |
3005
|
2561 else |
3933
|
2562 { |
4009
|
2563 symbol_record *fsr = fbi_sym_tab->lookup (arg, true); |
3933
|
2564 |
4009
|
2565 if (fsr && fsr->is_user_function ()) |
3933
|
2566 { |
4009
|
2567 octave_value tmp = fsr->def (); |
5759
|
2568 const octave_base_value& rep = tmp.get_rep (); |
3933
|
2569 |
|
2570 const octave_user_function& fcn |
5759
|
2571 = dynamic_cast<const octave_user_function&> (rep); |
3933
|
2572 |
|
2573 fcn.print_symtab_info (octave_stdout); |
|
2574 } |
|
2575 else |
|
2576 error ("no user-defined function named %s", arg.c_str ()); |
|
2577 } |
3005
|
2578 } |
|
2579 else if (nargin == 0) |
3933
|
2580 curr_sym_tab->print_info (octave_stdout); |
3005
|
2581 else |
5823
|
2582 print_usage (); |
3005
|
2583 |
|
2584 return retval; |
|
2585 } |
|
2586 |
3933
|
2587 DEFUN (__print_symbol_info__, args, , |
3446
|
2588 "-*- texinfo -*-\n\ |
|
2589 @deftypefn {Built-in Function} {} __dump_symbol_info__ (@var{name})\n\ |
3548
|
2590 Print symbol table information for the symbol @var{name}.\n\ |
3446
|
2591 @end deftypefn") |
3239
|
2592 { |
|
2593 octave_value_list retval; |
|
2594 |
|
2595 int nargin = args.length (); |
|
2596 |
|
2597 if (nargin == 1) |
|
2598 { |
3523
|
2599 std::string symbol_name = args(0).string_value (); |
3239
|
2600 |
|
2601 if (! error_state) |
|
2602 { |
|
2603 symbol_record *sr = curr_sym_tab->lookup (symbol_name); |
|
2604 |
|
2605 if (sr) |
3933
|
2606 sr->print_info (octave_stdout); |
3239
|
2607 else |
3933
|
2608 error ("__print_symbol_info__: symbol %s not found", |
3239
|
2609 symbol_name.c_str ()); |
|
2610 } |
|
2611 else |
5823
|
2612 print_usage (); |
3239
|
2613 } |
|
2614 else |
5823
|
2615 print_usage (); |
3239
|
2616 |
|
2617 return retval; |
|
2618 } |
|
2619 |
5794
|
2620 DEFUN (ignore_function_time_stamp, args, nargout, |
3372
|
2621 "-*- texinfo -*-\n\ |
5794
|
2622 @deftypefn {Built-in Function} {@var{val} =} ignore_function_time_stamp ()\n\ |
|
2623 @deftypefnx {Built-in Function} {@var{old_val} =} ignore_function_time_stamp (@var{new_val})\n\ |
|
2624 Query or set the internal variable that controls whether Octave checks\n\ |
|
2625 the time stamp on files each time it looks up functions defined in\n\ |
|
2626 function files. If the internal variable is set to @code{\"system\"},\n\ |
|
2627 Octave will not automatically recompile function files in subdirectories of\n\ |
3371
|
2628 @file{@var{octave-home}/lib/@var{version}} if they have changed since\n\ |
|
2629 they were last compiled, but will recompile other function files in the\n\ |
5814
|
2630 search path if they change. If set to @code{\"all\"}, Octave will not\n\ |
3371
|
2631 recompile any function files unless their definitions are removed with\n\ |
5794
|
2632 @code{clear}. If set to \"none\", Octave will always check time stamps\n\ |
|
2633 on files to determine whether functions defined in function files\n\ |
|
2634 need to recompiled.\n\ |
|
2635 @end deftypefn") |
|
2636 { |
|
2637 octave_value retval; |
|
2638 |
|
2639 if (nargout > 0) |
|
2640 { |
|
2641 switch (Vignore_function_time_stamp) |
|
2642 { |
|
2643 case 1: |
|
2644 retval = "system"; |
|
2645 break; |
|
2646 |
|
2647 case 2: |
|
2648 retval = "all"; |
|
2649 break; |
|
2650 |
|
2651 default: |
|
2652 retval = "none"; |
|
2653 break; |
|
2654 } |
|
2655 } |
|
2656 |
|
2657 int nargin = args.length (); |
|
2658 |
|
2659 if (nargin == 1) |
|
2660 { |
|
2661 std::string sval = args(0).string_value (); |
|
2662 |
|
2663 if (! error_state) |
|
2664 { |
|
2665 if (sval == "all") |
|
2666 Vignore_function_time_stamp = 2; |
|
2667 else if (sval == "system") |
|
2668 Vignore_function_time_stamp = 1; |
|
2669 else if (sval == "none") |
|
2670 Vignore_function_time_stamp = 0; |
|
2671 else |
|
2672 error ("ignore_function_time_stamp: expecting argument to be \"all\", \"system\", or \"none\""); |
|
2673 } |
|
2674 else |
|
2675 error ("ignore_function_time_stamp: expecting argument to be character string"); |
|
2676 } |
|
2677 else if (nargin > 1) |
5823
|
2678 print_usage (); |
5794
|
2679 |
|
2680 return retval; |
3016
|
2681 } |
|
2682 |
1
|
2683 /* |
|
2684 ;;; Local Variables: *** |
|
2685 ;;; mode: C++ *** |
|
2686 ;;; End: *** |
|
2687 */ |