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 |
1728
|
30 #include <string> |
|
31 |
2926
|
32 #include "file-stat.h" |
|
33 #include "oct-env.h" |
|
34 #include "glob-match.h" |
1755
|
35 #include "str-vec.h" |
|
36 |
2492
|
37 #include <defaults.h> |
1352
|
38 #include "defun.h" |
|
39 #include "dirfns.h" |
|
40 #include "error.h" |
2205
|
41 #include "gripes.h" |
1352
|
42 #include "help.h" |
3165
|
43 #include "input.h" |
1352
|
44 #include "lex.h" |
2926
|
45 #include "oct-map.h" |
|
46 #include "oct-obj.h" |
|
47 #include "ov.h" |
3933
|
48 #include "ov-usr-fcn.h" |
605
|
49 #include "pager.h" |
1352
|
50 #include "parse.h" |
2926
|
51 #include "symtab.h" |
2205
|
52 #include "toplev.h" |
1352
|
53 #include "unwind-prot.h" |
1
|
54 #include "utils.h" |
1352
|
55 #include "variables.h" |
2205
|
56 |
|
57 // Should Octave always check to see if function files have changed |
|
58 // since they were last compiled? |
2806
|
59 static int Vignore_function_time_stamp; |
2205
|
60 |
1
|
61 // Symbol table for symbols at the top level. |
581
|
62 symbol_table *top_level_sym_tab = 0; |
1
|
63 |
|
64 // Symbol table for the current scope. |
581
|
65 symbol_table *curr_sym_tab = 0; |
1
|
66 |
|
67 // Symbol table for global symbols. |
581
|
68 symbol_table *global_sym_tab = 0; |
1
|
69 |
593
|
70 // Initialization. |
|
71 |
|
72 // Create the initial symbol tables and set the current scope at the |
|
73 // top level. |
|
74 |
195
|
75 void |
|
76 initialize_symbol_tables (void) |
|
77 { |
581
|
78 if (! global_sym_tab) |
3005
|
79 global_sym_tab = new symbol_table (2048); |
195
|
80 |
581
|
81 if (! top_level_sym_tab) |
3005
|
82 top_level_sym_tab = new symbol_table (4096); |
195
|
83 |
|
84 curr_sym_tab = top_level_sym_tab; |
|
85 } |
|
86 |
593
|
87 // Attributes of variables and functions. |
|
88 |
|
89 // Is this variable a builtin? |
|
90 |
1827
|
91 bool |
3523
|
92 is_builtin_variable (const std::string& name) |
593
|
93 { |
2856
|
94 symbol_record *sr = global_sym_tab->lookup (name); |
593
|
95 return (sr && sr->is_builtin_variable ()); |
|
96 } |
|
97 |
|
98 // Is this a text-style function? |
|
99 |
1827
|
100 bool |
3523
|
101 is_text_function_name (const std::string& s) |
593
|
102 { |
|
103 symbol_record *sr = global_sym_tab->lookup (s); |
|
104 return (sr && sr->is_text_function ()); |
|
105 } |
|
106 |
3355
|
107 // Is this a built-in function? |
2294
|
108 |
|
109 bool |
3523
|
110 is_builtin_function_name (const std::string& s) |
2294
|
111 { |
|
112 symbol_record *sr = global_sym_tab->lookup (s); |
|
113 return (sr && sr->is_builtin_function ()); |
|
114 } |
|
115 |
|
116 // Is this a mapper function? |
|
117 |
|
118 bool |
3523
|
119 is_mapper_function_name (const std::string& s) |
2294
|
120 { |
|
121 symbol_record *sr = global_sym_tab->lookup (s); |
|
122 return (sr && sr->is_mapper_function ()); |
|
123 } |
|
124 |
593
|
125 // Is this function globally in this scope? |
|
126 |
1827
|
127 bool |
3523
|
128 is_globally_visible (const std::string& name) |
593
|
129 { |
2856
|
130 symbol_record *sr = curr_sym_tab->lookup (name); |
593
|
131 return (sr && sr->is_linked_to_global ()); |
|
132 } |
|
133 |
2086
|
134 // Is this octave_value a valid function? |
593
|
135 |
2975
|
136 octave_function * |
3523
|
137 is_valid_function (const std::string& fcn_name, const std::string& warn_for, bool warn) |
593
|
138 { |
2975
|
139 octave_function *ans = 0; |
593
|
140 |
|
141 symbol_record *sr = 0; |
1755
|
142 |
|
143 if (! fcn_name.empty ()) |
3618
|
144 { |
|
145 sr = global_sym_tab->lookup (fcn_name, true); |
|
146 |
|
147 lookup (sr, false); |
|
148 } |
593
|
149 |
|
150 if (sr) |
2975
|
151 { |
|
152 octave_value tmp = sr->def (); |
|
153 ans = tmp.function_value (true); |
|
154 } |
593
|
155 |
|
156 if (! sr || ! ans || ! sr->is_function ()) |
|
157 { |
|
158 if (warn) |
|
159 error ("%s: the symbol `%s' is not valid as a function", |
1755
|
160 warn_for.c_str (), fcn_name.c_str ()); |
593
|
161 ans = 0; |
|
162 } |
|
163 |
|
164 return ans; |
|
165 } |
|
166 |
2975
|
167 octave_function * |
3523
|
168 is_valid_function (const octave_value& arg, const std::string& warn_for, bool warn) |
3178
|
169 { |
|
170 octave_function *ans = 0; |
|
171 |
3523
|
172 std::string fcn_name; |
3178
|
173 |
|
174 if (arg.is_string ()) |
|
175 fcn_name = arg.string_value (); |
|
176 |
|
177 if (! error_state) |
|
178 ans = is_valid_function (fcn_name, warn_for, warn); |
|
179 else if (warn) |
|
180 error ("%s: expecting function name as argument", warn_for.c_str ()); |
|
181 |
|
182 return ans; |
|
183 } |
|
184 |
|
185 octave_function * |
3523
|
186 extract_function (const octave_value& arg, const std::string& warn_for, |
|
187 const std::string& fname, const std::string& header, |
|
188 const std::string& trailer) |
2796
|
189 { |
2975
|
190 octave_function *retval = 0; |
2796
|
191 |
|
192 retval = is_valid_function (arg, warn_for, 0); |
|
193 |
|
194 if (! retval) |
|
195 { |
3523
|
196 std::string s = arg.string_value (); |
2796
|
197 |
3523
|
198 std::string cmd = header; |
2796
|
199 cmd.append (s); |
|
200 cmd.append (trailer); |
|
201 |
|
202 if (! error_state) |
|
203 { |
|
204 int parse_status; |
|
205 |
2898
|
206 eval_string (cmd, true, parse_status); |
2796
|
207 |
|
208 if (parse_status == 0) |
|
209 { |
|
210 retval = is_valid_function (fname, warn_for, 0); |
|
211 |
|
212 if (! retval) |
|
213 { |
|
214 error ("%s: `%s' is not valid as a function", |
|
215 warn_for.c_str (), fname.c_str ()); |
|
216 return retval; |
|
217 } |
|
218 } |
|
219 else |
|
220 error ("%s: `%s' is not valid as a function", |
|
221 warn_for.c_str (), fname.c_str ()); |
|
222 } |
|
223 else |
|
224 error ("%s: expecting first argument to be a string", |
|
225 warn_for.c_str ()); |
|
226 } |
|
227 |
|
228 return retval; |
|
229 } |
|
230 |
2921
|
231 string_vector |
3523
|
232 get_struct_elts (const std::string& text) |
2921
|
233 { |
|
234 int n = 1; |
|
235 |
|
236 size_t pos = 0; |
|
237 |
|
238 size_t len = text.length (); |
|
239 |
|
240 while ((pos = text.find ('.', pos)) != NPOS) |
|
241 { |
|
242 if (++pos == len) |
|
243 break; |
|
244 |
|
245 n++; |
|
246 } |
|
247 |
|
248 string_vector retval (n); |
|
249 |
|
250 pos = 0; |
|
251 |
|
252 for (int i = 0; i < n; i++) |
|
253 { |
|
254 size_t len = text.find ('.', pos); |
|
255 |
|
256 if (len != NPOS) |
|
257 len -= pos; |
|
258 |
|
259 retval[i] = text.substr (pos, len); |
|
260 |
|
261 if (len != NPOS) |
|
262 pos += len + 1; |
|
263 } |
|
264 |
|
265 return retval; |
|
266 } |
|
267 |
|
268 string_vector |
3933
|
269 generate_struct_completions (const std::string& text, |
|
270 std::string& prefix, std::string& hint) |
2921
|
271 { |
|
272 string_vector names; |
|
273 |
|
274 size_t pos = text.rfind ('.'); |
|
275 |
3933
|
276 if (pos != NPOS) |
2921
|
277 { |
|
278 if (pos == text.length ()) |
|
279 hint = ""; |
|
280 else |
|
281 hint = text.substr (pos+1); |
|
282 |
|
283 prefix = text.substr (0, pos); |
|
284 } |
|
285 |
3933
|
286 int parse_status; |
2921
|
287 |
3935
|
288 unwind_protect_str (Vwarning_option); |
|
289 |
|
290 Vwarning_option = "off"; |
|
291 |
3933
|
292 octave_value tmp = eval_string (prefix, true, parse_status); |
2921
|
293 |
3935
|
294 unwind_protect::run (); |
|
295 |
3933
|
296 if (tmp.is_defined () && tmp.is_map ()) |
|
297 names = tmp.map_keys (); |
2921
|
298 |
|
299 return names; |
|
300 } |
|
301 |
|
302 bool |
3523
|
303 looks_like_struct (const std::string& text) |
2921
|
304 { |
3968
|
305 bool retval = false; |
|
306 |
|
307 symbol_record *sr = curr_sym_tab->lookup (text); |
2963
|
308 |
3968
|
309 if (sr && ! sr->is_function ()) |
|
310 { |
|
311 int parse_status; |
2921
|
312 |
3968
|
313 octave_value tmp = eval_string (text, true, parse_status); |
|
314 |
|
315 retval = (tmp.is_defined () && tmp.is_map ()); |
|
316 } |
|
317 |
|
318 return retval; |
2921
|
319 } |
2796
|
320 |
1957
|
321 DEFUN (is_global, args, , |
3361
|
322 "-*- texinfo -*-\n\ |
|
323 @deftypefn {Built-in Function} {} is_global (@var{name})\n\ |
|
324 Return 1 if @var{name} is globally visible. Otherwise, return 0. For\n\ |
|
325 example,\n\ |
|
326 \n\ |
|
327 @example\n\ |
|
328 @group\n\ |
|
329 global x\n\ |
|
330 is_global (\"x\")\n\ |
|
331 @result{} 1\n\ |
|
332 @end group\n\ |
|
333 @end example\n\ |
|
334 @end deftypefn") |
593
|
335 { |
2086
|
336 octave_value_list retval = 0.0; |
593
|
337 |
712
|
338 int nargin = args.length (); |
|
339 |
|
340 if (nargin != 1) |
593
|
341 { |
|
342 print_usage ("is_global"); |
|
343 return retval; |
|
344 } |
|
345 |
3523
|
346 std::string name = args(0).string_value (); |
593
|
347 |
636
|
348 if (error_state) |
|
349 { |
3523
|
350 error ("is_global: expecting std::string argument"); |
636
|
351 return retval; |
|
352 } |
|
353 |
2856
|
354 symbol_record *sr = curr_sym_tab->lookup (name); |
593
|
355 |
2800
|
356 retval = static_cast<double> (sr && sr->is_linked_to_global ()); |
593
|
357 |
|
358 return retval; |
|
359 } |
|
360 |
1957
|
361 DEFUN (exist, args, , |
3361
|
362 "-*- texinfo -*-\n\ |
|
363 @deftypefn {Built-in Function} {} exist (@var{name})\n\ |
|
364 Return 1 if the name exists as a variable, 2 if the name (after\n\ |
|
365 appending @samp{.m}) is a function file in the path, 3 if the name is a\n\ |
3476
|
366 @samp{.oct} file in the path, 5 if the name is a built-in function, or\n\ |
|
367 6 is the name is a built-in constant. Otherwise, return 0.\n\ |
1564
|
368 \n\ |
3361
|
369 This function also returns 2 if a regular file called @var{name}\n\ |
|
370 exists in Octave's @code{LOADPATH}. If you want information about\n\ |
|
371 other types of files, you should use some combination of the functions\n\ |
|
372 @code{file_in_path} and @code{stat} instead.\n\ |
|
373 @end deftypefn") |
593
|
374 { |
2086
|
375 octave_value_list retval; |
593
|
376 |
712
|
377 int nargin = args.length (); |
|
378 |
|
379 if (nargin != 1) |
593
|
380 { |
|
381 print_usage ("exist"); |
|
382 return retval; |
|
383 } |
|
384 |
3523
|
385 std::string name = args(0).string_value (); |
593
|
386 |
636
|
387 if (error_state) |
|
388 { |
3523
|
389 error ("exist: expecting std::string argument"); |
636
|
390 return retval; |
|
391 } |
|
392 |
3523
|
393 std::string struct_elts; |
|
394 std::string symbol_name = name; |
1755
|
395 |
|
396 size_t pos = name.find ('.'); |
|
397 |
2790
|
398 if (pos != NPOS && pos > 0) |
1277
|
399 { |
1755
|
400 struct_elts = name.substr (pos+1); |
2790
|
401 symbol_name = name.substr (0, pos); |
1277
|
402 } |
|
403 |
2856
|
404 symbol_record *sr = curr_sym_tab->lookup (symbol_name); |
3238
|
405 if (! (sr && (sr->is_defined () |
|
406 || (curr_sym_tab != top_level_sym_tab)))) |
2856
|
407 sr = global_sym_tab->lookup (symbol_name); |
593
|
408 |
|
409 retval = 0.0; |
|
410 |
|
411 if (sr && sr->is_variable () && sr->is_defined ()) |
1277
|
412 { |
2390
|
413 if (struct_elts.empty () || sr->is_map_element (struct_elts)) |
|
414 retval = 1.0; |
1277
|
415 } |
1421
|
416 else if (sr && sr->is_builtin_function ()) |
|
417 { |
|
418 retval = 5.0; |
|
419 } |
3476
|
420 else if (sr && sr->is_builtin_constant ()) |
|
421 { |
|
422 retval = 6.0; |
|
423 } |
1421
|
424 else if (sr && sr->is_user_function ()) |
|
425 { |
|
426 retval = 2.0; |
|
427 } |
593
|
428 else |
|
429 { |
3523
|
430 std::string path = fcn_file_in_path (name); |
1755
|
431 |
|
432 if (path.length () > 0) |
593
|
433 { |
|
434 retval = 2.0; |
|
435 } |
|
436 else |
|
437 { |
1421
|
438 path = oct_file_in_path (name); |
1755
|
439 |
|
440 if (path.length () > 0) |
1421
|
441 { |
|
442 retval = 3.0; |
|
443 } |
|
444 else |
|
445 { |
3523
|
446 std::string file_name = file_in_path (name, ""); |
1766
|
447 |
3096
|
448 if (! file_name.empty ()) |
|
449 { |
|
450 file_stat fs (file_name); |
|
451 |
|
452 if (fs && fs.is_reg ()) |
|
453 retval = 2.0; |
|
454 } |
1421
|
455 } |
593
|
456 } |
|
457 } |
|
458 |
|
459 return retval; |
|
460 } |
|
461 |
581
|
462 // Is there a corresponding function file that is newer than the |
|
463 // symbol definition? |
|
464 |
2926
|
465 static bool |
1
|
466 symbol_out_of_date (symbol_record *sr) |
|
467 { |
2926
|
468 bool retval = false; |
195
|
469 |
2926
|
470 if (Vignore_function_time_stamp != 2 && sr) |
1
|
471 { |
2975
|
472 octave_value ans = sr->def (); |
|
473 |
3022
|
474 octave_function *tmp = ans.function_value (true); |
2975
|
475 |
3022
|
476 if (tmp) |
|
477 { |
3523
|
478 std::string ff = tmp->fcn_file_name (); |
1755
|
479 |
3022
|
480 if (! (ff.empty () |
|
481 || (Vignore_function_time_stamp |
|
482 && tmp->is_system_fcn_file ()))) |
|
483 { |
3165
|
484 if (tmp->time_checked () < Vlast_prompt_time) |
|
485 { |
|
486 time_t tp = tmp->time_parsed (); |
2975
|
487 |
3523
|
488 std::string fname; |
3325
|
489 |
|
490 if (tmp->is_dld_function ()) |
|
491 fname = ff; |
|
492 else |
|
493 fname = fcn_file_in_path (ff); |
1755
|
494 |
3255
|
495 tmp->mark_fcn_file_up_to_date (octave_time ()); |
3165
|
496 |
|
497 file_stat fs (fname); |
3022
|
498 |
3165
|
499 if (fs && fs.is_newer (tp)) |
|
500 retval = true; |
|
501 } |
1
|
502 } |
|
503 } |
|
504 } |
2926
|
505 |
|
506 return retval; |
1
|
507 } |
|
508 |
1827
|
509 bool |
2856
|
510 lookup (symbol_record *sym_rec, bool exec_script) |
581
|
511 { |
1827
|
512 bool script_executed = false; |
581
|
513 |
|
514 if (! sym_rec->is_linked_to_global ()) |
|
515 { |
|
516 if (sym_rec->is_defined ()) |
|
517 { |
|
518 if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) |
1271
|
519 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
520 } |
|
521 else if (! sym_rec->is_formal_parameter ()) |
|
522 { |
|
523 link_to_builtin_or_function (sym_rec); |
1271
|
524 |
581
|
525 if (! sym_rec->is_defined ()) |
1271
|
526 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
527 else if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) |
1271
|
528 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
529 } |
|
530 } |
|
531 |
1271
|
532 return script_executed; |
581
|
533 } |
|
534 |
|
535 // Get the symbol record for the given name that is visible in the |
|
536 // current scope. Reread any function definitions that appear to be |
|
537 // out of date. If a function is available in a file but is not |
|
538 // currently loaded, this will load it and insert the name in the |
|
539 // current symbol table. |
|
540 |
|
541 symbol_record * |
3523
|
542 lookup_by_name (const std::string& nm, bool exec_script) |
581
|
543 { |
2856
|
544 symbol_record *sym_rec = curr_sym_tab->lookup (nm, true); |
581
|
545 |
|
546 lookup (sym_rec, exec_script); |
|
547 |
|
548 return sym_rec; |
|
549 } |
|
550 |
2849
|
551 octave_value |
3523
|
552 get_global_value (const std::string& nm) |
2849
|
553 { |
|
554 octave_value retval; |
|
555 |
|
556 symbol_record *sr = global_sym_tab->lookup (nm); |
|
557 |
|
558 if (sr) |
|
559 { |
2975
|
560 octave_value sr_def = sr->def (); |
2849
|
561 |
2975
|
562 if (sr_def.is_undefined ()) |
2849
|
563 error ("get_global_by_name: undefined symbol `%s'", nm.c_str ()); |
3088
|
564 else |
|
565 retval = sr_def; |
2849
|
566 } |
|
567 else |
|
568 error ("get_global_by_name: unknown symbol `%s'", nm.c_str ()); |
|
569 |
|
570 return retval; |
|
571 } |
|
572 |
|
573 void |
3523
|
574 set_global_value (const std::string& nm, const octave_value& val) |
2849
|
575 { |
2856
|
576 symbol_record *sr = global_sym_tab->lookup (nm, true); |
2849
|
577 |
|
578 if (sr) |
|
579 sr->define (val); |
|
580 else |
|
581 panic_impossible (); |
|
582 } |
|
583 |
593
|
584 // Variable values. |
195
|
585 |
581
|
586 // Look for the given name in the global symbol table. If it refers |
|
587 // to a string, return a new copy. If not, return 0; |
|
588 |
3523
|
589 std::string |
|
590 builtin_string_variable (const std::string& name) |
1
|
591 { |
2856
|
592 symbol_record *sr = global_sym_tab->lookup (name); |
195
|
593 |
1271
|
594 // It is a prorgramming error to look for builtins that aren't. |
195
|
595 |
529
|
596 assert (sr); |
195
|
597 |
3523
|
598 std::string retval; |
1
|
599 |
2975
|
600 octave_value val = sr->def (); |
195
|
601 |
2975
|
602 if (! error_state && val.is_string ()) |
|
603 retval = val.string_value (); |
1
|
604 |
|
605 return retval; |
|
606 } |
|
607 |
581
|
608 // Look for the given name in the global symbol table. If it refers |
1504
|
609 // to a real scalar, place the value in d and return 1. Otherwise, |
|
610 // return 0. |
581
|
611 |
1
|
612 int |
3523
|
613 builtin_real_scalar_variable (const std::string& name, double& d) |
1
|
614 { |
1504
|
615 int status = 0; |
2856
|
616 symbol_record *sr = global_sym_tab->lookup (name); |
195
|
617 |
1271
|
618 // It is a prorgramming error to look for builtins that aren't. |
195
|
619 |
529
|
620 assert (sr); |
1
|
621 |
2975
|
622 octave_value val = sr->def (); |
195
|
623 |
2975
|
624 if (! error_state && val.is_scalar_type ()) |
|
625 { |
|
626 d = val.double_value (); |
|
627 status = 1; |
1
|
628 } |
|
629 |
|
630 return status; |
|
631 } |
|
632 |
1093
|
633 // Look for the given name in the global symbol table. |
|
634 |
2086
|
635 octave_value |
3523
|
636 builtin_any_variable (const std::string& name) |
1093
|
637 { |
2856
|
638 symbol_record *sr = global_sym_tab->lookup (name); |
1093
|
639 |
1271
|
640 // It is a prorgramming error to look for builtins that aren't. |
1093
|
641 |
|
642 assert (sr); |
|
643 |
2975
|
644 return sr->def (); |
1093
|
645 } |
|
646 |
593
|
647 // Global stuff and links to builtin variables and functions. |
|
648 |
581
|
649 // Make the definition of the symbol record sr be the same as the |
|
650 // definition of the global variable of the same name, creating it if |
1418
|
651 // it doesn't already exist. |
581
|
652 |
195
|
653 void |
|
654 link_to_global_variable (symbol_record *sr) |
|
655 { |
2975
|
656 if (! sr->is_linked_to_global ()) |
195
|
657 { |
2975
|
658 sr->mark_as_linked_to_global (); |
195
|
659 |
2975
|
660 if (! error_state) |
|
661 { |
3523
|
662 std::string nm = sr->name (); |
2846
|
663 |
2975
|
664 symbol_record *gsr = global_sym_tab->lookup (nm, true); |
|
665 |
|
666 // There must be a better way to do this. XXX FIXME XXX |
195
|
667 |
2975
|
668 if (sr->is_variable ()) |
|
669 gsr->define (sr->def ()); |
1271
|
670 |
2975
|
671 // Make sure this symbol is a variable. |
2900
|
672 |
2975
|
673 if (! gsr->is_variable ()) |
|
674 gsr->define (octave_value ()); |
2900
|
675 |
2975
|
676 sr->alias (gsr, 1); |
|
677 } |
195
|
678 } |
|
679 } |
|
680 |
581
|
681 // Make the definition of the symbol record sr be the same as the |
|
682 // definition of the builtin variable of the same name. |
|
683 |
|
684 // Make the definition of the symbol record sr be the same as the |
3258
|
685 // definition of the builtin variable, constant, or function, or user |
|
686 // function of the same name, provided that the name has not been used |
|
687 // as a formal parameter. |
581
|
688 |
195
|
689 void |
|
690 link_to_builtin_or_function (symbol_record *sr) |
|
691 { |
2856
|
692 symbol_record *tmp_sym = global_sym_tab->lookup (sr->name ()); |
195
|
693 |
529
|
694 if (tmp_sym |
3258
|
695 && (tmp_sym->is_builtin_variable () |
|
696 || tmp_sym->is_builtin_constant () |
|
697 || tmp_sym->is_function ()) |
529
|
698 && ! tmp_sym->is_formal_parameter ()) |
|
699 sr->alias (tmp_sym); |
195
|
700 } |
|
701 |
581
|
702 // Force a link to a function in the current symbol table. This is |
|
703 // used just after defining a function to avoid different behavior |
|
704 // depending on whether or not the function has been evaluated after |
|
705 // being defined. |
|
706 // |
|
707 // Return without doing anything if there isn't a function with the |
|
708 // given name defined in the global symbol table. |
|
709 |
195
|
710 void |
3523
|
711 force_link_to_function (const std::string& id_name) |
195
|
712 { |
2856
|
713 symbol_record *gsr = global_sym_tab->lookup (id_name, true); |
195
|
714 if (gsr->is_function ()) |
|
715 { |
|
716 curr_sym_tab->clear (id_name); |
2856
|
717 symbol_record *csr = curr_sym_tab->lookup (id_name, true); |
195
|
718 csr->alias (gsr); |
|
719 } |
|
720 } |
|
721 |
2294
|
722 DEFUN (document, args, , |
3361
|
723 "-*- texinfo -*-\n\ |
|
724 @deftypefn {Built-in Function} {} document (@var{symbol}, @var{text})\n\ |
|
725 Set the documentation string for @var{symbol} to @var{text}.\n\ |
|
726 @end deftypefn") |
593
|
727 { |
2294
|
728 octave_value retval; |
1755
|
729 |
2294
|
730 int nargin = args.length (); |
1755
|
731 |
2294
|
732 if (nargin == 2) |
593
|
733 { |
3523
|
734 std::string name = args(0).string_value (); |
593
|
735 |
2294
|
736 if (! error_state) |
593
|
737 { |
3523
|
738 std::string help = args(1).string_value (); |
593
|
739 |
2294
|
740 if (! error_state) |
|
741 { |
|
742 if (is_builtin_variable (name) |
|
743 || is_text_function_name (name) |
|
744 || is_mapper_function_name (name) |
|
745 || is_builtin_function_name (name)) |
|
746 error ("document: can't redefine help for built-in variables and functions"); |
|
747 else |
|
748 { |
2856
|
749 symbol_record *sym_rec = curr_sym_tab->lookup (name); |
2294
|
750 |
|
751 if (sym_rec) |
|
752 sym_rec->document (help); |
|
753 else |
|
754 error ("document: no such symbol `%s'", name.c_str ()); |
|
755 } |
|
756 } |
593
|
757 } |
|
758 } |
|
759 else |
|
760 print_usage ("document"); |
|
761 |
|
762 return retval; |
|
763 } |
|
764 |
2086
|
765 static octave_value_list |
1755
|
766 do_who (int argc, const string_vector& argv) |
529
|
767 { |
2086
|
768 octave_value_list retval; |
529
|
769 |
2856
|
770 bool show_builtins = false; |
3248
|
771 bool show_functions = false; |
|
772 bool show_variables = false; |
2856
|
773 bool show_verbose = false; |
529
|
774 |
3523
|
775 std::string my_name = argv[0]; |
584
|
776 |
1857
|
777 int i; |
|
778 for (i = 1; i < argc; i++) |
529
|
779 { |
1755
|
780 if (argv[i] == "-all" || argv[i] == "-a") |
529
|
781 { |
2856
|
782 show_builtins = true; |
|
783 show_functions = true; |
|
784 show_variables = true; |
529
|
785 } |
1755
|
786 else if (argv[i] == "-builtins" || argv[i] == "-b") |
2856
|
787 show_builtins = true; |
1755
|
788 else if (argv[i] == "-functions" || argv[i] == "-f") |
2856
|
789 show_functions = true; |
1755
|
790 else if (argv[i] == "-long" || argv[i] == "-l") |
2856
|
791 show_verbose = true; |
1755
|
792 else if (argv[i] == "-variables" || argv[i] == "-v") |
2856
|
793 show_variables = true; |
1755
|
794 else if (argv[i][0] == '-') |
|
795 warning ("%s: unrecognized option `%s'", my_name.c_str (), |
|
796 argv[i].c_str ()); |
529
|
797 else |
867
|
798 break; |
529
|
799 } |
|
800 |
3248
|
801 // If no options were specified to select the type of symbol to |
|
802 // display, then set defaults. |
|
803 |
|
804 if (! (show_builtins || show_functions || show_variables)) |
|
805 { |
|
806 show_functions = (curr_sym_tab == top_level_sym_tab); |
|
807 show_variables = true; |
|
808 } |
|
809 |
1857
|
810 int npats = argc - i; |
|
811 string_vector pats (npats); |
|
812 for (int j = 0; j < npats; j++) |
|
813 pats[j] = argv[i+j]; |
|
814 |
1271
|
815 // If the user specified -l and nothing else, show variables. If |
|
816 // evaluating this at the top level, also show functions. |
529
|
817 |
|
818 if (show_verbose && ! (show_builtins || show_functions || show_variables)) |
|
819 { |
|
820 show_functions = (curr_sym_tab == top_level_sym_tab); |
|
821 show_variables = 1; |
|
822 } |
|
823 |
|
824 int pad_after = 0; |
|
825 |
|
826 if (show_builtins) |
|
827 { |
3011
|
828 pad_after += global_sym_tab->maybe_list |
3259
|
829 ("*** built-in constants:", pats, octave_stdout, |
|
830 show_verbose, symbol_record::BUILTIN_CONSTANT, SYMTAB_ALL_SCOPES); |
|
831 |
|
832 pad_after += global_sym_tab->maybe_list |
3013
|
833 ("*** built-in variables:", pats, octave_stdout, |
3011
|
834 show_verbose, symbol_record::BUILTIN_VARIABLE, SYMTAB_ALL_SCOPES); |
529
|
835 |
3011
|
836 pad_after += global_sym_tab->maybe_list |
3013
|
837 ("*** built-in functions:", pats, octave_stdout, |
3011
|
838 show_verbose, symbol_record::BUILTIN_FUNCTION, SYMTAB_ALL_SCOPES); |
529
|
839 } |
|
840 |
|
841 if (show_functions) |
|
842 { |
3011
|
843 pad_after += global_sym_tab->maybe_list |
3013
|
844 ("*** currently compiled functions:", pats, |
3011
|
845 octave_stdout, show_verbose, symbol_record::USER_FUNCTION, |
|
846 SYMTAB_ALL_SCOPES); |
529
|
847 } |
|
848 |
|
849 if (show_variables) |
|
850 { |
3011
|
851 pad_after += curr_sym_tab->maybe_list |
3013
|
852 ("*** local user variables:", pats, octave_stdout, |
3011
|
853 show_verbose, symbol_record::USER_VARIABLE, SYMTAB_LOCAL_SCOPE); |
529
|
854 |
3011
|
855 pad_after += curr_sym_tab->maybe_list |
3013
|
856 ("*** globally visible user variables:", pats, |
3011
|
857 octave_stdout, show_verbose, symbol_record::USER_VARIABLE, |
|
858 SYMTAB_GLOBAL_SCOPE); |
529
|
859 } |
|
860 |
|
861 if (pad_after) |
2095
|
862 octave_stdout << "\n"; |
529
|
863 |
581
|
864 return retval; |
|
865 } |
|
866 |
1957
|
867 DEFUN_TEXT (who, args, , |
3361
|
868 "-*- texinfo -*-\n\ |
|
869 @deffn {Command} who options pattern @dots{}\n\ |
|
870 @deffnx {Command} whos options pattern @dots{}\n\ |
|
871 List currently defined symbols matching the given patterns. The\n\ |
|
872 following are valid options. They may be shortened to one character but\n\ |
|
873 may not be combined.\n\ |
|
874 \n\ |
|
875 @table @code\n\ |
|
876 @item -all\n\ |
|
877 List all currently defined symbols.\n\ |
|
878 \n\ |
|
879 @item -builtins\n\ |
|
880 List built-in variables and functions. This includes all currently\n\ |
|
881 compiled function files, but does not include all function files that\n\ |
|
882 are in the @code{LOADPATH}.\n\ |
581
|
883 \n\ |
3361
|
884 @item -functions\n\ |
|
885 List user-defined functions.\n\ |
|
886 \n\ |
|
887 @item -long\n\ |
|
888 Print a long listing including the type and dimensions of any symbols.\n\ |
|
889 The symbols in the first column of output indicate whether it is\n\ |
|
890 possible to redefine the symbol, and whether it is possible for it to be\n\ |
|
891 cleared.\n\ |
|
892 \n\ |
|
893 @item -variables\n\ |
|
894 List user-defined variables.\n\ |
|
895 @end table\n\ |
|
896 \n\ |
|
897 Valid patterns are the same as described for the @code{clear} command\n\ |
|
898 above. If no patterns are supplied, all symbols from the given category\n\ |
|
899 are listed. By default, only user defined functions and variables\n\ |
|
900 visible in the local scope are displayed.\n\ |
|
901 \n\ |
|
902 The command @kbd{whos} is equivalent to @kbd{who -long}.\n\ |
|
903 @end deffn") |
581
|
904 { |
2086
|
905 octave_value_list retval; |
581
|
906 |
1755
|
907 int argc = args.length () + 1; |
|
908 |
1968
|
909 string_vector argv = args.make_argv ("who"); |
1755
|
910 |
|
911 if (error_state) |
|
912 return retval; |
581
|
913 |
1488
|
914 retval = do_who (argc, argv); |
581
|
915 |
529
|
916 return retval; |
|
917 } |
|
918 |
1957
|
919 DEFUN_TEXT (whos, args, , |
3458
|
920 "-*- texinfo -*-\n\ |
|
921 @deffn {Command} whos options pattern @dots{}\n\ |
|
922 See who.\n\ |
|
923 @end deffn") |
581
|
924 { |
2086
|
925 octave_value_list retval; |
581
|
926 |
712
|
927 int nargin = args.length (); |
|
928 |
2086
|
929 octave_value_list tmp_args; |
742
|
930 for (int i = nargin; i > 0; i--) |
|
931 tmp_args(i) = args(i-1); |
|
932 tmp_args(0) = "-long"; |
581
|
933 |
742
|
934 int argc = tmp_args.length () + 1; |
1755
|
935 |
1980
|
936 string_vector argv = tmp_args.make_argv ("whos"); |
581
|
937 |
|
938 if (error_state) |
|
939 return retval; |
|
940 |
1488
|
941 retval = do_who (argc, argv); |
581
|
942 |
|
943 return retval; |
|
944 } |
|
945 |
593
|
946 // Defining variables. |
|
947 |
1162
|
948 void |
2856
|
949 bind_ans (const octave_value& val, bool print) |
1162
|
950 { |
2856
|
951 static symbol_record *sr = global_sym_tab->lookup ("ans", true); |
1162
|
952 |
2978
|
953 if (val.is_defined ()) |
|
954 { |
|
955 sr->define (val); |
1162
|
956 |
2978
|
957 if (print) |
|
958 val.print_with_name (octave_stdout, "ans"); |
|
959 } |
1162
|
960 } |
|
961 |
3259
|
962 // Give a global constant a definition. This will insert the symbol |
|
963 // in the global table if necessary. |
|
964 |
|
965 // How is this different than install_builtin_constant? Are both |
|
966 // functions needed? |
|
967 |
|
968 void |
3523
|
969 bind_builtin_constant (const std::string& name, const octave_value& val, |
|
970 bool protect, bool eternal, const std::string& help) |
3259
|
971 { |
|
972 symbol_record *sym_rec = global_sym_tab->lookup (name, true); |
|
973 sym_rec->unprotect (); |
|
974 |
3523
|
975 std::string tmp_help = help.empty () ? sym_rec->help () : help; |
3259
|
976 |
|
977 sym_rec->define_builtin_const (val); |
|
978 |
|
979 sym_rec->document (tmp_help); |
|
980 |
|
981 if (protect) |
|
982 sym_rec->protect (); |
|
983 |
|
984 if (eternal) |
|
985 sym_rec->make_eternal (); |
|
986 } |
|
987 |
593
|
988 // Give a global variable a definition. This will insert the symbol |
|
989 // in the global table if necessary. |
|
990 |
|
991 // How is this different than install_builtin_variable? Are both |
|
992 // functions needed? |
|
993 |
|
994 void |
3523
|
995 bind_builtin_variable (const std::string& varname, const octave_value& val, |
2953
|
996 bool protect, bool eternal, |
3005
|
997 symbol_record::change_function chg_fcn, |
3523
|
998 const std::string& help) |
593
|
999 { |
2856
|
1000 symbol_record *sr = global_sym_tab->lookup (varname, true); |
593
|
1001 |
1271
|
1002 // It is a programming error for a builtin symbol to be missing. |
|
1003 // Besides, we just inserted it, so it must be there. |
593
|
1004 |
|
1005 assert (sr); |
|
1006 |
|
1007 sr->unprotect (); |
|
1008 |
1271
|
1009 // Must do this before define, since define will call the special |
|
1010 // variable function only if it knows about it, and it needs to, so |
|
1011 // that user prefs can be properly initialized. |
593
|
1012 |
3005
|
1013 if (chg_fcn) |
|
1014 sr->set_change_function (chg_fcn); |
593
|
1015 |
|
1016 sr->define_builtin_var (val); |
|
1017 |
|
1018 if (protect) |
|
1019 sr->protect (); |
|
1020 |
|
1021 if (eternal) |
|
1022 sr->make_eternal (); |
|
1023 |
1755
|
1024 sr->document (help); |
529
|
1025 } |
|
1026 |
593
|
1027 // Deleting names from the symbol tables. |
|
1028 |
3681
|
1029 static inline bool |
|
1030 var_matches_any_pattern (const std::string& nm, |
|
1031 const string_vector& argv, int argc, int idx) |
|
1032 { |
|
1033 bool retval = false; |
|
1034 |
|
1035 for (int k = idx; k < argc; k++) |
|
1036 { |
|
1037 std::string patstr = argv[k]; |
|
1038 |
|
1039 if (! patstr.empty ()) |
|
1040 { |
|
1041 glob_match pattern (patstr); |
|
1042 |
|
1043 if (pattern.match (nm)) |
|
1044 { |
|
1045 retval = true; |
|
1046 break; |
|
1047 } |
|
1048 } |
|
1049 } |
|
1050 |
|
1051 return retval; |
|
1052 } |
|
1053 |
1957
|
1054 DEFUN_TEXT (clear, args, , |
3361
|
1055 "-*- texinfo -*-\n\ |
|
1056 @deffn {Command} clear [-x] pattern @dots{}\n\ |
|
1057 Delete the names matching the given patterns from the symbol table. The\n\ |
|
1058 pattern may contain the following special characters:\n\ |
|
1059 @table @code\n\ |
|
1060 @item ?\n\ |
|
1061 Match any single character.\n\ |
668
|
1062 \n\ |
3361
|
1063 @item *\n\ |
|
1064 Match zero or more characters.\n\ |
|
1065 \n\ |
|
1066 @item [ @var{list} ]\n\ |
|
1067 Match the list of characters specified by @var{list}. If the first\n\ |
|
1068 character is @code{!} or @code{^}, match all characters except those\n\ |
|
1069 specified by @var{list}. For example, the pattern @samp{[a-zA-Z]} will\n\ |
|
1070 match all lower and upper case alphabetic characters.\n\ |
|
1071 @end table\n\ |
|
1072 \n\ |
|
1073 For example, the command\n\ |
593
|
1074 \n\ |
3361
|
1075 @example\n\ |
|
1076 clear foo b*r\n\ |
|
1077 @end example\n\ |
|
1078 \n\ |
|
1079 @noindent\n\ |
|
1080 clears the name @code{foo} and all names that begin with the letter\n\ |
|
1081 @code{b} and end with the letter @code{r}.\n\ |
668
|
1082 \n\ |
3361
|
1083 If @code{clear} is called without any arguments, all user-defined\n\ |
|
1084 variables (local and global) are cleared from the symbol table. If\n\ |
|
1085 @code{clear} is called with at least one argument, only the visible\n\ |
|
1086 names matching the arguments are cleared. For example, suppose you have\n\ |
|
1087 defined a function @code{foo}, and then hidden it by performing the\n\ |
|
1088 assignment @code{foo = 2}. Executing the command @kbd{clear foo} once\n\ |
|
1089 will clear the variable definition and restore the definition of\n\ |
|
1090 @code{foo} as a function. Executing @kbd{clear foo} a second time will\n\ |
|
1091 clear the function definition.\n\ |
|
1092 \n\ |
|
1093 With -x, clear the variables that don't match the patterns.\n\ |
|
1094 \n\ |
|
1095 This command may not be used within a function body.\n\ |
|
1096 @end deffn") |
529
|
1097 { |
2086
|
1098 octave_value_list retval; |
593
|
1099 |
1755
|
1100 int argc = args.length () + 1; |
593
|
1101 |
1968
|
1102 string_vector argv = args.make_argv ("clear"); |
1755
|
1103 |
|
1104 if (error_state) |
|
1105 return retval; |
668
|
1106 |
1271
|
1107 // Always clear the local table, but don't clear currently compiled |
|
1108 // functions unless we are at the top level. (Allowing that to |
|
1109 // happen inside functions would result in pretty odd behavior...) |
593
|
1110 |
2856
|
1111 bool clear_user_functions = (curr_sym_tab == top_level_sym_tab); |
593
|
1112 |
1755
|
1113 if (argc == 1) |
593
|
1114 { |
|
1115 curr_sym_tab->clear (); |
|
1116 global_sym_tab->clear (clear_user_functions); |
|
1117 } |
529
|
1118 else |
|
1119 { |
668
|
1120 int exclusive = 0; |
|
1121 |
1755
|
1122 int idx = 1; |
|
1123 |
|
1124 if (argc > 1) |
668
|
1125 { |
1755
|
1126 if (argv[idx] == "-x") |
3125
|
1127 { |
|
1128 idx++; |
|
1129 exclusive = 1; |
|
1130 } |
668
|
1131 } |
|
1132 |
1755
|
1133 string_vector lvars; |
|
1134 string_vector gvars; |
|
1135 string_vector fcns; |
668
|
1136 |
|
1137 if (argc > 0) |
593
|
1138 { |
3013
|
1139 string_vector tmp; |
|
1140 |
3325
|
1141 lvars = curr_sym_tab->name_list |
3355
|
1142 (tmp, false, SYMTAB_VARIABLES, SYMTAB_LOCAL_SCOPE); |
668
|
1143 |
3325
|
1144 gvars = curr_sym_tab->name_list |
3355
|
1145 (tmp, false, SYMTAB_VARIABLES, SYMTAB_GLOBAL_SCOPE); |
668
|
1146 |
3325
|
1147 fcns = global_sym_tab->name_list |
3355
|
1148 (tmp, false, |
3325
|
1149 symbol_record::USER_FUNCTION|symbol_record::DLD_FUNCTION, |
|
1150 SYMTAB_ALL_SCOPES); |
668
|
1151 } |
|
1152 |
2438
|
1153 // XXX FIXME XXX -- this needs to be optimized to avoid the |
|
1154 // pattern matching code if the string doesn't contain any |
|
1155 // globbing patterns. |
|
1156 |
3681
|
1157 if (exclusive) |
668
|
1158 { |
3681
|
1159 int lcount = lvars.length (); |
|
1160 |
|
1161 for (int i = 0; i < lcount; i++) |
|
1162 { |
|
1163 std::string nm = lvars[i]; |
668
|
1164 |
3681
|
1165 if (! var_matches_any_pattern (nm, argv, argc, idx)) |
|
1166 curr_sym_tab->clear (nm); |
|
1167 } |
|
1168 |
|
1169 int gcount = gvars.length (); |
|
1170 |
|
1171 for (int i = 0; i < gcount; i++) |
593
|
1172 { |
3681
|
1173 std::string nm = gvars[i]; |
1755
|
1174 |
3681
|
1175 if (! var_matches_any_pattern (nm, argv, argc, idx)) |
593
|
1176 { |
3681
|
1177 int count = curr_sym_tab->clear (nm); |
|
1178 |
|
1179 if (count > 0) |
|
1180 global_sym_tab->clear (nm, clear_user_functions); |
593
|
1181 } |
3681
|
1182 } |
|
1183 |
|
1184 int fcount = fcns.length (); |
|
1185 |
|
1186 for (int i = 0; i < fcount; i++) |
|
1187 { |
|
1188 std::string nm = fcns[i]; |
|
1189 |
|
1190 if (! var_matches_any_pattern (nm, argv, argc, idx)) |
|
1191 { |
|
1192 curr_sym_tab->clear (nm); |
529
|
1193 |
3681
|
1194 global_sym_tab->clear (nm, clear_user_functions); |
|
1195 } |
|
1196 } |
|
1197 } |
|
1198 else |
|
1199 { |
|
1200 for (int k = idx; k < argc; k++) |
|
1201 { |
|
1202 std::string patstr = argv[k]; |
|
1203 |
|
1204 if (! patstr.empty ()) |
593
|
1205 { |
3681
|
1206 glob_match pattern (patstr); |
|
1207 |
|
1208 int lcount = lvars.length (); |
|
1209 |
|
1210 for (int i = 0; i < lcount; i++) |
593
|
1211 { |
3681
|
1212 std::string nm = lvars[i]; |
|
1213 |
|
1214 if (pattern.match (nm)) |
|
1215 curr_sym_tab->clear (nm); |
593
|
1216 } |
3681
|
1217 |
|
1218 int gcount = gvars.length (); |
|
1219 |
|
1220 for (int i = 0; i < gcount; i++) |
|
1221 { |
|
1222 std::string nm = gvars[i]; |
|
1223 |
|
1224 if (pattern.match (nm)) |
|
1225 { |
|
1226 int count = curr_sym_tab->clear (nm); |
529
|
1227 |
3681
|
1228 if (count > 0) |
|
1229 global_sym_tab->clear (nm, clear_user_functions); |
|
1230 } |
|
1231 } |
|
1232 |
|
1233 int fcount = fcns.length (); |
|
1234 |
|
1235 for (int i = 0; i < fcount; i++) |
593
|
1236 { |
3681
|
1237 std::string nm = fcns[i]; |
|
1238 |
|
1239 if (pattern.match (nm)) |
|
1240 { |
|
1241 curr_sym_tab->clear (nm); |
|
1242 |
|
1243 global_sym_tab->clear (nm, clear_user_functions); |
|
1244 } |
593
|
1245 } |
|
1246 } |
|
1247 } |
|
1248 } |
|
1249 } |
|
1250 |
|
1251 return retval; |
529
|
1252 } |
|
1253 |
3933
|
1254 DEFUN (__print_symtab_info__, args, , |
3446
|
1255 "-*- texinfo -*-\n\ |
3933
|
1256 @deftypefn {Built-in Function} {} __print_symtab_info__ ()\n\ |
3446
|
1257 Print raw symbol table statistices.\n\ |
|
1258 @end deftypefn") |
3005
|
1259 { |
|
1260 octave_value_list retval; |
|
1261 |
|
1262 int nargin = args.length (); |
|
1263 |
|
1264 if (nargin == 1) |
|
1265 { |
3523
|
1266 std::string arg = args(0).string_value (); |
3005
|
1267 |
|
1268 if (arg == "global") |
3933
|
1269 global_sym_tab->print_info (octave_stdout); |
|
1270 else if (arg == "top-level") |
|
1271 top_level_sym_tab->print_info (octave_stdout); |
3005
|
1272 else |
3933
|
1273 { |
|
1274 symbol_record *gsr = global_sym_tab->lookup (arg, true); |
|
1275 |
|
1276 if (gsr && gsr->is_user_function ()) |
|
1277 { |
|
1278 octave_value tmp = gsr->def (); |
|
1279 const octave_value& rep = tmp.get_rep (); |
|
1280 |
|
1281 const octave_user_function& fcn |
|
1282 = static_cast<const octave_user_function&> (rep); |
|
1283 |
|
1284 fcn.print_symtab_info (octave_stdout); |
|
1285 } |
|
1286 else |
|
1287 error ("no user-defined function named %s", arg.c_str ()); |
|
1288 } |
3005
|
1289 } |
|
1290 else if (nargin == 0) |
3933
|
1291 curr_sym_tab->print_info (octave_stdout); |
3005
|
1292 else |
3933
|
1293 print_usage ("__print_symtab_info__"); |
3005
|
1294 |
|
1295 return retval; |
|
1296 } |
|
1297 |
3933
|
1298 DEFUN (__print_symbol_info__, args, , |
3446
|
1299 "-*- texinfo -*-\n\ |
|
1300 @deftypefn {Built-in Function} {} __dump_symbol_info__ (@var{name})\n\ |
3548
|
1301 Print symbol table information for the symbol @var{name}.\n\ |
3446
|
1302 @end deftypefn") |
3239
|
1303 { |
|
1304 octave_value_list retval; |
|
1305 |
|
1306 int nargin = args.length (); |
|
1307 |
|
1308 if (nargin == 1) |
|
1309 { |
3523
|
1310 std::string symbol_name = args(0).string_value (); |
3239
|
1311 |
|
1312 if (! error_state) |
|
1313 { |
|
1314 symbol_record *sr = curr_sym_tab->lookup (symbol_name); |
|
1315 |
|
1316 if (sr) |
3933
|
1317 sr->print_info (octave_stdout); |
3239
|
1318 else |
3933
|
1319 error ("__print_symbol_info__: symbol %s not found", |
3239
|
1320 symbol_name.c_str ()); |
|
1321 } |
|
1322 else |
3933
|
1323 print_usage ("__print_symbol_info__"); |
3239
|
1324 } |
|
1325 else |
3933
|
1326 print_usage ("__print_symbol_info__"); |
3239
|
1327 |
|
1328 return retval; |
|
1329 } |
|
1330 |
3016
|
1331 // XXX FIXME XXX -- some of these should do their own checking to be |
|
1332 // able to provide more meaningful warning or error messages. |
|
1333 |
|
1334 static int |
|
1335 ignore_function_time_stamp (void) |
|
1336 { |
|
1337 int pref = 0; |
|
1338 |
3523
|
1339 std::string val = builtin_string_variable ("ignore_function_time_stamp"); |
3016
|
1340 |
|
1341 if (! val.empty ()) |
|
1342 { |
3565
|
1343 if (val == "all") |
3016
|
1344 pref = 2; |
3565
|
1345 else if (val == "system") |
3016
|
1346 pref = 1; |
|
1347 } |
|
1348 |
|
1349 Vignore_function_time_stamp = pref; |
|
1350 |
|
1351 return 0; |
|
1352 } |
|
1353 |
|
1354 // XXX FIXME XXX -- there still may be better places for some of these |
|
1355 // to be defined. |
|
1356 |
|
1357 void |
|
1358 symbols_of_variables (void) |
|
1359 { |
3258
|
1360 DEFVAR (ans, , 0, |
3372
|
1361 "-*- texinfo -*-\n\ |
|
1362 @defvr {Built-in Variable} ans\n\ |
|
1363 This variable holds the most recently computed result that was not\n\ |
|
1364 explicitly assigned to a variable. For example, after the expression\n\ |
|
1365 \n\ |
|
1366 @example\n\ |
|
1367 3^2 + 4^2\n\ |
|
1368 @end example\n\ |
|
1369 \n\ |
|
1370 @noindent\n\ |
|
1371 is evaluated, the value of @code{ans} is 25.\n\ |
|
1372 @end defvr"); |
3016
|
1373 |
3258
|
1374 DEFVAR (ignore_function_time_stamp, "system", ignore_function_time_stamp, |
3371
|
1375 "-*- texinfo -*-\n\ |
|
1376 @defvr {Built-in Variable} ignore_function_time_stamp\n\ |
|
1377 This variable can be used to prevent Octave from making the system call\n\ |
|
1378 @code{stat} each time it looks up functions defined in function files.\n\ |
|
1379 If @code{ignore_function_time_stamp} to @code{\"system\"}, Octave will not\n\ |
|
1380 automatically recompile function files in subdirectories of\n\ |
|
1381 @file{@var{octave-home}/lib/@var{version}} if they have changed since\n\ |
|
1382 they were last compiled, but will recompile other function files in the\n\ |
|
1383 @code{LOADPATH} if they change. If set to @code{\"all\"}, Octave will not\n\ |
|
1384 recompile any function files unless their definitions are removed with\n\ |
|
1385 @code{clear}. For any other value of @code{ignore_function_time_stamp},\n\ |
|
1386 Octave will always check to see if functions defined in function files\n\ |
|
1387 need to recompiled. The default value of @code{ignore_function_time_stamp} is\n\ |
|
1388 @code{\"system\"}.\n\ |
|
1389 @end defvr"); |
3016
|
1390 } |
|
1391 |
1
|
1392 /* |
|
1393 ;;; Local Variables: *** |
|
1394 ;;; mode: C++ *** |
|
1395 ;;; End: *** |
|
1396 */ |