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