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