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