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