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