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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
1
|
26 #endif |
|
27 |
1468
|
28 #include <cstdio> |
1343
|
29 #include <cstring> |
605
|
30 |
4207
|
31 #include <set> |
1728
|
32 #include <string> |
|
33 |
2926
|
34 #include "file-stat.h" |
|
35 #include "oct-env.h" |
4604
|
36 #include "file-ops.h" |
2926
|
37 #include "glob-match.h" |
1755
|
38 #include "str-vec.h" |
|
39 |
2492
|
40 #include <defaults.h> |
4435
|
41 #include "Cell.h" |
1352
|
42 #include "defun.h" |
|
43 #include "dirfns.h" |
|
44 #include "error.h" |
2205
|
45 #include "gripes.h" |
1352
|
46 #include "help.h" |
3165
|
47 #include "input.h" |
1352
|
48 #include "lex.h" |
5832
|
49 #include "load-path.h" |
2926
|
50 #include "oct-map.h" |
|
51 #include "oct-obj.h" |
|
52 #include "ov.h" |
3933
|
53 #include "ov-usr-fcn.h" |
605
|
54 #include "pager.h" |
1352
|
55 #include "parse.h" |
2926
|
56 #include "symtab.h" |
2205
|
57 #include "toplev.h" |
1352
|
58 #include "unwind-prot.h" |
1
|
59 #include "utils.h" |
1352
|
60 #include "variables.h" |
2205
|
61 |
|
62 // Should Octave always check to see if function files have changed |
|
63 // since they were last compiled? |
5794
|
64 static int Vignore_function_time_stamp = 1; |
2205
|
65 |
1
|
66 // Symbol table for symbols at the top level. |
581
|
67 symbol_table *top_level_sym_tab = 0; |
1
|
68 |
|
69 // Symbol table for the current scope. |
581
|
70 symbol_table *curr_sym_tab = 0; |
1
|
71 |
4245
|
72 // Symbol table for the current caller scope. |
|
73 symbol_table *curr_caller_sym_tab = 0; |
|
74 |
1
|
75 // Symbol table for global symbols. |
581
|
76 symbol_table *global_sym_tab = 0; |
1
|
77 |
4009
|
78 // Symbol table for functions and built-in symbols. |
|
79 symbol_table *fbi_sym_tab = 0; |
|
80 |
4700
|
81 bool |
4208
|
82 at_top_level (void) |
|
83 { |
|
84 return (curr_sym_tab == top_level_sym_tab); |
|
85 } |
|
86 |
593
|
87 // Initialization. |
|
88 |
|
89 // Create the initial symbol tables and set the current scope at the |
|
90 // top level. |
|
91 |
195
|
92 void |
|
93 initialize_symbol_tables (void) |
|
94 { |
4009
|
95 if (! fbi_sym_tab) |
4238
|
96 fbi_sym_tab = new symbol_table (2048, "FBI"); |
4009
|
97 |
581
|
98 if (! global_sym_tab) |
4238
|
99 global_sym_tab = new symbol_table (2048, "GLOBAL"); |
195
|
100 |
581
|
101 if (! top_level_sym_tab) |
4238
|
102 top_level_sym_tab = new symbol_table (4096, "TOP"); |
195
|
103 |
4245
|
104 curr_caller_sym_tab = curr_sym_tab = top_level_sym_tab; |
195
|
105 } |
|
106 |
593
|
107 // Attributes of variables and functions. |
|
108 |
4208
|
109 // Is this a command-style function? |
593
|
110 |
4208
|
111 static std::set <std::string> command_set; |
4207
|
112 |
|
113 static inline bool |
4208
|
114 is_marked_as_command (const std::string& s) |
4207
|
115 { |
4208
|
116 return command_set.find (s) != command_set.end (); |
4207
|
117 } |
|
118 |
|
119 static inline void |
4208
|
120 mark_as_command (const std::string& s) |
4207
|
121 { |
4208
|
122 command_set.insert (s); |
4207
|
123 } |
|
124 |
|
125 static inline void |
4208
|
126 unmark_command (const std::string& s) |
4207
|
127 { |
4208
|
128 command_set.erase (s); |
4207
|
129 |
|
130 symbol_record *sr = fbi_sym_tab->lookup (s); |
|
131 |
|
132 if (sr) |
4208
|
133 sr->unmark_command (); |
4207
|
134 } |
|
135 |
4208
|
136 DEFCMD (mark_as_command, args, , |
4207
|
137 "-*- texinfo -*-\n\ |
4208
|
138 @deftypefn {Built-in Function} {} mark_as_command (@var{name})\n\ |
|
139 Enter @var{name} into the list of commands.\n\ |
5642
|
140 @seealso{unmark_command, iscommand}\n\ |
|
141 @end deftypefn") |
4207
|
142 { |
|
143 octave_value_list retval; |
|
144 |
4208
|
145 if (at_top_level ()) |
|
146 { |
|
147 int nargin = args.length (); |
4207
|
148 |
4208
|
149 if (nargin > 0) |
|
150 { |
|
151 int argc = nargin + 1; |
4207
|
152 |
4208
|
153 string_vector argv = args.make_argv ("mark_as_command"); |
4207
|
154 |
4208
|
155 if (! error_state) |
|
156 { |
|
157 for (int i = 1; i < argc; i++) |
|
158 mark_as_command (argv[i]); |
|
159 } |
4207
|
160 } |
4208
|
161 else |
5823
|
162 print_usage (); |
4207
|
163 } |
|
164 else |
4208
|
165 warning ("mark_as_command: invalid use inside function body"); |
4207
|
166 |
|
167 return retval; |
|
168 } |
|
169 |
4208
|
170 DEFCMD (unmark_command, args, , |
4207
|
171 "-*- texinfo -*-\n\ |
5102
|
172 @deftypefn {Built-in Function} {} unmark_command (@var{name})\n\ |
4208
|
173 Remove @var{name} from the list of commands.\n\ |
5642
|
174 @seealso{mark_as_command, iscommand}\n\ |
|
175 @end deftypefn") |
4207
|
176 { |
|
177 octave_value_list retval; |
|
178 |
4208
|
179 if (at_top_level ()) |
|
180 { |
|
181 int nargin = args.length (); |
4207
|
182 |
4208
|
183 if (nargin > 0) |
|
184 { |
|
185 int argc = nargin + 1; |
4207
|
186 |
4208
|
187 string_vector argv = args.make_argv ("unmark_command"); |
4207
|
188 |
4208
|
189 if (! error_state) |
|
190 { |
|
191 for (int i = 1; i < argc; i++) |
|
192 unmark_command (argv[i]); |
|
193 } |
4207
|
194 } |
4208
|
195 else |
5823
|
196 print_usage (); |
4207
|
197 } |
|
198 else |
4208
|
199 warning ("mark_as_command: invalid use inside function body"); |
4207
|
200 |
|
201 return retval; |
|
202 } |
|
203 |
1827
|
204 bool |
4208
|
205 is_command_name (const std::string& s) |
593
|
206 { |
4207
|
207 bool retval = false; |
|
208 |
4009
|
209 symbol_record *sr = fbi_sym_tab->lookup (s); |
4207
|
210 |
|
211 if (sr) |
|
212 { |
4208
|
213 if (sr->is_command ()) |
4207
|
214 retval = true; |
4208
|
215 else if (is_marked_as_command (s)) |
4207
|
216 { |
4208
|
217 sr->mark_as_command (); |
4207
|
218 retval = true; |
|
219 } |
|
220 } |
|
221 else |
4208
|
222 retval = is_marked_as_command (s); |
4207
|
223 |
|
224 return retval; |
593
|
225 } |
|
226 |
5102
|
227 DEFCMD (iscommand, args, , |
|
228 "-*- texinfo -*-\n\ |
|
229 @deftypefn {Built-in Function} {} iscommand (@var{name})\n\ |
|
230 Return true if @var{name} is a command style function. If @var{name}\n\ |
|
231 is omitted, return a list of identifiers which are marked as commands with\n\ |
|
232 mark_as_command.\n\ |
5642
|
233 @seealso{mark_as_command, unmark_command}\n\ |
|
234 @end deftypefn") |
5102
|
235 { |
|
236 octave_value retval; |
|
237 |
|
238 int nargin = args.length (); |
|
239 |
|
240 if (nargin == 0) |
|
241 { |
|
242 string_vector lst (command_set.size ()); |
|
243 |
|
244 int i = 0; |
|
245 for (std::set<std::string>::const_iterator p = command_set.begin (); |
|
246 p != command_set.end (); p++) |
|
247 lst[i++] = *p; |
|
248 |
|
249 retval = Cell (lst.qsort ()); |
|
250 } |
|
251 else if (nargin == 1) |
|
252 { |
|
253 string_vector argv = args.make_argv ("iscommand"); |
|
254 |
|
255 if (! error_state) |
|
256 { |
|
257 std::string s = argv[1]; |
|
258 retval = is_command_name(s); |
|
259 } |
|
260 } |
|
261 else |
5823
|
262 print_usage (); |
5102
|
263 |
|
264 return retval; |
|
265 } |
|
266 |
|
267 // Is this a raw input command? |
|
268 |
|
269 static std::set <std::string> rawcommand_set; |
|
270 |
5685
|
271 bool |
5102
|
272 is_marked_as_rawcommand (const std::string& s) |
|
273 { |
|
274 return rawcommand_set.find (s) != rawcommand_set.end (); |
|
275 } |
|
276 |
5685
|
277 void |
5102
|
278 mark_as_rawcommand (const std::string& s) |
|
279 { |
|
280 command_set.insert (s); |
|
281 rawcommand_set.insert (s); |
|
282 } |
|
283 |
5685
|
284 void |
5102
|
285 unmark_rawcommand (const std::string& s) |
|
286 { |
|
287 rawcommand_set.erase (s); |
|
288 |
|
289 symbol_record *sr = fbi_sym_tab->lookup (s); |
|
290 |
|
291 if (sr) |
|
292 sr->unmark_rawcommand (); |
|
293 } |
|
294 |
|
295 DEFCMD (mark_as_rawcommand, args, , |
|
296 "-*- texinfo -*-\n\ |
|
297 @deftypefn {Built-in Function} {} mark_as_rawcommand (@var{name})\n\ |
|
298 Enter @var{name} into the list of raw input commands and to the list of\n\ |
|
299 command style functions.\n\ |
|
300 Raw input commands are like normal command style functions, but they\n\ |
|
301 receive their input unprocessed (ie. strings still contain the quotes\n\ |
|
302 and escapes they had when input). However, comments and continuations\n\ |
|
303 are handled as usual, you cannot pass a token starting with a comment\n\ |
|
304 character ('#' or '%') to your function, and the last token cannot be\n\ |
|
305 a continuation token ('\\' or '...').\n\ |
5642
|
306 @seealso{unmark_rawcommand, israwcommand, iscommand, mark_as_command}\n\ |
|
307 @end deftypefn") |
5102
|
308 { |
|
309 octave_value_list retval; |
|
310 |
|
311 if (at_top_level ()) |
|
312 { |
|
313 int nargin = args.length (); |
|
314 |
|
315 if (nargin > 0) |
|
316 { |
|
317 int argc = nargin + 1; |
|
318 |
|
319 string_vector argv = args.make_argv ("mark_as_rawcommand"); |
|
320 |
|
321 if (! error_state) |
|
322 { |
|
323 for (int i = 1; i < argc; i++) |
|
324 mark_as_rawcommand (argv[i]); |
|
325 } |
|
326 } |
|
327 else |
5823
|
328 print_usage (); |
5102
|
329 } |
|
330 else |
|
331 warning ("mark_as_rawcommand: invalid use inside function body"); |
|
332 |
|
333 return retval; |
|
334 } |
|
335 |
|
336 DEFCMD (unmark_rawcommand, args, , |
|
337 "-*- texinfo -*-\n\ |
|
338 @deftypefn {Built-in Function} {} unmark_rawcommand (@var{name})\n\ |
|
339 Remove @var{name} from the list of raw input commands.\n\ |
|
340 Note that this does not remove @var{name} from the list of command style\n\ |
|
341 functions.\n\ |
5642
|
342 @seealso{mark_as_rawcommand, israwcommand, iscommand, unmark_command}\n\ |
|
343 @end deftypefn") |
5102
|
344 { |
|
345 octave_value_list retval; |
|
346 |
|
347 if (at_top_level ()) |
|
348 { |
|
349 int nargin = args.length (); |
|
350 |
|
351 if (nargin > 0) |
|
352 { |
|
353 int argc = nargin + 1; |
|
354 |
|
355 string_vector argv = args.make_argv ("unmark_rawcommand"); |
|
356 |
|
357 if (! error_state) |
|
358 { |
|
359 for (int i = 1; i < argc; i++) |
|
360 unmark_rawcommand (argv[i]); |
|
361 } |
|
362 } |
|
363 else |
5823
|
364 print_usage (); |
5102
|
365 } |
|
366 else |
|
367 warning ("unmark_rawcommand: invalid use inside function body"); |
|
368 |
|
369 return retval; |
|
370 } |
|
371 |
|
372 bool |
|
373 is_rawcommand_name (const std::string& s) |
|
374 { |
|
375 bool retval = false; |
|
376 |
|
377 symbol_record *sr = fbi_sym_tab->lookup (s); |
|
378 |
|
379 if (sr) |
|
380 { |
|
381 if (sr->is_rawcommand ()) |
|
382 retval = true; |
|
383 else if (is_marked_as_rawcommand (s)) |
|
384 { |
|
385 sr->mark_as_rawcommand (); |
|
386 retval = true; |
|
387 } |
|
388 } |
|
389 else |
|
390 retval = is_marked_as_rawcommand (s); |
|
391 |
|
392 return retval; |
|
393 } |
|
394 |
|
395 DEFCMD (israwcommand, args, , |
|
396 "-*- texinfo -*-\n\ |
|
397 @deftypefn {Built-in Function} {} israwcommand (@var{name})\n\ |
|
398 Return true if @var{name} is a raw input command function.\n\ |
|
399 If @var{name} is omitted, return a list of identifiers which are marked as\n\ |
|
400 raw input commands with mark_as_rawcommand.\n\ |
5642
|
401 @seealso{mark_as_rawcommand, unmark_rawcommand}\n\ |
|
402 @end deftypefn") |
5102
|
403 { |
|
404 octave_value retval; |
|
405 |
|
406 int nargin = args.length (); |
|
407 |
|
408 if (nargin == 0) |
|
409 { |
|
410 string_vector lst (rawcommand_set.size()); |
|
411 |
|
412 int i = 0; |
|
413 for (std::set<std::string>::const_iterator p = rawcommand_set.begin (); |
|
414 p != rawcommand_set.end (); |
|
415 p++) |
|
416 lst[i++] = *p; |
|
417 |
|
418 retval = Cell (lst.qsort ()); |
|
419 } |
|
420 else if (nargin == 1) |
|
421 { |
|
422 string_vector argv = args.make_argv ("israwcommand"); |
|
423 |
|
424 if (! error_state) |
|
425 { |
|
426 std::string s = argv[1]; |
|
427 retval = is_rawcommand_name(s); |
|
428 } |
|
429 } |
|
430 else |
5823
|
431 print_usage (); |
5102
|
432 |
|
433 return retval; |
|
434 } |
|
435 |
3355
|
436 // Is this a built-in function? |
2294
|
437 |
|
438 bool |
3523
|
439 is_builtin_function_name (const std::string& s) |
2294
|
440 { |
4009
|
441 symbol_record *sr = fbi_sym_tab->lookup (s); |
2294
|
442 return (sr && sr->is_builtin_function ()); |
|
443 } |
|
444 |
|
445 // Is this a mapper function? |
|
446 |
|
447 bool |
3523
|
448 is_mapper_function_name (const std::string& s) |
2294
|
449 { |
4009
|
450 symbol_record *sr = fbi_sym_tab->lookup (s); |
2294
|
451 return (sr && sr->is_mapper_function ()); |
|
452 } |
|
453 |
593
|
454 // Is this function globally in this scope? |
|
455 |
1827
|
456 bool |
3523
|
457 is_globally_visible (const std::string& name) |
593
|
458 { |
2856
|
459 symbol_record *sr = curr_sym_tab->lookup (name); |
593
|
460 return (sr && sr->is_linked_to_global ()); |
|
461 } |
|
462 |
2086
|
463 // Is this octave_value a valid function? |
593
|
464 |
2975
|
465 octave_function * |
4345
|
466 is_valid_function (const std::string& fcn_name, |
|
467 const std::string& warn_for, bool warn) |
593
|
468 { |
2975
|
469 octave_function *ans = 0; |
593
|
470 |
|
471 symbol_record *sr = 0; |
1755
|
472 |
|
473 if (! fcn_name.empty ()) |
3618
|
474 { |
4009
|
475 sr = fbi_sym_tab->lookup (fcn_name, true); |
3618
|
476 |
|
477 lookup (sr, false); |
|
478 } |
593
|
479 |
|
480 if (sr) |
2975
|
481 { |
|
482 octave_value tmp = sr->def (); |
|
483 ans = tmp.function_value (true); |
|
484 } |
593
|
485 |
|
486 if (! sr || ! ans || ! sr->is_function ()) |
|
487 { |
|
488 if (warn) |
|
489 error ("%s: the symbol `%s' is not valid as a function", |
1755
|
490 warn_for.c_str (), fcn_name.c_str ()); |
593
|
491 ans = 0; |
|
492 } |
|
493 |
|
494 return ans; |
|
495 } |
|
496 |
2975
|
497 octave_function * |
4345
|
498 is_valid_function (const octave_value& arg, |
|
499 const std::string& warn_for, bool warn) |
3178
|
500 { |
|
501 octave_function *ans = 0; |
|
502 |
3523
|
503 std::string fcn_name; |
3178
|
504 |
|
505 if (arg.is_string ()) |
4700
|
506 { |
|
507 fcn_name = arg.string_value (); |
3178
|
508 |
4700
|
509 if (! error_state) |
|
510 ans = is_valid_function (fcn_name, warn_for, warn); |
|
511 else if (warn) |
|
512 error ("%s: expecting function name as argument", warn_for.c_str ()); |
|
513 } |
3178
|
514 else if (warn) |
|
515 error ("%s: expecting function name as argument", warn_for.c_str ()); |
|
516 |
|
517 return ans; |
|
518 } |
|
519 |
|
520 octave_function * |
3523
|
521 extract_function (const octave_value& arg, const std::string& warn_for, |
|
522 const std::string& fname, const std::string& header, |
|
523 const std::string& trailer) |
2796
|
524 { |
2975
|
525 octave_function *retval = 0; |
2796
|
526 |
|
527 retval = is_valid_function (arg, warn_for, 0); |
|
528 |
|
529 if (! retval) |
|
530 { |
3523
|
531 std::string s = arg.string_value (); |
2796
|
532 |
3523
|
533 std::string cmd = header; |
2796
|
534 cmd.append (s); |
|
535 cmd.append (trailer); |
|
536 |
|
537 if (! error_state) |
|
538 { |
|
539 int parse_status; |
|
540 |
2898
|
541 eval_string (cmd, true, parse_status); |
2796
|
542 |
|
543 if (parse_status == 0) |
|
544 { |
|
545 retval = is_valid_function (fname, warn_for, 0); |
|
546 |
|
547 if (! retval) |
|
548 { |
|
549 error ("%s: `%s' is not valid as a function", |
|
550 warn_for.c_str (), fname.c_str ()); |
|
551 return retval; |
|
552 } |
|
553 } |
|
554 else |
|
555 error ("%s: `%s' is not valid as a function", |
|
556 warn_for.c_str (), fname.c_str ()); |
|
557 } |
|
558 else |
|
559 error ("%s: expecting first argument to be a string", |
|
560 warn_for.c_str ()); |
|
561 } |
|
562 |
|
563 return retval; |
|
564 } |
|
565 |
2921
|
566 string_vector |
3523
|
567 get_struct_elts (const std::string& text) |
2921
|
568 { |
|
569 int n = 1; |
|
570 |
|
571 size_t pos = 0; |
|
572 |
|
573 size_t len = text.length (); |
|
574 |
|
575 while ((pos = text.find ('.', pos)) != NPOS) |
|
576 { |
|
577 if (++pos == len) |
|
578 break; |
|
579 |
|
580 n++; |
|
581 } |
|
582 |
|
583 string_vector retval (n); |
|
584 |
|
585 pos = 0; |
|
586 |
|
587 for (int i = 0; i < n; i++) |
|
588 { |
4587
|
589 len = text.find ('.', pos); |
2921
|
590 |
|
591 if (len != NPOS) |
|
592 len -= pos; |
|
593 |
|
594 retval[i] = text.substr (pos, len); |
|
595 |
|
596 if (len != NPOS) |
|
597 pos += len + 1; |
|
598 } |
|
599 |
|
600 return retval; |
|
601 } |
|
602 |
4179
|
603 static inline bool |
|
604 is_variable (const std::string& name) |
|
605 { |
|
606 bool retval = false; |
|
607 |
|
608 if (! name.empty ()) |
|
609 { |
|
610 symbol_record *sr = curr_sym_tab->lookup (name); |
|
611 |
|
612 if (! sr) |
|
613 sr = fbi_sym_tab->lookup (name); |
|
614 |
|
615 retval = (sr && sr->is_variable ()); |
|
616 } |
|
617 |
|
618 return retval; |
|
619 } |
|
620 |
2921
|
621 string_vector |
3933
|
622 generate_struct_completions (const std::string& text, |
|
623 std::string& prefix, std::string& hint) |
2921
|
624 { |
|
625 string_vector names; |
|
626 |
|
627 size_t pos = text.rfind ('.'); |
|
628 |
3933
|
629 if (pos != NPOS) |
2921
|
630 { |
|
631 if (pos == text.length ()) |
|
632 hint = ""; |
|
633 else |
|
634 hint = text.substr (pos+1); |
|
635 |
|
636 prefix = text.substr (0, pos); |
|
637 |
4179
|
638 std::string base_name = prefix; |
|
639 |
|
640 pos = base_name.find_first_of ("{(."); |
2921
|
641 |
4179
|
642 if (pos != NPOS) |
|
643 base_name = base_name.substr (0, pos); |
4143
|
644 |
4179
|
645 if (is_variable (base_name)) |
|
646 { |
|
647 int parse_status; |
|
648 |
|
649 unwind_protect::begin_frame ("generate_struct_completions"); |
3935
|
650 |
4452
|
651 unwind_protect_int (error_state); |
|
652 unwind_protect_int (warning_state); |
|
653 |
4179
|
654 unwind_protect_bool (discard_error_messages); |
4452
|
655 unwind_protect_bool (discard_warning_messages); |
3935
|
656 |
4179
|
657 discard_error_messages = true; |
4452
|
658 discard_warning_messages = true; |
2921
|
659 |
4179
|
660 octave_value tmp = eval_string (prefix, true, parse_status); |
|
661 |
|
662 unwind_protect::run_frame ("generate_struct_completions"); |
3935
|
663 |
4179
|
664 if (tmp.is_defined () && tmp.is_map ()) |
|
665 names = tmp.map_keys (); |
|
666 } |
|
667 } |
2921
|
668 |
|
669 return names; |
|
670 } |
|
671 |
5775
|
672 // FIXME -- this will have to be much smarter to work |
4179
|
673 // "correctly". |
|
674 |
2921
|
675 bool |
3523
|
676 looks_like_struct (const std::string& text) |
2921
|
677 { |
4604
|
678 bool retval = (! text.empty () |
|
679 && text != "." |
|
680 && text.find_first_of (file_ops::dir_sep_chars) == NPOS |
|
681 && text.find ("..") == NPOS |
|
682 && text.rfind ('.') != NPOS); |
3968
|
683 |
4179
|
684 #if 0 |
3968
|
685 symbol_record *sr = curr_sym_tab->lookup (text); |
2963
|
686 |
3968
|
687 if (sr && ! sr->is_function ()) |
|
688 { |
|
689 int parse_status; |
2921
|
690 |
4143
|
691 unwind_protect::begin_frame ("looks_like_struct"); |
|
692 |
|
693 unwind_protect_bool (discard_error_messages); |
|
694 unwind_protect_int (error_state); |
|
695 |
|
696 discard_error_messages = true; |
|
697 |
3968
|
698 octave_value tmp = eval_string (text, true, parse_status); |
|
699 |
4143
|
700 unwind_protect::run_frame ("looks_like_struct"); |
|
701 |
3968
|
702 retval = (tmp.is_defined () && tmp.is_map ()); |
|
703 } |
4179
|
704 #endif |
3968
|
705 |
|
706 return retval; |
2921
|
707 } |
2796
|
708 |
4028
|
709 DEFUN (isglobal, args, , |
3361
|
710 "-*- texinfo -*-\n\ |
4028
|
711 @deftypefn {Built-in Function} {} isglobal (@var{name})\n\ |
3361
|
712 Return 1 if @var{name} is globally visible. Otherwise, return 0. For\n\ |
|
713 example,\n\ |
|
714 \n\ |
|
715 @example\n\ |
|
716 @group\n\ |
|
717 global x\n\ |
4028
|
718 isglobal (\"x\")\n\ |
3361
|
719 @result{} 1\n\ |
|
720 @end group\n\ |
|
721 @end example\n\ |
|
722 @end deftypefn") |
593
|
723 { |
4233
|
724 octave_value retval = false; |
593
|
725 |
712
|
726 int nargin = args.length (); |
|
727 |
|
728 if (nargin != 1) |
593
|
729 { |
5823
|
730 print_usage (); |
593
|
731 return retval; |
|
732 } |
|
733 |
3523
|
734 std::string name = args(0).string_value (); |
593
|
735 |
636
|
736 if (error_state) |
|
737 { |
4028
|
738 error ("isglobal: expecting std::string argument"); |
636
|
739 return retval; |
|
740 } |
|
741 |
2856
|
742 symbol_record *sr = curr_sym_tab->lookup (name); |
593
|
743 |
4233
|
744 retval = (sr && sr->is_linked_to_global ()); |
593
|
745 |
|
746 return retval; |
|
747 } |
|
748 |
4016
|
749 int |
|
750 symbol_exist (const std::string& name, const std::string& type) |
593
|
751 { |
4016
|
752 int retval = 0; |
636
|
753 |
3523
|
754 std::string struct_elts; |
|
755 std::string symbol_name = name; |
1755
|
756 |
|
757 size_t pos = name.find ('.'); |
|
758 |
2790
|
759 if (pos != NPOS && pos > 0) |
1277
|
760 { |
1755
|
761 struct_elts = name.substr (pos+1); |
2790
|
762 symbol_name = name.substr (0, pos); |
1277
|
763 } |
|
764 |
4009
|
765 // We shouldn't need to look in the global symbol table, since any |
|
766 // name that is visible in the current scope will be in the local |
|
767 // symbol table. |
|
768 |
2856
|
769 symbol_record *sr = curr_sym_tab->lookup (symbol_name); |
593
|
770 |
4009
|
771 if (! (sr && sr->is_defined ())) |
|
772 sr = fbi_sym_tab->lookup (symbol_name); |
593
|
773 |
4009
|
774 if (sr && sr->is_defined ()) |
1277
|
775 { |
4357
|
776 bool not_a_struct = struct_elts.empty (); |
|
777 bool var_ok = not_a_struct || sr->is_map_element (struct_elts); |
|
778 |
4016
|
779 if (! retval |
4357
|
780 && var_ok |
4016
|
781 && (type == "any" || type == "var") |
4357
|
782 && sr->is_user_variable ()) |
4009
|
783 { |
4016
|
784 retval = 1; |
4009
|
785 } |
4016
|
786 |
|
787 if (! retval |
|
788 && (type == "any" || type == "builtin")) |
4009
|
789 { |
4357
|
790 if (not_a_struct && sr->is_builtin_function ()) |
4016
|
791 { |
|
792 retval = 5; |
|
793 } |
4009
|
794 } |
4016
|
795 |
|
796 if (! retval |
4357
|
797 && not_a_struct |
4016
|
798 && (type == "any" || type == "file") |
|
799 && (sr->is_user_function () || sr->is_dld_function ())) |
4009
|
800 { |
4261
|
801 octave_value t = sr->def (); |
4016
|
802 octave_function *f = t.function_value (true); |
|
803 std::string s = f ? f->fcn_file_name () : std::string (); |
|
804 |
4438
|
805 retval = s.empty () ? 103 : (sr->is_user_function () ? 2 : 3); |
4009
|
806 } |
1421
|
807 } |
4016
|
808 |
5140
|
809 if (! (type == "var" || type == "builtin")) |
593
|
810 { |
5140
|
811 if (! retval) |
593
|
812 { |
5484
|
813 std::string file_name = lookup_autoload (name); |
|
814 |
|
815 if (file_name.empty ()) |
5832
|
816 file_name = load_path::find_fcn (name); |
5140
|
817 |
|
818 size_t len = file_name.length (); |
|
819 |
5832
|
820 if (len > 0) |
4437
|
821 { |
5140
|
822 if (type == "any" || type == "file") |
|
823 { |
5864
|
824 if (len > 4 && (file_name.substr (len-4) == ".oct" |
|
825 || file_name.substr (len-4) == ".mex")) |
5140
|
826 retval = 3; |
|
827 else |
|
828 retval = 2; |
|
829 } |
4437
|
830 } |
593
|
831 } |
5140
|
832 |
|
833 if (! retval) |
593
|
834 { |
5140
|
835 std::string file_name = file_in_path (name, ""); |
|
836 |
|
837 if (file_name.empty ()) |
|
838 file_name = name; |
|
839 |
|
840 file_stat fs (file_name); |
|
841 |
|
842 if (fs) |
1421
|
843 { |
5140
|
844 if ((type == "any" || type == "file") |
|
845 && fs.is_reg ()) |
|
846 { |
|
847 retval = 2; |
|
848 } |
|
849 else if ((type == "any" || type == "dir") |
|
850 && fs.is_dir ()) |
|
851 { |
|
852 retval = 7; |
|
853 } |
1421
|
854 } |
593
|
855 } |
|
856 } |
|
857 |
|
858 return retval; |
|
859 } |
|
860 |
4962
|
861 #define GET_IDX(LEN) \ |
|
862 static_cast<int> ((LEN-1) * static_cast<double> (rand ()) / RAND_MAX) |
|
863 |
4954
|
864 std::string |
|
865 unique_symbol_name (const std::string& basename) |
|
866 { |
4962
|
867 static const std::string alpha |
|
868 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|
869 |
|
870 static size_t len = alpha.length (); |
|
871 |
|
872 std::string nm = basename + alpha[GET_IDX (len)]; |
|
873 |
|
874 size_t pos = nm.length (); |
|
875 |
|
876 if (nm.substr (0, 2) == "__") |
|
877 nm.append ("__"); |
|
878 |
|
879 while (symbol_exist (nm, "any")) |
|
880 nm.insert (pos++, 1, alpha[GET_IDX (len)]); |
|
881 |
|
882 return nm; |
4954
|
883 } |
|
884 |
4016
|
885 DEFUN (exist, args, , |
|
886 "-*- texinfo -*-\n\ |
|
887 @deftypefn {Built-in Function} {} exist (@var{name}, @var{type})\n\ |
|
888 Return 1 if the name exists as a variable, 2 if the name (after\n\ |
5814
|
889 appending @samp{.m}) is a function file in Octave's @code{path}, 3 if the\n\ |
5864
|
890 name is a @samp{.oct} or @samp{.mex} file in Octave's @code{path},\n\ |
|
891 5 if the name is a built-in function, 7 if the name is a directory, or 103\n\ |
4016
|
892 if the name is a function not associated with a file (entered on\n\ |
|
893 the command line).\n\ |
|
894 \n\ |
|
895 Otherwise, return 0.\n\ |
|
896 \n\ |
|
897 This function also returns 2 if a regular file called @var{name}\n\ |
5814
|
898 exists in Octave's search path. If you want information about\n\ |
4016
|
899 other types of files, you should use some combination of the functions\n\ |
|
900 @code{file_in_path} and @code{stat} instead.\n\ |
|
901 \n\ |
|
902 If the optional argument @var{type} is supplied, check only for\n\ |
|
903 symbols of the specified type. Valid types are\n\ |
|
904 \n\ |
|
905 @table @samp\n\ |
|
906 @item \"var\"\n\ |
|
907 Check only for variables.\n\ |
|
908 @item \"builtin\"\n\ |
|
909 Check only for built-in functions.\n\ |
|
910 @item \"file\"\n\ |
|
911 Check only for files.\n\ |
|
912 @item \"dir\"\n\ |
|
913 Check only for directories.\n\ |
|
914 @end table\n\ |
|
915 @end deftypefn") |
|
916 { |
4233
|
917 octave_value retval = false; |
4016
|
918 |
|
919 int nargin = args.length (); |
|
920 |
|
921 if (nargin == 1 || nargin == 2) |
|
922 { |
|
923 std::string name = args(0).string_value (); |
|
924 |
|
925 if (! error_state) |
|
926 { |
|
927 std::string type |
|
928 = (nargin == 2) ? args(1).string_value () : std::string ("any"); |
|
929 |
|
930 if (! error_state) |
4233
|
931 retval = symbol_exist (name, type); |
4016
|
932 else |
|
933 error ("exist: expecting second argument to be a string"); |
|
934 } |
|
935 else |
|
936 error ("exist: expecting first argument to be a string"); |
|
937 } |
|
938 else |
5823
|
939 print_usage (); |
4016
|
940 |
|
941 return retval; |
|
942 } |
|
943 |
5138
|
944 // Return TRUE if F and G are both names for the same file. |
|
945 |
|
946 static bool |
|
947 same_file (const std::string& f, const std::string& g) |
|
948 { |
|
949 std::string c_f = file_ops::canonicalize_file_name (f); |
|
950 std::string c_g = file_ops::canonicalize_file_name (g); |
|
951 |
|
952 file_stat f_fs (c_f); |
|
953 file_stat g_fs (c_g); |
|
954 |
|
955 return (f_fs.ino () == g_fs.ino () && f_fs.dev () == g_fs.dev ()); |
|
956 } |
|
957 |
5663
|
958 bool |
5397
|
959 fcn_out_of_date (octave_function *fcn, const std::string& ff, time_t tp) |
5312
|
960 { |
|
961 bool retval = false; |
|
962 |
5397
|
963 fcn->mark_fcn_file_up_to_date (octave_time ()); |
|
964 |
|
965 if (! (Vignore_function_time_stamp == 2 |
|
966 || (Vignore_function_time_stamp && fcn->is_system_fcn_file ()))) |
5312
|
967 { |
5397
|
968 file_stat fs (ff); |
|
969 |
|
970 if (fs && fs.is_newer (tp)) |
|
971 retval = true; |
5312
|
972 } |
|
973 |
|
974 return retval; |
|
975 } |
|
976 |
5397
|
977 // Is there a corresponding function file that is newer than the |
|
978 // symbol definition? |
|
979 |
5312
|
980 static bool |
1
|
981 symbol_out_of_date (symbol_record *sr) |
|
982 { |
2926
|
983 bool retval = false; |
195
|
984 |
5397
|
985 if (sr) |
1
|
986 { |
2975
|
987 octave_value ans = sr->def (); |
|
988 |
5397
|
989 octave_function *fcn = ans.function_value (true); |
|
990 |
5436
|
991 // No need to check nested functions. They can only be executed |
5437
|
992 // from within the parent function that contains them. Parent |
5436
|
993 // and nested functions will be updated simultaneously when we |
|
994 // check the parent. |
|
995 |
|
996 if (fcn && ! fcn->is_nested_function ()) |
5397
|
997 { |
|
998 std::string ff = fcn->fcn_file_name (); |
|
999 |
|
1000 if (! ff.empty ()) |
|
1001 { |
|
1002 if (fcn->time_checked () < Vlast_prompt_time) |
|
1003 { |
|
1004 time_t tp = fcn->time_parsed (); |
|
1005 |
|
1006 std::string nm = fcn->name (); |
|
1007 |
5775
|
1008 // FIXME -- the following code is repeated |
5534
|
1009 // in load_fcn_from_file in parse.y. |
|
1010 |
5397
|
1011 string_vector names (2); |
|
1012 |
5534
|
1013 int nm_len = nm.length (); |
|
1014 |
|
1015 std::string file; |
|
1016 |
|
1017 if (octave_env::absolute_pathname (nm) |
5864
|
1018 && ((nm_len > 4 && (nm.substr (nm_len-4) == ".oct" |
|
1019 || nm.substr (nm_len-4) == ".mex")) |
5534
|
1020 || (nm_len > 2 && nm.substr (nm_len-4) == ".m"))) |
|
1021 { |
|
1022 file = nm; |
|
1023 } |
|
1024 else |
|
1025 { |
|
1026 file = lookup_autoload (nm); |
|
1027 |
|
1028 if (file.empty ()) |
|
1029 { |
|
1030 file = octave_env::make_absolute |
5832
|
1031 (load_path::find_fcn (nm), octave_env::getcwd ()); |
5534
|
1032 } |
|
1033 } |
5397
|
1034 |
|
1035 if (same_file (file, ff)) |
|
1036 { |
|
1037 retval = fcn_out_of_date (fcn, ff, tp); |
|
1038 } |
|
1039 else |
|
1040 { |
|
1041 // Check the full function name. Maybe we alrady |
|
1042 // parsed it. |
|
1043 |
|
1044 symbol_record *full_sr = fbi_sym_tab->lookup (file); |
|
1045 |
|
1046 if (full_sr) |
|
1047 { |
|
1048 octave_value v = full_sr->def (); |
|
1049 |
|
1050 if (v.is_function ()) |
|
1051 { |
|
1052 // OK, swap the aliases around. |
|
1053 |
5775
|
1054 // FIXME -- this is a bit |
5397
|
1055 // tricky, so maybe some refactoring is |
|
1056 // in order here too... |
|
1057 |
|
1058 symbol_record *short_sr = fbi_sym_tab->lookup (nm); |
|
1059 |
|
1060 if (short_sr) |
|
1061 short_sr->alias (full_sr); |
|
1062 |
|
1063 // Make local symbol table entry point |
|
1064 // to correct global function too. |
|
1065 |
|
1066 sr->alias (full_sr); |
|
1067 |
|
1068 fcn = v.function_value (); |
|
1069 |
|
1070 retval = fcn_out_of_date (fcn, file, tp); |
|
1071 } |
|
1072 else |
|
1073 retval = true; |
|
1074 } |
|
1075 else |
|
1076 retval = true; |
|
1077 } |
|
1078 } |
|
1079 } |
|
1080 } |
1
|
1081 } |
2926
|
1082 |
|
1083 return retval; |
1
|
1084 } |
|
1085 |
1827
|
1086 bool |
2856
|
1087 lookup (symbol_record *sym_rec, bool exec_script) |
581
|
1088 { |
1827
|
1089 bool script_executed = false; |
581
|
1090 |
|
1091 if (! sym_rec->is_linked_to_global ()) |
|
1092 { |
|
1093 if (sym_rec->is_defined ()) |
|
1094 { |
|
1095 if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) |
1271
|
1096 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
1097 } |
|
1098 else if (! sym_rec->is_formal_parameter ()) |
|
1099 { |
|
1100 link_to_builtin_or_function (sym_rec); |
1271
|
1101 |
581
|
1102 if (! sym_rec->is_defined ()) |
1271
|
1103 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
1104 else if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) |
1271
|
1105 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
1106 } |
|
1107 } |
|
1108 |
1271
|
1109 return script_executed; |
581
|
1110 } |
|
1111 |
|
1112 // Get the symbol record for the given name that is visible in the |
|
1113 // current scope. Reread any function definitions that appear to be |
|
1114 // out of date. If a function is available in a file but is not |
|
1115 // currently loaded, this will load it and insert the name in the |
|
1116 // current symbol table. |
|
1117 |
|
1118 symbol_record * |
3523
|
1119 lookup_by_name (const std::string& nm, bool exec_script) |
581
|
1120 { |
2856
|
1121 symbol_record *sym_rec = curr_sym_tab->lookup (nm, true); |
581
|
1122 |
|
1123 lookup (sym_rec, exec_script); |
|
1124 |
|
1125 return sym_rec; |
|
1126 } |
|
1127 |
4930
|
1128 octave_value |
4342
|
1129 lookup_function (const std::string& nm) |
|
1130 { |
4930
|
1131 octave_value retval; |
4342
|
1132 |
|
1133 symbol_record *sr = 0; |
|
1134 |
|
1135 if (curr_parent_function) |
|
1136 { |
4748
|
1137 std::string parent = curr_parent_function->name (); |
4342
|
1138 |
|
1139 sr = fbi_sym_tab->lookup (parent + ":" + nm); |
|
1140 } |
|
1141 |
|
1142 if (! sr || ! sr->is_function ()) |
|
1143 { |
|
1144 sr = fbi_sym_tab->lookup (nm, true); |
|
1145 |
|
1146 if (sr && ! sr->is_function ()) |
|
1147 load_fcn_from_file (sr, false); |
|
1148 } |
|
1149 |
|
1150 if (sr) |
|
1151 { |
|
1152 octave_value v = sr->def (); |
|
1153 |
|
1154 if (v.is_function ()) |
4930
|
1155 retval = v; |
4342
|
1156 } |
|
1157 |
|
1158 return retval; |
|
1159 } |
|
1160 |
4930
|
1161 octave_value |
4700
|
1162 lookup_user_function (const std::string& nm) |
|
1163 { |
4930
|
1164 octave_value retval; |
4700
|
1165 |
|
1166 symbol_record *sr = 0; |
|
1167 |
|
1168 if (curr_parent_function) |
|
1169 { |
4748
|
1170 std::string parent = curr_parent_function->name (); |
4700
|
1171 |
|
1172 sr = fbi_sym_tab->lookup (parent + ":" + nm); |
|
1173 } |
|
1174 |
|
1175 if (! sr || ! sr->is_user_function ()) |
|
1176 { |
|
1177 sr = fbi_sym_tab->lookup (nm, true); |
|
1178 |
|
1179 if (sr && ! sr->is_user_function ()) |
|
1180 load_fcn_from_file (sr, false); |
|
1181 } |
|
1182 |
|
1183 if (sr) |
4930
|
1184 retval = sr->def (); |
4700
|
1185 |
|
1186 return retval; |
|
1187 } |
|
1188 |
2849
|
1189 octave_value |
4988
|
1190 lookup_function_handle (const std::string& nm) |
|
1191 { |
|
1192 octave_value retval; |
|
1193 |
|
1194 symbol_record *sr = curr_sym_tab->lookup (nm, true); |
|
1195 |
|
1196 if (sr && sr->def ().is_function_handle ()) |
|
1197 retval = sr->def (); |
|
1198 |
|
1199 return retval; |
|
1200 } |
|
1201 |
|
1202 octave_value |
5027
|
1203 get_global_value (const std::string& nm, bool silent) |
2849
|
1204 { |
|
1205 octave_value retval; |
|
1206 |
|
1207 symbol_record *sr = global_sym_tab->lookup (nm); |
|
1208 |
|
1209 if (sr) |
|
1210 { |
2975
|
1211 octave_value sr_def = sr->def (); |
2849
|
1212 |
5027
|
1213 if (sr_def.is_defined ()) |
|
1214 retval = sr_def; |
|
1215 else if (! silent) |
2849
|
1216 error ("get_global_by_name: undefined symbol `%s'", nm.c_str ()); |
|
1217 } |
5027
|
1218 else if (! silent) |
2849
|
1219 error ("get_global_by_name: unknown symbol `%s'", nm.c_str ()); |
|
1220 |
|
1221 return retval; |
|
1222 } |
|
1223 |
|
1224 void |
3523
|
1225 set_global_value (const std::string& nm, const octave_value& val) |
2849
|
1226 { |
2856
|
1227 symbol_record *sr = global_sym_tab->lookup (nm, true); |
2849
|
1228 |
|
1229 if (sr) |
|
1230 sr->define (val); |
|
1231 else |
|
1232 panic_impossible (); |
|
1233 } |
|
1234 |
593
|
1235 // Variable values. |
195
|
1236 |
5791
|
1237 octave_value |
|
1238 set_internal_variable (bool& var, const octave_value_list& args, |
5794
|
1239 int nargout, const char *nm) |
5791
|
1240 { |
5794
|
1241 octave_value retval; |
|
1242 |
5800
|
1243 int nargin = args.length (); |
|
1244 |
|
1245 if (nargout > 0 || nargin == 0) |
5794
|
1246 retval = var; |
5791
|
1247 |
|
1248 if (nargin == 1) |
|
1249 { |
|
1250 bool bval = args(0).bool_value (); |
|
1251 |
|
1252 if (! error_state) |
|
1253 var = bval; |
|
1254 else |
|
1255 error ("%s: expecting arg to be a logical value", nm); |
|
1256 } |
|
1257 else if (nargin > 1) |
5823
|
1258 print_usage (); |
5791
|
1259 |
|
1260 return retval; |
|
1261 } |
|
1262 |
|
1263 octave_value |
5794
|
1264 set_internal_variable (char& var, const octave_value_list& args, |
|
1265 int nargout, const char *nm) |
5791
|
1266 { |
5794
|
1267 octave_value retval; |
|
1268 |
5800
|
1269 int nargin = args.length (); |
|
1270 |
|
1271 if (nargout > 0 || nargin == 0) |
5794
|
1272 retval = var; |
5791
|
1273 |
|
1274 if (nargin == 1) |
|
1275 { |
|
1276 std::string sval = args(0).string_value (); |
|
1277 |
|
1278 if (! error_state) |
5794
|
1279 { |
|
1280 switch (sval.length ()) |
|
1281 { |
|
1282 case 1: |
|
1283 var = sval[0]; |
|
1284 break; |
|
1285 |
|
1286 case 0: |
|
1287 var = '\0'; |
|
1288 break; |
|
1289 |
|
1290 default: |
|
1291 error ("%s: argument must be a single character", nm); |
|
1292 break; |
|
1293 } |
|
1294 } |
|
1295 else |
|
1296 error ("%s: argument must be a single character", nm); |
|
1297 } |
|
1298 else if (nargin > 1) |
5823
|
1299 print_usage (); |
5794
|
1300 |
|
1301 return retval; |
|
1302 } |
|
1303 |
|
1304 octave_value |
|
1305 set_internal_variable (int& var, const octave_value_list& args, |
|
1306 int nargout, const char *nm, |
|
1307 int minval, int maxval) |
|
1308 { |
|
1309 octave_value retval; |
|
1310 |
5800
|
1311 int nargin = args.length (); |
|
1312 |
|
1313 if (nargout > 0 || nargin == 0) |
5794
|
1314 retval = var; |
|
1315 |
|
1316 if (nargin == 1) |
|
1317 { |
|
1318 int ival = args(0).int_value (); |
|
1319 |
|
1320 if (! error_state) |
|
1321 { |
|
1322 if (ival < minval) |
|
1323 error ("%s: expecting arg to be greater than %d", minval); |
|
1324 else if (ival > maxval) |
|
1325 error ("%s: expecting arg to be less than or equal to %d", maxval); |
|
1326 else |
|
1327 var = ival; |
|
1328 } |
|
1329 else |
|
1330 error ("%s: expecting arg to be an integer value", nm); |
|
1331 } |
|
1332 else if (nargin > 1) |
5823
|
1333 print_usage (); |
5794
|
1334 |
|
1335 return retval; |
|
1336 } |
|
1337 |
|
1338 octave_value |
|
1339 set_internal_variable (double& var, const octave_value_list& args, |
|
1340 int nargout, const char *nm, |
|
1341 double minval, double maxval) |
|
1342 { |
|
1343 octave_value retval; |
|
1344 |
5800
|
1345 int nargin = args.length (); |
|
1346 |
|
1347 if (nargout > 0 || nargin == 0) |
5794
|
1348 retval = var; |
|
1349 |
|
1350 if (nargin == 1) |
|
1351 { |
|
1352 double dval = args(0).scalar_value (); |
|
1353 |
|
1354 if (! error_state) |
|
1355 { |
|
1356 if (dval < minval) |
|
1357 error ("%s: expecting arg to be greater than %g", minval); |
|
1358 else if (dval > maxval) |
|
1359 error ("%s: expecting arg to be less than or equal to %g", maxval); |
|
1360 else |
|
1361 var = dval; |
|
1362 } |
|
1363 else |
|
1364 error ("%s: expecting arg to be a scalar value", nm); |
|
1365 } |
|
1366 else if (nargin > 1) |
5823
|
1367 print_usage (); |
5794
|
1368 |
|
1369 return retval; |
|
1370 } |
|
1371 |
|
1372 octave_value |
|
1373 set_internal_variable (std::string& var, const octave_value_list& args, |
|
1374 int nargout, const char *nm, bool empty_ok) |
|
1375 { |
|
1376 octave_value retval; |
|
1377 |
5800
|
1378 int nargin = args.length (); |
|
1379 |
|
1380 if (nargout > 0 || nargin == 0) |
5794
|
1381 retval = var; |
|
1382 |
|
1383 if (nargin == 1) |
|
1384 { |
|
1385 std::string sval = args(0).string_value (); |
|
1386 |
|
1387 if (! error_state) |
|
1388 { |
|
1389 if (empty_ok || ! sval.empty ()) |
|
1390 var = sval; |
|
1391 else |
|
1392 error ("%s: value must not be empty", nm); |
|
1393 } |
5791
|
1394 else |
|
1395 error ("%s: expecting arg to be a character string", nm); |
|
1396 } |
|
1397 else if (nargin > 1) |
5823
|
1398 print_usage (); |
1
|
1399 |
|
1400 return retval; |
|
1401 } |
|
1402 |
593
|
1403 // Global stuff and links to builtin variables and functions. |
|
1404 |
581
|
1405 // Make the definition of the symbol record sr be the same as the |
|
1406 // definition of the global variable of the same name, creating it if |
1418
|
1407 // it doesn't already exist. |
581
|
1408 |
195
|
1409 void |
|
1410 link_to_global_variable (symbol_record *sr) |
|
1411 { |
2975
|
1412 if (! sr->is_linked_to_global ()) |
195
|
1413 { |
2975
|
1414 sr->mark_as_linked_to_global (); |
195
|
1415 |
2975
|
1416 if (! error_state) |
|
1417 { |
3523
|
1418 std::string nm = sr->name (); |
2846
|
1419 |
2975
|
1420 symbol_record *gsr = global_sym_tab->lookup (nm, true); |
|
1421 |
|
1422 // Make sure this symbol is a variable. |
2900
|
1423 |
4009
|
1424 if (! gsr->is_user_variable ()) |
2975
|
1425 gsr->define (octave_value ()); |
2900
|
1426 |
4009
|
1427 sr->alias (gsr); |
2975
|
1428 } |
195
|
1429 } |
|
1430 } |
|
1431 |
581
|
1432 // Make the definition of the symbol record sr be the same as the |
|
1433 // definition of the builtin variable of the same name. |
|
1434 |
|
1435 // Make the definition of the symbol record sr be the same as the |
5794
|
1436 // definition of the builtin function, or user function of the same |
|
1437 // name, provided that the name has not been used as a formal parameter. |
581
|
1438 |
195
|
1439 void |
|
1440 link_to_builtin_or_function (symbol_record *sr) |
|
1441 { |
4238
|
1442 std::string nm = sr->name (); |
|
1443 |
|
1444 symbol_record *tmp_sym = 0; |
|
1445 |
|
1446 if (curr_parent_function) |
|
1447 { |
4748
|
1448 std::string parent = curr_parent_function->name (); |
4238
|
1449 |
|
1450 tmp_sym = fbi_sym_tab->lookup (parent + ":" + nm); |
|
1451 } |
|
1452 |
|
1453 if (! tmp_sym) |
|
1454 tmp_sym = fbi_sym_tab->lookup (nm); |
195
|
1455 |
529
|
1456 if (tmp_sym |
5794
|
1457 && tmp_sym->is_function () |
529
|
1458 && ! tmp_sym->is_formal_parameter ()) |
|
1459 sr->alias (tmp_sym); |
195
|
1460 } |
|
1461 |
581
|
1462 // Force a link to a function in the current symbol table. This is |
|
1463 // used just after defining a function to avoid different behavior |
|
1464 // depending on whether or not the function has been evaluated after |
|
1465 // being defined. |
|
1466 // |
|
1467 // Return without doing anything if there isn't a function with the |
|
1468 // given name defined in the global symbol table. |
|
1469 |
195
|
1470 void |
3523
|
1471 force_link_to_function (const std::string& id_name) |
195
|
1472 { |
4009
|
1473 symbol_record *fsr = fbi_sym_tab->lookup (id_name, true); |
|
1474 if (fsr->is_function ()) |
195
|
1475 { |
|
1476 curr_sym_tab->clear (id_name); |
2856
|
1477 symbol_record *csr = curr_sym_tab->lookup (id_name, true); |
4009
|
1478 csr->alias (fsr); |
195
|
1479 } |
|
1480 } |
|
1481 |
2294
|
1482 DEFUN (document, args, , |
3361
|
1483 "-*- texinfo -*-\n\ |
|
1484 @deftypefn {Built-in Function} {} document (@var{symbol}, @var{text})\n\ |
|
1485 Set the documentation string for @var{symbol} to @var{text}.\n\ |
|
1486 @end deftypefn") |
593
|
1487 { |
2294
|
1488 octave_value retval; |
1755
|
1489 |
2294
|
1490 int nargin = args.length (); |
1755
|
1491 |
2294
|
1492 if (nargin == 2) |
593
|
1493 { |
3523
|
1494 std::string name = args(0).string_value (); |
593
|
1495 |
2294
|
1496 if (! error_state) |
593
|
1497 { |
3523
|
1498 std::string help = args(1).string_value (); |
593
|
1499 |
2294
|
1500 if (! error_state) |
|
1501 { |
5794
|
1502 if (is_command_name (name) |
2294
|
1503 || is_mapper_function_name (name) |
|
1504 || is_builtin_function_name (name)) |
5794
|
1505 error ("document: can't redefine help for built-in functions"); |
2294
|
1506 else |
|
1507 { |
2856
|
1508 symbol_record *sym_rec = curr_sym_tab->lookup (name); |
2294
|
1509 |
|
1510 if (sym_rec) |
|
1511 sym_rec->document (help); |
|
1512 else |
|
1513 error ("document: no such symbol `%s'", name.c_str ()); |
|
1514 } |
|
1515 } |
593
|
1516 } |
|
1517 } |
|
1518 else |
5823
|
1519 print_usage (); |
593
|
1520 |
|
1521 return retval; |
|
1522 } |
|
1523 |
5775
|
1524 // FIXME -- this function is duplicated in symtab.cc with the |
5659
|
1525 // name maybe_list_cmp_fcn. |
|
1526 |
|
1527 static int |
|
1528 symbol_record_name_compare (const void *a_arg, const void *b_arg) |
|
1529 { |
5929
|
1530 const symbol_record *a = *(static_cast<symbol_record *const*> (a_arg)); |
|
1531 const symbol_record *b = *(static_cast<symbol_record *const*> (b_arg)); |
5659
|
1532 |
|
1533 std::string a_nm = a->name (); |
|
1534 std::string b_nm = b->name (); |
|
1535 |
|
1536 return a_nm.compare (b_nm); |
|
1537 } |
|
1538 |
4435
|
1539 static octave_value |
|
1540 do_who (int argc, const string_vector& argv, int return_list) |
529
|
1541 { |
4435
|
1542 octave_value retval; |
529
|
1543 |
2856
|
1544 bool show_builtins = false; |
3248
|
1545 bool show_functions = false; |
|
1546 bool show_variables = false; |
2856
|
1547 bool show_verbose = false; |
529
|
1548 |
3523
|
1549 std::string my_name = argv[0]; |
584
|
1550 |
1857
|
1551 int i; |
|
1552 for (i = 1; i < argc; i++) |
529
|
1553 { |
1755
|
1554 if (argv[i] == "-all" || argv[i] == "-a") |
529
|
1555 { |
2856
|
1556 show_builtins = true; |
|
1557 show_functions = true; |
|
1558 show_variables = true; |
529
|
1559 } |
1755
|
1560 else if (argv[i] == "-builtins" || argv[i] == "-b") |
2856
|
1561 show_builtins = true; |
1755
|
1562 else if (argv[i] == "-functions" || argv[i] == "-f") |
2856
|
1563 show_functions = true; |
1755
|
1564 else if (argv[i] == "-long" || argv[i] == "-l") |
2856
|
1565 show_verbose = true; |
1755
|
1566 else if (argv[i] == "-variables" || argv[i] == "-v") |
2856
|
1567 show_variables = true; |
1755
|
1568 else if (argv[i][0] == '-') |
|
1569 warning ("%s: unrecognized option `%s'", my_name.c_str (), |
|
1570 argv[i].c_str ()); |
529
|
1571 else |
867
|
1572 break; |
529
|
1573 } |
|
1574 |
3248
|
1575 // If no options were specified to select the type of symbol to |
|
1576 // display, then set defaults. |
|
1577 |
|
1578 if (! (show_builtins || show_functions || show_variables)) |
|
1579 { |
4208
|
1580 show_functions = at_top_level (); |
3248
|
1581 show_variables = true; |
|
1582 } |
|
1583 |
1857
|
1584 int npats = argc - i; |
|
1585 string_vector pats (npats); |
|
1586 for (int j = 0; j < npats; j++) |
|
1587 pats[j] = argv[i+j]; |
|
1588 |
1271
|
1589 // If the user specified -l and nothing else, show variables. If |
|
1590 // evaluating this at the top level, also show functions. |
529
|
1591 |
|
1592 if (show_verbose && ! (show_builtins || show_functions || show_variables)) |
|
1593 { |
4208
|
1594 show_functions = at_top_level (); |
529
|
1595 show_variables = 1; |
|
1596 } |
|
1597 |
4435
|
1598 if (return_list) |
529
|
1599 { |
5775
|
1600 // FIXME -- maybe symbol_list should return a std::list |
5659
|
1601 // object instead of an Array. |
|
1602 |
|
1603 dim_vector dv (0, 0); |
|
1604 |
|
1605 Array<symbol_record *> s3 (dv); |
|
1606 Array<symbol_record *> s4 (dv); |
|
1607 Array<symbol_record *> s5 (dv); |
|
1608 Array<symbol_record *> s6 (dv); |
|
1609 Array<symbol_record *> s7 (dv); |
5864
|
1610 Array<symbol_record *> s8 (dv); |
4435
|
1611 |
|
1612 if (show_builtins) |
|
1613 { |
5659
|
1614 s3 = fbi_sym_tab->symbol_list (pats, symbol_record::BUILTIN_FUNCTION, |
|
1615 SYMTAB_ALL_SCOPES); |
4435
|
1616 } |
|
1617 |
|
1618 if (show_functions) |
|
1619 { |
5659
|
1620 s4 = fbi_sym_tab->symbol_list (pats, symbol_record::DLD_FUNCTION, |
|
1621 SYMTAB_ALL_SCOPES); |
|
1622 |
|
1623 s5 = fbi_sym_tab->symbol_list (pats, symbol_record::USER_FUNCTION, |
|
1624 SYMTAB_ALL_SCOPES); |
5864
|
1625 |
|
1626 s6 = fbi_sym_tab->symbol_list (pats, symbol_record::MEX_FUNCTION, |
|
1627 SYMTAB_ALL_SCOPES); |
4435
|
1628 } |
|
1629 |
|
1630 if (show_variables) |
|
1631 { |
5864
|
1632 s7 = curr_sym_tab->symbol_list (pats, symbol_record::USER_VARIABLE, |
5659
|
1633 SYMTAB_LOCAL_SCOPE); |
|
1634 |
5864
|
1635 s8 = curr_sym_tab->symbol_list (pats, symbol_record::USER_VARIABLE, |
5659
|
1636 SYMTAB_GLOBAL_SCOPE); |
4435
|
1637 } |
|
1638 |
5659
|
1639 octave_idx_type s3_len = s3.length (); |
|
1640 octave_idx_type s4_len = s4.length (); |
|
1641 octave_idx_type s5_len = s5.length (); |
|
1642 octave_idx_type s6_len = s6.length (); |
|
1643 octave_idx_type s7_len = s7.length (); |
5864
|
1644 octave_idx_type s8_len = s8.length (); |
|
1645 |
|
1646 octave_idx_type symbols_len |
|
1647 = s3_len + s4_len + s5_len + s6_len + s7_len + s8_len; |
5659
|
1648 |
|
1649 Array<symbol_record *> symbols (dim_vector (symbols_len, 1)); |
|
1650 |
|
1651 octave_idx_type k = 0; |
|
1652 |
|
1653 symbols.insert (s3, k, 0); |
|
1654 k += s3_len; |
|
1655 symbols.insert (s4, k, 0); |
|
1656 k += s4_len; |
|
1657 symbols.insert (s5, k, 0); |
|
1658 k += s5_len; |
|
1659 symbols.insert (s6, k, 0); |
|
1660 k += s6_len; |
|
1661 symbols.insert (s7, k, 0); |
5864
|
1662 k += s7_len; |
|
1663 symbols.insert (s8, k, 0); |
5659
|
1664 |
|
1665 symbols.qsort (symbol_record_name_compare); |
|
1666 |
4435
|
1667 if (show_verbose) |
|
1668 { |
5659
|
1669 Array<octave_value> name_info (symbols_len, 1); |
|
1670 Array<octave_value> size_info (symbols_len, 1); |
|
1671 Array<octave_value> bytes_info (symbols_len, 1); |
|
1672 Array<octave_value> class_info (symbols_len, 1); |
|
1673 Array<octave_value> global_info (symbols_len, 1); |
|
1674 Array<octave_value> sparse_info (symbols_len, 1); |
|
1675 Array<octave_value> complex_info (symbols_len, 1); |
|
1676 Array<octave_value> nesting_info (symbols_len, 1); |
|
1677 |
|
1678 for (octave_idx_type j = 0; j < symbols_len; j++) |
|
1679 { |
|
1680 symbol_record *sr = symbols(j); |
|
1681 |
|
1682 Octave_map ni; |
|
1683 |
|
1684 std::string caller_function_name; |
5743
|
1685 |
|
1686 octave_function *caller = octave_call_stack::caller (); |
|
1687 if (caller) |
|
1688 caller_function_name = caller->name (); |
5659
|
1689 |
|
1690 ni.assign ("function", caller_function_name); |
|
1691 ni.assign ("level", 1); |
|
1692 |
|
1693 name_info(j) = sr->name (); |
|
1694 size_info(j) = sr->size (); |
|
1695 bytes_info(j) = sr->byte_size (); |
|
1696 class_info(j) = sr->class_name (); |
|
1697 global_info(j) = sr->is_linked_to_global (); |
|
1698 sparse_info(j) = sr->is_sparse_type (); |
|
1699 complex_info(j) = sr->is_complex_type (); |
|
1700 nesting_info(j) = ni; |
|
1701 } |
|
1702 |
|
1703 Octave_map info; |
|
1704 |
|
1705 info.assign ("name", name_info); |
|
1706 info.assign ("size", size_info); |
|
1707 info.assign ("bytes", bytes_info); |
|
1708 info.assign ("class", class_info); |
|
1709 info.assign ("global", global_info); |
|
1710 info.assign ("sparse", sparse_info); |
|
1711 info.assign ("complex", complex_info); |
|
1712 info.assign ("nesting", nesting_info); |
|
1713 |
|
1714 retval = info; |
4435
|
1715 } |
|
1716 else |
5659
|
1717 { |
|
1718 string_vector names; |
|
1719 |
|
1720 if (symbols_len > 0) |
|
1721 { |
|
1722 names.resize (symbols_len); |
|
1723 |
|
1724 for (octave_idx_type j = 0; j < symbols_len; j++) |
|
1725 names[j] = symbols(j)->name (); |
|
1726 } |
|
1727 |
|
1728 retval = Cell (names); |
|
1729 } |
529
|
1730 } |
4435
|
1731 else |
529
|
1732 { |
4435
|
1733 int pad_after = 0; |
|
1734 |
|
1735 if (show_builtins) |
|
1736 { |
|
1737 pad_after += fbi_sym_tab->maybe_list |
|
1738 ("*** built-in functions:", pats, octave_stdout, |
|
1739 show_verbose, symbol_record::BUILTIN_FUNCTION, SYMTAB_ALL_SCOPES); |
|
1740 } |
529
|
1741 |
4435
|
1742 if (show_functions) |
|
1743 { |
|
1744 pad_after += fbi_sym_tab->maybe_list |
|
1745 ("*** dynamically linked functions:", pats, |
|
1746 octave_stdout, show_verbose, symbol_record::DLD_FUNCTION, |
|
1747 SYMTAB_ALL_SCOPES); |
|
1748 |
|
1749 pad_after += fbi_sym_tab->maybe_list |
|
1750 ("*** currently compiled functions:", pats, |
|
1751 octave_stdout, show_verbose, symbol_record::USER_FUNCTION, |
|
1752 SYMTAB_ALL_SCOPES); |
5864
|
1753 |
|
1754 pad_after += fbi_sym_tab->maybe_list |
|
1755 ("*** mex functions:", pats, |
|
1756 octave_stdout, show_verbose, symbol_record::MEX_FUNCTION, |
|
1757 SYMTAB_ALL_SCOPES); |
4435
|
1758 } |
|
1759 |
|
1760 if (show_variables) |
|
1761 { |
|
1762 pad_after += curr_sym_tab->maybe_list |
|
1763 ("*** local user variables:", pats, octave_stdout, |
|
1764 show_verbose, symbol_record::USER_VARIABLE, SYMTAB_LOCAL_SCOPE); |
|
1765 |
|
1766 pad_after += curr_sym_tab->maybe_list |
|
1767 ("*** globally visible user variables:", pats, |
|
1768 octave_stdout, show_verbose, symbol_record::USER_VARIABLE, |
|
1769 SYMTAB_GLOBAL_SCOPE); |
|
1770 } |
|
1771 |
|
1772 if (pad_after) |
|
1773 octave_stdout << "\n"; |
529
|
1774 } |
|
1775 |
581
|
1776 return retval; |
|
1777 } |
|
1778 |
4435
|
1779 DEFCMD (who, args, nargout, |
3361
|
1780 "-*- texinfo -*-\n\ |
|
1781 @deffn {Command} who options pattern @dots{}\n\ |
|
1782 @deffnx {Command} whos options pattern @dots{}\n\ |
|
1783 List currently defined symbols matching the given patterns. The\n\ |
|
1784 following are valid options. They may be shortened to one character but\n\ |
|
1785 may not be combined.\n\ |
|
1786 \n\ |
|
1787 @table @code\n\ |
|
1788 @item -all\n\ |
|
1789 List all currently defined symbols.\n\ |
|
1790 \n\ |
|
1791 @item -builtins\n\ |
5794
|
1792 List built-in functions. This includes all currently\n\ |
3361
|
1793 compiled function files, but does not include all function files that\n\ |
5814
|
1794 are in the search path.\n\ |
581
|
1795 \n\ |
3361
|
1796 @item -functions\n\ |
|
1797 List user-defined functions.\n\ |
|
1798 \n\ |
|
1799 @item -long\n\ |
|
1800 Print a long listing including the type and dimensions of any symbols.\n\ |
|
1801 The symbols in the first column of output indicate whether it is\n\ |
|
1802 possible to redefine the symbol, and whether it is possible for it to be\n\ |
|
1803 cleared.\n\ |
|
1804 \n\ |
|
1805 @item -variables\n\ |
|
1806 List user-defined variables.\n\ |
|
1807 @end table\n\ |
|
1808 \n\ |
|
1809 Valid patterns are the same as described for the @code{clear} command\n\ |
|
1810 above. If no patterns are supplied, all symbols from the given category\n\ |
|
1811 are listed. By default, only user defined functions and variables\n\ |
|
1812 visible in the local scope are displayed.\n\ |
|
1813 \n\ |
|
1814 The command @kbd{whos} is equivalent to @kbd{who -long}.\n\ |
|
1815 @end deffn") |
581
|
1816 { |
4435
|
1817 octave_value retval; |
581
|
1818 |
4435
|
1819 if (nargout < 2) |
|
1820 { |
|
1821 int argc = args.length () + 1; |
|
1822 |
|
1823 string_vector argv = args.make_argv ("who"); |
1755
|
1824 |
4435
|
1825 if (error_state) |
|
1826 return retval; |
1755
|
1827 |
4435
|
1828 retval = do_who (argc, argv, nargout == 1); |
|
1829 } |
|
1830 else |
5823
|
1831 print_usage (); |
581
|
1832 |
529
|
1833 return retval; |
|
1834 } |
|
1835 |
4435
|
1836 DEFCMD (whos, args, nargout, |
3458
|
1837 "-*- texinfo -*-\n\ |
|
1838 @deffn {Command} whos options pattern @dots{}\n\ |
|
1839 See who.\n\ |
|
1840 @end deffn") |
581
|
1841 { |
4435
|
1842 octave_value retval; |
712
|
1843 |
4435
|
1844 if (nargout < 2) |
|
1845 { |
|
1846 int nargin = args.length (); |
|
1847 |
|
1848 octave_value_list tmp_args; |
|
1849 |
|
1850 for (int i = nargin; i > 0; i--) |
|
1851 tmp_args(i) = args(i-1); |
581
|
1852 |
4435
|
1853 tmp_args(0) = "-long"; |
1755
|
1854 |
4435
|
1855 int argc = tmp_args.length () + 1; |
|
1856 |
|
1857 string_vector argv = tmp_args.make_argv ("whos"); |
581
|
1858 |
4435
|
1859 if (error_state) |
|
1860 return retval; |
581
|
1861 |
4435
|
1862 retval = do_who (argc, argv, nargout == 1); |
|
1863 } |
|
1864 else |
5823
|
1865 print_usage (); |
581
|
1866 |
|
1867 return retval; |
|
1868 } |
|
1869 |
593
|
1870 // Defining variables. |
|
1871 |
1162
|
1872 void |
2856
|
1873 bind_ans (const octave_value& val, bool print) |
1162
|
1874 { |
5794
|
1875 symbol_record *sr = curr_sym_tab->lookup ("ans", true); |
1162
|
1876 |
2978
|
1877 if (val.is_defined ()) |
|
1878 { |
|
1879 sr->define (val); |
1162
|
1880 |
2978
|
1881 if (print) |
|
1882 val.print_with_name (octave_stdout, "ans"); |
|
1883 } |
1162
|
1884 } |
|
1885 |
593
|
1886 void |
5794
|
1887 bind_internal_variable (const std::string& fname, const octave_value& val) |
593
|
1888 { |
5794
|
1889 octave_value_list args; |
|
1890 |
|
1891 args(0) = val; |
|
1892 |
|
1893 feval (fname, args, 0); |
529
|
1894 } |
|
1895 |
4319
|
1896 void |
|
1897 mlock (const std::string& nm) |
|
1898 { |
|
1899 symbol_record *sr = fbi_sym_tab->lookup (nm, true); |
|
1900 |
|
1901 if (sr) |
|
1902 sr->mark_as_static (); |
|
1903 } |
|
1904 |
|
1905 void |
|
1906 munlock (const std::string& nm) |
|
1907 { |
|
1908 symbol_record *sr = fbi_sym_tab->lookup (nm); |
|
1909 |
|
1910 if (sr && sr->is_static ()) |
|
1911 sr->unmark_static (); |
|
1912 else |
|
1913 error ("munlock: %s is not locked", nm.c_str ()); |
|
1914 } |
|
1915 |
|
1916 bool |
|
1917 mislocked (const std::string& nm) |
|
1918 { |
|
1919 symbol_record *sr = fbi_sym_tab->lookup (nm); |
|
1920 |
|
1921 return (sr && sr->is_static ()); |
|
1922 } |
|
1923 |
|
1924 DEFCMD (mlock, args, , |
|
1925 "-*- texinfo -*-\n\ |
4526
|
1926 @deftypefn {Built-in Function} {} mlock (@var{name})\n\ |
4319
|
1927 Lock the named function into memory. If no function is named\n\ |
|
1928 then lock in the current function.\n\ |
5642
|
1929 @seealso{munlock, mislocked, persistent}\n\ |
|
1930 @end deftypefn") |
4319
|
1931 { |
|
1932 octave_value_list retval; |
|
1933 |
|
1934 if (args.length () == 1) |
|
1935 { |
|
1936 std::string name = args(0).string_value (); |
|
1937 |
|
1938 if (! error_state) |
|
1939 mlock (name); |
|
1940 else |
|
1941 error ("mlock: expecting argument to be a function name"); |
|
1942 } |
|
1943 else if (args.length () == 0) |
|
1944 { |
5744
|
1945 octave_user_function *fcn = octave_call_stack::caller_user_function (); |
5743
|
1946 |
|
1947 if (fcn) |
|
1948 mlock (fcn->name ()); |
4319
|
1949 else |
|
1950 error ("mlock: invalid use outside a function"); |
|
1951 } |
|
1952 else |
5823
|
1953 print_usage (); |
4319
|
1954 |
|
1955 return retval; |
|
1956 } |
|
1957 |
|
1958 DEFCMD (munlock, args, , |
|
1959 "-*- texinfo -*-\n\ |
|
1960 @deftypefn {Built-in Function} {} munlock (@var{fcn})\n\ |
|
1961 Unlock the named function. If no function is named\n\ |
|
1962 then unlock the current function.\n\ |
5642
|
1963 @seealso{mlock, mislocked, persistent}\n\ |
|
1964 @end deftypefn") |
4319
|
1965 { |
|
1966 octave_value_list retval; |
|
1967 |
|
1968 if (args.length() == 1) |
|
1969 { |
|
1970 std::string name = args(0).string_value (); |
|
1971 |
|
1972 if (! error_state) |
|
1973 munlock (name); |
|
1974 else |
|
1975 error ("munlock: expecting argument to be a function name"); |
|
1976 } |
|
1977 else if (args.length () == 0) |
|
1978 { |
5744
|
1979 octave_user_function *fcn = octave_call_stack::caller_user_function (); |
5743
|
1980 |
|
1981 if (fcn) |
|
1982 mlock (fcn->name ()); |
4319
|
1983 else |
|
1984 error ("munlock: invalid use outside a function"); |
|
1985 } |
|
1986 else |
5823
|
1987 print_usage (); |
4319
|
1988 |
|
1989 return retval; |
|
1990 } |
|
1991 |
|
1992 |
|
1993 DEFCMD (mislocked, args, , |
|
1994 "-*- texinfo -*-\n\ |
|
1995 @deftypefn {Built-in Function} {} mislocked (@var{fcn})\n\ |
|
1996 Return true if the named function is locked. If no function is named\n\ |
|
1997 then return true if the current function is locked.\n\ |
5642
|
1998 @seealso{mlock, munlock, persistent}\n\ |
|
1999 @end deftypefn") |
4319
|
2000 { |
|
2001 octave_value retval; |
|
2002 |
|
2003 if (args.length() == 1) |
|
2004 { |
|
2005 std::string name = args(0).string_value (); |
|
2006 |
|
2007 if (! error_state) |
|
2008 retval = mislocked (name); |
|
2009 else |
|
2010 error ("mislocked: expecting argument to be a function name"); |
|
2011 } |
|
2012 else if (args.length () == 0) |
|
2013 { |
5744
|
2014 octave_user_function *fcn = octave_call_stack::caller_user_function (); |
5743
|
2015 |
|
2016 if (fcn) |
|
2017 retval = mislocked (fcn->name ()); |
4319
|
2018 else |
|
2019 error ("mislocked: invalid use outside a function"); |
|
2020 } |
|
2021 else |
5823
|
2022 print_usage (); |
4319
|
2023 |
|
2024 return retval; |
|
2025 } |
|
2026 |
593
|
2027 // Deleting names from the symbol tables. |
|
2028 |
3681
|
2029 static inline bool |
4009
|
2030 name_matches_any_pattern (const std::string& nm, |
|
2031 const string_vector& argv, int argc, int idx) |
3681
|
2032 { |
|
2033 bool retval = false; |
|
2034 |
|
2035 for (int k = idx; k < argc; k++) |
|
2036 { |
|
2037 std::string patstr = argv[k]; |
|
2038 |
|
2039 if (! patstr.empty ()) |
|
2040 { |
|
2041 glob_match pattern (patstr); |
|
2042 |
|
2043 if (pattern.match (nm)) |
|
2044 { |
|
2045 retval = true; |
|
2046 break; |
|
2047 } |
|
2048 } |
|
2049 } |
|
2050 |
|
2051 return retval; |
|
2052 } |
|
2053 |
4009
|
2054 static inline bool |
|
2055 is_local_variable (const std::string& nm) |
|
2056 { |
|
2057 symbol_record *sr = curr_sym_tab->lookup (nm); |
|
2058 |
|
2059 return (sr && sr->is_variable ()); |
|
2060 } |
|
2061 |
|
2062 static inline void |
|
2063 maybe_warn_exclusive (bool exclusive) |
|
2064 { |
|
2065 if (exclusive) |
|
2066 warning ("clear: ignoring --exclusive option"); |
|
2067 } |
|
2068 |
|
2069 static inline void |
|
2070 do_clear_all (void) |
|
2071 { |
|
2072 curr_sym_tab->clear (); |
|
2073 fbi_sym_tab->clear_functions (); |
|
2074 global_sym_tab->clear (); |
|
2075 } |
|
2076 |
|
2077 static inline void |
|
2078 do_clear_functions (void) |
|
2079 { |
|
2080 curr_sym_tab->clear_functions (); |
|
2081 fbi_sym_tab->clear_functions (); |
|
2082 } |
|
2083 |
|
2084 static inline void |
|
2085 do_clear_globals (void) |
|
2086 { |
|
2087 curr_sym_tab->clear_globals (); |
|
2088 global_sym_tab->clear (); |
|
2089 } |
|
2090 |
|
2091 static inline void |
|
2092 do_clear_variables (void) |
|
2093 { |
|
2094 curr_sym_tab->clear (); |
|
2095 } |
|
2096 |
|
2097 static inline bool |
|
2098 do_clear_function (const std::string& nm) |
|
2099 { |
|
2100 bool b1 = curr_sym_tab->clear_function (nm); |
|
2101 |
|
2102 bool b2 = fbi_sym_tab->clear_function (nm); |
|
2103 |
|
2104 return b1 || b2; |
|
2105 } |
|
2106 |
|
2107 static inline bool |
|
2108 do_clear_global (const std::string& nm) |
|
2109 { |
|
2110 bool b1 = curr_sym_tab->clear_global (nm); |
|
2111 |
|
2112 bool b2 = global_sym_tab->clear_variable (nm); |
|
2113 |
|
2114 return b1 || b2; |
|
2115 } |
|
2116 |
|
2117 static inline bool |
|
2118 do_clear_variable (const std::string& nm) |
|
2119 { |
|
2120 return curr_sym_tab->clear_variable (nm); |
|
2121 } |
|
2122 |
|
2123 static inline bool |
|
2124 do_clear_symbol (const std::string& nm) |
|
2125 { |
|
2126 bool cleared = curr_sym_tab->clear_variable (nm); |
|
2127 |
|
2128 if (! cleared) |
|
2129 cleared = do_clear_function (nm); |
|
2130 |
|
2131 return cleared; |
|
2132 } |
|
2133 |
|
2134 static inline bool |
|
2135 do_clear_function_pattern (const std::string& pat) |
|
2136 { |
|
2137 bool b1 = curr_sym_tab->clear_function_pattern (pat); |
|
2138 |
|
2139 bool b2 = fbi_sym_tab->clear_function_pattern (pat); |
|
2140 |
|
2141 return b1 || b2; |
|
2142 } |
|
2143 |
|
2144 static inline bool |
|
2145 do_clear_global_pattern (const std::string& pat) |
|
2146 { |
|
2147 bool b1 = curr_sym_tab->clear_global_pattern (pat); |
|
2148 |
|
2149 bool b2 = global_sym_tab->clear_variable_pattern (pat); |
|
2150 |
|
2151 return b1 || b2; |
|
2152 } |
|
2153 |
|
2154 static inline bool |
|
2155 do_clear_variable_pattern (const std::string& pat) |
|
2156 { |
|
2157 return curr_sym_tab->clear_variable_pattern (pat); |
|
2158 } |
|
2159 |
|
2160 static inline bool |
|
2161 do_clear_symbol_pattern (const std::string& pat) |
|
2162 { |
5775
|
2163 // FIXME -- if we have a variable v1 and a function v2 and |
4009
|
2164 // someone says clear v*, we will clear the variable but not the |
|
2165 // function. Is that really what should happen? (I think it is |
|
2166 // what Matlab does.) |
|
2167 |
|
2168 bool cleared = curr_sym_tab->clear_variable_pattern (pat); |
|
2169 |
|
2170 if (! cleared) |
|
2171 cleared = do_clear_function_pattern (pat); |
|
2172 |
|
2173 return cleared; |
|
2174 } |
|
2175 |
|
2176 static inline void |
|
2177 do_clear_functions (const string_vector& argv, int argc, int idx, |
|
2178 bool exclusive = false) |
|
2179 { |
|
2180 if (idx == argc) |
|
2181 do_clear_functions (); |
|
2182 else |
|
2183 { |
|
2184 if (exclusive) |
|
2185 { |
|
2186 string_vector lfcns = curr_sym_tab->user_function_name_list (); |
|
2187 |
|
2188 int lcount = lfcns.length (); |
|
2189 |
|
2190 for (int i = 0; i < lcount; i++) |
|
2191 { |
|
2192 std::string nm = lfcns[i]; |
|
2193 |
|
2194 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2195 do_clear_function (nm); |
|
2196 } |
|
2197 |
|
2198 string_vector fcns = fbi_sym_tab->user_function_name_list (); |
|
2199 |
|
2200 int fcount = fcns.length (); |
|
2201 |
|
2202 for (int i = 0; i < fcount; i++) |
|
2203 { |
|
2204 std::string nm = fcns[i]; |
|
2205 |
|
2206 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2207 do_clear_function (nm); |
|
2208 } |
|
2209 } |
|
2210 else |
|
2211 { |
|
2212 while (idx < argc) |
|
2213 do_clear_function_pattern (argv[idx++]); |
|
2214 } |
|
2215 } |
|
2216 } |
|
2217 |
|
2218 static inline void |
|
2219 do_clear_globals (const string_vector& argv, int argc, int idx, |
|
2220 bool exclusive = false) |
|
2221 { |
|
2222 if (idx == argc) |
|
2223 do_clear_globals (); |
|
2224 else |
|
2225 { |
|
2226 if (exclusive) |
|
2227 { |
|
2228 string_vector lvars = curr_sym_tab->global_variable_name_list (); |
|
2229 |
|
2230 int lcount = lvars.length (); |
|
2231 |
|
2232 for (int i = 0; i < lcount; i++) |
|
2233 { |
|
2234 std::string nm = lvars[i]; |
|
2235 |
|
2236 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2237 do_clear_global (nm); |
|
2238 } |
|
2239 |
|
2240 string_vector gvars = global_sym_tab->global_variable_name_list (); |
|
2241 |
|
2242 int gcount = gvars.length (); |
|
2243 |
|
2244 for (int i = 0; i < gcount; i++) |
|
2245 { |
|
2246 std::string nm = gvars[i]; |
|
2247 |
|
2248 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2249 do_clear_global (nm); |
|
2250 } |
|
2251 } |
|
2252 else |
|
2253 { |
|
2254 while (idx < argc) |
|
2255 do_clear_global_pattern (argv[idx++]); |
|
2256 } |
|
2257 } |
|
2258 } |
|
2259 |
|
2260 static inline void |
|
2261 do_clear_variables (const string_vector& argv, int argc, int idx, |
|
2262 bool exclusive = false) |
|
2263 { |
|
2264 if (idx == argc) |
|
2265 do_clear_variables (); |
|
2266 else |
|
2267 { |
|
2268 if (exclusive) |
|
2269 { |
|
2270 string_vector lvars = curr_sym_tab->variable_name_list (); |
|
2271 |
|
2272 int lcount = lvars.length (); |
|
2273 |
|
2274 for (int i = 0; i < lcount; i++) |
|
2275 { |
|
2276 std::string nm = lvars[i]; |
|
2277 |
|
2278 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2279 do_clear_variable (nm); |
|
2280 } |
|
2281 } |
|
2282 else |
|
2283 { |
|
2284 while (idx < argc) |
|
2285 do_clear_variable_pattern (argv[idx++]); |
|
2286 } |
|
2287 } |
|
2288 } |
|
2289 |
|
2290 static inline void |
|
2291 do_clear_symbols (const string_vector& argv, int argc, int idx, |
|
2292 bool exclusive = false) |
|
2293 { |
|
2294 if (idx == argc) |
|
2295 do_clear_variables (); |
|
2296 else |
|
2297 { |
|
2298 if (exclusive) |
|
2299 { |
5775
|
2300 // FIXME -- is this really what we want, or do we |
4009
|
2301 // somehow want to only clear the functions that are not |
|
2302 // shadowed by local variables? It seems that would be a |
|
2303 // bit harder to do. |
|
2304 |
|
2305 do_clear_variables (argv, argc, idx, exclusive); |
|
2306 do_clear_functions (argv, argc, idx, exclusive); |
|
2307 } |
|
2308 else |
|
2309 { |
|
2310 while (idx < argc) |
|
2311 do_clear_symbol_pattern (argv[idx++]); |
|
2312 } |
|
2313 } |
|
2314 } |
|
2315 |
|
2316 static void |
|
2317 do_matlab_compatible_clear (const string_vector& argv, int argc, int idx) |
|
2318 { |
|
2319 // This is supposed to be mostly Matlab compatible. |
|
2320 |
|
2321 for (; idx < argc; idx++) |
|
2322 { |
|
2323 if (argv[idx] == "all" && ! is_local_variable ("all")) |
|
2324 { |
|
2325 do_clear_all (); |
|
2326 } |
|
2327 else if (argv[idx] == "functions" && ! is_local_variable ("functions")) |
|
2328 { |
|
2329 do_clear_functions (argv, argc, ++idx); |
|
2330 } |
|
2331 else if (argv[idx] == "global" && ! is_local_variable ("global")) |
|
2332 { |
|
2333 do_clear_globals (argv, argc, ++idx); |
|
2334 } |
|
2335 else if (argv[idx] == "variables" && ! is_local_variable ("variables")) |
|
2336 { |
|
2337 do_clear_variables (); |
|
2338 } |
|
2339 else |
|
2340 { |
|
2341 do_clear_symbol_pattern (argv[idx]); |
|
2342 } |
|
2343 } |
|
2344 } |
|
2345 |
|
2346 #define CLEAR_OPTION_ERROR(cond) \ |
|
2347 do \ |
|
2348 { \ |
|
2349 if (cond) \ |
|
2350 { \ |
5823
|
2351 print_usage (); \ |
4009
|
2352 return retval; \ |
|
2353 } \ |
|
2354 } \ |
|
2355 while (0) |
|
2356 |
4954
|
2357 bool |
|
2358 clear_function (const std::string& nm) |
|
2359 { |
|
2360 return do_clear_function (nm); |
|
2361 } |
|
2362 |
4988
|
2363 bool |
|
2364 clear_variable (const std::string& nm) |
|
2365 { |
|
2366 return do_clear_variable (nm); |
|
2367 } |
|
2368 |
|
2369 bool |
|
2370 clear_symbol (const std::string& nm) |
|
2371 { |
|
2372 return do_clear_symbol (nm); |
|
2373 } |
|
2374 |
4208
|
2375 DEFCMD (clear, args, , |
3361
|
2376 "-*- texinfo -*-\n\ |
|
2377 @deffn {Command} clear [-x] pattern @dots{}\n\ |
|
2378 Delete the names matching the given patterns from the symbol table. The\n\ |
|
2379 pattern may contain the following special characters:\n\ |
4016
|
2380 \n\ |
3361
|
2381 @table @code\n\ |
|
2382 @item ?\n\ |
|
2383 Match any single character.\n\ |
668
|
2384 \n\ |
3361
|
2385 @item *\n\ |
|
2386 Match zero or more characters.\n\ |
|
2387 \n\ |
|
2388 @item [ @var{list} ]\n\ |
|
2389 Match the list of characters specified by @var{list}. If the first\n\ |
|
2390 character is @code{!} or @code{^}, match all characters except those\n\ |
|
2391 specified by @var{list}. For example, the pattern @samp{[a-zA-Z]} will\n\ |
|
2392 match all lower and upper case alphabetic characters.\n\ |
|
2393 @end table\n\ |
|
2394 \n\ |
|
2395 For example, the command\n\ |
593
|
2396 \n\ |
3361
|
2397 @example\n\ |
|
2398 clear foo b*r\n\ |
|
2399 @end example\n\ |
|
2400 \n\ |
|
2401 @noindent\n\ |
|
2402 clears the name @code{foo} and all names that begin with the letter\n\ |
|
2403 @code{b} and end with the letter @code{r}.\n\ |
668
|
2404 \n\ |
3361
|
2405 If @code{clear} is called without any arguments, all user-defined\n\ |
|
2406 variables (local and global) are cleared from the symbol table. If\n\ |
|
2407 @code{clear} is called with at least one argument, only the visible\n\ |
|
2408 names matching the arguments are cleared. For example, suppose you have\n\ |
|
2409 defined a function @code{foo}, and then hidden it by performing the\n\ |
|
2410 assignment @code{foo = 2}. Executing the command @kbd{clear foo} once\n\ |
|
2411 will clear the variable definition and restore the definition of\n\ |
|
2412 @code{foo} as a function. Executing @kbd{clear foo} a second time will\n\ |
|
2413 clear the function definition.\n\ |
|
2414 \n\ |
|
2415 With -x, clear the variables that don't match the patterns.\n\ |
|
2416 \n\ |
|
2417 This command may not be used within a function body.\n\ |
|
2418 @end deffn") |
529
|
2419 { |
2086
|
2420 octave_value_list retval; |
593
|
2421 |
1755
|
2422 int argc = args.length () + 1; |
593
|
2423 |
1968
|
2424 string_vector argv = args.make_argv ("clear"); |
1755
|
2425 |
4009
|
2426 if (! error_state) |
529
|
2427 { |
4009
|
2428 if (argc == 1) |
593
|
2429 { |
4009
|
2430 do_clear_variables (); |
3681
|
2431 } |
|
2432 else |
|
2433 { |
4009
|
2434 int idx = 0; |
|
2435 |
|
2436 bool clear_all = false; |
|
2437 bool clear_functions = false; |
|
2438 bool clear_globals = false; |
|
2439 bool clear_variables = false; |
|
2440 bool exclusive = false; |
|
2441 bool have_dash_option = false; |
3681
|
2442 |
4009
|
2443 while (++idx < argc) |
|
2444 { |
4010
|
2445 if (argv[idx] == "-all" || argv[idx] == "-a") |
593
|
2446 { |
4009
|
2447 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681
|
2448 |
4009
|
2449 have_dash_option = true; |
|
2450 clear_all = true; |
|
2451 } |
4010
|
2452 else if (argv[idx] == "-exclusive" || argv[idx] == "-x") |
4009
|
2453 { |
|
2454 have_dash_option = true; |
|
2455 exclusive = true; |
|
2456 } |
4010
|
2457 else if (argv[idx] == "-functions" || argv[idx] == "-f") |
4009
|
2458 { |
|
2459 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681
|
2460 |
4009
|
2461 have_dash_option = true; |
|
2462 clear_functions = true; |
|
2463 } |
4010
|
2464 else if (argv[idx] == "-global" || argv[idx] == "-g") |
4009
|
2465 { |
|
2466 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
|
2467 |
|
2468 have_dash_option = true; |
|
2469 clear_globals = true; |
|
2470 } |
4010
|
2471 else if (argv[idx] == "-variables" || argv[idx] == "-v") |
4009
|
2472 { |
|
2473 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681
|
2474 |
4009
|
2475 have_dash_option = true; |
|
2476 clear_variables = true; |
|
2477 } |
|
2478 else |
|
2479 break; |
|
2480 } |
3681
|
2481 |
4224
|
2482 if (idx <= argc) |
4009
|
2483 { |
|
2484 if (! have_dash_option) |
|
2485 { |
|
2486 do_matlab_compatible_clear (argv, argc, idx); |
|
2487 } |
|
2488 else |
|
2489 { |
|
2490 if (clear_all) |
3681
|
2491 { |
4009
|
2492 maybe_warn_exclusive (exclusive); |
3681
|
2493 |
4009
|
2494 if (++idx < argc) |
|
2495 warning |
4010
|
2496 ("clear: ignoring extra arguments after -all"); |
3681
|
2497 |
4009
|
2498 curr_sym_tab->clear (); |
|
2499 fbi_sym_tab->clear_functions (); |
|
2500 global_sym_tab->clear (); |
|
2501 } |
|
2502 else if (clear_functions) |
|
2503 { |
|
2504 do_clear_functions (argv, argc, idx, exclusive); |
|
2505 } |
|
2506 else if (clear_globals) |
593
|
2507 { |
4009
|
2508 do_clear_globals (argv, argc, idx, exclusive); |
|
2509 } |
|
2510 else if (clear_variables) |
|
2511 { |
|
2512 do_clear_variables (argv, argc, idx, exclusive); |
|
2513 } |
|
2514 else |
|
2515 { |
|
2516 do_clear_symbols (argv, argc, idx, exclusive); |
593
|
2517 } |
|
2518 } |
|
2519 } |
|
2520 } |
|
2521 } |
|
2522 |
|
2523 return retval; |
529
|
2524 } |
|
2525 |
3933
|
2526 DEFUN (__print_symtab_info__, args, , |
3446
|
2527 "-*- texinfo -*-\n\ |
3933
|
2528 @deftypefn {Built-in Function} {} __print_symtab_info__ ()\n\ |
3446
|
2529 Print raw symbol table statistices.\n\ |
|
2530 @end deftypefn") |
3005
|
2531 { |
|
2532 octave_value_list retval; |
|
2533 |
|
2534 int nargin = args.length (); |
|
2535 |
|
2536 if (nargin == 1) |
|
2537 { |
3523
|
2538 std::string arg = args(0).string_value (); |
3005
|
2539 |
4009
|
2540 if (arg == "fbi") |
|
2541 fbi_sym_tab->print_info (octave_stdout); |
|
2542 else if (arg == "global") |
3933
|
2543 global_sym_tab->print_info (octave_stdout); |
|
2544 else if (arg == "top-level") |
|
2545 top_level_sym_tab->print_info (octave_stdout); |
3005
|
2546 else |
3933
|
2547 { |
4009
|
2548 symbol_record *fsr = fbi_sym_tab->lookup (arg, true); |
3933
|
2549 |
4009
|
2550 if (fsr && fsr->is_user_function ()) |
3933
|
2551 { |
4009
|
2552 octave_value tmp = fsr->def (); |
5759
|
2553 const octave_base_value& rep = tmp.get_rep (); |
3933
|
2554 |
|
2555 const octave_user_function& fcn |
5759
|
2556 = dynamic_cast<const octave_user_function&> (rep); |
3933
|
2557 |
|
2558 fcn.print_symtab_info (octave_stdout); |
|
2559 } |
|
2560 else |
|
2561 error ("no user-defined function named %s", arg.c_str ()); |
|
2562 } |
3005
|
2563 } |
|
2564 else if (nargin == 0) |
3933
|
2565 curr_sym_tab->print_info (octave_stdout); |
3005
|
2566 else |
5823
|
2567 print_usage (); |
3005
|
2568 |
|
2569 return retval; |
|
2570 } |
|
2571 |
3933
|
2572 DEFUN (__print_symbol_info__, args, , |
3446
|
2573 "-*- texinfo -*-\n\ |
|
2574 @deftypefn {Built-in Function} {} __dump_symbol_info__ (@var{name})\n\ |
3548
|
2575 Print symbol table information for the symbol @var{name}.\n\ |
3446
|
2576 @end deftypefn") |
3239
|
2577 { |
|
2578 octave_value_list retval; |
|
2579 |
|
2580 int nargin = args.length (); |
|
2581 |
|
2582 if (nargin == 1) |
|
2583 { |
3523
|
2584 std::string symbol_name = args(0).string_value (); |
3239
|
2585 |
|
2586 if (! error_state) |
|
2587 { |
|
2588 symbol_record *sr = curr_sym_tab->lookup (symbol_name); |
|
2589 |
|
2590 if (sr) |
3933
|
2591 sr->print_info (octave_stdout); |
3239
|
2592 else |
3933
|
2593 error ("__print_symbol_info__: symbol %s not found", |
3239
|
2594 symbol_name.c_str ()); |
|
2595 } |
|
2596 else |
5823
|
2597 print_usage (); |
3239
|
2598 } |
|
2599 else |
5823
|
2600 print_usage (); |
3239
|
2601 |
|
2602 return retval; |
|
2603 } |
|
2604 |
5794
|
2605 DEFUN (ignore_function_time_stamp, args, nargout, |
3372
|
2606 "-*- texinfo -*-\n\ |
5794
|
2607 @deftypefn {Built-in Function} {@var{val} =} ignore_function_time_stamp ()\n\ |
|
2608 @deftypefnx {Built-in Function} {@var{old_val} =} ignore_function_time_stamp (@var{new_val})\n\ |
|
2609 Query or set the internal variable that controls whether Octave checks\n\ |
|
2610 the time stamp on files each time it looks up functions defined in\n\ |
|
2611 function files. If the internal variable is set to @code{\"system\"},\n\ |
|
2612 Octave will not automatically recompile function files in subdirectories of\n\ |
3371
|
2613 @file{@var{octave-home}/lib/@var{version}} if they have changed since\n\ |
|
2614 they were last compiled, but will recompile other function files in the\n\ |
5814
|
2615 search path if they change. If set to @code{\"all\"}, Octave will not\n\ |
3371
|
2616 recompile any function files unless their definitions are removed with\n\ |
5794
|
2617 @code{clear}. If set to \"none\", Octave will always check time stamps\n\ |
|
2618 on files to determine whether functions defined in function files\n\ |
|
2619 need to recompiled.\n\ |
|
2620 @end deftypefn") |
|
2621 { |
|
2622 octave_value retval; |
|
2623 |
|
2624 if (nargout > 0) |
|
2625 { |
|
2626 switch (Vignore_function_time_stamp) |
|
2627 { |
|
2628 case 1: |
|
2629 retval = "system"; |
|
2630 break; |
|
2631 |
|
2632 case 2: |
|
2633 retval = "all"; |
|
2634 break; |
|
2635 |
|
2636 default: |
|
2637 retval = "none"; |
|
2638 break; |
|
2639 } |
|
2640 } |
|
2641 |
|
2642 int nargin = args.length (); |
|
2643 |
|
2644 if (nargin == 1) |
|
2645 { |
|
2646 std::string sval = args(0).string_value (); |
|
2647 |
|
2648 if (! error_state) |
|
2649 { |
|
2650 if (sval == "all") |
|
2651 Vignore_function_time_stamp = 2; |
|
2652 else if (sval == "system") |
|
2653 Vignore_function_time_stamp = 1; |
|
2654 else if (sval == "none") |
|
2655 Vignore_function_time_stamp = 0; |
|
2656 else |
|
2657 error ("ignore_function_time_stamp: expecting argument to be \"all\", \"system\", or \"none\""); |
|
2658 } |
|
2659 else |
|
2660 error ("ignore_function_time_stamp: expecting argument to be character string"); |
|
2661 } |
|
2662 else if (nargin > 1) |
5823
|
2663 print_usage (); |
5794
|
2664 |
|
2665 return retval; |
3016
|
2666 } |
|
2667 |
1
|
2668 /* |
|
2669 ;;; Local Variables: *** |
|
2670 ;;; mode: C++ *** |
|
2671 ;;; End: *** |
|
2672 */ |