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