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