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