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