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 { |
5832
|
824 if (len > 4 && file_name.substr (len-4) == ".oct") |
5140
|
825 retval = 3; |
|
826 else |
|
827 retval = 2; |
|
828 } |
4437
|
829 } |
593
|
830 } |
5140
|
831 |
|
832 if (! retval) |
593
|
833 { |
5140
|
834 std::string file_name = file_in_path (name, ""); |
|
835 |
|
836 if (file_name.empty ()) |
|
837 file_name = name; |
|
838 |
|
839 file_stat fs (file_name); |
|
840 |
|
841 if (fs) |
1421
|
842 { |
5140
|
843 if ((type == "any" || type == "file") |
|
844 && fs.is_reg ()) |
|
845 { |
|
846 retval = 2; |
|
847 } |
|
848 else if ((type == "any" || type == "dir") |
|
849 && fs.is_dir ()) |
|
850 { |
|
851 retval = 7; |
|
852 } |
1421
|
853 } |
593
|
854 } |
|
855 } |
|
856 |
|
857 return retval; |
|
858 } |
|
859 |
4962
|
860 #define GET_IDX(LEN) \ |
|
861 static_cast<int> ((LEN-1) * static_cast<double> (rand ()) / RAND_MAX) |
|
862 |
4954
|
863 std::string |
|
864 unique_symbol_name (const std::string& basename) |
|
865 { |
4962
|
866 static const std::string alpha |
|
867 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|
868 |
|
869 static size_t len = alpha.length (); |
|
870 |
|
871 std::string nm = basename + alpha[GET_IDX (len)]; |
|
872 |
|
873 size_t pos = nm.length (); |
|
874 |
|
875 if (nm.substr (0, 2) == "__") |
|
876 nm.append ("__"); |
|
877 |
|
878 while (symbol_exist (nm, "any")) |
|
879 nm.insert (pos++, 1, alpha[GET_IDX (len)]); |
|
880 |
|
881 return nm; |
4954
|
882 } |
|
883 |
4016
|
884 DEFUN (exist, args, , |
|
885 "-*- texinfo -*-\n\ |
|
886 @deftypefn {Built-in Function} {} exist (@var{name}, @var{type})\n\ |
|
887 Return 1 if the name exists as a variable, 2 if the name (after\n\ |
5814
|
888 appending @samp{.m}) is a function file in Octave's @code{path}, 3 if the\n\ |
|
889 name is a @samp{.oct} file in Octave's @code{path}, 5 if the name is a\n\ |
5794
|
890 built-in function, 7 if the name is a directory, or 103\n\ |
4016
|
891 if the name is a function not associated with a file (entered on\n\ |
|
892 the command line).\n\ |
|
893 \n\ |
|
894 Otherwise, return 0.\n\ |
|
895 \n\ |
|
896 This function also returns 2 if a regular file called @var{name}\n\ |
5814
|
897 exists in Octave's search path. If you want information about\n\ |
4016
|
898 other types of files, you should use some combination of the functions\n\ |
|
899 @code{file_in_path} and @code{stat} instead.\n\ |
|
900 \n\ |
|
901 If the optional argument @var{type} is supplied, check only for\n\ |
|
902 symbols of the specified type. Valid types are\n\ |
|
903 \n\ |
|
904 @table @samp\n\ |
|
905 @item \"var\"\n\ |
|
906 Check only for variables.\n\ |
|
907 @item \"builtin\"\n\ |
|
908 Check only for built-in functions.\n\ |
|
909 @item \"file\"\n\ |
|
910 Check only for files.\n\ |
|
911 @item \"dir\"\n\ |
|
912 Check only for directories.\n\ |
|
913 @end table\n\ |
|
914 @end deftypefn") |
|
915 { |
4233
|
916 octave_value retval = false; |
4016
|
917 |
|
918 int nargin = args.length (); |
|
919 |
|
920 if (nargin == 1 || nargin == 2) |
|
921 { |
|
922 std::string name = args(0).string_value (); |
|
923 |
|
924 if (! error_state) |
|
925 { |
|
926 std::string type |
|
927 = (nargin == 2) ? args(1).string_value () : std::string ("any"); |
|
928 |
|
929 if (! error_state) |
4233
|
930 retval = symbol_exist (name, type); |
4016
|
931 else |
|
932 error ("exist: expecting second argument to be a string"); |
|
933 } |
|
934 else |
|
935 error ("exist: expecting first argument to be a string"); |
|
936 } |
|
937 else |
5823
|
938 print_usage (); |
4016
|
939 |
|
940 return retval; |
|
941 } |
|
942 |
5138
|
943 // Return TRUE if F and G are both names for the same file. |
|
944 |
|
945 static bool |
|
946 same_file (const std::string& f, const std::string& g) |
|
947 { |
|
948 std::string c_f = file_ops::canonicalize_file_name (f); |
|
949 std::string c_g = file_ops::canonicalize_file_name (g); |
|
950 |
|
951 file_stat f_fs (c_f); |
|
952 file_stat g_fs (c_g); |
|
953 |
|
954 return (f_fs.ino () == g_fs.ino () && f_fs.dev () == g_fs.dev ()); |
|
955 } |
|
956 |
5663
|
957 bool |
5397
|
958 fcn_out_of_date (octave_function *fcn, const std::string& ff, time_t tp) |
5312
|
959 { |
|
960 bool retval = false; |
|
961 |
5397
|
962 fcn->mark_fcn_file_up_to_date (octave_time ()); |
|
963 |
|
964 if (! (Vignore_function_time_stamp == 2 |
|
965 || (Vignore_function_time_stamp && fcn->is_system_fcn_file ()))) |
5312
|
966 { |
5397
|
967 file_stat fs (ff); |
|
968 |
|
969 if (fs && fs.is_newer (tp)) |
|
970 retval = true; |
5312
|
971 } |
|
972 |
|
973 return retval; |
|
974 } |
|
975 |
5397
|
976 // Is there a corresponding function file that is newer than the |
|
977 // symbol definition? |
|
978 |
5312
|
979 static bool |
1
|
980 symbol_out_of_date (symbol_record *sr) |
|
981 { |
2926
|
982 bool retval = false; |
195
|
983 |
5397
|
984 if (sr) |
1
|
985 { |
2975
|
986 octave_value ans = sr->def (); |
|
987 |
5397
|
988 octave_function *fcn = ans.function_value (true); |
|
989 |
5436
|
990 // No need to check nested functions. They can only be executed |
5437
|
991 // from within the parent function that contains them. Parent |
5436
|
992 // and nested functions will be updated simultaneously when we |
|
993 // check the parent. |
|
994 |
|
995 if (fcn && ! fcn->is_nested_function ()) |
5397
|
996 { |
|
997 std::string ff = fcn->fcn_file_name (); |
|
998 |
|
999 if (! ff.empty ()) |
|
1000 { |
|
1001 if (fcn->time_checked () < Vlast_prompt_time) |
|
1002 { |
|
1003 time_t tp = fcn->time_parsed (); |
|
1004 |
|
1005 std::string nm = fcn->name (); |
|
1006 |
5775
|
1007 // FIXME -- the following code is repeated |
5534
|
1008 // in load_fcn_from_file in parse.y. |
|
1009 |
5397
|
1010 string_vector names (2); |
|
1011 |
5534
|
1012 int nm_len = nm.length (); |
|
1013 |
|
1014 std::string file; |
|
1015 |
|
1016 if (octave_env::absolute_pathname (nm) |
|
1017 && ((nm_len > 4 && nm.substr (nm_len-4) == ".oct") |
|
1018 || (nm_len > 2 && nm.substr (nm_len-4) == ".m"))) |
|
1019 { |
|
1020 file = nm; |
|
1021 } |
|
1022 else |
|
1023 { |
|
1024 file = lookup_autoload (nm); |
|
1025 |
|
1026 if (file.empty ()) |
|
1027 { |
|
1028 file = octave_env::make_absolute |
5832
|
1029 (load_path::find_fcn (nm), octave_env::getcwd ()); |
5534
|
1030 } |
|
1031 } |
5397
|
1032 |
|
1033 if (same_file (file, ff)) |
|
1034 { |
|
1035 retval = fcn_out_of_date (fcn, ff, tp); |
|
1036 } |
|
1037 else |
|
1038 { |
|
1039 // Check the full function name. Maybe we alrady |
|
1040 // parsed it. |
|
1041 |
|
1042 symbol_record *full_sr = fbi_sym_tab->lookup (file); |
|
1043 |
|
1044 if (full_sr) |
|
1045 { |
|
1046 octave_value v = full_sr->def (); |
|
1047 |
|
1048 if (v.is_function ()) |
|
1049 { |
|
1050 // OK, swap the aliases around. |
|
1051 |
5775
|
1052 // FIXME -- this is a bit |
5397
|
1053 // tricky, so maybe some refactoring is |
|
1054 // in order here too... |
|
1055 |
|
1056 symbol_record *short_sr = fbi_sym_tab->lookup (nm); |
|
1057 |
|
1058 if (short_sr) |
|
1059 short_sr->alias (full_sr); |
|
1060 |
|
1061 // Make local symbol table entry point |
|
1062 // to correct global function too. |
|
1063 |
|
1064 sr->alias (full_sr); |
|
1065 |
|
1066 fcn = v.function_value (); |
|
1067 |
|
1068 retval = fcn_out_of_date (fcn, file, tp); |
|
1069 } |
|
1070 else |
|
1071 retval = true; |
|
1072 } |
|
1073 else |
|
1074 retval = true; |
|
1075 } |
|
1076 } |
|
1077 } |
|
1078 } |
1
|
1079 } |
2926
|
1080 |
|
1081 return retval; |
1
|
1082 } |
|
1083 |
1827
|
1084 bool |
2856
|
1085 lookup (symbol_record *sym_rec, bool exec_script) |
581
|
1086 { |
1827
|
1087 bool script_executed = false; |
581
|
1088 |
|
1089 if (! sym_rec->is_linked_to_global ()) |
|
1090 { |
|
1091 if (sym_rec->is_defined ()) |
|
1092 { |
|
1093 if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) |
1271
|
1094 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
1095 } |
|
1096 else if (! sym_rec->is_formal_parameter ()) |
|
1097 { |
|
1098 link_to_builtin_or_function (sym_rec); |
1271
|
1099 |
581
|
1100 if (! sym_rec->is_defined ()) |
1271
|
1101 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
1102 else if (sym_rec->is_function () && symbol_out_of_date (sym_rec)) |
1271
|
1103 script_executed = load_fcn_from_file (sym_rec, exec_script); |
581
|
1104 } |
|
1105 } |
|
1106 |
1271
|
1107 return script_executed; |
581
|
1108 } |
|
1109 |
|
1110 // Get the symbol record for the given name that is visible in the |
|
1111 // current scope. Reread any function definitions that appear to be |
|
1112 // out of date. If a function is available in a file but is not |
|
1113 // currently loaded, this will load it and insert the name in the |
|
1114 // current symbol table. |
|
1115 |
|
1116 symbol_record * |
3523
|
1117 lookup_by_name (const std::string& nm, bool exec_script) |
581
|
1118 { |
2856
|
1119 symbol_record *sym_rec = curr_sym_tab->lookup (nm, true); |
581
|
1120 |
|
1121 lookup (sym_rec, exec_script); |
|
1122 |
|
1123 return sym_rec; |
|
1124 } |
|
1125 |
4930
|
1126 octave_value |
4342
|
1127 lookup_function (const std::string& nm) |
|
1128 { |
4930
|
1129 octave_value retval; |
4342
|
1130 |
|
1131 symbol_record *sr = 0; |
|
1132 |
|
1133 if (curr_parent_function) |
|
1134 { |
4748
|
1135 std::string parent = curr_parent_function->name (); |
4342
|
1136 |
|
1137 sr = fbi_sym_tab->lookup (parent + ":" + nm); |
|
1138 } |
|
1139 |
|
1140 if (! sr || ! sr->is_function ()) |
|
1141 { |
|
1142 sr = fbi_sym_tab->lookup (nm, true); |
|
1143 |
|
1144 if (sr && ! sr->is_function ()) |
|
1145 load_fcn_from_file (sr, false); |
|
1146 } |
|
1147 |
|
1148 if (sr) |
|
1149 { |
|
1150 octave_value v = sr->def (); |
|
1151 |
|
1152 if (v.is_function ()) |
4930
|
1153 retval = v; |
4342
|
1154 } |
|
1155 |
|
1156 return retval; |
|
1157 } |
|
1158 |
4930
|
1159 octave_value |
4700
|
1160 lookup_user_function (const std::string& nm) |
|
1161 { |
4930
|
1162 octave_value retval; |
4700
|
1163 |
|
1164 symbol_record *sr = 0; |
|
1165 |
|
1166 if (curr_parent_function) |
|
1167 { |
4748
|
1168 std::string parent = curr_parent_function->name (); |
4700
|
1169 |
|
1170 sr = fbi_sym_tab->lookup (parent + ":" + nm); |
|
1171 } |
|
1172 |
|
1173 if (! sr || ! sr->is_user_function ()) |
|
1174 { |
|
1175 sr = fbi_sym_tab->lookup (nm, true); |
|
1176 |
|
1177 if (sr && ! sr->is_user_function ()) |
|
1178 load_fcn_from_file (sr, false); |
|
1179 } |
|
1180 |
|
1181 if (sr) |
4930
|
1182 retval = sr->def (); |
4700
|
1183 |
|
1184 return retval; |
|
1185 } |
|
1186 |
2849
|
1187 octave_value |
4988
|
1188 lookup_function_handle (const std::string& nm) |
|
1189 { |
|
1190 octave_value retval; |
|
1191 |
|
1192 symbol_record *sr = curr_sym_tab->lookup (nm, true); |
|
1193 |
|
1194 if (sr && sr->def ().is_function_handle ()) |
|
1195 retval = sr->def (); |
|
1196 |
|
1197 return retval; |
|
1198 } |
|
1199 |
|
1200 octave_value |
5027
|
1201 get_global_value (const std::string& nm, bool silent) |
2849
|
1202 { |
|
1203 octave_value retval; |
|
1204 |
|
1205 symbol_record *sr = global_sym_tab->lookup (nm); |
|
1206 |
|
1207 if (sr) |
|
1208 { |
2975
|
1209 octave_value sr_def = sr->def (); |
2849
|
1210 |
5027
|
1211 if (sr_def.is_defined ()) |
|
1212 retval = sr_def; |
|
1213 else if (! silent) |
2849
|
1214 error ("get_global_by_name: undefined symbol `%s'", nm.c_str ()); |
|
1215 } |
5027
|
1216 else if (! silent) |
2849
|
1217 error ("get_global_by_name: unknown symbol `%s'", nm.c_str ()); |
|
1218 |
|
1219 return retval; |
|
1220 } |
|
1221 |
|
1222 void |
3523
|
1223 set_global_value (const std::string& nm, const octave_value& val) |
2849
|
1224 { |
2856
|
1225 symbol_record *sr = global_sym_tab->lookup (nm, true); |
2849
|
1226 |
|
1227 if (sr) |
|
1228 sr->define (val); |
|
1229 else |
|
1230 panic_impossible (); |
|
1231 } |
|
1232 |
593
|
1233 // Variable values. |
195
|
1234 |
5791
|
1235 octave_value |
|
1236 set_internal_variable (bool& var, const octave_value_list& args, |
5794
|
1237 int nargout, const char *nm) |
5791
|
1238 { |
5794
|
1239 octave_value retval; |
|
1240 |
5800
|
1241 int nargin = args.length (); |
|
1242 |
|
1243 if (nargout > 0 || nargin == 0) |
5794
|
1244 retval = var; |
5791
|
1245 |
|
1246 if (nargin == 1) |
|
1247 { |
|
1248 bool bval = args(0).bool_value (); |
|
1249 |
|
1250 if (! error_state) |
|
1251 var = bval; |
|
1252 else |
|
1253 error ("%s: expecting arg to be a logical value", nm); |
|
1254 } |
|
1255 else if (nargin > 1) |
5823
|
1256 print_usage (); |
5791
|
1257 |
|
1258 return retval; |
|
1259 } |
|
1260 |
|
1261 octave_value |
5794
|
1262 set_internal_variable (char& var, const octave_value_list& args, |
|
1263 int nargout, const char *nm) |
5791
|
1264 { |
5794
|
1265 octave_value retval; |
|
1266 |
5800
|
1267 int nargin = args.length (); |
|
1268 |
|
1269 if (nargout > 0 || nargin == 0) |
5794
|
1270 retval = var; |
5791
|
1271 |
|
1272 if (nargin == 1) |
|
1273 { |
|
1274 std::string sval = args(0).string_value (); |
|
1275 |
|
1276 if (! error_state) |
5794
|
1277 { |
|
1278 switch (sval.length ()) |
|
1279 { |
|
1280 case 1: |
|
1281 var = sval[0]; |
|
1282 break; |
|
1283 |
|
1284 case 0: |
|
1285 var = '\0'; |
|
1286 break; |
|
1287 |
|
1288 default: |
|
1289 error ("%s: argument must be a single character", nm); |
|
1290 break; |
|
1291 } |
|
1292 } |
|
1293 else |
|
1294 error ("%s: argument must be a single character", nm); |
|
1295 } |
|
1296 else if (nargin > 1) |
5823
|
1297 print_usage (); |
5794
|
1298 |
|
1299 return retval; |
|
1300 } |
|
1301 |
|
1302 octave_value |
|
1303 set_internal_variable (int& var, const octave_value_list& args, |
|
1304 int nargout, const char *nm, |
|
1305 int minval, int maxval) |
|
1306 { |
|
1307 octave_value retval; |
|
1308 |
5800
|
1309 int nargin = args.length (); |
|
1310 |
|
1311 if (nargout > 0 || nargin == 0) |
5794
|
1312 retval = var; |
|
1313 |
|
1314 if (nargin == 1) |
|
1315 { |
|
1316 int ival = args(0).int_value (); |
|
1317 |
|
1318 if (! error_state) |
|
1319 { |
|
1320 if (ival < minval) |
|
1321 error ("%s: expecting arg to be greater than %d", minval); |
|
1322 else if (ival > maxval) |
|
1323 error ("%s: expecting arg to be less than or equal to %d", maxval); |
|
1324 else |
|
1325 var = ival; |
|
1326 } |
|
1327 else |
|
1328 error ("%s: expecting arg to be an integer value", nm); |
|
1329 } |
|
1330 else if (nargin > 1) |
5823
|
1331 print_usage (); |
5794
|
1332 |
|
1333 return retval; |
|
1334 } |
|
1335 |
|
1336 octave_value |
|
1337 set_internal_variable (double& var, const octave_value_list& args, |
|
1338 int nargout, const char *nm, |
|
1339 double minval, double maxval) |
|
1340 { |
|
1341 octave_value retval; |
|
1342 |
5800
|
1343 int nargin = args.length (); |
|
1344 |
|
1345 if (nargout > 0 || nargin == 0) |
5794
|
1346 retval = var; |
|
1347 |
|
1348 if (nargin == 1) |
|
1349 { |
|
1350 double dval = args(0).scalar_value (); |
|
1351 |
|
1352 if (! error_state) |
|
1353 { |
|
1354 if (dval < minval) |
|
1355 error ("%s: expecting arg to be greater than %g", minval); |
|
1356 else if (dval > maxval) |
|
1357 error ("%s: expecting arg to be less than or equal to %g", maxval); |
|
1358 else |
|
1359 var = dval; |
|
1360 } |
|
1361 else |
|
1362 error ("%s: expecting arg to be a scalar value", nm); |
|
1363 } |
|
1364 else if (nargin > 1) |
5823
|
1365 print_usage (); |
5794
|
1366 |
|
1367 return retval; |
|
1368 } |
|
1369 |
|
1370 octave_value |
|
1371 set_internal_variable (std::string& var, const octave_value_list& args, |
|
1372 int nargout, const char *nm, bool empty_ok) |
|
1373 { |
|
1374 octave_value retval; |
|
1375 |
5800
|
1376 int nargin = args.length (); |
|
1377 |
|
1378 if (nargout > 0 || nargin == 0) |
5794
|
1379 retval = var; |
|
1380 |
|
1381 if (nargin == 1) |
|
1382 { |
|
1383 std::string sval = args(0).string_value (); |
|
1384 |
|
1385 if (! error_state) |
|
1386 { |
|
1387 if (empty_ok || ! sval.empty ()) |
|
1388 var = sval; |
|
1389 else |
|
1390 error ("%s: value must not be empty", nm); |
|
1391 } |
5791
|
1392 else |
|
1393 error ("%s: expecting arg to be a character string", nm); |
|
1394 } |
|
1395 else if (nargin > 1) |
5823
|
1396 print_usage (); |
1
|
1397 |
|
1398 return retval; |
|
1399 } |
|
1400 |
593
|
1401 // Global stuff and links to builtin variables and functions. |
|
1402 |
581
|
1403 // Make the definition of the symbol record sr be the same as the |
|
1404 // definition of the global variable of the same name, creating it if |
1418
|
1405 // it doesn't already exist. |
581
|
1406 |
195
|
1407 void |
|
1408 link_to_global_variable (symbol_record *sr) |
|
1409 { |
2975
|
1410 if (! sr->is_linked_to_global ()) |
195
|
1411 { |
2975
|
1412 sr->mark_as_linked_to_global (); |
195
|
1413 |
2975
|
1414 if (! error_state) |
|
1415 { |
3523
|
1416 std::string nm = sr->name (); |
2846
|
1417 |
2975
|
1418 symbol_record *gsr = global_sym_tab->lookup (nm, true); |
|
1419 |
|
1420 // Make sure this symbol is a variable. |
2900
|
1421 |
4009
|
1422 if (! gsr->is_user_variable ()) |
2975
|
1423 gsr->define (octave_value ()); |
2900
|
1424 |
4009
|
1425 sr->alias (gsr); |
2975
|
1426 } |
195
|
1427 } |
|
1428 } |
|
1429 |
581
|
1430 // Make the definition of the symbol record sr be the same as the |
|
1431 // definition of the builtin variable of the same name. |
|
1432 |
|
1433 // Make the definition of the symbol record sr be the same as the |
5794
|
1434 // definition of the builtin function, or user function of the same |
|
1435 // name, provided that the name has not been used as a formal parameter. |
581
|
1436 |
195
|
1437 void |
|
1438 link_to_builtin_or_function (symbol_record *sr) |
|
1439 { |
4238
|
1440 std::string nm = sr->name (); |
|
1441 |
|
1442 symbol_record *tmp_sym = 0; |
|
1443 |
|
1444 if (curr_parent_function) |
|
1445 { |
4748
|
1446 std::string parent = curr_parent_function->name (); |
4238
|
1447 |
|
1448 tmp_sym = fbi_sym_tab->lookup (parent + ":" + nm); |
|
1449 } |
|
1450 |
|
1451 if (! tmp_sym) |
|
1452 tmp_sym = fbi_sym_tab->lookup (nm); |
195
|
1453 |
529
|
1454 if (tmp_sym |
5794
|
1455 && tmp_sym->is_function () |
529
|
1456 && ! tmp_sym->is_formal_parameter ()) |
|
1457 sr->alias (tmp_sym); |
195
|
1458 } |
|
1459 |
581
|
1460 // Force a link to a function in the current symbol table. This is |
|
1461 // used just after defining a function to avoid different behavior |
|
1462 // depending on whether or not the function has been evaluated after |
|
1463 // being defined. |
|
1464 // |
|
1465 // Return without doing anything if there isn't a function with the |
|
1466 // given name defined in the global symbol table. |
|
1467 |
195
|
1468 void |
3523
|
1469 force_link_to_function (const std::string& id_name) |
195
|
1470 { |
4009
|
1471 symbol_record *fsr = fbi_sym_tab->lookup (id_name, true); |
|
1472 if (fsr->is_function ()) |
195
|
1473 { |
|
1474 curr_sym_tab->clear (id_name); |
2856
|
1475 symbol_record *csr = curr_sym_tab->lookup (id_name, true); |
4009
|
1476 csr->alias (fsr); |
195
|
1477 } |
|
1478 } |
|
1479 |
2294
|
1480 DEFUN (document, args, , |
3361
|
1481 "-*- texinfo -*-\n\ |
|
1482 @deftypefn {Built-in Function} {} document (@var{symbol}, @var{text})\n\ |
|
1483 Set the documentation string for @var{symbol} to @var{text}.\n\ |
|
1484 @end deftypefn") |
593
|
1485 { |
2294
|
1486 octave_value retval; |
1755
|
1487 |
2294
|
1488 int nargin = args.length (); |
1755
|
1489 |
2294
|
1490 if (nargin == 2) |
593
|
1491 { |
3523
|
1492 std::string name = args(0).string_value (); |
593
|
1493 |
2294
|
1494 if (! error_state) |
593
|
1495 { |
3523
|
1496 std::string help = args(1).string_value (); |
593
|
1497 |
2294
|
1498 if (! error_state) |
|
1499 { |
5794
|
1500 if (is_command_name (name) |
2294
|
1501 || is_mapper_function_name (name) |
|
1502 || is_builtin_function_name (name)) |
5794
|
1503 error ("document: can't redefine help for built-in functions"); |
2294
|
1504 else |
|
1505 { |
2856
|
1506 symbol_record *sym_rec = curr_sym_tab->lookup (name); |
2294
|
1507 |
|
1508 if (sym_rec) |
|
1509 sym_rec->document (help); |
|
1510 else |
|
1511 error ("document: no such symbol `%s'", name.c_str ()); |
|
1512 } |
|
1513 } |
593
|
1514 } |
|
1515 } |
|
1516 else |
5823
|
1517 print_usage (); |
593
|
1518 |
|
1519 return retval; |
|
1520 } |
|
1521 |
5775
|
1522 // FIXME -- this function is duplicated in symtab.cc with the |
5659
|
1523 // name maybe_list_cmp_fcn. |
|
1524 |
|
1525 static int |
|
1526 symbol_record_name_compare (const void *a_arg, const void *b_arg) |
|
1527 { |
5760
|
1528 const symbol_record *a = static_cast<const symbol_record *> (a_arg); |
|
1529 const symbol_record *b = static_cast<const symbol_record *> (b_arg); |
5659
|
1530 |
|
1531 std::string a_nm = a->name (); |
|
1532 std::string b_nm = b->name (); |
|
1533 |
|
1534 return a_nm.compare (b_nm); |
|
1535 } |
|
1536 |
4435
|
1537 static octave_value |
|
1538 do_who (int argc, const string_vector& argv, int return_list) |
529
|
1539 { |
4435
|
1540 octave_value retval; |
529
|
1541 |
2856
|
1542 bool show_builtins = false; |
3248
|
1543 bool show_functions = false; |
|
1544 bool show_variables = false; |
2856
|
1545 bool show_verbose = false; |
529
|
1546 |
3523
|
1547 std::string my_name = argv[0]; |
584
|
1548 |
1857
|
1549 int i; |
|
1550 for (i = 1; i < argc; i++) |
529
|
1551 { |
1755
|
1552 if (argv[i] == "-all" || argv[i] == "-a") |
529
|
1553 { |
2856
|
1554 show_builtins = true; |
|
1555 show_functions = true; |
|
1556 show_variables = true; |
529
|
1557 } |
1755
|
1558 else if (argv[i] == "-builtins" || argv[i] == "-b") |
2856
|
1559 show_builtins = true; |
1755
|
1560 else if (argv[i] == "-functions" || argv[i] == "-f") |
2856
|
1561 show_functions = true; |
1755
|
1562 else if (argv[i] == "-long" || argv[i] == "-l") |
2856
|
1563 show_verbose = true; |
1755
|
1564 else if (argv[i] == "-variables" || argv[i] == "-v") |
2856
|
1565 show_variables = true; |
1755
|
1566 else if (argv[i][0] == '-') |
|
1567 warning ("%s: unrecognized option `%s'", my_name.c_str (), |
|
1568 argv[i].c_str ()); |
529
|
1569 else |
867
|
1570 break; |
529
|
1571 } |
|
1572 |
3248
|
1573 // If no options were specified to select the type of symbol to |
|
1574 // display, then set defaults. |
|
1575 |
|
1576 if (! (show_builtins || show_functions || show_variables)) |
|
1577 { |
4208
|
1578 show_functions = at_top_level (); |
3248
|
1579 show_variables = true; |
|
1580 } |
|
1581 |
1857
|
1582 int npats = argc - i; |
|
1583 string_vector pats (npats); |
|
1584 for (int j = 0; j < npats; j++) |
|
1585 pats[j] = argv[i+j]; |
|
1586 |
1271
|
1587 // If the user specified -l and nothing else, show variables. If |
|
1588 // evaluating this at the top level, also show functions. |
529
|
1589 |
|
1590 if (show_verbose && ! (show_builtins || show_functions || show_variables)) |
|
1591 { |
4208
|
1592 show_functions = at_top_level (); |
529
|
1593 show_variables = 1; |
|
1594 } |
|
1595 |
4435
|
1596 if (return_list) |
529
|
1597 { |
5775
|
1598 // FIXME -- maybe symbol_list should return a std::list |
5659
|
1599 // object instead of an Array. |
|
1600 |
|
1601 dim_vector dv (0, 0); |
|
1602 |
|
1603 Array<symbol_record *> s3 (dv); |
|
1604 Array<symbol_record *> s4 (dv); |
|
1605 Array<symbol_record *> s5 (dv); |
|
1606 Array<symbol_record *> s6 (dv); |
|
1607 Array<symbol_record *> s7 (dv); |
4435
|
1608 |
|
1609 if (show_builtins) |
|
1610 { |
5659
|
1611 s3 = fbi_sym_tab->symbol_list (pats, symbol_record::BUILTIN_FUNCTION, |
|
1612 SYMTAB_ALL_SCOPES); |
4435
|
1613 } |
|
1614 |
|
1615 if (show_functions) |
|
1616 { |
5659
|
1617 s4 = fbi_sym_tab->symbol_list (pats, symbol_record::DLD_FUNCTION, |
|
1618 SYMTAB_ALL_SCOPES); |
|
1619 |
|
1620 s5 = fbi_sym_tab->symbol_list (pats, symbol_record::USER_FUNCTION, |
|
1621 SYMTAB_ALL_SCOPES); |
4435
|
1622 } |
|
1623 |
|
1624 if (show_variables) |
|
1625 { |
5659
|
1626 s6 = curr_sym_tab->symbol_list (pats, symbol_record::USER_VARIABLE, |
|
1627 SYMTAB_LOCAL_SCOPE); |
|
1628 |
|
1629 s7 = curr_sym_tab->symbol_list (pats, symbol_record::USER_VARIABLE, |
|
1630 SYMTAB_GLOBAL_SCOPE); |
4435
|
1631 } |
|
1632 |
5659
|
1633 octave_idx_type s3_len = s3.length (); |
|
1634 octave_idx_type s4_len = s4.length (); |
|
1635 octave_idx_type s5_len = s5.length (); |
|
1636 octave_idx_type s6_len = s6.length (); |
|
1637 octave_idx_type s7_len = s7.length (); |
|
1638 |
5794
|
1639 octave_idx_type symbols_len = s3_len + s4_len + s5_len + s6_len + s7_len; |
5659
|
1640 |
|
1641 Array<symbol_record *> symbols (dim_vector (symbols_len, 1)); |
|
1642 |
|
1643 octave_idx_type k = 0; |
|
1644 |
|
1645 symbols.insert (s3, k, 0); |
|
1646 k += s3_len; |
|
1647 symbols.insert (s4, k, 0); |
|
1648 k += s4_len; |
|
1649 symbols.insert (s5, k, 0); |
|
1650 k += s5_len; |
|
1651 symbols.insert (s6, k, 0); |
|
1652 k += s6_len; |
|
1653 symbols.insert (s7, k, 0); |
|
1654 |
|
1655 symbols.qsort (symbol_record_name_compare); |
|
1656 |
4435
|
1657 if (show_verbose) |
|
1658 { |
5659
|
1659 Array<octave_value> name_info (symbols_len, 1); |
|
1660 Array<octave_value> size_info (symbols_len, 1); |
|
1661 Array<octave_value> bytes_info (symbols_len, 1); |
|
1662 Array<octave_value> class_info (symbols_len, 1); |
|
1663 Array<octave_value> global_info (symbols_len, 1); |
|
1664 Array<octave_value> sparse_info (symbols_len, 1); |
|
1665 Array<octave_value> complex_info (symbols_len, 1); |
|
1666 Array<octave_value> nesting_info (symbols_len, 1); |
|
1667 |
|
1668 for (octave_idx_type j = 0; j < symbols_len; j++) |
|
1669 { |
|
1670 symbol_record *sr = symbols(j); |
|
1671 |
|
1672 Octave_map ni; |
|
1673 |
|
1674 std::string caller_function_name; |
5743
|
1675 |
|
1676 octave_function *caller = octave_call_stack::caller (); |
|
1677 if (caller) |
|
1678 caller_function_name = caller->name (); |
5659
|
1679 |
|
1680 ni.assign ("function", caller_function_name); |
|
1681 ni.assign ("level", 1); |
|
1682 |
|
1683 name_info(j) = sr->name (); |
|
1684 size_info(j) = sr->size (); |
|
1685 bytes_info(j) = sr->byte_size (); |
|
1686 class_info(j) = sr->class_name (); |
|
1687 global_info(j) = sr->is_linked_to_global (); |
|
1688 sparse_info(j) = sr->is_sparse_type (); |
|
1689 complex_info(j) = sr->is_complex_type (); |
|
1690 nesting_info(j) = ni; |
|
1691 } |
|
1692 |
|
1693 Octave_map info; |
|
1694 |
|
1695 info.assign ("name", name_info); |
|
1696 info.assign ("size", size_info); |
|
1697 info.assign ("bytes", bytes_info); |
|
1698 info.assign ("class", class_info); |
|
1699 info.assign ("global", global_info); |
|
1700 info.assign ("sparse", sparse_info); |
|
1701 info.assign ("complex", complex_info); |
|
1702 info.assign ("nesting", nesting_info); |
|
1703 |
|
1704 retval = info; |
4435
|
1705 } |
|
1706 else |
5659
|
1707 { |
|
1708 string_vector names; |
|
1709 |
|
1710 if (symbols_len > 0) |
|
1711 { |
|
1712 names.resize (symbols_len); |
|
1713 |
|
1714 for (octave_idx_type j = 0; j < symbols_len; j++) |
|
1715 names[j] = symbols(j)->name (); |
|
1716 } |
|
1717 |
|
1718 retval = Cell (names); |
|
1719 } |
529
|
1720 } |
4435
|
1721 else |
529
|
1722 { |
4435
|
1723 int pad_after = 0; |
|
1724 |
|
1725 if (show_builtins) |
|
1726 { |
|
1727 pad_after += fbi_sym_tab->maybe_list |
|
1728 ("*** built-in functions:", pats, octave_stdout, |
|
1729 show_verbose, symbol_record::BUILTIN_FUNCTION, SYMTAB_ALL_SCOPES); |
|
1730 } |
529
|
1731 |
4435
|
1732 if (show_functions) |
|
1733 { |
|
1734 pad_after += fbi_sym_tab->maybe_list |
|
1735 ("*** dynamically linked functions:", pats, |
|
1736 octave_stdout, show_verbose, symbol_record::DLD_FUNCTION, |
|
1737 SYMTAB_ALL_SCOPES); |
|
1738 |
|
1739 pad_after += fbi_sym_tab->maybe_list |
|
1740 ("*** currently compiled functions:", pats, |
|
1741 octave_stdout, show_verbose, symbol_record::USER_FUNCTION, |
|
1742 SYMTAB_ALL_SCOPES); |
|
1743 } |
|
1744 |
|
1745 if (show_variables) |
|
1746 { |
|
1747 pad_after += curr_sym_tab->maybe_list |
|
1748 ("*** local user variables:", pats, octave_stdout, |
|
1749 show_verbose, symbol_record::USER_VARIABLE, SYMTAB_LOCAL_SCOPE); |
|
1750 |
|
1751 pad_after += curr_sym_tab->maybe_list |
|
1752 ("*** globally visible user variables:", pats, |
|
1753 octave_stdout, show_verbose, symbol_record::USER_VARIABLE, |
|
1754 SYMTAB_GLOBAL_SCOPE); |
|
1755 } |
|
1756 |
|
1757 if (pad_after) |
|
1758 octave_stdout << "\n"; |
529
|
1759 } |
|
1760 |
581
|
1761 return retval; |
|
1762 } |
|
1763 |
4435
|
1764 DEFCMD (who, args, nargout, |
3361
|
1765 "-*- texinfo -*-\n\ |
|
1766 @deffn {Command} who options pattern @dots{}\n\ |
|
1767 @deffnx {Command} whos options pattern @dots{}\n\ |
|
1768 List currently defined symbols matching the given patterns. The\n\ |
|
1769 following are valid options. They may be shortened to one character but\n\ |
|
1770 may not be combined.\n\ |
|
1771 \n\ |
|
1772 @table @code\n\ |
|
1773 @item -all\n\ |
|
1774 List all currently defined symbols.\n\ |
|
1775 \n\ |
|
1776 @item -builtins\n\ |
5794
|
1777 List built-in functions. This includes all currently\n\ |
3361
|
1778 compiled function files, but does not include all function files that\n\ |
5814
|
1779 are in the search path.\n\ |
581
|
1780 \n\ |
3361
|
1781 @item -functions\n\ |
|
1782 List user-defined functions.\n\ |
|
1783 \n\ |
|
1784 @item -long\n\ |
|
1785 Print a long listing including the type and dimensions of any symbols.\n\ |
|
1786 The symbols in the first column of output indicate whether it is\n\ |
|
1787 possible to redefine the symbol, and whether it is possible for it to be\n\ |
|
1788 cleared.\n\ |
|
1789 \n\ |
|
1790 @item -variables\n\ |
|
1791 List user-defined variables.\n\ |
|
1792 @end table\n\ |
|
1793 \n\ |
|
1794 Valid patterns are the same as described for the @code{clear} command\n\ |
|
1795 above. If no patterns are supplied, all symbols from the given category\n\ |
|
1796 are listed. By default, only user defined functions and variables\n\ |
|
1797 visible in the local scope are displayed.\n\ |
|
1798 \n\ |
|
1799 The command @kbd{whos} is equivalent to @kbd{who -long}.\n\ |
|
1800 @end deffn") |
581
|
1801 { |
4435
|
1802 octave_value retval; |
581
|
1803 |
4435
|
1804 if (nargout < 2) |
|
1805 { |
|
1806 int argc = args.length () + 1; |
|
1807 |
|
1808 string_vector argv = args.make_argv ("who"); |
1755
|
1809 |
4435
|
1810 if (error_state) |
|
1811 return retval; |
1755
|
1812 |
4435
|
1813 retval = do_who (argc, argv, nargout == 1); |
|
1814 } |
|
1815 else |
5823
|
1816 print_usage (); |
581
|
1817 |
529
|
1818 return retval; |
|
1819 } |
|
1820 |
4435
|
1821 DEFCMD (whos, args, nargout, |
3458
|
1822 "-*- texinfo -*-\n\ |
|
1823 @deffn {Command} whos options pattern @dots{}\n\ |
|
1824 See who.\n\ |
|
1825 @end deffn") |
581
|
1826 { |
4435
|
1827 octave_value retval; |
712
|
1828 |
4435
|
1829 if (nargout < 2) |
|
1830 { |
|
1831 int nargin = args.length (); |
|
1832 |
|
1833 octave_value_list tmp_args; |
|
1834 |
|
1835 for (int i = nargin; i > 0; i--) |
|
1836 tmp_args(i) = args(i-1); |
581
|
1837 |
4435
|
1838 tmp_args(0) = "-long"; |
1755
|
1839 |
4435
|
1840 int argc = tmp_args.length () + 1; |
|
1841 |
|
1842 string_vector argv = tmp_args.make_argv ("whos"); |
581
|
1843 |
4435
|
1844 if (error_state) |
|
1845 return retval; |
581
|
1846 |
4435
|
1847 retval = do_who (argc, argv, nargout == 1); |
|
1848 } |
|
1849 else |
5823
|
1850 print_usage (); |
581
|
1851 |
|
1852 return retval; |
|
1853 } |
|
1854 |
593
|
1855 // Defining variables. |
|
1856 |
1162
|
1857 void |
2856
|
1858 bind_ans (const octave_value& val, bool print) |
1162
|
1859 { |
5794
|
1860 symbol_record *sr = curr_sym_tab->lookup ("ans", true); |
1162
|
1861 |
2978
|
1862 if (val.is_defined ()) |
|
1863 { |
|
1864 sr->define (val); |
1162
|
1865 |
2978
|
1866 if (print) |
|
1867 val.print_with_name (octave_stdout, "ans"); |
|
1868 } |
1162
|
1869 } |
|
1870 |
593
|
1871 void |
5794
|
1872 bind_internal_variable (const std::string& fname, const octave_value& val) |
593
|
1873 { |
5794
|
1874 octave_value_list args; |
|
1875 |
|
1876 args(0) = val; |
|
1877 |
|
1878 feval (fname, args, 0); |
529
|
1879 } |
|
1880 |
4319
|
1881 void |
|
1882 mlock (const std::string& nm) |
|
1883 { |
|
1884 symbol_record *sr = fbi_sym_tab->lookup (nm, true); |
|
1885 |
|
1886 if (sr) |
|
1887 sr->mark_as_static (); |
|
1888 } |
|
1889 |
|
1890 void |
|
1891 munlock (const std::string& nm) |
|
1892 { |
|
1893 symbol_record *sr = fbi_sym_tab->lookup (nm); |
|
1894 |
|
1895 if (sr && sr->is_static ()) |
|
1896 sr->unmark_static (); |
|
1897 else |
|
1898 error ("munlock: %s is not locked", nm.c_str ()); |
|
1899 } |
|
1900 |
|
1901 bool |
|
1902 mislocked (const std::string& nm) |
|
1903 { |
|
1904 symbol_record *sr = fbi_sym_tab->lookup (nm); |
|
1905 |
|
1906 return (sr && sr->is_static ()); |
|
1907 } |
|
1908 |
|
1909 DEFCMD (mlock, args, , |
|
1910 "-*- texinfo -*-\n\ |
4526
|
1911 @deftypefn {Built-in Function} {} mlock (@var{name})\n\ |
4319
|
1912 Lock the named function into memory. If no function is named\n\ |
|
1913 then lock in the current function.\n\ |
5642
|
1914 @seealso{munlock, mislocked, persistent}\n\ |
|
1915 @end deftypefn") |
4319
|
1916 { |
|
1917 octave_value_list retval; |
|
1918 |
|
1919 if (args.length () == 1) |
|
1920 { |
|
1921 std::string name = args(0).string_value (); |
|
1922 |
|
1923 if (! error_state) |
|
1924 mlock (name); |
|
1925 else |
|
1926 error ("mlock: expecting argument to be a function name"); |
|
1927 } |
|
1928 else if (args.length () == 0) |
|
1929 { |
5744
|
1930 octave_user_function *fcn = octave_call_stack::caller_user_function (); |
5743
|
1931 |
|
1932 if (fcn) |
|
1933 mlock (fcn->name ()); |
4319
|
1934 else |
|
1935 error ("mlock: invalid use outside a function"); |
|
1936 } |
|
1937 else |
5823
|
1938 print_usage (); |
4319
|
1939 |
|
1940 return retval; |
|
1941 } |
|
1942 |
|
1943 DEFCMD (munlock, args, , |
|
1944 "-*- texinfo -*-\n\ |
|
1945 @deftypefn {Built-in Function} {} munlock (@var{fcn})\n\ |
|
1946 Unlock the named function. If no function is named\n\ |
|
1947 then unlock the current function.\n\ |
5642
|
1948 @seealso{mlock, mislocked, persistent}\n\ |
|
1949 @end deftypefn") |
4319
|
1950 { |
|
1951 octave_value_list retval; |
|
1952 |
|
1953 if (args.length() == 1) |
|
1954 { |
|
1955 std::string name = args(0).string_value (); |
|
1956 |
|
1957 if (! error_state) |
|
1958 munlock (name); |
|
1959 else |
|
1960 error ("munlock: expecting argument to be a function name"); |
|
1961 } |
|
1962 else if (args.length () == 0) |
|
1963 { |
5744
|
1964 octave_user_function *fcn = octave_call_stack::caller_user_function (); |
5743
|
1965 |
|
1966 if (fcn) |
|
1967 mlock (fcn->name ()); |
4319
|
1968 else |
|
1969 error ("munlock: invalid use outside a function"); |
|
1970 } |
|
1971 else |
5823
|
1972 print_usage (); |
4319
|
1973 |
|
1974 return retval; |
|
1975 } |
|
1976 |
|
1977 |
|
1978 DEFCMD (mislocked, args, , |
|
1979 "-*- texinfo -*-\n\ |
|
1980 @deftypefn {Built-in Function} {} mislocked (@var{fcn})\n\ |
|
1981 Return true if the named function is locked. If no function is named\n\ |
|
1982 then return true if the current function is locked.\n\ |
5642
|
1983 @seealso{mlock, munlock, persistent}\n\ |
|
1984 @end deftypefn") |
4319
|
1985 { |
|
1986 octave_value retval; |
|
1987 |
|
1988 if (args.length() == 1) |
|
1989 { |
|
1990 std::string name = args(0).string_value (); |
|
1991 |
|
1992 if (! error_state) |
|
1993 retval = mislocked (name); |
|
1994 else |
|
1995 error ("mislocked: expecting argument to be a function name"); |
|
1996 } |
|
1997 else if (args.length () == 0) |
|
1998 { |
5744
|
1999 octave_user_function *fcn = octave_call_stack::caller_user_function (); |
5743
|
2000 |
|
2001 if (fcn) |
|
2002 retval = mislocked (fcn->name ()); |
4319
|
2003 else |
|
2004 error ("mislocked: invalid use outside a function"); |
|
2005 } |
|
2006 else |
5823
|
2007 print_usage (); |
4319
|
2008 |
|
2009 return retval; |
|
2010 } |
|
2011 |
593
|
2012 // Deleting names from the symbol tables. |
|
2013 |
3681
|
2014 static inline bool |
4009
|
2015 name_matches_any_pattern (const std::string& nm, |
|
2016 const string_vector& argv, int argc, int idx) |
3681
|
2017 { |
|
2018 bool retval = false; |
|
2019 |
|
2020 for (int k = idx; k < argc; k++) |
|
2021 { |
|
2022 std::string patstr = argv[k]; |
|
2023 |
|
2024 if (! patstr.empty ()) |
|
2025 { |
|
2026 glob_match pattern (patstr); |
|
2027 |
|
2028 if (pattern.match (nm)) |
|
2029 { |
|
2030 retval = true; |
|
2031 break; |
|
2032 } |
|
2033 } |
|
2034 } |
|
2035 |
|
2036 return retval; |
|
2037 } |
|
2038 |
4009
|
2039 static inline bool |
|
2040 is_local_variable (const std::string& nm) |
|
2041 { |
|
2042 symbol_record *sr = curr_sym_tab->lookup (nm); |
|
2043 |
|
2044 return (sr && sr->is_variable ()); |
|
2045 } |
|
2046 |
|
2047 static inline void |
|
2048 maybe_warn_exclusive (bool exclusive) |
|
2049 { |
|
2050 if (exclusive) |
|
2051 warning ("clear: ignoring --exclusive option"); |
|
2052 } |
|
2053 |
|
2054 static inline void |
|
2055 do_clear_all (void) |
|
2056 { |
|
2057 curr_sym_tab->clear (); |
|
2058 fbi_sym_tab->clear_functions (); |
|
2059 global_sym_tab->clear (); |
|
2060 } |
|
2061 |
|
2062 static inline void |
|
2063 do_clear_functions (void) |
|
2064 { |
|
2065 curr_sym_tab->clear_functions (); |
|
2066 fbi_sym_tab->clear_functions (); |
|
2067 } |
|
2068 |
|
2069 static inline void |
|
2070 do_clear_globals (void) |
|
2071 { |
|
2072 curr_sym_tab->clear_globals (); |
|
2073 global_sym_tab->clear (); |
|
2074 } |
|
2075 |
|
2076 static inline void |
|
2077 do_clear_variables (void) |
|
2078 { |
|
2079 curr_sym_tab->clear (); |
|
2080 } |
|
2081 |
|
2082 static inline bool |
|
2083 do_clear_function (const std::string& nm) |
|
2084 { |
|
2085 bool b1 = curr_sym_tab->clear_function (nm); |
|
2086 |
|
2087 bool b2 = fbi_sym_tab->clear_function (nm); |
|
2088 |
|
2089 return b1 || b2; |
|
2090 } |
|
2091 |
|
2092 static inline bool |
|
2093 do_clear_global (const std::string& nm) |
|
2094 { |
|
2095 bool b1 = curr_sym_tab->clear_global (nm); |
|
2096 |
|
2097 bool b2 = global_sym_tab->clear_variable (nm); |
|
2098 |
|
2099 return b1 || b2; |
|
2100 } |
|
2101 |
|
2102 static inline bool |
|
2103 do_clear_variable (const std::string& nm) |
|
2104 { |
|
2105 return curr_sym_tab->clear_variable (nm); |
|
2106 } |
|
2107 |
|
2108 static inline bool |
|
2109 do_clear_symbol (const std::string& nm) |
|
2110 { |
|
2111 bool cleared = curr_sym_tab->clear_variable (nm); |
|
2112 |
|
2113 if (! cleared) |
|
2114 cleared = do_clear_function (nm); |
|
2115 |
|
2116 return cleared; |
|
2117 } |
|
2118 |
|
2119 static inline bool |
|
2120 do_clear_function_pattern (const std::string& pat) |
|
2121 { |
|
2122 bool b1 = curr_sym_tab->clear_function_pattern (pat); |
|
2123 |
|
2124 bool b2 = fbi_sym_tab->clear_function_pattern (pat); |
|
2125 |
|
2126 return b1 || b2; |
|
2127 } |
|
2128 |
|
2129 static inline bool |
|
2130 do_clear_global_pattern (const std::string& pat) |
|
2131 { |
|
2132 bool b1 = curr_sym_tab->clear_global_pattern (pat); |
|
2133 |
|
2134 bool b2 = global_sym_tab->clear_variable_pattern (pat); |
|
2135 |
|
2136 return b1 || b2; |
|
2137 } |
|
2138 |
|
2139 static inline bool |
|
2140 do_clear_variable_pattern (const std::string& pat) |
|
2141 { |
|
2142 return curr_sym_tab->clear_variable_pattern (pat); |
|
2143 } |
|
2144 |
|
2145 static inline bool |
|
2146 do_clear_symbol_pattern (const std::string& pat) |
|
2147 { |
5775
|
2148 // FIXME -- if we have a variable v1 and a function v2 and |
4009
|
2149 // someone says clear v*, we will clear the variable but not the |
|
2150 // function. Is that really what should happen? (I think it is |
|
2151 // what Matlab does.) |
|
2152 |
|
2153 bool cleared = curr_sym_tab->clear_variable_pattern (pat); |
|
2154 |
|
2155 if (! cleared) |
|
2156 cleared = do_clear_function_pattern (pat); |
|
2157 |
|
2158 return cleared; |
|
2159 } |
|
2160 |
|
2161 static inline void |
|
2162 do_clear_functions (const string_vector& argv, int argc, int idx, |
|
2163 bool exclusive = false) |
|
2164 { |
|
2165 if (idx == argc) |
|
2166 do_clear_functions (); |
|
2167 else |
|
2168 { |
|
2169 if (exclusive) |
|
2170 { |
|
2171 string_vector lfcns = curr_sym_tab->user_function_name_list (); |
|
2172 |
|
2173 int lcount = lfcns.length (); |
|
2174 |
|
2175 for (int i = 0; i < lcount; i++) |
|
2176 { |
|
2177 std::string nm = lfcns[i]; |
|
2178 |
|
2179 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2180 do_clear_function (nm); |
|
2181 } |
|
2182 |
|
2183 string_vector fcns = fbi_sym_tab->user_function_name_list (); |
|
2184 |
|
2185 int fcount = fcns.length (); |
|
2186 |
|
2187 for (int i = 0; i < fcount; i++) |
|
2188 { |
|
2189 std::string nm = fcns[i]; |
|
2190 |
|
2191 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2192 do_clear_function (nm); |
|
2193 } |
|
2194 } |
|
2195 else |
|
2196 { |
|
2197 while (idx < argc) |
|
2198 do_clear_function_pattern (argv[idx++]); |
|
2199 } |
|
2200 } |
|
2201 } |
|
2202 |
|
2203 static inline void |
|
2204 do_clear_globals (const string_vector& argv, int argc, int idx, |
|
2205 bool exclusive = false) |
|
2206 { |
|
2207 if (idx == argc) |
|
2208 do_clear_globals (); |
|
2209 else |
|
2210 { |
|
2211 if (exclusive) |
|
2212 { |
|
2213 string_vector lvars = curr_sym_tab->global_variable_name_list (); |
|
2214 |
|
2215 int lcount = lvars.length (); |
|
2216 |
|
2217 for (int i = 0; i < lcount; i++) |
|
2218 { |
|
2219 std::string nm = lvars[i]; |
|
2220 |
|
2221 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2222 do_clear_global (nm); |
|
2223 } |
|
2224 |
|
2225 string_vector gvars = global_sym_tab->global_variable_name_list (); |
|
2226 |
|
2227 int gcount = gvars.length (); |
|
2228 |
|
2229 for (int i = 0; i < gcount; i++) |
|
2230 { |
|
2231 std::string nm = gvars[i]; |
|
2232 |
|
2233 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2234 do_clear_global (nm); |
|
2235 } |
|
2236 } |
|
2237 else |
|
2238 { |
|
2239 while (idx < argc) |
|
2240 do_clear_global_pattern (argv[idx++]); |
|
2241 } |
|
2242 } |
|
2243 } |
|
2244 |
|
2245 static inline void |
|
2246 do_clear_variables (const string_vector& argv, int argc, int idx, |
|
2247 bool exclusive = false) |
|
2248 { |
|
2249 if (idx == argc) |
|
2250 do_clear_variables (); |
|
2251 else |
|
2252 { |
|
2253 if (exclusive) |
|
2254 { |
|
2255 string_vector lvars = curr_sym_tab->variable_name_list (); |
|
2256 |
|
2257 int lcount = lvars.length (); |
|
2258 |
|
2259 for (int i = 0; i < lcount; i++) |
|
2260 { |
|
2261 std::string nm = lvars[i]; |
|
2262 |
|
2263 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
|
2264 do_clear_variable (nm); |
|
2265 } |
|
2266 } |
|
2267 else |
|
2268 { |
|
2269 while (idx < argc) |
|
2270 do_clear_variable_pattern (argv[idx++]); |
|
2271 } |
|
2272 } |
|
2273 } |
|
2274 |
|
2275 static inline void |
|
2276 do_clear_symbols (const string_vector& argv, int argc, int idx, |
|
2277 bool exclusive = false) |
|
2278 { |
|
2279 if (idx == argc) |
|
2280 do_clear_variables (); |
|
2281 else |
|
2282 { |
|
2283 if (exclusive) |
|
2284 { |
5775
|
2285 // FIXME -- is this really what we want, or do we |
4009
|
2286 // somehow want to only clear the functions that are not |
|
2287 // shadowed by local variables? It seems that would be a |
|
2288 // bit harder to do. |
|
2289 |
|
2290 do_clear_variables (argv, argc, idx, exclusive); |
|
2291 do_clear_functions (argv, argc, idx, exclusive); |
|
2292 } |
|
2293 else |
|
2294 { |
|
2295 while (idx < argc) |
|
2296 do_clear_symbol_pattern (argv[idx++]); |
|
2297 } |
|
2298 } |
|
2299 } |
|
2300 |
|
2301 static void |
|
2302 do_matlab_compatible_clear (const string_vector& argv, int argc, int idx) |
|
2303 { |
|
2304 // This is supposed to be mostly Matlab compatible. |
|
2305 |
|
2306 for (; idx < argc; idx++) |
|
2307 { |
|
2308 if (argv[idx] == "all" && ! is_local_variable ("all")) |
|
2309 { |
|
2310 do_clear_all (); |
|
2311 } |
|
2312 else if (argv[idx] == "functions" && ! is_local_variable ("functions")) |
|
2313 { |
|
2314 do_clear_functions (argv, argc, ++idx); |
|
2315 } |
|
2316 else if (argv[idx] == "global" && ! is_local_variable ("global")) |
|
2317 { |
|
2318 do_clear_globals (argv, argc, ++idx); |
|
2319 } |
|
2320 else if (argv[idx] == "variables" && ! is_local_variable ("variables")) |
|
2321 { |
|
2322 do_clear_variables (); |
|
2323 } |
|
2324 else |
|
2325 { |
|
2326 do_clear_symbol_pattern (argv[idx]); |
|
2327 } |
|
2328 } |
|
2329 } |
|
2330 |
|
2331 #define CLEAR_OPTION_ERROR(cond) \ |
|
2332 do \ |
|
2333 { \ |
|
2334 if (cond) \ |
|
2335 { \ |
5823
|
2336 print_usage (); \ |
4009
|
2337 return retval; \ |
|
2338 } \ |
|
2339 } \ |
|
2340 while (0) |
|
2341 |
4954
|
2342 bool |
|
2343 clear_function (const std::string& nm) |
|
2344 { |
|
2345 return do_clear_function (nm); |
|
2346 } |
|
2347 |
4988
|
2348 bool |
|
2349 clear_variable (const std::string& nm) |
|
2350 { |
|
2351 return do_clear_variable (nm); |
|
2352 } |
|
2353 |
|
2354 bool |
|
2355 clear_symbol (const std::string& nm) |
|
2356 { |
|
2357 return do_clear_symbol (nm); |
|
2358 } |
|
2359 |
4208
|
2360 DEFCMD (clear, args, , |
3361
|
2361 "-*- texinfo -*-\n\ |
|
2362 @deffn {Command} clear [-x] pattern @dots{}\n\ |
|
2363 Delete the names matching the given patterns from the symbol table. The\n\ |
|
2364 pattern may contain the following special characters:\n\ |
4016
|
2365 \n\ |
3361
|
2366 @table @code\n\ |
|
2367 @item ?\n\ |
|
2368 Match any single character.\n\ |
668
|
2369 \n\ |
3361
|
2370 @item *\n\ |
|
2371 Match zero or more characters.\n\ |
|
2372 \n\ |
|
2373 @item [ @var{list} ]\n\ |
|
2374 Match the list of characters specified by @var{list}. If the first\n\ |
|
2375 character is @code{!} or @code{^}, match all characters except those\n\ |
|
2376 specified by @var{list}. For example, the pattern @samp{[a-zA-Z]} will\n\ |
|
2377 match all lower and upper case alphabetic characters.\n\ |
|
2378 @end table\n\ |
|
2379 \n\ |
|
2380 For example, the command\n\ |
593
|
2381 \n\ |
3361
|
2382 @example\n\ |
|
2383 clear foo b*r\n\ |
|
2384 @end example\n\ |
|
2385 \n\ |
|
2386 @noindent\n\ |
|
2387 clears the name @code{foo} and all names that begin with the letter\n\ |
|
2388 @code{b} and end with the letter @code{r}.\n\ |
668
|
2389 \n\ |
3361
|
2390 If @code{clear} is called without any arguments, all user-defined\n\ |
|
2391 variables (local and global) are cleared from the symbol table. If\n\ |
|
2392 @code{clear} is called with at least one argument, only the visible\n\ |
|
2393 names matching the arguments are cleared. For example, suppose you have\n\ |
|
2394 defined a function @code{foo}, and then hidden it by performing the\n\ |
|
2395 assignment @code{foo = 2}. Executing the command @kbd{clear foo} once\n\ |
|
2396 will clear the variable definition and restore the definition of\n\ |
|
2397 @code{foo} as a function. Executing @kbd{clear foo} a second time will\n\ |
|
2398 clear the function definition.\n\ |
|
2399 \n\ |
|
2400 With -x, clear the variables that don't match the patterns.\n\ |
|
2401 \n\ |
|
2402 This command may not be used within a function body.\n\ |
|
2403 @end deffn") |
529
|
2404 { |
2086
|
2405 octave_value_list retval; |
593
|
2406 |
1755
|
2407 int argc = args.length () + 1; |
593
|
2408 |
1968
|
2409 string_vector argv = args.make_argv ("clear"); |
1755
|
2410 |
4009
|
2411 if (! error_state) |
529
|
2412 { |
4009
|
2413 if (argc == 1) |
593
|
2414 { |
4009
|
2415 do_clear_variables (); |
3681
|
2416 } |
|
2417 else |
|
2418 { |
4009
|
2419 int idx = 0; |
|
2420 |
|
2421 bool clear_all = false; |
|
2422 bool clear_functions = false; |
|
2423 bool clear_globals = false; |
|
2424 bool clear_variables = false; |
|
2425 bool exclusive = false; |
|
2426 bool have_dash_option = false; |
3681
|
2427 |
4009
|
2428 while (++idx < argc) |
|
2429 { |
4010
|
2430 if (argv[idx] == "-all" || argv[idx] == "-a") |
593
|
2431 { |
4009
|
2432 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681
|
2433 |
4009
|
2434 have_dash_option = true; |
|
2435 clear_all = true; |
|
2436 } |
4010
|
2437 else if (argv[idx] == "-exclusive" || argv[idx] == "-x") |
4009
|
2438 { |
|
2439 have_dash_option = true; |
|
2440 exclusive = true; |
|
2441 } |
4010
|
2442 else if (argv[idx] == "-functions" || argv[idx] == "-f") |
4009
|
2443 { |
|
2444 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681
|
2445 |
4009
|
2446 have_dash_option = true; |
|
2447 clear_functions = true; |
|
2448 } |
4010
|
2449 else if (argv[idx] == "-global" || argv[idx] == "-g") |
4009
|
2450 { |
|
2451 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
|
2452 |
|
2453 have_dash_option = true; |
|
2454 clear_globals = true; |
|
2455 } |
4010
|
2456 else if (argv[idx] == "-variables" || argv[idx] == "-v") |
4009
|
2457 { |
|
2458 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681
|
2459 |
4009
|
2460 have_dash_option = true; |
|
2461 clear_variables = true; |
|
2462 } |
|
2463 else |
|
2464 break; |
|
2465 } |
3681
|
2466 |
4224
|
2467 if (idx <= argc) |
4009
|
2468 { |
|
2469 if (! have_dash_option) |
|
2470 { |
|
2471 do_matlab_compatible_clear (argv, argc, idx); |
|
2472 } |
|
2473 else |
|
2474 { |
|
2475 if (clear_all) |
3681
|
2476 { |
4009
|
2477 maybe_warn_exclusive (exclusive); |
3681
|
2478 |
4009
|
2479 if (++idx < argc) |
|
2480 warning |
4010
|
2481 ("clear: ignoring extra arguments after -all"); |
3681
|
2482 |
4009
|
2483 curr_sym_tab->clear (); |
|
2484 fbi_sym_tab->clear_functions (); |
|
2485 global_sym_tab->clear (); |
|
2486 } |
|
2487 else if (clear_functions) |
|
2488 { |
|
2489 do_clear_functions (argv, argc, idx, exclusive); |
|
2490 } |
|
2491 else if (clear_globals) |
593
|
2492 { |
4009
|
2493 do_clear_globals (argv, argc, idx, exclusive); |
|
2494 } |
|
2495 else if (clear_variables) |
|
2496 { |
|
2497 do_clear_variables (argv, argc, idx, exclusive); |
|
2498 } |
|
2499 else |
|
2500 { |
|
2501 do_clear_symbols (argv, argc, idx, exclusive); |
593
|
2502 } |
|
2503 } |
|
2504 } |
|
2505 } |
|
2506 } |
|
2507 |
|
2508 return retval; |
529
|
2509 } |
|
2510 |
3933
|
2511 DEFUN (__print_symtab_info__, args, , |
3446
|
2512 "-*- texinfo -*-\n\ |
3933
|
2513 @deftypefn {Built-in Function} {} __print_symtab_info__ ()\n\ |
3446
|
2514 Print raw symbol table statistices.\n\ |
|
2515 @end deftypefn") |
3005
|
2516 { |
|
2517 octave_value_list retval; |
|
2518 |
|
2519 int nargin = args.length (); |
|
2520 |
|
2521 if (nargin == 1) |
|
2522 { |
3523
|
2523 std::string arg = args(0).string_value (); |
3005
|
2524 |
4009
|
2525 if (arg == "fbi") |
|
2526 fbi_sym_tab->print_info (octave_stdout); |
|
2527 else if (arg == "global") |
3933
|
2528 global_sym_tab->print_info (octave_stdout); |
|
2529 else if (arg == "top-level") |
|
2530 top_level_sym_tab->print_info (octave_stdout); |
3005
|
2531 else |
3933
|
2532 { |
4009
|
2533 symbol_record *fsr = fbi_sym_tab->lookup (arg, true); |
3933
|
2534 |
4009
|
2535 if (fsr && fsr->is_user_function ()) |
3933
|
2536 { |
4009
|
2537 octave_value tmp = fsr->def (); |
5759
|
2538 const octave_base_value& rep = tmp.get_rep (); |
3933
|
2539 |
|
2540 const octave_user_function& fcn |
5759
|
2541 = dynamic_cast<const octave_user_function&> (rep); |
3933
|
2542 |
|
2543 fcn.print_symtab_info (octave_stdout); |
|
2544 } |
|
2545 else |
|
2546 error ("no user-defined function named %s", arg.c_str ()); |
|
2547 } |
3005
|
2548 } |
|
2549 else if (nargin == 0) |
3933
|
2550 curr_sym_tab->print_info (octave_stdout); |
3005
|
2551 else |
5823
|
2552 print_usage (); |
3005
|
2553 |
|
2554 return retval; |
|
2555 } |
|
2556 |
3933
|
2557 DEFUN (__print_symbol_info__, args, , |
3446
|
2558 "-*- texinfo -*-\n\ |
|
2559 @deftypefn {Built-in Function} {} __dump_symbol_info__ (@var{name})\n\ |
3548
|
2560 Print symbol table information for the symbol @var{name}.\n\ |
3446
|
2561 @end deftypefn") |
3239
|
2562 { |
|
2563 octave_value_list retval; |
|
2564 |
|
2565 int nargin = args.length (); |
|
2566 |
|
2567 if (nargin == 1) |
|
2568 { |
3523
|
2569 std::string symbol_name = args(0).string_value (); |
3239
|
2570 |
|
2571 if (! error_state) |
|
2572 { |
|
2573 symbol_record *sr = curr_sym_tab->lookup (symbol_name); |
|
2574 |
|
2575 if (sr) |
3933
|
2576 sr->print_info (octave_stdout); |
3239
|
2577 else |
3933
|
2578 error ("__print_symbol_info__: symbol %s not found", |
3239
|
2579 symbol_name.c_str ()); |
|
2580 } |
|
2581 else |
5823
|
2582 print_usage (); |
3239
|
2583 } |
|
2584 else |
5823
|
2585 print_usage (); |
3239
|
2586 |
|
2587 return retval; |
|
2588 } |
|
2589 |
5794
|
2590 DEFUN (ignore_function_time_stamp, args, nargout, |
3372
|
2591 "-*- texinfo -*-\n\ |
5794
|
2592 @deftypefn {Built-in Function} {@var{val} =} ignore_function_time_stamp ()\n\ |
|
2593 @deftypefnx {Built-in Function} {@var{old_val} =} ignore_function_time_stamp (@var{new_val})\n\ |
|
2594 Query or set the internal variable that controls whether Octave checks\n\ |
|
2595 the time stamp on files each time it looks up functions defined in\n\ |
|
2596 function files. If the internal variable is set to @code{\"system\"},\n\ |
|
2597 Octave will not automatically recompile function files in subdirectories of\n\ |
3371
|
2598 @file{@var{octave-home}/lib/@var{version}} if they have changed since\n\ |
|
2599 they were last compiled, but will recompile other function files in the\n\ |
5814
|
2600 search path if they change. If set to @code{\"all\"}, Octave will not\n\ |
3371
|
2601 recompile any function files unless their definitions are removed with\n\ |
5794
|
2602 @code{clear}. If set to \"none\", Octave will always check time stamps\n\ |
|
2603 on files to determine whether functions defined in function files\n\ |
|
2604 need to recompiled.\n\ |
|
2605 @end deftypefn") |
|
2606 { |
|
2607 octave_value retval; |
|
2608 |
|
2609 if (nargout > 0) |
|
2610 { |
|
2611 switch (Vignore_function_time_stamp) |
|
2612 { |
|
2613 case 1: |
|
2614 retval = "system"; |
|
2615 break; |
|
2616 |
|
2617 case 2: |
|
2618 retval = "all"; |
|
2619 break; |
|
2620 |
|
2621 default: |
|
2622 retval = "none"; |
|
2623 break; |
|
2624 } |
|
2625 } |
|
2626 |
|
2627 int nargin = args.length (); |
|
2628 |
|
2629 if (nargin == 1) |
|
2630 { |
|
2631 std::string sval = args(0).string_value (); |
|
2632 |
|
2633 if (! error_state) |
|
2634 { |
|
2635 if (sval == "all") |
|
2636 Vignore_function_time_stamp = 2; |
|
2637 else if (sval == "system") |
|
2638 Vignore_function_time_stamp = 1; |
|
2639 else if (sval == "none") |
|
2640 Vignore_function_time_stamp = 0; |
|
2641 else |
|
2642 error ("ignore_function_time_stamp: expecting argument to be \"all\", \"system\", or \"none\""); |
|
2643 } |
|
2644 else |
|
2645 error ("ignore_function_time_stamp: expecting argument to be character string"); |
|
2646 } |
|
2647 else if (nargin > 1) |
5823
|
2648 print_usage (); |
5794
|
2649 |
|
2650 return retval; |
3016
|
2651 } |
|
2652 |
1
|
2653 /* |
|
2654 ;;; Local Variables: *** |
|
2655 ;;; mode: C++ *** |
|
2656 ;;; End: *** |
|
2657 */ |