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