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 |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
240
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
1
|
25 #endif |
|
26 |
1468
|
27 #include <cstdio> |
1343
|
28 #include <cstring> |
605
|
29 |
4207
|
30 #include <set> |
1728
|
31 #include <string> |
|
32 |
2926
|
33 #include "file-stat.h" |
|
34 #include "oct-env.h" |
|
35 #include "glob-match.h" |
1755
|
36 #include "str-vec.h" |
|
37 |
2492
|
38 #include <defaults.h> |
1352
|
39 #include "defun.h" |
|
40 #include "dirfns.h" |
|
41 #include "error.h" |
2205
|
42 #include "gripes.h" |
1352
|
43 #include "help.h" |
3165
|
44 #include "input.h" |
1352
|
45 #include "lex.h" |
2926
|
46 #include "oct-map.h" |
|
47 #include "oct-obj.h" |
|
48 #include "ov.h" |
3933
|
49 #include "ov-usr-fcn.h" |
605
|
50 #include "pager.h" |
1352
|
51 #include "parse.h" |
2926
|
52 #include "symtab.h" |
2205
|
53 #include "toplev.h" |
1352
|
54 #include "unwind-prot.h" |
1
|
55 #include "utils.h" |
1352
|
56 #include "variables.h" |
2205
|
57 |
|
58 // Should Octave always check to see if function files have changed |
|
59 // since they were last compiled? |
2806
|
60 static int Vignore_function_time_stamp; |
2205
|
61 |
1
|
62 // Symbol table for symbols at the top level. |
581
|
63 symbol_table *top_level_sym_tab = 0; |
1
|
64 |
|
65 // Symbol table for the current scope. |
581
|
66 symbol_table *curr_sym_tab = 0; |
1
|
67 |
4245
|
68 // Symbol table for the current caller scope. |
|
69 symbol_table *curr_caller_sym_tab = 0; |
|
70 |
1
|
71 // Symbol table for global symbols. |
581
|
72 symbol_table *global_sym_tab = 0; |
1
|
73 |
4009
|
74 // Symbol table for functions and built-in symbols. |
|
75 symbol_table *fbi_sym_tab = 0; |
|
76 |
4208
|
77 static inline bool |
|
78 at_top_level (void) |
|
79 { |
|
80 return (curr_sym_tab == top_level_sym_tab); |
|
81 } |
|
82 |
593
|
83 // Initialization. |
|
84 |
|
85 // Create the initial symbol tables and set the current scope at the |
|
86 // top level. |
|
87 |
195
|
88 void |
|
89 initialize_symbol_tables (void) |
|
90 { |
4009
|
91 if (! fbi_sym_tab) |
4238
|
92 fbi_sym_tab = new symbol_table (2048, "FBI"); |
4009
|
93 |
581
|
94 if (! global_sym_tab) |
4238
|
95 global_sym_tab = new symbol_table (2048, "GLOBAL"); |
195
|
96 |
581
|
97 if (! top_level_sym_tab) |
4238
|
98 top_level_sym_tab = new symbol_table (4096, "TOP"); |
195
|
99 |
4245
|
100 curr_caller_sym_tab = curr_sym_tab = top_level_sym_tab; |
195
|
101 } |
|
102 |
593
|
103 // Attributes of variables and functions. |
|
104 |
|
105 // Is this variable a builtin? |
|
106 |
1827
|
107 bool |
3523
|
108 is_builtin_variable (const std::string& name) |
593
|
109 { |
4009
|
110 symbol_record *sr = fbi_sym_tab->lookup (name); |
593
|
111 return (sr && sr->is_builtin_variable ()); |
|
112 } |
|
113 |
4208
|
114 // Is this a command-style function? |
593
|
115 |
4208
|
116 static std::set <std::string> command_set; |
4207
|
117 |
|
118 static inline bool |
4208
|
119 is_marked_as_command (const std::string& s) |
4207
|
120 { |
4208
|
121 return command_set.find (s) != command_set.end (); |
4207
|
122 } |
|
123 |
|
124 static inline void |
4208
|
125 mark_as_command (const std::string& s) |
4207
|
126 { |
4208
|
127 command_set.insert (s); |
4207
|
128 } |
|
129 |
|
130 static inline void |
4208
|
131 unmark_command (const std::string& s) |
4207
|
132 { |
4208
|
133 command_set.erase (s); |
4207
|
134 |
|
135 symbol_record *sr = fbi_sym_tab->lookup (s); |
|
136 |
|
137 if (sr) |
4208
|
138 sr->unmark_command (); |
4207
|
139 } |
|
140 |
4208
|
141 DEFCMD (mark_as_command, args, , |
4207
|
142 "-*- texinfo -*-\n\ |
4208
|
143 @deftypefn {Built-in Function} {} mark_as_command (@var{name})\n\ |
|
144 Enter @var{name} into the list of commands.\n\ |
4207
|
145 @end deftypefn") |
|
146 { |
|
147 octave_value_list retval; |
|
148 |
4208
|
149 if (at_top_level ()) |
|
150 { |
|
151 int nargin = args.length (); |
4207
|
152 |
4208
|
153 if (nargin > 0) |
|
154 { |
|
155 int argc = nargin + 1; |
4207
|
156 |
4208
|
157 string_vector argv = args.make_argv ("mark_as_command"); |
4207
|
158 |
4208
|
159 if (! error_state) |
|
160 { |
|
161 for (int i = 1; i < argc; i++) |
|
162 mark_as_command (argv[i]); |
|
163 } |
4207
|
164 } |
4208
|
165 else |
|
166 print_usage ("mark_as_command"); |
4207
|
167 } |
|
168 else |
4208
|
169 warning ("mark_as_command: invalid use inside function body"); |
4207
|
170 |
|
171 return retval; |
|
172 } |
|
173 |
4208
|
174 DEFCMD (unmark_command, args, , |
4207
|
175 "-*- texinfo -*-\n\ |
4208
|
176 @deftypefn {Built-in Function} {} mark_as_command (@var{name})\n\ |
|
177 Remove @var{name} from the list of commands.\n\ |
4207
|
178 @end deftypefn") |
|
179 { |
|
180 octave_value_list retval; |
|
181 |
4208
|
182 if (at_top_level ()) |
|
183 { |
|
184 int nargin = args.length (); |
4207
|
185 |
4208
|
186 if (nargin > 0) |
|
187 { |
|
188 int argc = nargin + 1; |
4207
|
189 |
4208
|
190 string_vector argv = args.make_argv ("unmark_command"); |
4207
|
191 |
4208
|
192 if (! error_state) |
|
193 { |
|
194 for (int i = 1; i < argc; i++) |
|
195 unmark_command (argv[i]); |
|
196 } |
4207
|
197 } |
4208
|
198 else |
|
199 print_usage ("unmark_command"); |
4207
|
200 } |
|
201 else |
4208
|
202 warning ("mark_as_command: invalid use inside function body"); |
4207
|
203 |
|
204 return retval; |
|
205 } |
|
206 |
1827
|
207 bool |
4208
|
208 is_command_name (const std::string& s) |
593
|
209 { |
4207
|
210 bool retval = false; |
|
211 |
4009
|
212 symbol_record *sr = fbi_sym_tab->lookup (s); |
4207
|
213 |
|
214 if (sr) |
|
215 { |
4208
|
216 if (sr->is_command ()) |
4207
|
217 retval = true; |
4208
|
218 else if (is_marked_as_command (s)) |
4207
|
219 { |
4208
|
220 sr->mark_as_command (); |
4207
|
221 retval = true; |
|
222 } |
|
223 } |
|
224 else |
4208
|
225 retval = is_marked_as_command (s); |
4207
|
226 |
|
227 return retval; |
593
|
228 } |
|
229 |
3355
|
230 // Is this a built-in function? |
2294
|
231 |
|
232 bool |
3523
|
233 is_builtin_function_name (const std::string& s) |
2294
|
234 { |
4009
|
235 symbol_record *sr = fbi_sym_tab->lookup (s); |
2294
|
236 return (sr && sr->is_builtin_function ()); |
|
237 } |
|
238 |
|
239 // Is this a mapper function? |
|
240 |
|
241 bool |
3523
|
242 is_mapper_function_name (const std::string& s) |
2294
|
243 { |
4009
|
244 symbol_record *sr = fbi_sym_tab->lookup (s); |
2294
|
245 return (sr && sr->is_mapper_function ()); |
|
246 } |
|
247 |
593
|
248 // Is this function globally in this scope? |
|
249 |
1827
|
250 bool |
3523
|
251 is_globally_visible (const std::string& name) |
593
|
252 { |
2856
|
253 symbol_record *sr = curr_sym_tab->lookup (name); |
593
|
254 return (sr && sr->is_linked_to_global ()); |
|
255 } |
|
256 |
2086
|
257 // Is this octave_value a valid function? |
593
|
258 |
2975
|
259 octave_function * |
4345
|
260 is_valid_function (const std::string& fcn_name, |
|
261 const std::string& warn_for, bool warn) |
593
|
262 { |
2975
|
263 octave_function *ans = 0; |
593
|
264 |
|
265 symbol_record *sr = 0; |
1755
|
266 |
|
267 if (! fcn_name.empty ()) |
3618
|
268 { |
4009
|
269 sr = fbi_sym_tab->lookup (fcn_name, true); |
3618
|
270 |
|
271 lookup (sr, false); |
|
272 } |
593
|
273 |
|
274 if (sr) |
2975
|
275 { |
|
276 octave_value tmp = sr->def (); |
|
277 ans = tmp.function_value (true); |
|
278 } |
593
|
279 |
|
280 if (! sr || ! ans || ! sr->is_function ()) |
|
281 { |
|
282 if (warn) |
|
283 error ("%s: the symbol `%s' is not valid as a function", |
1755
|
284 warn_for.c_str (), fcn_name.c_str ()); |
593
|
285 ans = 0; |
|
286 } |
|
287 |
|
288 return ans; |
|
289 } |
|
290 |
2975
|
291 octave_function * |
4345
|
292 is_valid_function (const octave_value& arg, |
|
293 const std::string& warn_for, bool warn) |
3178
|
294 { |
|
295 octave_function *ans = 0; |
|
296 |
3523
|
297 std::string fcn_name; |
3178
|
298 |
|
299 if (arg.is_string ()) |
|
300 fcn_name = arg.string_value (); |
|
301 |
|
302 if (! error_state) |
|
303 ans = is_valid_function (fcn_name, warn_for, warn); |
|
304 else if (warn) |
|
305 error ("%s: expecting function name as argument", warn_for.c_str ()); |
|
306 |
|
307 return ans; |
|
308 } |
|
309 |
|
310 octave_function * |
3523
|
311 extract_function (const octave_value& arg, const std::string& warn_for, |
|
312 const std::string& fname, const std::string& header, |
|
313 const std::string& trailer) |
2796
|
314 { |
2975
|
315 octave_function *retval = 0; |
2796
|
316 |
|
317 retval = is_valid_function (arg, warn_for, 0); |
|
318 |
|
319 if (! retval) |
|
320 { |
3523
|
321 std::string s = arg.string_value (); |
2796
|
322 |
3523
|
323 std::string cmd = header; |
2796
|
324 cmd.append (s); |
|
325 cmd.append (trailer); |
|
326 |
|
327 if (! error_state) |
|
328 { |
|
329 int parse_status; |
|
330 |
2898
|
331 eval_string (cmd, true, parse_status); |
2796
|
332 |
|
333 if (parse_status == 0) |
|
334 { |
|
335 retval = is_valid_function (fname, warn_for, 0); |
|
336 |
|
337 if (! retval) |
|
338 { |
|
339 error ("%s: `%s' is not valid as a function", |
|
340 warn_for.c_str (), fname.c_str ()); |
|
341 return retval; |
|
342 } |
|
343 } |
|
344 else |
|
345 error ("%s: `%s' is not valid as a function", |
|
346 warn_for.c_str (), fname.c_str ()); |
|
347 } |
|
348 else |
|
349 error ("%s: expecting first argument to be a string", |
|
350 warn_for.c_str ()); |
|
351 } |
|
352 |
|
353 return retval; |
|
354 } |
|
355 |
2921
|
356 string_vector |
3523
|
357 get_struct_elts (const std::string& text) |
2921
|
358 { |
|
359 int n = 1; |
|
360 |
|
361 size_t pos = 0; |
|
362 |
|
363 size_t len = text.length (); |
|
364 |
|
365 while ((pos = text.find ('.', pos)) != NPOS) |
|
366 { |
|
367 if (++pos == len) |
|
368 break; |
|
369 |
|
370 n++; |
|
371 } |
|
372 |
|
373 string_vector retval (n); |
|
374 |
|
375 pos = 0; |
|
376 |
|
377 for (int i = 0; i < n; i++) |
|
378 { |
|
379 size_t len = text.find ('.', pos); |
|
380 |
|
381 if (len != NPOS) |
|
382 len -= pos; |
|
383 |
|
384 retval[i] = text.substr (pos, len); |
|
385 |
|
386 if (len != NPOS) |
|
387 pos += len + 1; |
|
388 } |
|
389 |
|
390 return retval; |
|
391 } |
|
392 |
4179
|
393 static inline bool |
|
394 is_variable (const std::string& name) |
|
395 { |
|
396 bool retval = false; |
|
397 |
|
398 if (! name.empty ()) |
|
399 { |
|
400 symbol_record *sr = curr_sym_tab->lookup (name); |
|
401 |
|
402 if (! sr) |
|
403 sr = fbi_sym_tab->lookup (name); |
|
404 |
|
405 retval = (sr && sr->is_variable ()); |
|
406 } |
|
407 |
|
408 return retval; |
|
409 } |
|
410 |
2921
|
411 string_vector |
3933
|
412 generate_struct_completions (const std::string& text, |
|
413 std::string& prefix, std::string& hint) |
2921
|
414 { |
|
415 string_vector names; |
|
416 |
|
417 size_t pos = text.rfind ('.'); |
|
418 |
3933
|
419 if (pos != NPOS) |
2921
|
420 { |
|
421 if (pos == text.length ()) |
|
422 hint = ""; |
|
423 else |
|
424 hint = text.substr (pos+1); |
|
425 |
|
426 prefix = text.substr (0, pos); |
|
427 |
4179
|
428 std::string base_name = prefix; |
|
429 |
|
430 pos = base_name.find_first_of ("{(."); |
2921
|
431 |
4179
|
432 if (pos != NPOS) |
|
433 base_name = base_name.substr (0, pos); |
4143
|
434 |
4179
|
435 if (is_variable (base_name)) |
|
436 { |
|
437 int parse_status; |
|
438 |
|
439 unwind_protect::begin_frame ("generate_struct_completions"); |
3935
|
440 |
4179
|
441 unwind_protect_str (Vwarning_option); |
|
442 unwind_protect_bool (discard_error_messages); |
|
443 unwind_protect_int (error_state); |
3935
|
444 |
4179
|
445 Vwarning_option = "off"; |
|
446 discard_error_messages = true; |
2921
|
447 |
4179
|
448 octave_value tmp = eval_string (prefix, true, parse_status); |
|
449 |
|
450 unwind_protect::run_frame ("generate_struct_completions"); |
3935
|
451 |
4179
|
452 if (tmp.is_defined () && tmp.is_map ()) |
|
453 names = tmp.map_keys (); |
|
454 } |
|
455 } |
2921
|
456 |
|
457 return names; |
|
458 } |
|
459 |
4179
|
460 // XXX FIXME XXX -- this will have to be much smarter to work |
|
461 // "correctly". |
|
462 |
2921
|
463 bool |
3523
|
464 looks_like_struct (const std::string& text) |
2921
|
465 { |
3968
|
466 bool retval = false; |
|
467 |
4179
|
468 #if 0 |
3968
|
469 symbol_record *sr = curr_sym_tab->lookup (text); |
2963
|
470 |
3968
|
471 if (sr && ! sr->is_function ()) |
|
472 { |
|
473 int parse_status; |
2921
|
474 |
4143
|
475 unwind_protect::begin_frame ("looks_like_struct"); |
|
476 |
|
477 unwind_protect_str (Vwarning_option); |
|
478 unwind_protect_bool (discard_error_messages); |
|
479 unwind_protect_int (error_state); |
|
480 |
|
481 Vwarning_option = "off"; |
|
482 discard_error_messages = true; |
|
483 |
3968
|
484 octave_value tmp = eval_string (text, true, parse_status); |
|
485 |
4143
|
486 unwind_protect::run_frame ("looks_like_struct"); |
|
487 |
3968
|
488 retval = (tmp.is_defined () && tmp.is_map ()); |
|
489 } |
4179
|
490 #endif |
3968
|
491 |
|
492 return retval; |
2921
|
493 } |
2796
|
494 |
4028
|
495 DEFUN (isglobal, args, , |
3361
|
496 "-*- texinfo -*-\n\ |
4028
|
497 @deftypefn {Built-in Function} {} isglobal (@var{name})\n\ |
3361
|
498 Return 1 if @var{name} is globally visible. Otherwise, return 0. For\n\ |
|
499 example,\n\ |
|
500 \n\ |
|
501 @example\n\ |
|
502 @group\n\ |
|
503 global x\n\ |
4028
|
504 isglobal (\"x\")\n\ |
3361
|
505 @result{} 1\n\ |
|
506 @end group\n\ |
|
507 @end example\n\ |
|
508 @end deftypefn") |
593
|
509 { |
4233
|
510 octave_value retval = false; |
593
|
511 |
712
|
512 int nargin = args.length (); |
|
513 |
|
514 if (nargin != 1) |
593
|
515 { |
4028
|
516 print_usage ("isglobal"); |
593
|
517 return retval; |
|
518 } |
|
519 |
3523
|
520 std::string name = args(0).string_value (); |
593
|
521 |
636
|
522 if (error_state) |
|
523 { |
4028
|
524 error ("isglobal: expecting std::string argument"); |
636
|
525 return retval; |
|
526 } |
|
527 |
2856
|
528 symbol_record *sr = curr_sym_tab->lookup (name); |
593
|
529 |
4233
|
530 retval = (sr && sr->is_linked_to_global ()); |
593
|
531 |
|
532 return retval; |
|
533 } |
|
534 |
4016
|
535 int |
|
536 symbol_exist (const std::string& name, const std::string& type) |
593
|
537 { |
4016
|
538 int retval = 0; |
636
|
539 |
3523
|
540 std::string struct_elts; |
|
541 std::string symbol_name = name; |
1755
|
542 |
|
543 size_t pos = name.find ('.'); |
|
544 |
2790
|
545 if (pos != NPOS && pos > 0) |
1277
|
546 { |
1755
|
547 struct_elts = name.substr (pos+1); |
2790
|
548 symbol_name = name.substr (0, pos); |
1277
|
549 } |
|
550 |
4009
|
551 // We shouldn't need to look in the global symbol table, since any |
|
552 // name that is visible in the current scope will be in the local |
|
553 // symbol table. |
|
554 |
2856
|
555 symbol_record *sr = curr_sym_tab->lookup (symbol_name); |
593
|
556 |
4009
|
557 if (! (sr && sr->is_defined ())) |
|
558 sr = fbi_sym_tab->lookup (symbol_name); |
593
|
559 |
4009
|
560 if (sr && sr->is_defined ()) |
1277
|
561 { |
4016
|
562 if (! retval |
|
563 && (type == "any" || type == "var") |
|
564 && sr->is_variable () |
|
565 && (struct_elts.empty () || sr->is_map_element (struct_elts))) |
4009
|
566 { |
4016
|
567 retval = 1; |
4009
|
568 } |
4016
|
569 |
|
570 if (! retval |
|
571 && (type == "any" || type == "builtin")) |
4009
|
572 { |
4016
|
573 if (sr->is_builtin_function ()) |
|
574 { |
|
575 retval = 5; |
|
576 } |
|
577 else if (sr->is_builtin_variable ()) |
|
578 { |
|
579 retval = 101; |
|
580 } |
|
581 else if (sr->is_builtin_constant ()) |
|
582 { |
|
583 retval = 102; |
|
584 } |
4009
|
585 } |
4016
|
586 |
|
587 if (! retval |
|
588 && (type == "any" || type == "file") |
|
589 && (sr->is_user_function () || sr->is_dld_function ())) |
4009
|
590 { |
4261
|
591 octave_value t = sr->def (); |
4016
|
592 octave_function *f = t.function_value (true); |
|
593 std::string s = f ? f->fcn_file_name () : std::string (); |
|
594 |
|
595 retval = s.empty () ? 103 : 2; |
4009
|
596 } |
1421
|
597 } |
4016
|
598 |
|
599 if (! retval) |
593
|
600 { |
4016
|
601 std::string file_name = fcn_file_in_path (name); |
1755
|
602 |
4016
|
603 if ((type == "any" || type == "file") && ! file_name.empty ()) |
|
604 { |
|
605 retval = 2; |
|
606 } |
|
607 } |
|
608 |
|
609 if (! retval) |
|
610 { |
|
611 std::string file_name = oct_file_in_path (name); |
|
612 |
|
613 if ((type == "any" || type == "file") && ! file_name.empty ()) |
593
|
614 { |
4016
|
615 retval = 3; |
593
|
616 } |
4016
|
617 } |
|
618 |
|
619 if (! retval) |
|
620 { |
|
621 std::string file_name = file_in_path (name, ""); |
|
622 |
|
623 if (file_name.empty ()) |
|
624 file_name = name; |
|
625 |
|
626 file_stat fs (file_name); |
|
627 |
|
628 if (fs) |
593
|
629 { |
4016
|
630 if ((type == "any" || type == "file") |
|
631 && fs.is_reg ()) |
1421
|
632 { |
4016
|
633 retval = 2; |
1421
|
634 } |
4016
|
635 else if ((type == "any" || type == "dir") |
|
636 && fs.is_dir ()) |
1421
|
637 { |
4016
|
638 retval = 7; |
1421
|
639 } |
593
|
640 } |
|
641 } |
|
642 |
|
643 return retval; |
|
644 } |
|
645 |
4016
|
646 DEFUN (exist, args, , |
|
647 "-*- texinfo -*-\n\ |
|
648 @deftypefn {Built-in Function} {} exist (@var{name}, @var{type})\n\ |
|
649 Return 1 if the name exists as a variable, 2 if the name (after\n\ |
|
650 appending @samp{.m}) is a function file in Octave's LOADPATH, 3 if the\n\ |
|
651 name is a @samp{.oct} file in Octave's LOADPATH, 5 if the name is a\n\ |
|
652 built-in function, 7 if the name is a directory, 101 if the name is\n\ |
|
653 a built-in variable, 102 if the name is a built-in constant, or 103\n\ |
|
654 if the name is a function not associated with a file (entered on\n\ |
|
655 the command line).\n\ |
|
656 \n\ |
|
657 Otherwise, return 0.\n\ |
|
658 \n\ |
|
659 This function also returns 2 if a regular file called @var{name}\n\ |
|
660 exists in Octave's @code{LOADPATH}. If you want information about\n\ |
|
661 other types of files, you should use some combination of the functions\n\ |
|
662 @code{file_in_path} and @code{stat} instead.\n\ |
|
663 \n\ |
|
664 If the optional argument @var{type} is supplied, check only for\n\ |
|
665 symbols of the specified type. Valid types are\n\ |
|
666 \n\ |
|
667 @table @samp\n\ |
|
668 @item \"var\"\n\ |
|
669 Check only for variables.\n\ |
|
670 @item \"builtin\"\n\ |
|
671 Check only for built-in functions.\n\ |
|
672 @item \"file\"\n\ |
|
673 Check only for files.\n\ |
|
674 @item \"dir\"\n\ |
|
675 Check only for directories.\n\ |
|
676 @end table\n\ |
|
677 @end deftypefn") |
|
678 { |
4233
|
679 octave_value retval = false; |
4016
|
680 |
|
681 int nargin = args.length (); |
|
682 |
|
683 if (nargin == 1 || nargin == 2) |
|
684 { |
|
685 std::string name = args(0).string_value (); |
|
686 |
|
687 if (! error_state) |
|
688 { |
|
689 std::string type |
|
690 = (nargin == 2) ? args(1).string_value () : std::string ("any"); |
|
691 |
|
692 if (! error_state) |
4233
|
693 retval = symbol_exist (name, type); |
4016
|
694 else |
|
695 error ("exist: expecting second argument to be a string"); |
|
696 } |
|
697 else |
|
698 error ("exist: expecting first argument to be a string"); |
|
699 } |
|
700 else |
|
701 print_usage ("exist"); |
|
702 |
|
703 return retval; |
|
704 } |
|
705 |
581
|
706 // Is there a corresponding function file that is newer than the |
|
707 // symbol definition? |
|
708 |
2926
|
709 static bool |
1
|
710 symbol_out_of_date (symbol_record *sr) |
|
711 { |
2926
|
712 bool retval = false; |
195
|
713 |
2926
|
714 if (Vignore_function_time_stamp != 2 && sr) |
1
|
715 { |
2975
|
716 octave_value ans = sr->def (); |
|
717 |
3022
|
718 octave_function *tmp = ans.function_value (true); |
2975
|
719 |
3022
|
720 if (tmp) |
|
721 { |
3523
|
722 std::string ff = tmp->fcn_file_name (); |
1755
|
723 |
3022
|
724 if (! (ff.empty () |
|
725 || (Vignore_function_time_stamp |
|
726 && tmp->is_system_fcn_file ()))) |
|
727 { |
3165
|
728 if (tmp->time_checked () < Vlast_prompt_time) |
|
729 { |
|
730 time_t tp = tmp->time_parsed (); |
2975
|
731 |
3523
|
732 std::string fname; |
3325
|
733 |
|
734 if (tmp->is_dld_function ()) |
|
735 fname = ff; |
|
736 else |
|
737 fname = fcn_file_in_path (ff); |
1755
|
738 |
3255
|
739 tmp->mark_fcn_file_up_to_date (octave_time ()); |
3165
|
740 |
|
741 file_stat fs (fname); |
3022
|
742 |
3165
|
743 if (fs && fs.is_newer (tp)) |
|
744 retval = true; |
|
745 } |
1
|
746 } |
|
747 } |
|
748 } |
2926
|
749 |
|
750 return retval; |
1
|
751 } |
|
752 |
1827
|
753 bool |
2856
|
754 lookup (symbol_record *sym_rec, bool exec_script) |
581
|
755 { |
1827
|
756 bool script_executed = false; |
581
|
757 |
|
758 if (! sym_rec->is_linked_to_global ()) |
|
759 { |
|
760 if (sym_rec->is_defined ()) |
|
761 { |
|
762 if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) |
1271
|
763 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
764 } |
|
765 else if (! sym_rec->is_formal_parameter ()) |
|
766 { |
|
767 link_to_builtin_or_function (sym_rec); |
1271
|
768 |
581
|
769 if (! sym_rec->is_defined ()) |
1271
|
770 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
771 else if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) |
1271
|
772 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
773 } |
|
774 } |
|
775 |
1271
|
776 return script_executed; |
581
|
777 } |
|
778 |
|
779 // Get the symbol record for the given name that is visible in the |
|
780 // current scope. Reread any function definitions that appear to be |
|
781 // out of date. If a function is available in a file but is not |
|
782 // currently loaded, this will load it and insert the name in the |
|
783 // current symbol table. |
|
784 |
|
785 symbol_record * |
3523
|
786 lookup_by_name (const std::string& nm, bool exec_script) |
581
|
787 { |
2856
|
788 symbol_record *sym_rec = curr_sym_tab->lookup (nm, true); |
581
|
789 |
|
790 lookup (sym_rec, exec_script); |
|
791 |
|
792 return sym_rec; |
|
793 } |
|
794 |
4342
|
795 octave_function * |
|
796 lookup_function (const std::string& nm) |
|
797 { |
|
798 octave_function *retval = 0; |
|
799 |
|
800 symbol_record *sr = 0; |
|
801 |
|
802 if (curr_parent_function) |
|
803 { |
|
804 std::string parent = curr_parent_function->function_name (); |
|
805 |
|
806 sr = fbi_sym_tab->lookup (parent + ":" + nm); |
|
807 } |
|
808 |
|
809 if (! sr || ! sr->is_function ()) |
|
810 { |
|
811 sr = fbi_sym_tab->lookup (nm, true); |
|
812 |
|
813 if (sr && ! sr->is_function ()) |
|
814 load_fcn_from_file (sr, false); |
|
815 } |
|
816 |
|
817 if (sr) |
|
818 { |
|
819 octave_value v = sr->def (); |
|
820 |
|
821 if (v.is_function ()) |
|
822 retval = v.function_value (); |
|
823 } |
|
824 |
|
825 return retval; |
|
826 } |
|
827 |
2849
|
828 octave_value |
3523
|
829 get_global_value (const std::string& nm) |
2849
|
830 { |
|
831 octave_value retval; |
|
832 |
|
833 symbol_record *sr = global_sym_tab->lookup (nm); |
|
834 |
|
835 if (sr) |
|
836 { |
2975
|
837 octave_value sr_def = sr->def (); |
2849
|
838 |
2975
|
839 if (sr_def.is_undefined ()) |
2849
|
840 error ("get_global_by_name: undefined symbol `%s'", nm.c_str ()); |
3088
|
841 else |
|
842 retval = sr_def; |
2849
|
843 } |
|
844 else |
|
845 error ("get_global_by_name: unknown symbol `%s'", nm.c_str ()); |
|
846 |
|
847 return retval; |
|
848 } |
|
849 |
|
850 void |
3523
|
851 set_global_value (const std::string& nm, const octave_value& val) |
2849
|
852 { |
2856
|
853 symbol_record *sr = global_sym_tab->lookup (nm, true); |
2849
|
854 |
|
855 if (sr) |
|
856 sr->define (val); |
|
857 else |
|
858 panic_impossible (); |
|
859 } |
|
860 |
593
|
861 // Variable values. |
195
|
862 |
581
|
863 // Look for the given name in the global symbol table. If it refers |
|
864 // to a string, return a new copy. If not, return 0; |
|
865 |
3523
|
866 std::string |
|
867 builtin_string_variable (const std::string& name) |
1
|
868 { |
4009
|
869 symbol_record *sr = fbi_sym_tab->lookup (name); |
195
|
870 |
4329
|
871 // It is a programming error to look for builtins that aren't. |
195
|
872 |
4280
|
873 // Use != here to avoid possible conversion to int of smaller type |
|
874 // than the sr pointer. |
|
875 |
|
876 assert (sr != 0); |
195
|
877 |
3523
|
878 std::string retval; |
1
|
879 |
2975
|
880 octave_value val = sr->def (); |
195
|
881 |
2975
|
882 if (! error_state && val.is_string ()) |
|
883 retval = val.string_value (); |
1
|
884 |
|
885 return retval; |
|
886 } |
|
887 |
581
|
888 // Look for the given name in the global symbol table. If it refers |
1504
|
889 // to a real scalar, place the value in d and return 1. Otherwise, |
|
890 // return 0. |
581
|
891 |
1
|
892 int |
3523
|
893 builtin_real_scalar_variable (const std::string& name, double& d) |
1
|
894 { |
1504
|
895 int status = 0; |
4009
|
896 symbol_record *sr = fbi_sym_tab->lookup (name); |
195
|
897 |
4329
|
898 // It is a programming error to look for builtins that aren't. |
195
|
899 |
4280
|
900 // Use != here to avoid possible conversion to int of smaller type |
|
901 // than the sr pointer. |
|
902 |
|
903 assert (sr != 0); |
1
|
904 |
2975
|
905 octave_value val = sr->def (); |
195
|
906 |
2975
|
907 if (! error_state && val.is_scalar_type ()) |
|
908 { |
|
909 d = val.double_value (); |
|
910 status = 1; |
1
|
911 } |
|
912 |
|
913 return status; |
|
914 } |
|
915 |
1093
|
916 // Look for the given name in the global symbol table. |
|
917 |
2086
|
918 octave_value |
3523
|
919 builtin_any_variable (const std::string& name) |
1093
|
920 { |
4009
|
921 symbol_record *sr = fbi_sym_tab->lookup (name); |
1093
|
922 |
4329
|
923 // It is a programming error to look for builtins that aren't. |
1093
|
924 |
4280
|
925 // Use != here to avoid possible conversion to int of smaller type |
|
926 // than the sr pointer. |
|
927 |
|
928 assert (sr != 0); |
1093
|
929 |
2975
|
930 return sr->def (); |
1093
|
931 } |
|
932 |
593
|
933 // Global stuff and links to builtin variables and functions. |
|
934 |
581
|
935 // Make the definition of the symbol record sr be the same as the |
|
936 // definition of the global variable of the same name, creating it if |
1418
|
937 // it doesn't already exist. |
581
|
938 |
195
|
939 void |
|
940 link_to_global_variable (symbol_record *sr) |
|
941 { |
2975
|
942 if (! sr->is_linked_to_global ()) |
195
|
943 { |
2975
|
944 sr->mark_as_linked_to_global (); |
195
|
945 |
2975
|
946 if (! error_state) |
|
947 { |
3523
|
948 std::string nm = sr->name (); |
2846
|
949 |
2975
|
950 symbol_record *gsr = global_sym_tab->lookup (nm, true); |
|
951 |
|
952 // Make sure this symbol is a variable. |
2900
|
953 |
4009
|
954 if (! gsr->is_user_variable ()) |
2975
|
955 gsr->define (octave_value ()); |
2900
|
956 |
4009
|
957 sr->alias (gsr); |
2975
|
958 } |
195
|
959 } |
|
960 } |
|
961 |
581
|
962 // Make the definition of the symbol record sr be the same as the |
|
963 // definition of the builtin variable of the same name. |
|
964 |
|
965 // Make the definition of the symbol record sr be the same as the |
3258
|
966 // definition of the builtin variable, constant, or function, or user |
|
967 // function of the same name, provided that the name has not been used |
|
968 // as a formal parameter. |
581
|
969 |
195
|
970 void |
|
971 link_to_builtin_or_function (symbol_record *sr) |
|
972 { |
4238
|
973 std::string nm = sr->name (); |
|
974 |
|
975 symbol_record *tmp_sym = 0; |
|
976 |
|
977 if (curr_parent_function) |
|
978 { |
|
979 std::string parent = curr_parent_function->function_name (); |
|
980 |
|
981 tmp_sym = fbi_sym_tab->lookup (parent + ":" + nm); |
|
982 } |
|
983 |
|
984 if (! tmp_sym) |
|
985 tmp_sym = fbi_sym_tab->lookup (nm); |
195
|
986 |
529
|
987 if (tmp_sym |
3258
|
988 && (tmp_sym->is_builtin_variable () |
|
989 || tmp_sym->is_builtin_constant () |
|
990 || tmp_sym->is_function ()) |
529
|
991 && ! tmp_sym->is_formal_parameter ()) |
|
992 sr->alias (tmp_sym); |
195
|
993 } |
|
994 |
581
|
995 // Force a link to a function in the current symbol table. This is |
|
996 // used just after defining a function to avoid different behavior |
|
997 // depending on whether or not the function has been evaluated after |
|
998 // being defined. |
|
999 // |
|
1000 // Return without doing anything if there isn't a function with the |
|
1001 // given name defined in the global symbol table. |
|
1002 |
195
|
1003 void |
3523
|
1004 force_link_to_function (const std::string& id_name) |
195
|
1005 { |
4009
|
1006 symbol_record *fsr = fbi_sym_tab->lookup (id_name, true); |
|
1007 if (fsr->is_function ()) |
195
|
1008 { |
|
1009 curr_sym_tab->clear (id_name); |
2856
|
1010 symbol_record *csr = curr_sym_tab->lookup (id_name, true); |
4009
|
1011 csr->alias (fsr); |
195
|
1012 } |
|
1013 } |
|
1014 |
2294
|
1015 DEFUN (document, args, , |
3361
|
1016 "-*- texinfo -*-\n\ |
|
1017 @deftypefn {Built-in Function} {} document (@var{symbol}, @var{text})\n\ |
|
1018 Set the documentation string for @var{symbol} to @var{text}.\n\ |
|
1019 @end deftypefn") |
593
|
1020 { |
2294
|
1021 octave_value retval; |
1755
|
1022 |
2294
|
1023 int nargin = args.length (); |
1755
|
1024 |
2294
|
1025 if (nargin == 2) |
593
|
1026 { |
3523
|
1027 std::string name = args(0).string_value (); |
593
|
1028 |
2294
|
1029 if (! error_state) |
593
|
1030 { |
3523
|
1031 std::string help = args(1).string_value (); |
593
|
1032 |
2294
|
1033 if (! error_state) |
|
1034 { |
|
1035 if (is_builtin_variable (name) |
4208
|
1036 || is_command_name (name) |
2294
|
1037 || is_mapper_function_name (name) |
|
1038 || is_builtin_function_name (name)) |
|
1039 error ("document: can't redefine help for built-in variables and functions"); |
|
1040 else |
|
1041 { |
2856
|
1042 symbol_record *sym_rec = curr_sym_tab->lookup (name); |
2294
|
1043 |
|
1044 if (sym_rec) |
|
1045 sym_rec->document (help); |
|
1046 else |
|
1047 error ("document: no such symbol `%s'", name.c_str ()); |
|
1048 } |
|
1049 } |
593
|
1050 } |
|
1051 } |
|
1052 else |
|
1053 print_usage ("document"); |
|
1054 |
|
1055 return retval; |
|
1056 } |
|
1057 |
2086
|
1058 static octave_value_list |
1755
|
1059 do_who (int argc, const string_vector& argv) |
529
|
1060 { |
2086
|
1061 octave_value_list retval; |
529
|
1062 |
2856
|
1063 bool show_builtins = false; |
3248
|
1064 bool show_functions = false; |
|
1065 bool show_variables = false; |
2856
|
1066 bool show_verbose = false; |
529
|
1067 |
3523
|
1068 std::string my_name = argv[0]; |
584
|
1069 |
1857
|
1070 int i; |
|
1071 for (i = 1; i < argc; i++) |
529
|
1072 { |
1755
|
1073 if (argv[i] == "-all" || argv[i] == "-a") |
529
|
1074 { |
2856
|
1075 show_builtins = true; |
|
1076 show_functions = true; |
|
1077 show_variables = true; |
529
|
1078 } |
1755
|
1079 else if (argv[i] == "-builtins" || argv[i] == "-b") |
2856
|
1080 show_builtins = true; |
1755
|
1081 else if (argv[i] == "-functions" || argv[i] == "-f") |
2856
|
1082 show_functions = true; |
1755
|
1083 else if (argv[i] == "-long" || argv[i] == "-l") |
2856
|
1084 show_verbose = true; |
1755
|
1085 else if (argv[i] == "-variables" || argv[i] == "-v") |
2856
|
1086 show_variables = true; |
1755
|
1087 else if (argv[i][0] == '-') |
|
1088 warning ("%s: unrecognized option `%s'", my_name.c_str (), |
|
1089 argv[i].c_str ()); |
529
|
1090 else |
867
|
1091 break; |
529
|
1092 } |
|
1093 |
3248
|
1094 // If no options were specified to select the type of symbol to |
|
1095 // display, then set defaults. |
|
1096 |
|
1097 if (! (show_builtins || show_functions || show_variables)) |
|
1098 { |
4208
|
1099 show_functions = at_top_level (); |
3248
|
1100 show_variables = true; |
|
1101 } |
|
1102 |
1857
|
1103 int npats = argc - i; |
|
1104 string_vector pats (npats); |
|
1105 for (int j = 0; j < npats; j++) |
|
1106 pats[j] = argv[i+j]; |
|
1107 |
1271
|
1108 // If the user specified -l and nothing else, show variables. If |
|
1109 // evaluating this at the top level, also show functions. |
529
|
1110 |
|
1111 if (show_verbose && ! (show_builtins || show_functions || show_variables)) |
|
1112 { |
4208
|
1113 show_functions = at_top_level (); |
529
|
1114 show_variables = 1; |
|
1115 } |
|
1116 |
|
1117 int pad_after = 0; |
|
1118 |
|
1119 if (show_builtins) |
|
1120 { |
4009
|
1121 pad_after += fbi_sym_tab->maybe_list |
3259
|
1122 ("*** built-in constants:", pats, octave_stdout, |
|
1123 show_verbose, symbol_record::BUILTIN_CONSTANT, SYMTAB_ALL_SCOPES); |
|
1124 |
4009
|
1125 pad_after += fbi_sym_tab->maybe_list |
3013
|
1126 ("*** built-in variables:", pats, octave_stdout, |
3011
|
1127 show_verbose, symbol_record::BUILTIN_VARIABLE, SYMTAB_ALL_SCOPES); |
529
|
1128 |
4009
|
1129 pad_after += fbi_sym_tab->maybe_list |
3013
|
1130 ("*** built-in functions:", pats, octave_stdout, |
3011
|
1131 show_verbose, symbol_record::BUILTIN_FUNCTION, SYMTAB_ALL_SCOPES); |
529
|
1132 } |
|
1133 |
|
1134 if (show_functions) |
|
1135 { |
4009
|
1136 pad_after += fbi_sym_tab->maybe_list |
4108
|
1137 ("*** dynamically linked functions:", pats, |
|
1138 octave_stdout, show_verbose, symbol_record::DLD_FUNCTION, |
|
1139 SYMTAB_ALL_SCOPES); |
|
1140 |
|
1141 pad_after += fbi_sym_tab->maybe_list |
3013
|
1142 ("*** currently compiled functions:", pats, |
3011
|
1143 octave_stdout, show_verbose, symbol_record::USER_FUNCTION, |
|
1144 SYMTAB_ALL_SCOPES); |
529
|
1145 } |
|
1146 |
|
1147 if (show_variables) |
|
1148 { |
3011
|
1149 pad_after += curr_sym_tab->maybe_list |
3013
|
1150 ("*** local user variables:", pats, octave_stdout, |
3011
|
1151 show_verbose, symbol_record::USER_VARIABLE, SYMTAB_LOCAL_SCOPE); |
529
|
1152 |
3011
|
1153 pad_after += curr_sym_tab->maybe_list |
3013
|
1154 ("*** globally visible user variables:", pats, |
3011
|
1155 octave_stdout, show_verbose, symbol_record::USER_VARIABLE, |
|
1156 SYMTAB_GLOBAL_SCOPE); |
529
|
1157 } |
|
1158 |
|
1159 if (pad_after) |
2095
|
1160 octave_stdout << "\n"; |
529
|
1161 |
581
|
1162 return retval; |
|
1163 } |
|
1164 |
4208
|
1165 DEFCMD (who, args, , |
3361
|
1166 "-*- texinfo -*-\n\ |
|
1167 @deffn {Command} who options pattern @dots{}\n\ |
|
1168 @deffnx {Command} whos options pattern @dots{}\n\ |
|
1169 List currently defined symbols matching the given patterns. The\n\ |
|
1170 following are valid options. They may be shortened to one character but\n\ |
|
1171 may not be combined.\n\ |
|
1172 \n\ |
|
1173 @table @code\n\ |
|
1174 @item -all\n\ |
|
1175 List all currently defined symbols.\n\ |
|
1176 \n\ |
|
1177 @item -builtins\n\ |
|
1178 List built-in variables and functions. This includes all currently\n\ |
|
1179 compiled function files, but does not include all function files that\n\ |
|
1180 are in the @code{LOADPATH}.\n\ |
581
|
1181 \n\ |
3361
|
1182 @item -functions\n\ |
|
1183 List user-defined functions.\n\ |
|
1184 \n\ |
|
1185 @item -long\n\ |
|
1186 Print a long listing including the type and dimensions of any symbols.\n\ |
|
1187 The symbols in the first column of output indicate whether it is\n\ |
|
1188 possible to redefine the symbol, and whether it is possible for it to be\n\ |
|
1189 cleared.\n\ |
|
1190 \n\ |
|
1191 @item -variables\n\ |
|
1192 List user-defined variables.\n\ |
|
1193 @end table\n\ |
|
1194 \n\ |
|
1195 Valid patterns are the same as described for the @code{clear} command\n\ |
|
1196 above. If no patterns are supplied, all symbols from the given category\n\ |
|
1197 are listed. By default, only user defined functions and variables\n\ |
|
1198 visible in the local scope are displayed.\n\ |
|
1199 \n\ |
|
1200 The command @kbd{whos} is equivalent to @kbd{who -long}.\n\ |
|
1201 @end deffn") |
581
|
1202 { |
2086
|
1203 octave_value_list retval; |
581
|
1204 |
1755
|
1205 int argc = args.length () + 1; |
|
1206 |
1968
|
1207 string_vector argv = args.make_argv ("who"); |
1755
|
1208 |
|
1209 if (error_state) |
|
1210 return retval; |
581
|
1211 |
1488
|
1212 retval = do_who (argc, argv); |
581
|
1213 |
529
|
1214 return retval; |
|
1215 } |
|
1216 |
4208
|
1217 DEFCMD (whos, args, , |
3458
|
1218 "-*- texinfo -*-\n\ |
|
1219 @deffn {Command} whos options pattern @dots{}\n\ |
|
1220 See who.\n\ |
|
1221 @end deffn") |
581
|
1222 { |
2086
|
1223 octave_value_list retval; |
581
|
1224 |
712
|
1225 int nargin = args.length (); |
|
1226 |
2086
|
1227 octave_value_list tmp_args; |
742
|
1228 for (int i = nargin; i > 0; i--) |
|
1229 tmp_args(i) = args(i-1); |
|
1230 tmp_args(0) = "-long"; |
581
|
1231 |
742
|
1232 int argc = tmp_args.length () + 1; |
1755
|
1233 |
1980
|
1234 string_vector argv = tmp_args.make_argv ("whos"); |
581
|
1235 |
|
1236 if (error_state) |
|
1237 return retval; |
|
1238 |
1488
|
1239 retval = do_who (argc, argv); |
581
|
1240 |
|
1241 return retval; |
|
1242 } |
|
1243 |
593
|
1244 // Defining variables. |
|
1245 |
1162
|
1246 void |
2856
|
1247 bind_ans (const octave_value& val, bool print) |
1162
|
1248 { |
4009
|
1249 static symbol_record *sr = fbi_sym_tab->lookup ("ans", true); |
1162
|
1250 |
2978
|
1251 if (val.is_defined ()) |
|
1252 { |
|
1253 sr->define (val); |
1162
|
1254 |
2978
|
1255 if (print) |
|
1256 val.print_with_name (octave_stdout, "ans"); |
|
1257 } |
1162
|
1258 } |
|
1259 |
3259
|
1260 // Give a global constant a definition. This will insert the symbol |
|
1261 // in the global table if necessary. |
|
1262 |
|
1263 // How is this different than install_builtin_constant? Are both |
|
1264 // functions needed? |
|
1265 |
|
1266 void |
3523
|
1267 bind_builtin_constant (const std::string& name, const octave_value& val, |
|
1268 bool protect, bool eternal, const std::string& help) |
3259
|
1269 { |
4009
|
1270 symbol_record *sym_rec = fbi_sym_tab->lookup (name, true); |
3259
|
1271 sym_rec->unprotect (); |
|
1272 |
3523
|
1273 std::string tmp_help = help.empty () ? sym_rec->help () : help; |
3259
|
1274 |
|
1275 sym_rec->define_builtin_const (val); |
|
1276 |
|
1277 sym_rec->document (tmp_help); |
|
1278 |
|
1279 if (protect) |
|
1280 sym_rec->protect (); |
|
1281 |
|
1282 if (eternal) |
|
1283 sym_rec->make_eternal (); |
|
1284 } |
|
1285 |
593
|
1286 // Give a global variable a definition. This will insert the symbol |
|
1287 // in the global table if necessary. |
|
1288 |
|
1289 // How is this different than install_builtin_variable? Are both |
|
1290 // functions needed? |
|
1291 |
|
1292 void |
3523
|
1293 bind_builtin_variable (const std::string& varname, const octave_value& val, |
2953
|
1294 bool protect, bool eternal, |
3005
|
1295 symbol_record::change_function chg_fcn, |
3523
|
1296 const std::string& help) |
593
|
1297 { |
4009
|
1298 symbol_record *sr = fbi_sym_tab->lookup (varname, true); |
593
|
1299 |
1271
|
1300 // It is a programming error for a builtin symbol to be missing. |
|
1301 // Besides, we just inserted it, so it must be there. |
593
|
1302 |
4280
|
1303 // Use != here to avoid possible conversion to int of smaller type |
|
1304 // than the sr pointer. |
|
1305 |
|
1306 assert (sr != 0); |
593
|
1307 |
|
1308 sr->unprotect (); |
|
1309 |
1271
|
1310 // Must do this before define, since define will call the special |
|
1311 // variable function only if it knows about it, and it needs to, so |
|
1312 // that user prefs can be properly initialized. |
593
|
1313 |
3005
|
1314 if (chg_fcn) |
|
1315 sr->set_change_function (chg_fcn); |
593
|
1316 |
|
1317 sr->define_builtin_var (val); |
|
1318 |
|
1319 if (protect) |
|
1320 sr->protect (); |
|
1321 |
|
1322 if (eternal) |
|
1323 sr->make_eternal (); |
|
1324 |
1755
|
1325 sr->document (help); |
529
|
1326 } |
|
1327 |
4319
|
1328 void |
|
1329 mlock (const std::string& nm) |
|
1330 { |
|
1331 symbol_record *sr = fbi_sym_tab->lookup (nm, true); |
|
1332 |
|
1333 if (sr) |
|
1334 sr->mark_as_static (); |
|
1335 } |
|
1336 |
|
1337 void |
|
1338 munlock (const std::string& nm) |
|
1339 { |
|
1340 symbol_record *sr = fbi_sym_tab->lookup (nm); |
|
1341 |
|
1342 if (sr && sr->is_static ()) |
|
1343 sr->unmark_static (); |
|
1344 else |
|
1345 error ("munlock: %s is not locked", nm.c_str ()); |
|
1346 } |
|
1347 |
|
1348 bool |
|
1349 mislocked (const std::string& nm) |
|
1350 { |
|
1351 symbol_record *sr = fbi_sym_tab->lookup (nm); |
|
1352 |
|
1353 return (sr && sr->is_static ()); |
|
1354 } |
|
1355 |
|
1356 DEFCMD (mlock, args, , |
|
1357 "-*- texinfo -*-\n\ |
|
1358 @deftypefnx {Built-in Function} {} mlock (@var{name})\n\ |
|
1359 Lock the named function into memory. If no function is named\n\ |
|
1360 then lock in the current function.\n\ |
|
1361 @end deftypefn\n\ |
|
1362 @seealso{munlock, mislocked, and persistent}") |
|
1363 { |
|
1364 octave_value_list retval; |
|
1365 |
|
1366 if (args.length () == 1) |
|
1367 { |
|
1368 std::string name = args(0).string_value (); |
|
1369 |
|
1370 if (! error_state) |
|
1371 mlock (name); |
|
1372 else |
|
1373 error ("mlock: expecting argument to be a function name"); |
|
1374 } |
|
1375 else if (args.length () == 0) |
|
1376 { |
|
1377 if (curr_function) |
|
1378 mlock (curr_function->function_name ()); |
|
1379 else |
|
1380 error ("mlock: invalid use outside a function"); |
|
1381 } |
|
1382 else |
|
1383 print_usage ("mlock"); |
|
1384 |
|
1385 return retval; |
|
1386 } |
|
1387 |
|
1388 DEFCMD (munlock, args, , |
|
1389 "-*- texinfo -*-\n\ |
|
1390 @deftypefn {Built-in Function} {} munlock (@var{fcn})\n\ |
|
1391 Unlock the named function. If no function is named\n\ |
|
1392 then unlock the current function.\n\ |
|
1393 @end deftypefn\n\ |
|
1394 @seealso{mlock, mislocked, and persistent}") |
|
1395 { |
|
1396 octave_value_list retval; |
|
1397 |
|
1398 if (args.length() == 1) |
|
1399 { |
|
1400 std::string name = args(0).string_value (); |
|
1401 |
|
1402 if (! error_state) |
|
1403 munlock (name); |
|
1404 else |
|
1405 error ("munlock: expecting argument to be a function name"); |
|
1406 } |
|
1407 else if (args.length () == 0) |
|
1408 { |
|
1409 if (curr_function) |
|
1410 mlock (curr_function->function_name ()); |
|
1411 else |
|
1412 error ("munlock: invalid use outside a function"); |
|
1413 } |
|
1414 else |
|
1415 print_usage ("munlock"); |
|
1416 |
|
1417 return retval; |
|
1418 } |
|
1419 |
|
1420 |
|
1421 DEFCMD (mislocked, args, , |
|
1422 "-*- texinfo -*-\n\ |
|
1423 @deftypefn {Built-in Function} {} mislocked (@var{fcn})\n\ |
|
1424 Return true if the named function is locked. If no function is named\n\ |
|
1425 then return true if the current function is locked.\n\ |
|
1426 @end deftypefn\n\ |
|
1427 @seealso{mlock, munlock, and persistent}") |
|
1428 { |
|
1429 octave_value retval; |
|
1430 |
|
1431 if (args.length() == 1) |
|
1432 { |
|
1433 std::string name = args(0).string_value (); |
|
1434 |
|
1435 if (! error_state) |
|
1436 retval = mislocked (name); |
|
1437 else |
|
1438 error ("mislocked: expecting argument to be a function name"); |
|
1439 } |
|
1440 else if (args.length () == 0) |
|
1441 { |
|
1442 if (curr_function) |
|
1443 retval = mislocked (curr_function->function_name ()); |
|
1444 else |
|
1445 error ("mislocked: invalid use outside a function"); |
|
1446 } |
|
1447 else |
|
1448 print_usage ("mislocked"); |
|
1449 |
|
1450 return retval; |
|
1451 } |
|
1452 |
593
|
1453 // Deleting names from the symbol tables. |
|
1454 |
3681
|
1455 static inline bool |
4009
|
1456 name_matches_any_pattern (const std::string& nm, |
|
1457 const string_vector& argv, int argc, int idx) |
3681
|
1458 { |
|
1459 bool retval = false; |
|
1460 |
|
1461 for (int k = idx; k < argc; k++) |
|
1462 { |
|
1463 std::string patstr = argv[k]; |
|
1464 |
|
1465 if (! patstr.empty ()) |
|
1466 { |
|
1467 glob_match pattern (patstr); |
|
1468 |
|
1469 if (pattern.match (nm)) |
|
1470 { |
|
1471 retval = true; |
|
1472 break; |
|
1473 } |
|
1474 } |
|
1475 } |
|
1476 |
|
1477 return retval; |
|
1478 } |
|
1479 |
4009
|
1480 static inline bool |
|
1481 is_local_variable (const std::string& nm) |
|
1482 { |
|
1483 symbol_record *sr = curr_sym_tab->lookup (nm); |
|
1484 |
|
1485 return (sr && sr->is_variable ()); |
|
1486 } |
|
1487 |
|
1488 static inline void |
|
1489 maybe_warn_exclusive (bool exclusive) |
|
1490 { |
|
1491 if (exclusive) |
|
1492 warning ("clear: ignoring --exclusive option"); |
|
1493 } |
|
1494 |
|
1495 static inline void |
|
1496 do_clear_all (void) |
|
1497 { |
|
1498 curr_sym_tab->clear (); |
|
1499 fbi_sym_tab->clear_functions (); |
|
1500 global_sym_tab->clear (); |
|
1501 } |
|
1502 |
|
1503 static inline void |
|
1504 do_clear_functions (void) |
|
1505 { |
|
1506 curr_sym_tab->clear_functions (); |
|
1507 fbi_sym_tab->clear_functions (); |
|
1508 } |
|
1509 |
|
1510 static inline void |
|
1511 do_clear_globals (void) |
|
1512 { |
|
1513 curr_sym_tab->clear_globals (); |
|
1514 global_sym_tab->clear (); |
|
1515 } |
|
1516 |
|
1517 static inline void |
|
1518 do_clear_variables (void) |
|
1519 { |
|
1520 curr_sym_tab->clear (); |
|
1521 } |
|
1522 |
|
1523 static inline bool |
|
1524 do_clear_function (const std::string& nm) |
|
1525 { |
|
1526 bool b1 = curr_sym_tab->clear_function (nm); |
|
1527 |
|
1528 bool b2 = fbi_sym_tab->clear_function (nm); |
|
1529 |
|
1530 return b1 || b2; |
|
1531 } |
|
1532 |
|
1533 static inline bool |
|
1534 do_clear_global (const std::string& nm) |
|
1535 { |
|
1536 bool b1 = curr_sym_tab->clear_global (nm); |
|
1537 |
|
1538 bool b2 = global_sym_tab->clear_variable (nm); |
|
1539 |
|
1540 return b1 || b2; |
|
1541 } |
|
1542 |
|
1543 static inline bool |
|
1544 do_clear_variable (const std::string& nm) |
|
1545 { |
|
1546 return curr_sym_tab->clear_variable (nm); |
|
1547 } |
|
1548 |
|
1549 static inline bool |
|
1550 do_clear_symbol (const std::string& nm) |
|
1551 { |
|
1552 bool cleared = curr_sym_tab->clear_variable (nm); |
|
1553 |
|
1554 if (! cleared) |
|
1555 cleared = do_clear_function (nm); |
|
1556 |
|
1557 return cleared; |
|
1558 } |
|
1559 |
|
1560 static inline bool |
|
1561 do_clear_function_pattern (const std::string& pat) |
|
1562 { |
|
1563 bool b1 = curr_sym_tab->clear_function_pattern (pat); |
|
1564 |
|
1565 bool b2 = fbi_sym_tab->clear_function_pattern (pat); |
|
1566 |
|
1567 return b1 || b2; |
|
1568 } |
|
1569 |
|
1570 static inline bool |
|
1571 do_clear_global_pattern (const std::string& pat) |
|
1572 { |
|
1573 bool b1 = curr_sym_tab->clear_global_pattern (pat); |
|
1574 |
|
1575 bool b2 = global_sym_tab->clear_variable_pattern (pat); |
|
1576 |
|
1577 return b1 || b2; |
|
1578 } |
|
1579 |
|
1580 static inline bool |
|
1581 do_clear_variable_pattern (const std::string& pat) |
|
1582 { |
|
1583 return curr_sym_tab->clear_variable_pattern (pat); |
|
1584 } |
|
1585 |
|
1586 static inline bool |
|
1587 do_clear_symbol_pattern (const std::string& pat) |
|
1588 { |
|
1589 // XXX FIXME XXX -- if we have a variable v1 and a function v2 and |
|
1590 // someone says clear v*, we will clear the variable but not the |
|
1591 // function. Is that really what should happen? (I think it is |
|
1592 // what Matlab does.) |
|
1593 |
|
1594 bool cleared = curr_sym_tab->clear_variable_pattern (pat); |
|
1595 |
|
1596 if (! cleared) |
|
1597 cleared = do_clear_function_pattern (pat); |
|
1598 |
|
1599 return cleared; |
|
1600 } |
|
1601 |
|
1602 static inline void |
|
1603 do_clear_functions (const string_vector& argv, int argc, int idx, |
|
1604 bool exclusive = false) |
|
1605 { |
|
1606 if (idx == argc) |
|
1607 do_clear_functions (); |
|
1608 else |
|
1609 { |
|
1610 if (exclusive) |
|
1611 { |
|
1612 string_vector lfcns = curr_sym_tab->user_function_name_list (); |
|
1613 |
|
1614 int lcount = lfcns.length (); |
|
1615 |
|
1616 for (int i = 0; i < lcount; i++) |
|
1617 { |
|
1618 std::string nm = lfcns[i]; |
|
1619 |
|
1620 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
1621 do_clear_function (nm); |
|
1622 } |
|
1623 |
|
1624 string_vector fcns = fbi_sym_tab->user_function_name_list (); |
|
1625 |
|
1626 int fcount = fcns.length (); |
|
1627 |
|
1628 for (int i = 0; i < fcount; i++) |
|
1629 { |
|
1630 std::string nm = fcns[i]; |
|
1631 |
|
1632 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
1633 do_clear_function (nm); |
|
1634 } |
|
1635 } |
|
1636 else |
|
1637 { |
|
1638 while (idx < argc) |
|
1639 do_clear_function_pattern (argv[idx++]); |
|
1640 } |
|
1641 } |
|
1642 } |
|
1643 |
|
1644 static inline void |
|
1645 do_clear_globals (const string_vector& argv, int argc, int idx, |
|
1646 bool exclusive = false) |
|
1647 { |
|
1648 if (idx == argc) |
|
1649 do_clear_globals (); |
|
1650 else |
|
1651 { |
|
1652 if (exclusive) |
|
1653 { |
|
1654 string_vector lvars = curr_sym_tab->global_variable_name_list (); |
|
1655 |
|
1656 int lcount = lvars.length (); |
|
1657 |
|
1658 for (int i = 0; i < lcount; i++) |
|
1659 { |
|
1660 std::string nm = lvars[i]; |
|
1661 |
|
1662 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
1663 do_clear_global (nm); |
|
1664 } |
|
1665 |
|
1666 string_vector gvars = global_sym_tab->global_variable_name_list (); |
|
1667 |
|
1668 int gcount = gvars.length (); |
|
1669 |
|
1670 for (int i = 0; i < gcount; i++) |
|
1671 { |
|
1672 std::string nm = gvars[i]; |
|
1673 |
|
1674 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
1675 do_clear_global (nm); |
|
1676 } |
|
1677 } |
|
1678 else |
|
1679 { |
|
1680 while (idx < argc) |
|
1681 do_clear_global_pattern (argv[idx++]); |
|
1682 } |
|
1683 } |
|
1684 } |
|
1685 |
|
1686 static inline void |
|
1687 do_clear_variables (const string_vector& argv, int argc, int idx, |
|
1688 bool exclusive = false) |
|
1689 { |
|
1690 if (idx == argc) |
|
1691 do_clear_variables (); |
|
1692 else |
|
1693 { |
|
1694 if (exclusive) |
|
1695 { |
|
1696 string_vector lvars = curr_sym_tab->variable_name_list (); |
|
1697 |
|
1698 int lcount = lvars.length (); |
|
1699 |
|
1700 for (int i = 0; i < lcount; i++) |
|
1701 { |
|
1702 std::string nm = lvars[i]; |
|
1703 |
|
1704 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
1705 do_clear_variable (nm); |
|
1706 } |
|
1707 } |
|
1708 else |
|
1709 { |
|
1710 while (idx < argc) |
|
1711 do_clear_variable_pattern (argv[idx++]); |
|
1712 } |
|
1713 } |
|
1714 } |
|
1715 |
|
1716 static inline void |
|
1717 do_clear_symbols (const string_vector& argv, int argc, int idx, |
|
1718 bool exclusive = false) |
|
1719 { |
|
1720 if (idx == argc) |
|
1721 do_clear_variables (); |
|
1722 else |
|
1723 { |
|
1724 if (exclusive) |
|
1725 { |
|
1726 // XXX FIXME XXX -- is this really what we want, or do we |
|
1727 // somehow want to only clear the functions that are not |
|
1728 // shadowed by local variables? It seems that would be a |
|
1729 // bit harder to do. |
|
1730 |
|
1731 do_clear_variables (argv, argc, idx, exclusive); |
|
1732 do_clear_functions (argv, argc, idx, exclusive); |
|
1733 } |
|
1734 else |
|
1735 { |
|
1736 while (idx < argc) |
|
1737 do_clear_symbol_pattern (argv[idx++]); |
|
1738 } |
|
1739 } |
|
1740 } |
|
1741 |
|
1742 static void |
|
1743 do_matlab_compatible_clear (const string_vector& argv, int argc, int idx) |
|
1744 { |
|
1745 // This is supposed to be mostly Matlab compatible. |
|
1746 |
|
1747 for (; idx < argc; idx++) |
|
1748 { |
|
1749 if (argv[idx] == "all" && ! is_local_variable ("all")) |
|
1750 { |
|
1751 do_clear_all (); |
|
1752 } |
|
1753 else if (argv[idx] == "functions" && ! is_local_variable ("functions")) |
|
1754 { |
|
1755 do_clear_functions (argv, argc, ++idx); |
|
1756 } |
|
1757 else if (argv[idx] == "global" && ! is_local_variable ("global")) |
|
1758 { |
|
1759 do_clear_globals (argv, argc, ++idx); |
|
1760 } |
|
1761 else if (argv[idx] == "variables" && ! is_local_variable ("variables")) |
|
1762 { |
|
1763 do_clear_variables (); |
|
1764 } |
|
1765 else |
|
1766 { |
|
1767 do_clear_symbol_pattern (argv[idx]); |
|
1768 } |
|
1769 } |
|
1770 } |
|
1771 |
|
1772 #define CLEAR_OPTION_ERROR(cond) \ |
|
1773 do \ |
|
1774 { \ |
|
1775 if (cond) \ |
|
1776 { \ |
|
1777 print_usage ("clear"); \ |
|
1778 return retval; \ |
|
1779 } \ |
|
1780 } \ |
|
1781 while (0) |
|
1782 |
4208
|
1783 DEFCMD (clear, args, , |
3361
|
1784 "-*- texinfo -*-\n\ |
|
1785 @deffn {Command} clear [-x] pattern @dots{}\n\ |
|
1786 Delete the names matching the given patterns from the symbol table. The\n\ |
|
1787 pattern may contain the following special characters:\n\ |
4016
|
1788 \n\ |
3361
|
1789 @table @code\n\ |
|
1790 @item ?\n\ |
|
1791 Match any single character.\n\ |
668
|
1792 \n\ |
3361
|
1793 @item *\n\ |
|
1794 Match zero or more characters.\n\ |
|
1795 \n\ |
|
1796 @item [ @var{list} ]\n\ |
|
1797 Match the list of characters specified by @var{list}. If the first\n\ |
|
1798 character is @code{!} or @code{^}, match all characters except those\n\ |
|
1799 specified by @var{list}. For example, the pattern @samp{[a-zA-Z]} will\n\ |
|
1800 match all lower and upper case alphabetic characters.\n\ |
|
1801 @end table\n\ |
|
1802 \n\ |
|
1803 For example, the command\n\ |
593
|
1804 \n\ |
3361
|
1805 @example\n\ |
|
1806 clear foo b*r\n\ |
|
1807 @end example\n\ |
|
1808 \n\ |
|
1809 @noindent\n\ |
|
1810 clears the name @code{foo} and all names that begin with the letter\n\ |
|
1811 @code{b} and end with the letter @code{r}.\n\ |
668
|
1812 \n\ |
3361
|
1813 If @code{clear} is called without any arguments, all user-defined\n\ |
|
1814 variables (local and global) are cleared from the symbol table. If\n\ |
|
1815 @code{clear} is called with at least one argument, only the visible\n\ |
|
1816 names matching the arguments are cleared. For example, suppose you have\n\ |
|
1817 defined a function @code{foo}, and then hidden it by performing the\n\ |
|
1818 assignment @code{foo = 2}. Executing the command @kbd{clear foo} once\n\ |
|
1819 will clear the variable definition and restore the definition of\n\ |
|
1820 @code{foo} as a function. Executing @kbd{clear foo} a second time will\n\ |
|
1821 clear the function definition.\n\ |
|
1822 \n\ |
|
1823 With -x, clear the variables that don't match the patterns.\n\ |
|
1824 \n\ |
|
1825 This command may not be used within a function body.\n\ |
|
1826 @end deffn") |
529
|
1827 { |
2086
|
1828 octave_value_list retval; |
593
|
1829 |
1755
|
1830 int argc = args.length () + 1; |
593
|
1831 |
1968
|
1832 string_vector argv = args.make_argv ("clear"); |
1755
|
1833 |
4009
|
1834 if (! error_state) |
529
|
1835 { |
4009
|
1836 if (argc == 1) |
593
|
1837 { |
4009
|
1838 do_clear_variables (); |
3681
|
1839 } |
|
1840 else |
|
1841 { |
4009
|
1842 int idx = 0; |
|
1843 |
|
1844 bool clear_all = false; |
|
1845 bool clear_functions = false; |
|
1846 bool clear_globals = false; |
|
1847 bool clear_variables = false; |
|
1848 bool exclusive = false; |
|
1849 bool have_dash_option = false; |
3681
|
1850 |
4009
|
1851 while (++idx < argc) |
|
1852 { |
4010
|
1853 if (argv[idx] == "-all" || argv[idx] == "-a") |
593
|
1854 { |
4009
|
1855 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681
|
1856 |
4009
|
1857 have_dash_option = true; |
|
1858 clear_all = true; |
|
1859 } |
4010
|
1860 else if (argv[idx] == "-exclusive" || argv[idx] == "-x") |
4009
|
1861 { |
|
1862 have_dash_option = true; |
|
1863 exclusive = true; |
|
1864 } |
4010
|
1865 else if (argv[idx] == "-functions" || argv[idx] == "-f") |
4009
|
1866 { |
|
1867 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681
|
1868 |
4009
|
1869 have_dash_option = true; |
|
1870 clear_functions = true; |
|
1871 } |
4010
|
1872 else if (argv[idx] == "-global" || argv[idx] == "-g") |
4009
|
1873 { |
|
1874 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
|
1875 |
|
1876 have_dash_option = true; |
|
1877 clear_globals = true; |
|
1878 } |
4010
|
1879 else if (argv[idx] == "-variables" || argv[idx] == "-v") |
4009
|
1880 { |
|
1881 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681
|
1882 |
4009
|
1883 have_dash_option = true; |
|
1884 clear_variables = true; |
|
1885 } |
|
1886 else |
|
1887 break; |
|
1888 } |
3681
|
1889 |
4224
|
1890 if (idx <= argc) |
4009
|
1891 { |
|
1892 if (! have_dash_option) |
|
1893 { |
|
1894 do_matlab_compatible_clear (argv, argc, idx); |
|
1895 } |
|
1896 else |
|
1897 { |
|
1898 if (clear_all) |
3681
|
1899 { |
4009
|
1900 maybe_warn_exclusive (exclusive); |
3681
|
1901 |
4009
|
1902 if (++idx < argc) |
|
1903 warning |
4010
|
1904 ("clear: ignoring extra arguments after -all"); |
3681
|
1905 |
4009
|
1906 curr_sym_tab->clear (); |
|
1907 fbi_sym_tab->clear_functions (); |
|
1908 global_sym_tab->clear (); |
|
1909 } |
|
1910 else if (clear_functions) |
|
1911 { |
|
1912 do_clear_functions (argv, argc, idx, exclusive); |
|
1913 } |
|
1914 else if (clear_globals) |
593
|
1915 { |
4009
|
1916 do_clear_globals (argv, argc, idx, exclusive); |
|
1917 } |
|
1918 else if (clear_variables) |
|
1919 { |
|
1920 do_clear_variables (argv, argc, idx, exclusive); |
|
1921 } |
|
1922 else |
|
1923 { |
|
1924 do_clear_symbols (argv, argc, idx, exclusive); |
593
|
1925 } |
|
1926 } |
|
1927 } |
|
1928 } |
|
1929 } |
|
1930 |
|
1931 return retval; |
529
|
1932 } |
|
1933 |
3933
|
1934 DEFUN (__print_symtab_info__, args, , |
3446
|
1935 "-*- texinfo -*-\n\ |
3933
|
1936 @deftypefn {Built-in Function} {} __print_symtab_info__ ()\n\ |
3446
|
1937 Print raw symbol table statistices.\n\ |
|
1938 @end deftypefn") |
3005
|
1939 { |
|
1940 octave_value_list retval; |
|
1941 |
|
1942 int nargin = args.length (); |
|
1943 |
|
1944 if (nargin == 1) |
|
1945 { |
3523
|
1946 std::string arg = args(0).string_value (); |
3005
|
1947 |
4009
|
1948 if (arg == "fbi") |
|
1949 fbi_sym_tab->print_info (octave_stdout); |
|
1950 else if (arg == "global") |
3933
|
1951 global_sym_tab->print_info (octave_stdout); |
|
1952 else if (arg == "top-level") |
|
1953 top_level_sym_tab->print_info (octave_stdout); |
3005
|
1954 else |
3933
|
1955 { |
4009
|
1956 symbol_record *fsr = fbi_sym_tab->lookup (arg, true); |
3933
|
1957 |
4009
|
1958 if (fsr && fsr->is_user_function ()) |
3933
|
1959 { |
4009
|
1960 octave_value tmp = fsr->def (); |
3933
|
1961 const octave_value& rep = tmp.get_rep (); |
|
1962 |
|
1963 const octave_user_function& fcn |
|
1964 = static_cast<const octave_user_function&> (rep); |
|
1965 |
|
1966 fcn.print_symtab_info (octave_stdout); |
|
1967 } |
|
1968 else |
|
1969 error ("no user-defined function named %s", arg.c_str ()); |
|
1970 } |
3005
|
1971 } |
|
1972 else if (nargin == 0) |
3933
|
1973 curr_sym_tab->print_info (octave_stdout); |
3005
|
1974 else |
3933
|
1975 print_usage ("__print_symtab_info__"); |
3005
|
1976 |
|
1977 return retval; |
|
1978 } |
|
1979 |
3933
|
1980 DEFUN (__print_symbol_info__, args, , |
3446
|
1981 "-*- texinfo -*-\n\ |
|
1982 @deftypefn {Built-in Function} {} __dump_symbol_info__ (@var{name})\n\ |
3548
|
1983 Print symbol table information for the symbol @var{name}.\n\ |
3446
|
1984 @end deftypefn") |
3239
|
1985 { |
|
1986 octave_value_list retval; |
|
1987 |
|
1988 int nargin = args.length (); |
|
1989 |
|
1990 if (nargin == 1) |
|
1991 { |
3523
|
1992 std::string symbol_name = args(0).string_value (); |
3239
|
1993 |
|
1994 if (! error_state) |
|
1995 { |
|
1996 symbol_record *sr = curr_sym_tab->lookup (symbol_name); |
|
1997 |
|
1998 if (sr) |
3933
|
1999 sr->print_info (octave_stdout); |
3239
|
2000 else |
3933
|
2001 error ("__print_symbol_info__: symbol %s not found", |
3239
|
2002 symbol_name.c_str ()); |
|
2003 } |
|
2004 else |
3933
|
2005 print_usage ("__print_symbol_info__"); |
3239
|
2006 } |
|
2007 else |
3933
|
2008 print_usage ("__print_symbol_info__"); |
3239
|
2009 |
|
2010 return retval; |
|
2011 } |
|
2012 |
3016
|
2013 // XXX FIXME XXX -- some of these should do their own checking to be |
|
2014 // able to provide more meaningful warning or error messages. |
|
2015 |
|
2016 static int |
|
2017 ignore_function_time_stamp (void) |
|
2018 { |
|
2019 int pref = 0; |
|
2020 |
3523
|
2021 std::string val = builtin_string_variable ("ignore_function_time_stamp"); |
3016
|
2022 |
|
2023 if (! val.empty ()) |
|
2024 { |
3565
|
2025 if (val == "all") |
3016
|
2026 pref = 2; |
3565
|
2027 else if (val == "system") |
3016
|
2028 pref = 1; |
|
2029 } |
|
2030 |
|
2031 Vignore_function_time_stamp = pref; |
|
2032 |
|
2033 return 0; |
|
2034 } |
|
2035 |
|
2036 // XXX FIXME XXX -- there still may be better places for some of these |
|
2037 // to be defined. |
|
2038 |
|
2039 void |
|
2040 symbols_of_variables (void) |
|
2041 { |
3258
|
2042 DEFVAR (ans, , 0, |
3372
|
2043 "-*- texinfo -*-\n\ |
|
2044 @defvr {Built-in Variable} ans\n\ |
|
2045 This variable holds the most recently computed result that was not\n\ |
|
2046 explicitly assigned to a variable. For example, after the expression\n\ |
|
2047 \n\ |
|
2048 @example\n\ |
|
2049 3^2 + 4^2\n\ |
|
2050 @end example\n\ |
|
2051 \n\ |
|
2052 @noindent\n\ |
|
2053 is evaluated, the value of @code{ans} is 25.\n\ |
|
2054 @end defvr"); |
3016
|
2055 |
3258
|
2056 DEFVAR (ignore_function_time_stamp, "system", ignore_function_time_stamp, |
3371
|
2057 "-*- texinfo -*-\n\ |
|
2058 @defvr {Built-in Variable} ignore_function_time_stamp\n\ |
|
2059 This variable can be used to prevent Octave from making the system call\n\ |
|
2060 @code{stat} each time it looks up functions defined in function files.\n\ |
|
2061 If @code{ignore_function_time_stamp} to @code{\"system\"}, Octave will not\n\ |
|
2062 automatically recompile function files in subdirectories of\n\ |
|
2063 @file{@var{octave-home}/lib/@var{version}} if they have changed since\n\ |
|
2064 they were last compiled, but will recompile other function files in the\n\ |
|
2065 @code{LOADPATH} if they change. If set to @code{\"all\"}, Octave will not\n\ |
|
2066 recompile any function files unless their definitions are removed with\n\ |
|
2067 @code{clear}. For any other value of @code{ignore_function_time_stamp},\n\ |
|
2068 Octave will always check to see if functions defined in function files\n\ |
|
2069 need to recompiled. The default value of @code{ignore_function_time_stamp} is\n\ |
|
2070 @code{\"system\"}.\n\ |
|
2071 @end defvr"); |
3016
|
2072 } |
|
2073 |
1
|
2074 /* |
|
2075 ;;; Local Variables: *** |
|
2076 ;;; mode: C++ *** |
|
2077 ;;; End: *** |
|
2078 */ |