Mercurial > octave-nkf
annotate src/variables.cc @ 7586:84122fb29c75
whos: handle index expressions
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 12 Mar 2008 21:17:07 -0400 |
parents | c9a476b1e664 |
children | ec78d83a7fde |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, |
4 2003, 2004, 2005, 2006, 2007 John W. Eaton | |
1 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
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 |
7336 | 31 #include <iomanip> |
4207 | 32 #include <set> |
1728 | 33 #include <string> |
34 | |
2926 | 35 #include "file-stat.h" |
36 #include "oct-env.h" | |
4604 | 37 #include "file-ops.h" |
2926 | 38 #include "glob-match.h" |
1755 | 39 #include "str-vec.h" |
40 | |
2492 | 41 #include <defaults.h> |
4435 | 42 #include "Cell.h" |
1352 | 43 #include "defun.h" |
44 #include "dirfns.h" | |
45 #include "error.h" | |
2205 | 46 #include "gripes.h" |
1352 | 47 #include "help.h" |
3165 | 48 #include "input.h" |
1352 | 49 #include "lex.h" |
5832 | 50 #include "load-path.h" |
2926 | 51 #include "oct-map.h" |
52 #include "oct-obj.h" | |
53 #include "ov.h" | |
3933 | 54 #include "ov-usr-fcn.h" |
605 | 55 #include "pager.h" |
1352 | 56 #include "parse.h" |
2926 | 57 #include "symtab.h" |
2205 | 58 #include "toplev.h" |
1352 | 59 #include "unwind-prot.h" |
1 | 60 #include "utils.h" |
1352 | 61 #include "variables.h" |
2205 | 62 |
63 // Should Octave always check to see if function files have changed | |
64 // since they were last compiled? | |
5794 | 65 static int Vignore_function_time_stamp = 1; |
2205 | 66 |
7336 | 67 // Defines layout for the whos/who -long command |
68 static std::string Vwhos_line_format | |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
69 = " %a:4; %ln:6; %cs:16:6:1; %rb:12; %lc:-1;\n"; |
195 | 70 |
6068 | 71 void |
6072 | 72 clear_mex_functions (void) |
6068 | 73 { |
7336 | 74 symbol_table::clear_mex_functions (); |
75 } | |
76 | |
77 void | |
78 clear_function (const std::string& nm) | |
79 { | |
80 symbol_table::clear_function (nm); | |
81 } | |
82 | |
83 void | |
84 clear_variable (const std::string& nm) | |
85 { | |
86 symbol_table::clear_variable (nm); | |
87 } | |
88 | |
89 void | |
90 clear_symbol (const std::string& nm) | |
91 { | |
92 symbol_table::clear_symbol (nm); | |
6068 | 93 } |
94 | |
593 | 95 // Attributes of variables and functions. |
96 | |
4208 | 97 // Is this a command-style function? |
593 | 98 |
4208 | 99 static std::set <std::string> command_set; |
4207 | 100 |
7336 | 101 void |
4208 | 102 mark_as_command (const std::string& s) |
4207 | 103 { |
4208 | 104 command_set.insert (s); |
4207 | 105 } |
106 | |
107 static inline void | |
4208 | 108 unmark_command (const std::string& s) |
4207 | 109 { |
4208 | 110 command_set.erase (s); |
4207 | 111 } |
112 | |
4208 | 113 DEFCMD (mark_as_command, args, , |
4207 | 114 "-*- texinfo -*-\n\ |
4208 | 115 @deftypefn {Built-in Function} {} mark_as_command (@var{name})\n\ |
116 Enter @var{name} into the list of commands.\n\ | |
5642 | 117 @seealso{unmark_command, iscommand}\n\ |
118 @end deftypefn") | |
4207 | 119 { |
120 octave_value_list retval; | |
121 | |
7336 | 122 if (symbol_table::at_top_level ()) |
4208 | 123 { |
124 int nargin = args.length (); | |
4207 | 125 |
4208 | 126 if (nargin > 0) |
127 { | |
128 int argc = nargin + 1; | |
4207 | 129 |
4208 | 130 string_vector argv = args.make_argv ("mark_as_command"); |
4207 | 131 |
4208 | 132 if (! error_state) |
133 { | |
134 for (int i = 1; i < argc; i++) | |
135 mark_as_command (argv[i]); | |
136 } | |
4207 | 137 } |
4208 | 138 else |
5823 | 139 print_usage (); |
4207 | 140 } |
141 else | |
4208 | 142 warning ("mark_as_command: invalid use inside function body"); |
4207 | 143 |
144 return retval; | |
145 } | |
146 | |
4208 | 147 DEFCMD (unmark_command, args, , |
4207 | 148 "-*- texinfo -*-\n\ |
5102 | 149 @deftypefn {Built-in Function} {} unmark_command (@var{name})\n\ |
4208 | 150 Remove @var{name} from the list of commands.\n\ |
5642 | 151 @seealso{mark_as_command, iscommand}\n\ |
152 @end deftypefn") | |
4207 | 153 { |
154 octave_value_list retval; | |
155 | |
7336 | 156 if (symbol_table::at_top_level ()) |
4208 | 157 { |
158 int nargin = args.length (); | |
4207 | 159 |
4208 | 160 if (nargin > 0) |
161 { | |
162 int argc = nargin + 1; | |
4207 | 163 |
4208 | 164 string_vector argv = args.make_argv ("unmark_command"); |
4207 | 165 |
4208 | 166 if (! error_state) |
167 { | |
168 for (int i = 1; i < argc; i++) | |
169 unmark_command (argv[i]); | |
170 } | |
4207 | 171 } |
4208 | 172 else |
5823 | 173 print_usage (); |
4207 | 174 } |
175 else | |
4208 | 176 warning ("mark_as_command: invalid use inside function body"); |
4207 | 177 |
178 return retval; | |
179 } | |
180 | |
1827 | 181 bool |
4208 | 182 is_command_name (const std::string& s) |
593 | 183 { |
7336 | 184 return command_set.find (s) != command_set.end (); |
593 | 185 } |
186 | |
7336 | 187 |
5102 | 188 DEFCMD (iscommand, args, , |
189 "-*- texinfo -*-\n\ | |
190 @deftypefn {Built-in Function} {} iscommand (@var{name})\n\ | |
191 Return true if @var{name} is a command style function. If @var{name}\n\ | |
192 is omitted, return a list of identifiers which are marked as commands with\n\ | |
6637 | 193 @code{mark_as_command}.\n\ |
5642 | 194 @seealso{mark_as_command, unmark_command}\n\ |
195 @end deftypefn") | |
5102 | 196 { |
197 octave_value retval; | |
198 | |
199 int nargin = args.length (); | |
200 | |
201 if (nargin == 0) | |
202 { | |
203 string_vector lst (command_set.size ()); | |
204 | |
205 int i = 0; | |
206 for (std::set<std::string>::const_iterator p = command_set.begin (); | |
207 p != command_set.end (); p++) | |
208 lst[i++] = *p; | |
209 | |
210 retval = Cell (lst.qsort ()); | |
211 } | |
212 else if (nargin == 1) | |
213 { | |
214 string_vector argv = args.make_argv ("iscommand"); | |
215 | |
216 if (! error_state) | |
217 { | |
218 std::string s = argv[1]; | |
219 retval = is_command_name(s); | |
220 } | |
221 } | |
222 else | |
5823 | 223 print_usage (); |
5102 | 224 |
225 return retval; | |
226 } | |
227 | |
228 // Is this a raw input command? | |
229 | |
230 static std::set <std::string> rawcommand_set; | |
231 | |
5685 | 232 void |
5102 | 233 mark_as_rawcommand (const std::string& s) |
234 { | |
235 command_set.insert (s); | |
236 rawcommand_set.insert (s); | |
237 } | |
238 | |
5685 | 239 void |
5102 | 240 unmark_rawcommand (const std::string& s) |
241 { | |
242 rawcommand_set.erase (s); | |
243 } | |
244 | |
245 DEFCMD (mark_as_rawcommand, args, , | |
246 "-*- texinfo -*-\n\ | |
247 @deftypefn {Built-in Function} {} mark_as_rawcommand (@var{name})\n\ | |
248 Enter @var{name} into the list of raw input commands and to the list of\n\ | |
249 command style functions.\n\ | |
250 Raw input commands are like normal command style functions, but they\n\ | |
251 receive their input unprocessed (ie. strings still contain the quotes\n\ | |
252 and escapes they had when input). However, comments and continuations\n\ | |
253 are handled as usual, you cannot pass a token starting with a comment\n\ | |
254 character ('#' or '%') to your function, and the last token cannot be\n\ | |
255 a continuation token ('\\' or '...').\n\ | |
5642 | 256 @seealso{unmark_rawcommand, israwcommand, iscommand, mark_as_command}\n\ |
257 @end deftypefn") | |
5102 | 258 { |
259 octave_value_list retval; | |
260 | |
7336 | 261 if (symbol_table::at_top_level ()) |
5102 | 262 { |
263 int nargin = args.length (); | |
264 | |
265 if (nargin > 0) | |
266 { | |
267 int argc = nargin + 1; | |
268 | |
269 string_vector argv = args.make_argv ("mark_as_rawcommand"); | |
270 | |
271 if (! error_state) | |
272 { | |
273 for (int i = 1; i < argc; i++) | |
274 mark_as_rawcommand (argv[i]); | |
275 } | |
276 } | |
277 else | |
5823 | 278 print_usage (); |
5102 | 279 } |
280 else | |
281 warning ("mark_as_rawcommand: invalid use inside function body"); | |
282 | |
283 return retval; | |
284 } | |
285 | |
286 DEFCMD (unmark_rawcommand, args, , | |
287 "-*- texinfo -*-\n\ | |
288 @deftypefn {Built-in Function} {} unmark_rawcommand (@var{name})\n\ | |
289 Remove @var{name} from the list of raw input commands.\n\ | |
290 Note that this does not remove @var{name} from the list of command style\n\ | |
291 functions.\n\ | |
5642 | 292 @seealso{mark_as_rawcommand, israwcommand, iscommand, unmark_command}\n\ |
293 @end deftypefn") | |
5102 | 294 { |
295 octave_value_list retval; | |
296 | |
7336 | 297 if (symbol_table::at_top_level ()) |
5102 | 298 { |
299 int nargin = args.length (); | |
300 | |
301 if (nargin > 0) | |
302 { | |
303 int argc = nargin + 1; | |
304 | |
305 string_vector argv = args.make_argv ("unmark_rawcommand"); | |
306 | |
307 if (! error_state) | |
308 { | |
309 for (int i = 1; i < argc; i++) | |
310 unmark_rawcommand (argv[i]); | |
311 } | |
312 } | |
313 else | |
5823 | 314 print_usage (); |
5102 | 315 } |
316 else | |
317 warning ("unmark_rawcommand: invalid use inside function body"); | |
318 | |
319 return retval; | |
320 } | |
321 | |
322 bool | |
323 is_rawcommand_name (const std::string& s) | |
324 { | |
7336 | 325 return rawcommand_set.find (s) != rawcommand_set.end (); |
5102 | 326 } |
327 | |
328 DEFCMD (israwcommand, args, , | |
329 "-*- texinfo -*-\n\ | |
330 @deftypefn {Built-in Function} {} israwcommand (@var{name})\n\ | |
331 Return true if @var{name} is a raw input command function.\n\ | |
332 If @var{name} is omitted, return a list of identifiers which are marked as\n\ | |
333 raw input commands with mark_as_rawcommand.\n\ | |
5642 | 334 @seealso{mark_as_rawcommand, unmark_rawcommand}\n\ |
335 @end deftypefn") | |
5102 | 336 { |
337 octave_value retval; | |
338 | |
339 int nargin = args.length (); | |
340 | |
341 if (nargin == 0) | |
342 { | |
343 string_vector lst (rawcommand_set.size()); | |
344 | |
345 int i = 0; | |
346 for (std::set<std::string>::const_iterator p = rawcommand_set.begin (); | |
347 p != rawcommand_set.end (); | |
348 p++) | |
349 lst[i++] = *p; | |
350 | |
351 retval = Cell (lst.qsort ()); | |
352 } | |
353 else if (nargin == 1) | |
354 { | |
355 string_vector argv = args.make_argv ("israwcommand"); | |
356 | |
357 if (! error_state) | |
358 { | |
359 std::string s = argv[1]; | |
360 retval = is_rawcommand_name(s); | |
361 } | |
362 } | |
363 else | |
5823 | 364 print_usage (); |
5102 | 365 |
366 return retval; | |
367 } | |
368 | |
2086 | 369 // Is this octave_value a valid function? |
593 | 370 |
2975 | 371 octave_function * |
4345 | 372 is_valid_function (const std::string& fcn_name, |
373 const std::string& warn_for, bool warn) | |
593 | 374 { |
2975 | 375 octave_function *ans = 0; |
593 | 376 |
1755 | 377 if (! fcn_name.empty ()) |
3618 | 378 { |
7336 | 379 octave_value val = symbol_table::find_function (fcn_name); |
380 | |
381 if (val.is_defined ()) | |
382 ans = val.function_value (true); | |
3618 | 383 } |
593 | 384 |
7336 | 385 if (! ans && warn) |
386 error ("%s: the symbol `%s' is not valid as a function", | |
387 warn_for.c_str (), fcn_name.c_str ()); | |
593 | 388 |
389 return ans; | |
390 } | |
391 | |
2975 | 392 octave_function * |
4345 | 393 is_valid_function (const octave_value& arg, |
394 const std::string& warn_for, bool warn) | |
3178 | 395 { |
396 octave_function *ans = 0; | |
397 | |
3523 | 398 std::string fcn_name; |
3178 | 399 |
400 if (arg.is_string ()) | |
4700 | 401 { |
402 fcn_name = arg.string_value (); | |
3178 | 403 |
4700 | 404 if (! error_state) |
405 ans = is_valid_function (fcn_name, warn_for, warn); | |
406 else if (warn) | |
407 error ("%s: expecting function name as argument", warn_for.c_str ()); | |
408 } | |
3178 | 409 else if (warn) |
410 error ("%s: expecting function name as argument", warn_for.c_str ()); | |
411 | |
412 return ans; | |
413 } | |
414 | |
415 octave_function * | |
3523 | 416 extract_function (const octave_value& arg, const std::string& warn_for, |
417 const std::string& fname, const std::string& header, | |
418 const std::string& trailer) | |
2796 | 419 { |
2975 | 420 octave_function *retval = 0; |
2796 | 421 |
422 retval = is_valid_function (arg, warn_for, 0); | |
423 | |
424 if (! retval) | |
425 { | |
3523 | 426 std::string s = arg.string_value (); |
2796 | 427 |
3523 | 428 std::string cmd = header; |
2796 | 429 cmd.append (s); |
430 cmd.append (trailer); | |
431 | |
432 if (! error_state) | |
433 { | |
434 int parse_status; | |
435 | |
2898 | 436 eval_string (cmd, true, parse_status); |
2796 | 437 |
438 if (parse_status == 0) | |
439 { | |
440 retval = is_valid_function (fname, warn_for, 0); | |
441 | |
442 if (! retval) | |
443 { | |
444 error ("%s: `%s' is not valid as a function", | |
445 warn_for.c_str (), fname.c_str ()); | |
446 return retval; | |
447 } | |
448 } | |
449 else | |
450 error ("%s: `%s' is not valid as a function", | |
451 warn_for.c_str (), fname.c_str ()); | |
452 } | |
453 else | |
454 error ("%s: expecting first argument to be a string", | |
455 warn_for.c_str ()); | |
456 } | |
457 | |
458 return retval; | |
459 } | |
460 | |
2921 | 461 string_vector |
3523 | 462 get_struct_elts (const std::string& text) |
2921 | 463 { |
464 int n = 1; | |
465 | |
466 size_t pos = 0; | |
467 | |
468 size_t len = text.length (); | |
469 | |
470 while ((pos = text.find ('.', pos)) != NPOS) | |
471 { | |
472 if (++pos == len) | |
473 break; | |
474 | |
475 n++; | |
476 } | |
477 | |
478 string_vector retval (n); | |
479 | |
480 pos = 0; | |
481 | |
482 for (int i = 0; i < n; i++) | |
483 { | |
4587 | 484 len = text.find ('.', pos); |
2921 | 485 |
486 if (len != NPOS) | |
487 len -= pos; | |
488 | |
489 retval[i] = text.substr (pos, len); | |
490 | |
491 if (len != NPOS) | |
492 pos += len + 1; | |
493 } | |
494 | |
495 return retval; | |
496 } | |
497 | |
4179 | 498 static inline bool |
499 is_variable (const std::string& name) | |
500 { | |
501 bool retval = false; | |
502 | |
503 if (! name.empty ()) | |
504 { | |
7336 | 505 octave_value val = symbol_table::varval (name); |
506 | |
507 retval = val.is_defined (); | |
4179 | 508 } |
509 | |
510 return retval; | |
511 } | |
512 | |
2921 | 513 string_vector |
3933 | 514 generate_struct_completions (const std::string& text, |
515 std::string& prefix, std::string& hint) | |
2921 | 516 { |
517 string_vector names; | |
518 | |
519 size_t pos = text.rfind ('.'); | |
520 | |
3933 | 521 if (pos != NPOS) |
2921 | 522 { |
523 if (pos == text.length ()) | |
524 hint = ""; | |
525 else | |
526 hint = text.substr (pos+1); | |
527 | |
528 prefix = text.substr (0, pos); | |
529 | |
4179 | 530 std::string base_name = prefix; |
531 | |
532 pos = base_name.find_first_of ("{(."); | |
2921 | 533 |
4179 | 534 if (pos != NPOS) |
535 base_name = base_name.substr (0, pos); | |
4143 | 536 |
4179 | 537 if (is_variable (base_name)) |
538 { | |
539 int parse_status; | |
540 | |
541 unwind_protect::begin_frame ("generate_struct_completions"); | |
3935 | 542 |
4452 | 543 unwind_protect_int (error_state); |
544 unwind_protect_int (warning_state); | |
545 | |
4179 | 546 unwind_protect_bool (discard_error_messages); |
4452 | 547 unwind_protect_bool (discard_warning_messages); |
3935 | 548 |
4179 | 549 discard_error_messages = true; |
4452 | 550 discard_warning_messages = true; |
2921 | 551 |
4179 | 552 octave_value tmp = eval_string (prefix, true, parse_status); |
553 | |
554 unwind_protect::run_frame ("generate_struct_completions"); | |
3935 | 555 |
4179 | 556 if (tmp.is_defined () && tmp.is_map ()) |
557 names = tmp.map_keys (); | |
558 } | |
559 } | |
2921 | 560 |
561 return names; | |
562 } | |
563 | |
5775 | 564 // FIXME -- this will have to be much smarter to work |
4179 | 565 // "correctly". |
566 | |
2921 | 567 bool |
3523 | 568 looks_like_struct (const std::string& text) |
2921 | 569 { |
4604 | 570 bool retval = (! text.empty () |
571 && text != "." | |
572 && text.find_first_of (file_ops::dir_sep_chars) == NPOS | |
573 && text.find ("..") == NPOS | |
574 && text.rfind ('.') != NPOS); | |
3968 | 575 |
4179 | 576 #if 0 |
3968 | 577 symbol_record *sr = curr_sym_tab->lookup (text); |
2963 | 578 |
3968 | 579 if (sr && ! sr->is_function ()) |
580 { | |
581 int parse_status; | |
2921 | 582 |
4143 | 583 unwind_protect::begin_frame ("looks_like_struct"); |
584 | |
585 unwind_protect_bool (discard_error_messages); | |
586 unwind_protect_int (error_state); | |
587 | |
588 discard_error_messages = true; | |
589 | |
3968 | 590 octave_value tmp = eval_string (text, true, parse_status); |
591 | |
4143 | 592 unwind_protect::run_frame ("looks_like_struct"); |
593 | |
3968 | 594 retval = (tmp.is_defined () && tmp.is_map ()); |
595 } | |
4179 | 596 #endif |
3968 | 597 |
598 return retval; | |
2921 | 599 } |
2796 | 600 |
5930 | 601 static octave_value |
602 do_isglobal (const octave_value_list& args) | |
593 | 603 { |
4233 | 604 octave_value retval = false; |
593 | 605 |
712 | 606 int nargin = args.length (); |
607 | |
608 if (nargin != 1) | |
593 | 609 { |
5823 | 610 print_usage (); |
593 | 611 return retval; |
612 } | |
613 | |
3523 | 614 std::string name = args(0).string_value (); |
593 | 615 |
636 | 616 if (error_state) |
617 { | |
4028 | 618 error ("isglobal: expecting std::string argument"); |
636 | 619 return retval; |
620 } | |
621 | |
7336 | 622 return symbol_table::is_global (name); |
593 | 623 } |
624 | |
5930 | 625 DEFUN (isglobal, args, , |
626 "-*- texinfo -*-\n\ | |
627 @deftypefn {Built-in Function} {} isglobal (@var{name})\n\ | |
628 Return 1 if @var{name} is globally visible. Otherwise, return 0. For\n\ | |
629 example,\n\ | |
630 \n\ | |
631 @example\n\ | |
632 @group\n\ | |
633 global x\n\ | |
634 isglobal (\"x\")\n\ | |
635 @result{} 1\n\ | |
636 @end group\n\ | |
637 @end example\n\ | |
638 @end deftypefn") | |
639 { | |
640 return do_isglobal (args); | |
641 } | |
642 | |
643 DEFUN (is_global, args, , | |
644 "-*- texinfo -*-\n\ | |
645 @deftypefn {Built-in Function} {} isglobal (@var{name})\n\ | |
646 This function has been deprecated. Use isglobal instead.\n\ | |
647 @end deftypefn") | |
648 { | |
649 return do_isglobal (args); | |
650 } | |
651 | |
4016 | 652 int |
653 symbol_exist (const std::string& name, const std::string& type) | |
593 | 654 { |
4016 | 655 int retval = 0; |
636 | 656 |
3523 | 657 std::string struct_elts; |
658 std::string symbol_name = name; | |
1755 | 659 |
660 size_t pos = name.find ('.'); | |
661 | |
2790 | 662 if (pos != NPOS && pos > 0) |
1277 | 663 { |
1755 | 664 struct_elts = name.substr (pos+1); |
2790 | 665 symbol_name = name.substr (0, pos); |
1277 | 666 } |
667 | |
4009 | 668 // We shouldn't need to look in the global symbol table, since any |
669 // name that is visible in the current scope will be in the local | |
670 // symbol table. | |
671 | |
7336 | 672 octave_value_list evaluated_args; |
673 bool args_evaluated; | |
674 | |
675 octave_value val = symbol_table::find (symbol_name, 0, string_vector (), | |
676 evaluated_args, args_evaluated); | |
677 | |
678 if (val.is_defined ()) | |
1277 | 679 { |
4357 | 680 bool not_a_struct = struct_elts.empty (); |
7336 | 681 bool var_ok = not_a_struct /* || val.is_map_element (struct_elts) */; |
4357 | 682 |
4016 | 683 if (! retval |
4357 | 684 && var_ok |
4016 | 685 && (type == "any" || type == "var") |
7336 | 686 && val.is_constant ()) |
4009 | 687 { |
4016 | 688 retval = 1; |
4009 | 689 } |
4016 | 690 |
691 if (! retval | |
692 && (type == "any" || type == "builtin")) | |
4009 | 693 { |
7336 | 694 if (not_a_struct && val.is_builtin_function ()) |
4016 | 695 { |
696 retval = 5; | |
697 } | |
4009 | 698 } |
4016 | 699 |
700 if (! retval | |
4357 | 701 && not_a_struct |
4016 | 702 && (type == "any" || type == "file") |
7336 | 703 && (val.is_user_function () || val.is_dld_function ())) |
4009 | 704 { |
7336 | 705 octave_function *f = val.function_value (true); |
4016 | 706 std::string s = f ? f->fcn_file_name () : std::string (); |
707 | |
7336 | 708 retval = s.empty () ? 103 : (val.is_user_function () ? 2 : 3); |
4009 | 709 } |
1421 | 710 } |
4016 | 711 |
5140 | 712 if (! (type == "var" || type == "builtin")) |
593 | 713 { |
5140 | 714 if (! retval) |
593 | 715 { |
5484 | 716 std::string file_name = lookup_autoload (name); |
717 | |
718 if (file_name.empty ()) | |
5832 | 719 file_name = load_path::find_fcn (name); |
5140 | 720 |
721 size_t len = file_name.length (); | |
722 | |
5832 | 723 if (len > 0) |
4437 | 724 { |
5140 | 725 if (type == "any" || type == "file") |
726 { | |
5864 | 727 if (len > 4 && (file_name.substr (len-4) == ".oct" |
728 || file_name.substr (len-4) == ".mex")) | |
5140 | 729 retval = 3; |
730 else | |
731 retval = 2; | |
732 } | |
4437 | 733 } |
593 | 734 } |
5140 | 735 |
736 if (! retval) | |
593 | 737 { |
5140 | 738 std::string file_name = file_in_path (name, ""); |
739 | |
740 if (file_name.empty ()) | |
741 file_name = name; | |
742 | |
743 file_stat fs (file_name); | |
744 | |
745 if (fs) | |
1421 | 746 { |
5140 | 747 if ((type == "any" || type == "file") |
748 && fs.is_reg ()) | |
749 { | |
750 retval = 2; | |
751 } | |
752 else if ((type == "any" || type == "dir") | |
753 && fs.is_dir ()) | |
754 { | |
755 retval = 7; | |
756 } | |
1421 | 757 } |
593 | 758 } |
759 } | |
760 | |
761 return retval; | |
762 } | |
763 | |
4962 | 764 #define GET_IDX(LEN) \ |
765 static_cast<int> ((LEN-1) * static_cast<double> (rand ()) / RAND_MAX) | |
766 | |
4954 | 767 std::string |
768 unique_symbol_name (const std::string& basename) | |
769 { | |
4962 | 770 static const std::string alpha |
771 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
772 | |
773 static size_t len = alpha.length (); | |
774 | |
775 std::string nm = basename + alpha[GET_IDX (len)]; | |
776 | |
777 size_t pos = nm.length (); | |
778 | |
779 if (nm.substr (0, 2) == "__") | |
780 nm.append ("__"); | |
781 | |
782 while (symbol_exist (nm, "any")) | |
783 nm.insert (pos++, 1, alpha[GET_IDX (len)]); | |
784 | |
785 return nm; | |
4954 | 786 } |
787 | |
4016 | 788 DEFUN (exist, args, , |
789 "-*- texinfo -*-\n\ | |
790 @deftypefn {Built-in Function} {} exist (@var{name}, @var{type})\n\ | |
791 Return 1 if the name exists as a variable, 2 if the name (after\n\ | |
5814 | 792 appending @samp{.m}) is a function file in Octave's @code{path}, 3 if the\n\ |
5864 | 793 name is a @samp{.oct} or @samp{.mex} file in Octave's @code{path},\n\ |
794 5 if the name is a built-in function, 7 if the name is a directory, or 103\n\ | |
4016 | 795 if the name is a function not associated with a file (entered on\n\ |
796 the command line).\n\ | |
797 \n\ | |
798 Otherwise, return 0.\n\ | |
799 \n\ | |
800 This function also returns 2 if a regular file called @var{name}\n\ | |
5814 | 801 exists in Octave's search path. If you want information about\n\ |
4016 | 802 other types of files, you should use some combination of the functions\n\ |
803 @code{file_in_path} and @code{stat} instead.\n\ | |
804 \n\ | |
805 If the optional argument @var{type} is supplied, check only for\n\ | |
806 symbols of the specified type. Valid types are\n\ | |
807 \n\ | |
808 @table @samp\n\ | |
809 @item \"var\"\n\ | |
810 Check only for variables.\n\ | |
811 @item \"builtin\"\n\ | |
812 Check only for built-in functions.\n\ | |
813 @item \"file\"\n\ | |
814 Check only for files.\n\ | |
815 @item \"dir\"\n\ | |
816 Check only for directories.\n\ | |
817 @end table\n\ | |
818 @end deftypefn") | |
819 { | |
4233 | 820 octave_value retval = false; |
4016 | 821 |
822 int nargin = args.length (); | |
823 | |
824 if (nargin == 1 || nargin == 2) | |
825 { | |
826 std::string name = args(0).string_value (); | |
827 | |
828 if (! error_state) | |
829 { | |
830 std::string type | |
831 = (nargin == 2) ? args(1).string_value () : std::string ("any"); | |
832 | |
833 if (! error_state) | |
4233 | 834 retval = symbol_exist (name, type); |
4016 | 835 else |
836 error ("exist: expecting second argument to be a string"); | |
837 } | |
838 else | |
839 error ("exist: expecting first argument to be a string"); | |
840 } | |
841 else | |
5823 | 842 print_usage (); |
4016 | 843 |
844 return retval; | |
845 } | |
846 | |
2849 | 847 octave_value |
4988 | 848 lookup_function_handle (const std::string& nm) |
849 { | |
7336 | 850 octave_value val = symbol_table::varval (nm); |
851 | |
852 return val.is_function_handle () ? val : octave_value (); | |
4988 | 853 } |
854 | |
855 octave_value | |
5027 | 856 get_global_value (const std::string& nm, bool silent) |
2849 | 857 { |
7336 | 858 octave_value val = symbol_table::varval (nm, symbol_table::global_scope ()); |
859 | |
860 if (val.is_undefined () && ! silent) | |
861 error ("get_global_by_name: undefined symbol `%s'", nm.c_str ()); | |
862 | |
863 return val; | |
2849 | 864 } |
865 | |
866 void | |
3523 | 867 set_global_value (const std::string& nm, const octave_value& val) |
2849 | 868 { |
7336 | 869 symbol_table::varref (nm, symbol_table::global_scope ()) = val; |
2849 | 870 } |
871 | |
593 | 872 // Variable values. |
195 | 873 |
5791 | 874 octave_value |
875 set_internal_variable (bool& var, const octave_value_list& args, | |
5794 | 876 int nargout, const char *nm) |
5791 | 877 { |
5794 | 878 octave_value retval; |
879 | |
5800 | 880 int nargin = args.length (); |
881 | |
882 if (nargout > 0 || nargin == 0) | |
5794 | 883 retval = var; |
5791 | 884 |
885 if (nargin == 1) | |
886 { | |
887 bool bval = args(0).bool_value (); | |
888 | |
889 if (! error_state) | |
890 var = bval; | |
891 else | |
892 error ("%s: expecting arg to be a logical value", nm); | |
893 } | |
894 else if (nargin > 1) | |
5823 | 895 print_usage (); |
5791 | 896 |
897 return retval; | |
898 } | |
899 | |
900 octave_value | |
5794 | 901 set_internal_variable (char& var, const octave_value_list& args, |
902 int nargout, const char *nm) | |
5791 | 903 { |
5794 | 904 octave_value retval; |
905 | |
5800 | 906 int nargin = args.length (); |
907 | |
908 if (nargout > 0 || nargin == 0) | |
5794 | 909 retval = var; |
5791 | 910 |
911 if (nargin == 1) | |
912 { | |
913 std::string sval = args(0).string_value (); | |
914 | |
915 if (! error_state) | |
5794 | 916 { |
917 switch (sval.length ()) | |
918 { | |
919 case 1: | |
920 var = sval[0]; | |
921 break; | |
922 | |
923 case 0: | |
924 var = '\0'; | |
925 break; | |
926 | |
927 default: | |
928 error ("%s: argument must be a single character", nm); | |
929 break; | |
930 } | |
931 } | |
932 else | |
933 error ("%s: argument must be a single character", nm); | |
934 } | |
935 else if (nargin > 1) | |
5823 | 936 print_usage (); |
5794 | 937 |
938 return retval; | |
939 } | |
940 | |
941 octave_value | |
942 set_internal_variable (int& var, const octave_value_list& args, | |
943 int nargout, const char *nm, | |
944 int minval, int maxval) | |
945 { | |
946 octave_value retval; | |
947 | |
5800 | 948 int nargin = args.length (); |
949 | |
950 if (nargout > 0 || nargin == 0) | |
5794 | 951 retval = var; |
952 | |
953 if (nargin == 1) | |
954 { | |
955 int ival = args(0).int_value (); | |
956 | |
957 if (! error_state) | |
958 { | |
959 if (ival < minval) | |
960 error ("%s: expecting arg to be greater than %d", minval); | |
961 else if (ival > maxval) | |
962 error ("%s: expecting arg to be less than or equal to %d", maxval); | |
963 else | |
964 var = ival; | |
965 } | |
966 else | |
967 error ("%s: expecting arg to be an integer value", nm); | |
968 } | |
969 else if (nargin > 1) | |
5823 | 970 print_usage (); |
5794 | 971 |
972 return retval; | |
973 } | |
974 | |
975 octave_value | |
976 set_internal_variable (double& var, const octave_value_list& args, | |
977 int nargout, const char *nm, | |
978 double minval, double maxval) | |
979 { | |
980 octave_value retval; | |
981 | |
5800 | 982 int nargin = args.length (); |
983 | |
984 if (nargout > 0 || nargin == 0) | |
5794 | 985 retval = var; |
986 | |
987 if (nargin == 1) | |
988 { | |
989 double dval = args(0).scalar_value (); | |
990 | |
991 if (! error_state) | |
992 { | |
993 if (dval < minval) | |
994 error ("%s: expecting arg to be greater than %g", minval); | |
995 else if (dval > maxval) | |
996 error ("%s: expecting arg to be less than or equal to %g", maxval); | |
997 else | |
998 var = dval; | |
999 } | |
1000 else | |
1001 error ("%s: expecting arg to be a scalar value", nm); | |
1002 } | |
1003 else if (nargin > 1) | |
5823 | 1004 print_usage (); |
5794 | 1005 |
1006 return retval; | |
1007 } | |
1008 | |
1009 octave_value | |
1010 set_internal_variable (std::string& var, const octave_value_list& args, | |
1011 int nargout, const char *nm, bool empty_ok) | |
1012 { | |
1013 octave_value retval; | |
1014 | |
5800 | 1015 int nargin = args.length (); |
1016 | |
1017 if (nargout > 0 || nargin == 0) | |
5794 | 1018 retval = var; |
1019 | |
1020 if (nargin == 1) | |
1021 { | |
1022 std::string sval = args(0).string_value (); | |
1023 | |
1024 if (! error_state) | |
1025 { | |
1026 if (empty_ok || ! sval.empty ()) | |
1027 var = sval; | |
1028 else | |
1029 error ("%s: value must not be empty", nm); | |
1030 } | |
5791 | 1031 else |
1032 error ("%s: expecting arg to be a character string", nm); | |
1033 } | |
1034 else if (nargin > 1) | |
5823 | 1035 print_usage (); |
1 | 1036 |
1037 return retval; | |
1038 } | |
1039 | |
7336 | 1040 struct |
1041 whos_parameter | |
195 | 1042 { |
7336 | 1043 char command; |
1044 char modifier; | |
1045 int parameter_length; | |
1046 int first_parameter_length; | |
1047 int balance; | |
1048 std::string text; | |
1049 std::string line; | |
1050 }; | |
1051 | |
1052 static void | |
1053 print_descriptor (std::ostream& os, std::list<whos_parameter> params) | |
1054 { | |
1055 // This method prints a line of information on a given symbol | |
1056 std::list<whos_parameter>::iterator i = params.begin (); | |
1057 std::ostringstream param_buf; | |
1058 | |
1059 while (i != params.end ()) | |
195 | 1060 { |
7336 | 1061 whos_parameter param = *i; |
1062 | |
1063 if (param.command != '\0') | |
1064 { | |
1065 // Do the actual printing | |
1066 switch (param.modifier) | |
1067 { | |
1068 case 'l': | |
1069 os << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); | |
1070 param_buf << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); | |
1071 break; | |
1072 | |
1073 case 'r': | |
1074 os << std::setiosflags (std::ios::right) << std::setw (param.parameter_length); | |
1075 param_buf << std::setiosflags (std::ios::right) << std::setw (param.parameter_length); | |
1076 break; | |
1077 | |
1078 case 'c': | |
1079 if (param.command != 's') | |
1080 { | |
1081 os << std::setiosflags (std::ios::left) | |
1082 << std::setw (param.parameter_length); | |
1083 param_buf << std::setiosflags (std::ios::left) | |
1084 << std::setw (param.parameter_length); | |
1085 } | |
1086 break; | |
1087 | |
1088 default: | |
1089 os << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); | |
1090 param_buf << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); | |
1091 } | |
1092 | |
1093 if (param.command == 's' && param.modifier == 'c') | |
1094 { | |
1095 int a, b; | |
1096 | |
1097 if (param.modifier == 'c') | |
1098 { | |
1099 a = param.first_parameter_length - param.balance; | |
1100 a = (a < 0 ? 0 : a); | |
1101 b = param.parameter_length - a - param.text . length (); | |
1102 b = (b < 0 ? 0 : b); | |
1103 os << std::setiosflags (std::ios::left) << std::setw (a) | |
1104 << "" << std::resetiosflags (std::ios::left) << param.text | |
1105 << std::setiosflags (std::ios::left) | |
1106 << std::setw (b) << "" | |
1107 << std::resetiosflags (std::ios::left); | |
1108 param_buf << std::setiosflags (std::ios::left) << std::setw (a) | |
1109 << "" << std::resetiosflags (std::ios::left) << param.line | |
1110 << std::setiosflags (std::ios::left) | |
1111 << std::setw (b) << "" | |
1112 << std::resetiosflags (std::ios::left); | |
1113 } | |
1114 } | |
1115 else | |
1116 { | |
1117 os << param.text; | |
1118 param_buf << param.line; | |
1119 } | |
1120 os << std::resetiosflags (std::ios::left) | |
1121 << std::resetiosflags (std::ios::right); | |
1122 param_buf << std::resetiosflags (std::ios::left) | |
1123 << std::resetiosflags (std::ios::right); | |
1124 i++; | |
1125 } | |
1126 else | |
2975 | 1127 { |
7336 | 1128 os << param.text; |
1129 param_buf << param.line; | |
1130 i++; | |
2975 | 1131 } |
195 | 1132 } |
7336 | 1133 |
1134 os << param_buf.str (); | |
195 | 1135 } |
1136 | |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1137 class |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1138 symbol_info_list |
593 | 1139 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1140 private: |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1141 struct symbol_info |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1142 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1143 symbol_info (const symbol_table::symbol_record& sr, |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1144 const std::string& expr_str = std::string (), |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1145 const octave_value& expr_val = octave_value ()) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1146 : name (expr_str.empty () ? sr.name () : expr_str), |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1147 is_automatic (sr.is_automatic ()), |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1148 is_formal (sr.is_formal ()), |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1149 is_global (sr.is_global ()), |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1150 is_persistent (sr.is_persistent ()), |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1151 varval (expr_val.is_undefined () ? sr.varval () : expr_val) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1152 { } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1153 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1154 void display_line (std::ostream& os, |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1155 const std::list<whos_parameter>& params) const |
593 | 1156 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1157 dim_vector dims = varval.dims (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1158 std::string dims_str = dims.str (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1159 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1160 std::list<whos_parameter>::const_iterator i = params.begin (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1161 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1162 while (i != params.end ()) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1163 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1164 whos_parameter param = *i; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1165 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1166 if (param.command != '\0') |
2294 | 1167 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1168 // Do the actual printing. |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1169 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1170 switch (param.modifier) |
2294 | 1171 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1172 case 'l': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1173 os << std::setiosflags (std::ios::left) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1174 << std::setw (param.parameter_length); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1175 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1176 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1177 case 'r': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1178 os << std::setiosflags (std::ios::right) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1179 << std::setw (param.parameter_length); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1180 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1181 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1182 case 'c': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1183 if (param.command == 's') |
7336 | 1184 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1185 int front = param.first_parameter_length |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1186 - dims_str.find ('x'); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1187 int back = param.parameter_length |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1188 - dims_str.length () |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1189 - front; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1190 front = (front > 0) ? front : 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1191 back = (back > 0) ? back : 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1192 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1193 os << std::setiosflags (std::ios::left) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1194 << std::setw (front) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1195 << "" |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1196 << std::resetiosflags (std::ios::left) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1197 << dims_str |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1198 << std::setiosflags (std::ios::left) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1199 << std::setw (back) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1200 << "" |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1201 << std::resetiosflags (std::ios::left); |
7336 | 1202 } |
2294 | 1203 else |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1204 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1205 os << std::setiosflags (std::ios::left) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1206 << std::setw (param.parameter_length); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1207 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1208 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1209 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1210 default: |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1211 error ("whos_line_format: modifier `%c' unknown", |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1212 param.modifier); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1213 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1214 os << std::setiosflags (std::ios::right) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1215 << std::setw (param.parameter_length); |
2294 | 1216 } |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1217 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1218 switch (param.command) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1219 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1220 case 'a': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1221 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1222 char tmp[5]; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1223 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1224 tmp[0] = (is_automatic ? 'a' : ' '); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1225 tmp[1] = (is_formal ? 'f' : ' '); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1226 tmp[2] = (is_global ? 'g' : ' '); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1227 tmp[3] = (is_persistent ? 'p' : ' '); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1228 tmp[4] = 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1229 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1230 os << tmp; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1231 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1232 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1233 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1234 case 'b': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1235 os << varval.byte_size (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1236 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1237 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1238 case 'c': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1239 os << varval.class_name (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1240 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1241 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1242 case 'e': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1243 os << varval.capacity (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1244 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1245 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1246 case 'n': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1247 os << name; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1248 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1249 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1250 case 's': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1251 if (param.modifier != 'c') |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1252 os << dims_str; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1253 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1254 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1255 case 't': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1256 os << varval.type_name (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1257 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1258 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1259 default: |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1260 error ("whos_line_format: command `%c' unknown", |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1261 param.command); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1262 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1263 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1264 os << std::resetiosflags (std::ios::left) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1265 << std::resetiosflags (std::ios::right); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1266 i++; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1267 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1268 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1269 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1270 os << param.text; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1271 i++; |
2294 | 1272 } |
593 | 1273 } |
1274 } | |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1275 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1276 std::string name; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1277 bool is_automatic; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1278 bool is_formal; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1279 bool is_global; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1280 bool is_persistent; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1281 octave_value varval; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1282 }; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1283 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1284 public: |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1285 symbol_info_list (void) : lst () { } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1286 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1287 symbol_info_list (const symbol_info_list& sil) : lst (sil.lst) { } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1288 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1289 symbol_info_list& operator = (const symbol_info_list& sil) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1290 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1291 if (this != &sil) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1292 lst = sil.lst; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1293 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1294 return *this; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1295 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1296 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1297 ~symbol_info_list (void) { } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1298 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1299 void append (const symbol_table::symbol_record& sr) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1300 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1301 lst.push_back (symbol_info (sr)); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1302 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1303 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1304 void append (const symbol_table::symbol_record& sr, |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1305 const std::string& expr_str, |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1306 const octave_value& expr_val) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1307 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1308 lst.push_back (symbol_info (sr, expr_str, expr_val)); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1309 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1310 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1311 size_t size (void) const { return lst.size (); } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1312 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1313 bool empty (void) const { return lst.empty (); } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1314 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1315 Octave_map |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1316 map_value (const std::string& caller_function_name, int nesting_level) const |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1317 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1318 size_t len = lst.size (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1319 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1320 Array<octave_value> name_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1321 Array<octave_value> size_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1322 Array<octave_value> bytes_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1323 Array<octave_value> class_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1324 Array<octave_value> global_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1325 Array<octave_value> sparse_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1326 Array<octave_value> complex_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1327 Array<octave_value> nesting_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1328 Array<octave_value> persistent_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1329 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1330 std::list<symbol_info>::const_iterator p = lst.begin (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1331 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1332 for (size_t j = 0; j < len; j++) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1333 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1334 const symbol_info& si = *p++; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1335 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1336 Octave_map ni; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1337 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1338 ni.assign ("function", caller_function_name); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1339 ni.assign ("level", nesting_level); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1340 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1341 name_info(j) = si.name; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1342 global_info(j) = si.is_global; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1343 persistent_info(j) = si.is_persistent; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1344 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1345 octave_value val = si.varval; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1346 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1347 size_info(j) = val.size (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1348 bytes_info(j) = val.byte_size (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1349 class_info(j) = val.class_name (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1350 sparse_info(j) = val.is_sparse_type (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1351 complex_info(j) = val.is_complex_type (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1352 nesting_info(j) = ni; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1353 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1354 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1355 Octave_map info; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1356 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1357 info.assign ("name", name_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1358 info.assign ("size", size_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1359 info.assign ("bytes", bytes_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1360 info.assign ("class", class_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1361 info.assign ("global", global_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1362 info.assign ("sparse", sparse_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1363 info.assign ("complex", complex_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1364 info.assign ("nesting", nesting_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1365 info.assign ("persistent", persistent_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1366 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1367 return info; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1368 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1369 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1370 void display (std::ostream& os) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1371 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1372 if (! lst.empty ()) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1373 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1374 size_t bytes = 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1375 size_t elements = 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1376 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1377 std::list<whos_parameter> params = parse_whos_line_format (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1378 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1379 print_descriptor (os, params); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1380 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1381 octave_stdout << "\n"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1382 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1383 for (std::list<symbol_info>::const_iterator p = lst.begin (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1384 p != lst.end (); p++) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1385 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1386 p->display_line (os, params); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1387 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1388 octave_value val = p->varval; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1389 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1390 elements += val.capacity (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1391 bytes += val.byte_size (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1392 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1393 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1394 os << "\nTotal is " << elements |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1395 << (elements == 1 ? " element" : " elements") |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1396 << " using " << bytes << (bytes == 1 ? " byte" : " bytes") |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1397 << "\n"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1398 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1399 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1400 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1401 // Parse the string whos_line_format, and return a parameter list, |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1402 // containing all information needed to print the given |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1403 // attributtes of the symbols. |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1404 std::list<whos_parameter> parse_whos_line_format (void) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1405 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1406 int idx; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1407 size_t format_len = Vwhos_line_format.length (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1408 char garbage; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1409 std::list<whos_parameter> params; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1410 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1411 size_t bytes1; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1412 int elements1; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1413 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1414 std::string param_string = "abcenst"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1415 Array<int> param_length (dim_vector (param_string.length (), 1)); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1416 Array<std::string> param_names (dim_vector (param_string.length (), 1)); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1417 size_t pos_a, pos_b, pos_c, pos_e, pos_n, pos_s, pos_t; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1418 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1419 pos_a = param_string.find ('a'); // Attributes |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1420 pos_b = param_string.find ('b'); // Bytes |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1421 pos_c = param_string.find ('c'); // Class |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1422 pos_e = param_string.find ('e'); // Elements |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1423 pos_n = param_string.find ('n'); // Name |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1424 pos_s = param_string.find ('s'); // Size |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1425 pos_t = param_string.find ('t'); // Type |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1426 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1427 param_names(pos_a) = "Attr"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1428 param_names(pos_b) = "Bytes"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1429 param_names(pos_c) = "Class"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1430 param_names(pos_e) = "Elements"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1431 param_names(pos_n) = "Name"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1432 param_names(pos_s) = "Size"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1433 param_names(pos_t) = "Type"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1434 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1435 for (size_t i = 0; i < param_string.length (); i++) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1436 param_length(i) = param_names(i) . length (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1437 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1438 // Calculating necessary spacing for name column, |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1439 // bytes column, elements column and class column |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1440 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1441 for (std::list<symbol_info>::const_iterator p = lst.begin (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1442 p != lst.end (); p++) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1443 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1444 std::stringstream ss1, ss2; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1445 std::string str; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1446 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1447 str = p->name; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1448 param_length(pos_n) = ((str.length () |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1449 > static_cast<size_t> (param_length(pos_n))) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1450 ? str.length () : param_length(pos_n)); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1451 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1452 octave_value val = p->varval; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1453 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1454 str = val.type_name (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1455 param_length(pos_t) = ((str.length () |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1456 > static_cast<size_t> (param_length(pos_t))) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1457 ? str.length () : param_length(pos_t)); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1458 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1459 elements1 = val.capacity (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1460 ss1 << elements1; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1461 str = ss1.str (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1462 param_length(pos_e) = ((str.length () |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1463 > static_cast<size_t> (param_length(pos_e))) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1464 ? str.length () : param_length(pos_e)); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1465 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1466 bytes1 = val.byte_size (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1467 ss2 << bytes1; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1468 str = ss2.str (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1469 param_length(pos_b) = ((str.length () |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1470 > static_cast<size_t> (param_length(pos_b))) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1471 ? str.length () : param_length (pos_b)); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1472 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1473 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1474 idx = 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1475 while (static_cast<size_t> (idx) < format_len) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1476 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1477 whos_parameter param; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1478 param.command = '\0'; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1479 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1480 if (Vwhos_line_format[idx] == '%') |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1481 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1482 bool error_encountered = false; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1483 param.modifier = 'r'; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1484 param.parameter_length = 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1485 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1486 int a = 0, b = -1, balance = 1; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1487 unsigned int items; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1488 size_t pos; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1489 std::string cmd; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1490 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1491 // Parse one command from whos_line_format |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1492 cmd = Vwhos_line_format.substr (idx, Vwhos_line_format.length ()); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1493 pos = cmd.find (';'); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1494 if (pos != NPOS) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1495 cmd = cmd.substr (0, pos+1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1496 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1497 error ("parameter without ; in whos_line_format"); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1498 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1499 idx += cmd.length (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1500 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1501 // FIXME -- use iostream functions instead of sscanf! |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1502 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1503 if (cmd.find_first_of ("crl") != 1) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1504 items = sscanf (cmd.c_str (), "%c%c:%d:%d:%d;", |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1505 &garbage, ¶m.command, &a, &b, &balance); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1506 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1507 items = sscanf (cmd.c_str (), "%c%c%c:%d:%d:%d;", |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1508 &garbage, ¶m.modifier, ¶m.command, |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1509 &a, &b, &balance) - 1; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1510 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1511 if (items < 2) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1512 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1513 error ("whos_line_format: parameter structure without command in whos_line_format"); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1514 error_encountered = true; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1515 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1516 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1517 // Insert data into parameter |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1518 param.first_parameter_length = 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1519 pos = param_string.find (param.command); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1520 if (pos != NPOS) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1521 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1522 param.parameter_length = param_length(pos); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1523 param.text = param_names(pos); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1524 param.line.assign (param_names(pos).length (), '='); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1525 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1526 param.parameter_length = (a > param.parameter_length |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1527 ? a : param.parameter_length); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1528 if (param.command == 's' && param.modifier == 'c' && b > 0) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1529 param.first_parameter_length = b; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1530 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1531 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1532 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1533 error ("whos_line_format: '%c' is not a command", |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1534 param.command); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1535 error_encountered = true; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1536 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1537 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1538 if (param.command == 's') |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1539 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1540 // Have to calculate space needed for printing |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1541 // matrix dimensions Space needed for Size column is |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1542 // hard to determine in prior, because it depends on |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1543 // dimensions to be shown. That is why it is |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1544 // recalculated for each Size-command int first, |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1545 // rest = 0, total; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1546 int rest = 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1547 int first = param.first_parameter_length; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1548 int total = param.parameter_length; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1549 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1550 for (std::list<symbol_info>::const_iterator p = lst.begin (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1551 p != lst.end (); p++) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1552 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1553 octave_value val = p->varval; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1554 dim_vector dims = val.dims (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1555 std::string dims_str = dims.str (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1556 int first1 = dims_str.find ('x'); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1557 int total1 = dims_str.length (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1558 int rest1 = total1 - first1; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1559 rest = (rest1 > rest ? rest1 : rest); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1560 first = (first1 > first ? first1 : first); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1561 total = (total1 > total ? total1 : total); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1562 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1563 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1564 if (param.modifier == 'c') |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1565 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1566 if (first < balance) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1567 first += balance - first; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1568 if (rest + balance < param.parameter_length) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1569 rest += param.parameter_length - rest - balance; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1570 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1571 param.parameter_length = first + rest; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1572 param.first_parameter_length = first; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1573 param.balance = balance; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1574 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1575 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1576 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1577 param.parameter_length = total; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1578 param.first_parameter_length = 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1579 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1580 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1581 else if (param.modifier == 'c') |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1582 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1583 error ("whos_line_format: modifier 'c' not available for command '%c'", |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1584 param.command); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1585 error_encountered = true; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1586 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1587 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1588 // What happens if whos_line_format contains negative numbers |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1589 // at param_length positions? |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1590 param.balance = (b < 0 ? 0 : param.balance); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1591 param.first_parameter_length = (b < 0 ? 0 : |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1592 param.first_parameter_length); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1593 param.parameter_length = (a < 0 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1594 ? 0 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1595 : (param.parameter_length |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1596 < param_length(pos_s) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1597 ? param_length(pos_s) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1598 : param.parameter_length)); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1599 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1600 // Parameter will not be pushed into parameter list if ... |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1601 if (! error_encountered) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1602 params.push_back (param); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1603 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1604 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1605 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1606 // Text string, to be printed as it is ... |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1607 std::string text; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1608 size_t pos; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1609 text = Vwhos_line_format.substr (idx, Vwhos_line_format.length ()); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1610 pos = text.find ('%'); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1611 if (pos != NPOS) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1612 text = text.substr (0, pos); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1613 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1614 // Push parameter into list ... |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1615 idx += text.length (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1616 param.text=text; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1617 param.line.assign (text.length(), ' '); |
7336 | 1618 params.push_back (param); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1619 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1620 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1621 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1622 return params; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1623 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1624 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1625 private: |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1626 std::list<symbol_info> lst; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1627 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1628 }; |
5659 | 1629 |
4435 | 1630 static octave_value |
7336 | 1631 do_who (int argc, const string_vector& argv, bool return_list, |
1632 bool verbose = false) | |
529 | 1633 { |
4435 | 1634 octave_value retval; |
529 | 1635 |
3523 | 1636 std::string my_name = argv[0]; |
584 | 1637 |
7336 | 1638 bool global_only = false; |
1639 | |
1857 | 1640 int i; |
1641 for (i = 1; i < argc; i++) | |
529 | 1642 { |
7336 | 1643 if (argv[i] == "-regexp" || argv[i] == "-file") |
529 | 1644 { |
7336 | 1645 error ("%s: `%s' option not implemented", my_name.c_str (), |
1646 argv[i].c_str ()); | |
1647 | |
1648 return retval; | |
529 | 1649 } |
7336 | 1650 else if (argv[i] == "global") |
1651 global_only = true; | |
1755 | 1652 else if (argv[i][0] == '-') |
1653 warning ("%s: unrecognized option `%s'", my_name.c_str (), | |
1654 argv[i].c_str ()); | |
529 | 1655 else |
867 | 1656 break; |
529 | 1657 } |
1658 | |
7336 | 1659 int npats = argc - i; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1660 string_vector pats; |
7336 | 1661 if (npats > 0) |
3248 | 1662 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1663 pats.resize (npats); |
7336 | 1664 for (int j = 0; j < npats; j++) |
1665 pats[j] = argv[i+j]; | |
3248 | 1666 } |
7336 | 1667 else |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1668 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1669 pats.resize (++npats); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1670 pats[0] = "*"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1671 } |
7336 | 1672 |
1673 symbol_table::scope_id scope = global_only | |
1674 ? symbol_table::global_scope () : symbol_table::current_scope (); | |
1675 | |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1676 symbol_info_list symbol_stats; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1677 std::list<std::string> symbol_names; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1678 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1679 for (int j = 0; j < npats; j++) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1680 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1681 std::string pat = pats[j]; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1682 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1683 size_t pos = pat.find_first_of (".({"); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1684 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1685 if (pos != NPOS && pos > 0) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1686 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1687 if (verbose) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1688 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1689 // NOTE: we can only display information for |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1690 // expressions based on global values if the variable is |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1691 // global in the current scope because we currently have |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1692 // no way of looking up the base value in the global |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1693 // scope and then evaluating the arguments in the |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1694 // current scope. |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1695 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1696 std::string base_name = pat.substr (0, pos); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1697 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1698 if (symbol_table::is_variable (base_name)) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1699 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1700 symbol_table::symbol_record sr |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1701 = symbol_table::find_symbol (base_name); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1702 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1703 if (! global_only || sr.is_global ()) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1704 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1705 int parse_status; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1706 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1707 octave_value expr_val |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1708 = eval_string (pat, true, parse_status); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1709 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1710 if (! error_state) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1711 symbol_stats.append (sr, pat, expr_val); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1712 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1713 return retval; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1714 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1715 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1716 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1717 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1718 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1719 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1720 std::list<symbol_table::symbol_record> tmp |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1721 = symbol_table::glob_variables (pats[j], scope); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1722 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1723 for (std::list<symbol_table::symbol_record>::const_iterator p = tmp.begin (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1724 p != tmp.end (); p++) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1725 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1726 if (verbose) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1727 symbol_stats.append (*p); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1728 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1729 symbol_names.push_back (p->name ()); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1730 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1731 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1732 } |
529 | 1733 |
4435 | 1734 if (return_list) |
529 | 1735 { |
7336 | 1736 if (verbose) |
4435 | 1737 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1738 std::string caller_function_name; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1739 octave_function *caller = octave_call_stack::caller (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1740 if (caller) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1741 caller_function_name = caller->name (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1742 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1743 retval = symbol_stats.map_value (caller_function_name, 1); |
4435 | 1744 } |
1745 else | |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1746 retval = Cell (string_vector (symbol_names)); |
529 | 1747 } |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1748 else if (! (symbol_stats.empty () && symbol_names.empty ())) |
529 | 1749 { |
7336 | 1750 if (global_only) |
1751 octave_stdout << "Global variables:\n\n"; | |
1752 else | |
1753 octave_stdout << "Variables in the current scope:\n\n"; | |
1754 | |
1755 if (verbose) | |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1756 symbol_stats.display (octave_stdout); |
7336 | 1757 else |
4435 | 1758 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1759 string_vector names (symbol_names); |
7336 | 1760 |
1761 names.list_in_columns (octave_stdout); | |
4435 | 1762 } |
1763 | |
7336 | 1764 octave_stdout << "\n"; |
529 | 1765 } |
1766 | |
581 | 1767 return retval; |
1768 } | |
1769 | |
4435 | 1770 DEFCMD (who, args, nargout, |
3361 | 1771 "-*- texinfo -*-\n\ |
1772 @deffn {Command} who options pattern @dots{}\n\ | |
1773 @deffnx {Command} whos options pattern @dots{}\n\ | |
1774 List currently defined symbols matching the given patterns. The\n\ | |
1775 following are valid options. They may be shortened to one character but\n\ | |
1776 may not be combined.\n\ | |
1777 \n\ | |
1778 @table @code\n\ | |
1779 @item -all\n\ | |
1780 List all currently defined symbols.\n\ | |
1781 \n\ | |
1782 @item -builtins\n\ | |
5794 | 1783 List built-in functions. This includes all currently\n\ |
3361 | 1784 compiled function files, but does not include all function files that\n\ |
5814 | 1785 are in the search path.\n\ |
581 | 1786 \n\ |
3361 | 1787 @item -functions\n\ |
1788 List user-defined functions.\n\ | |
1789 \n\ | |
1790 @item -long\n\ | |
1791 Print a long listing including the type and dimensions of any symbols.\n\ | |
1792 The symbols in the first column of output indicate whether it is\n\ | |
1793 possible to redefine the symbol, and whether it is possible for it to be\n\ | |
1794 cleared.\n\ | |
1795 \n\ | |
1796 @item -variables\n\ | |
1797 List user-defined variables.\n\ | |
1798 @end table\n\ | |
1799 \n\ | |
1800 Valid patterns are the same as described for the @code{clear} command\n\ | |
1801 above. If no patterns are supplied, all symbols from the given category\n\ | |
1802 are listed. By default, only user defined functions and variables\n\ | |
1803 visible in the local scope are displayed.\n\ | |
1804 \n\ | |
1805 The command @kbd{whos} is equivalent to @kbd{who -long}.\n\ | |
1806 @end deffn") | |
581 | 1807 { |
4435 | 1808 octave_value retval; |
581 | 1809 |
4435 | 1810 if (nargout < 2) |
1811 { | |
1812 int argc = args.length () + 1; | |
1813 | |
1814 string_vector argv = args.make_argv ("who"); | |
1755 | 1815 |
7336 | 1816 if (! error_state) |
1817 retval = do_who (argc, argv, nargout == 1); | |
4435 | 1818 } |
1819 else | |
5823 | 1820 print_usage (); |
581 | 1821 |
529 | 1822 return retval; |
1823 } | |
1824 | |
4435 | 1825 DEFCMD (whos, args, nargout, |
3458 | 1826 "-*- texinfo -*-\n\ |
1827 @deffn {Command} whos options pattern @dots{}\n\ | |
1828 See who.\n\ | |
1829 @end deffn") | |
581 | 1830 { |
4435 | 1831 octave_value retval; |
712 | 1832 |
4435 | 1833 if (nargout < 2) |
1834 { | |
7336 | 1835 int argc = args.length () + 1; |
1836 | |
1837 string_vector argv = args.make_argv ("whos"); | |
1838 | |
1839 if (! error_state) | |
1840 retval = do_who (argc, argv, nargout == 1, true); | |
4435 | 1841 } |
1842 else | |
5823 | 1843 print_usage (); |
581 | 1844 |
1845 return retval; | |
1846 } | |
1847 | |
593 | 1848 // Defining variables. |
1849 | |
1162 | 1850 void |
2856 | 1851 bind_ans (const octave_value& val, bool print) |
1162 | 1852 { |
7336 | 1853 static std::string ans = "ans"; |
1162 | 1854 |
2978 | 1855 if (val.is_defined ()) |
1856 { | |
7531
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1857 if (val.is_cs_list ()) |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1858 { |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1859 octave_value_list lst = val.list_value (); |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1860 |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1861 for (octave_idx_type i = 0; i < lst.length (); i++) |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1862 bind_ans (lst(i), print); |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1863 } |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1864 else |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1865 { |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1866 symbol_table::varref (ans) = val; |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1867 |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1868 if (print) |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1869 val.print_with_name (octave_stdout, ans); |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1870 } |
2978 | 1871 } |
1162 | 1872 } |
1873 | |
593 | 1874 void |
5794 | 1875 bind_internal_variable (const std::string& fname, const octave_value& val) |
593 | 1876 { |
5794 | 1877 octave_value_list args; |
1878 | |
1879 args(0) = val; | |
1880 | |
1881 feval (fname, args, 0); | |
529 | 1882 } |
1883 | |
4319 | 1884 void |
7336 | 1885 mlock (void) |
4319 | 1886 { |
7336 | 1887 octave_function *fcn = octave_call_stack::caller (); |
1888 | |
1889 if (fcn) | |
1890 fcn->lock (); | |
1891 else | |
1892 error ("mlock: invalid use outside a function"); | |
4319 | 1893 } |
1894 | |
1895 void | |
1896 munlock (const std::string& nm) | |
1897 { | |
7336 | 1898 octave_value val = symbol_table::find_function (nm); |
1899 | |
1900 if (val.is_defined ()) | |
1901 { | |
1902 octave_function *fcn = val.function_value (); | |
1903 | |
1904 if (fcn) | |
1905 fcn->unlock (); | |
1906 } | |
4319 | 1907 } |
1908 | |
1909 bool | |
1910 mislocked (const std::string& nm) | |
1911 { | |
7336 | 1912 bool retval = false; |
1913 | |
1914 octave_value val = symbol_table::find_function (nm); | |
1915 | |
1916 if (val.is_defined ()) | |
1917 { | |
1918 octave_function *fcn = val.function_value (); | |
1919 | |
1920 if (fcn) | |
1921 retval = fcn->islocked (); | |
1922 } | |
1923 | |
1924 return retval; | |
4319 | 1925 } |
1926 | |
1927 DEFCMD (mlock, args, , | |
1928 "-*- texinfo -*-\n\ | |
4526 | 1929 @deftypefn {Built-in Function} {} mlock (@var{name})\n\ |
7336 | 1930 Lock the current function into memory so that it can't be cleared.\n\ |
5642 | 1931 @seealso{munlock, mislocked, persistent}\n\ |
1932 @end deftypefn") | |
4319 | 1933 { |
1934 octave_value_list retval; | |
1935 | |
7336 | 1936 if (args.length () == 0) |
1937 mlock (); | |
4319 | 1938 else |
5823 | 1939 print_usage (); |
4319 | 1940 |
1941 return retval; | |
1942 } | |
1943 | |
1944 DEFCMD (munlock, args, , | |
1945 "-*- texinfo -*-\n\ | |
1946 @deftypefn {Built-in Function} {} munlock (@var{fcn})\n\ | |
1947 Unlock the named function. If no function is named\n\ | |
1948 then unlock the current function.\n\ | |
5642 | 1949 @seealso{mlock, mislocked, persistent}\n\ |
1950 @end deftypefn") | |
4319 | 1951 { |
1952 octave_value_list retval; | |
1953 | |
1954 if (args.length() == 1) | |
1955 { | |
1956 std::string name = args(0).string_value (); | |
1957 | |
1958 if (! error_state) | |
1959 munlock (name); | |
1960 else | |
1961 error ("munlock: expecting argument to be a function name"); | |
1962 } | |
1963 else if (args.length () == 0) | |
1964 { | |
7336 | 1965 octave_function *fcn = octave_call_stack::caller (); |
5743 | 1966 |
1967 if (fcn) | |
7336 | 1968 fcn->unlock (); |
4319 | 1969 else |
1970 error ("munlock: invalid use outside a function"); | |
1971 } | |
1972 else | |
5823 | 1973 print_usage (); |
4319 | 1974 |
1975 return retval; | |
1976 } | |
1977 | |
1978 | |
1979 DEFCMD (mislocked, args, , | |
1980 "-*- texinfo -*-\n\ | |
1981 @deftypefn {Built-in Function} {} mislocked (@var{fcn})\n\ | |
1982 Return true if the named function is locked. If no function is named\n\ | |
1983 then return true if the current function is locked.\n\ | |
5642 | 1984 @seealso{mlock, munlock, persistent}\n\ |
1985 @end deftypefn") | |
4319 | 1986 { |
1987 octave_value retval; | |
1988 | |
1989 if (args.length() == 1) | |
1990 { | |
1991 std::string name = args(0).string_value (); | |
1992 | |
1993 if (! error_state) | |
1994 retval = mislocked (name); | |
1995 else | |
1996 error ("mislocked: expecting argument to be a function name"); | |
1997 } | |
1998 else if (args.length () == 0) | |
1999 { | |
7336 | 2000 octave_function *fcn = octave_call_stack::caller (); |
5743 | 2001 |
2002 if (fcn) | |
7336 | 2003 retval = fcn->islocked (); |
4319 | 2004 else |
2005 error ("mislocked: invalid use outside a function"); | |
2006 } | |
2007 else | |
5823 | 2008 print_usage (); |
4319 | 2009 |
2010 return retval; | |
2011 } | |
2012 | |
593 | 2013 // Deleting names from the symbol tables. |
2014 | |
3681 | 2015 static inline bool |
4009 | 2016 name_matches_any_pattern (const std::string& nm, |
2017 const string_vector& argv, int argc, int idx) | |
3681 | 2018 { |
2019 bool retval = false; | |
2020 | |
2021 for (int k = idx; k < argc; k++) | |
2022 { | |
2023 std::string patstr = argv[k]; | |
2024 | |
2025 if (! patstr.empty ()) | |
2026 { | |
2027 glob_match pattern (patstr); | |
2028 | |
2029 if (pattern.match (nm)) | |
2030 { | |
2031 retval = true; | |
2032 break; | |
2033 } | |
2034 } | |
2035 } | |
2036 | |
2037 return retval; | |
2038 } | |
2039 | |
4009 | 2040 static inline void |
2041 maybe_warn_exclusive (bool exclusive) | |
2042 { | |
2043 if (exclusive) | |
2044 warning ("clear: ignoring --exclusive option"); | |
2045 } | |
2046 | |
7336 | 2047 static void |
4009 | 2048 do_clear_functions (const string_vector& argv, int argc, int idx, |
2049 bool exclusive = false) | |
2050 { | |
2051 if (idx == argc) | |
7336 | 2052 symbol_table::clear_functions (); |
4009 | 2053 else |
2054 { | |
2055 if (exclusive) | |
2056 { | |
7336 | 2057 string_vector fcns = symbol_table::user_function_names (); |
4009 | 2058 |
2059 int fcount = fcns.length (); | |
2060 | |
2061 for (int i = 0; i < fcount; i++) | |
2062 { | |
2063 std::string nm = fcns[i]; | |
2064 | |
2065 if (! name_matches_any_pattern (nm, argv, argc, idx)) | |
7336 | 2066 symbol_table::clear_function (nm); |
4009 | 2067 } |
2068 } | |
2069 else | |
2070 { | |
2071 while (idx < argc) | |
7336 | 2072 symbol_table::clear_function_pattern (argv[idx++]); |
4009 | 2073 } |
2074 } | |
2075 } | |
2076 | |
7336 | 2077 static void |
4009 | 2078 do_clear_globals (const string_vector& argv, int argc, int idx, |
2079 bool exclusive = false) | |
2080 { | |
2081 if (idx == argc) | |
7336 | 2082 symbol_table::clear_variables(symbol_table::global_scope ()); |
4009 | 2083 else |
2084 { | |
2085 if (exclusive) | |
2086 { | |
7336 | 2087 string_vector gvars |
2088 = symbol_table::variable_names (symbol_table::global_scope ()); | |
4009 | 2089 |
2090 int gcount = gvars.length (); | |
2091 | |
2092 for (int i = 0; i < gcount; i++) | |
2093 { | |
2094 std::string nm = gvars[i]; | |
2095 | |
2096 if (! name_matches_any_pattern (nm, argv, argc, idx)) | |
7336 | 2097 symbol_table::clear_global (nm); |
4009 | 2098 } |
2099 } | |
2100 else | |
2101 { | |
2102 while (idx < argc) | |
7336 | 2103 symbol_table::clear_global_pattern (argv[idx++]); |
4009 | 2104 } |
2105 } | |
2106 } | |
2107 | |
7336 | 2108 static void |
4009 | 2109 do_clear_variables (const string_vector& argv, int argc, int idx, |
2110 bool exclusive = false) | |
2111 { | |
2112 if (idx == argc) | |
7336 | 2113 symbol_table::clear_variables (); |
4009 | 2114 else |
2115 { | |
2116 if (exclusive) | |
2117 { | |
7336 | 2118 string_vector lvars = symbol_table::variable_names (); |
4009 | 2119 |
2120 int lcount = lvars.length (); | |
2121 | |
2122 for (int i = 0; i < lcount; i++) | |
2123 { | |
2124 std::string nm = lvars[i]; | |
2125 | |
2126 if (! name_matches_any_pattern (nm, argv, argc, idx)) | |
7336 | 2127 symbol_table::clear_variable (nm); |
4009 | 2128 } |
2129 } | |
2130 else | |
2131 { | |
2132 while (idx < argc) | |
7336 | 2133 symbol_table::clear_variable_pattern (argv[idx++]); |
4009 | 2134 } |
2135 } | |
2136 } | |
2137 | |
7336 | 2138 static void |
4009 | 2139 do_clear_symbols (const string_vector& argv, int argc, int idx, |
2140 bool exclusive = false) | |
2141 { | |
2142 if (idx == argc) | |
7336 | 2143 symbol_table::clear_variables (); |
4009 | 2144 else |
2145 { | |
2146 if (exclusive) | |
2147 { | |
5775 | 2148 // FIXME -- is this really what we want, or do we |
4009 | 2149 // somehow want to only clear the functions that are not |
2150 // shadowed by local variables? It seems that would be a | |
2151 // bit harder to do. | |
2152 | |
2153 do_clear_variables (argv, argc, idx, exclusive); | |
2154 do_clear_functions (argv, argc, idx, exclusive); | |
2155 } | |
2156 else | |
2157 { | |
2158 while (idx < argc) | |
7336 | 2159 symbol_table::clear_symbol_pattern (argv[idx++]); |
4009 | 2160 } |
2161 } | |
2162 } | |
2163 | |
2164 static void | |
2165 do_matlab_compatible_clear (const string_vector& argv, int argc, int idx) | |
2166 { | |
2167 // This is supposed to be mostly Matlab compatible. | |
2168 | |
2169 for (; idx < argc; idx++) | |
2170 { | |
7336 | 2171 if (argv[idx] == "all" |
2172 && ! symbol_table::is_local_variable ("all")) | |
4009 | 2173 { |
7336 | 2174 symbol_table::clear_all (); |
4009 | 2175 } |
7336 | 2176 else if (argv[idx] == "functions" |
2177 && ! symbol_table::is_local_variable ("functions")) | |
4009 | 2178 { |
2179 do_clear_functions (argv, argc, ++idx); | |
2180 } | |
7336 | 2181 else if (argv[idx] == "global" |
2182 && ! symbol_table::is_local_variable ("global")) | |
4009 | 2183 { |
2184 do_clear_globals (argv, argc, ++idx); | |
2185 } | |
7336 | 2186 else if (argv[idx] == "variables" |
2187 && ! symbol_table::is_local_variable ("variables")) | |
4009 | 2188 { |
7336 | 2189 symbol_table::clear_variables (); |
4009 | 2190 } |
2191 else | |
2192 { | |
7336 | 2193 symbol_table::clear_symbol_pattern (argv[idx]); |
4009 | 2194 } |
2195 } | |
2196 } | |
2197 | |
2198 #define CLEAR_OPTION_ERROR(cond) \ | |
2199 do \ | |
2200 { \ | |
2201 if (cond) \ | |
2202 { \ | |
5823 | 2203 print_usage (); \ |
4009 | 2204 return retval; \ |
2205 } \ | |
2206 } \ | |
2207 while (0) | |
2208 | |
4208 | 2209 DEFCMD (clear, args, , |
3361 | 2210 "-*- texinfo -*-\n\ |
7347 | 2211 @deffn {Command} clear [options] pattern @dots{}\n\ |
3361 | 2212 Delete the names matching the given patterns from the symbol table. The\n\ |
2213 pattern may contain the following special characters:\n\ | |
4016 | 2214 \n\ |
3361 | 2215 @table @code\n\ |
2216 @item ?\n\ | |
2217 Match any single character.\n\ | |
668 | 2218 \n\ |
3361 | 2219 @item *\n\ |
2220 Match zero or more characters.\n\ | |
2221 \n\ | |
2222 @item [ @var{list} ]\n\ | |
2223 Match the list of characters specified by @var{list}. If the first\n\ | |
2224 character is @code{!} or @code{^}, match all characters except those\n\ | |
2225 specified by @var{list}. For example, the pattern @samp{[a-zA-Z]} will\n\ | |
2226 match all lower and upper case alphabetic characters.\n\ | |
2227 @end table\n\ | |
2228 \n\ | |
2229 For example, the command\n\ | |
593 | 2230 \n\ |
3361 | 2231 @example\n\ |
2232 clear foo b*r\n\ | |
2233 @end example\n\ | |
2234 \n\ | |
2235 @noindent\n\ | |
2236 clears the name @code{foo} and all names that begin with the letter\n\ | |
2237 @code{b} and end with the letter @code{r}.\n\ | |
668 | 2238 \n\ |
3361 | 2239 If @code{clear} is called without any arguments, all user-defined\n\ |
2240 variables (local and global) are cleared from the symbol table. If\n\ | |
2241 @code{clear} is called with at least one argument, only the visible\n\ | |
2242 names matching the arguments are cleared. For example, suppose you have\n\ | |
2243 defined a function @code{foo}, and then hidden it by performing the\n\ | |
2244 assignment @code{foo = 2}. Executing the command @kbd{clear foo} once\n\ | |
2245 will clear the variable definition and restore the definition of\n\ | |
2246 @code{foo} as a function. Executing @kbd{clear foo} a second time will\n\ | |
2247 clear the function definition.\n\ | |
2248 \n\ | |
7347 | 2249 The following options are available in both long and short form\n\ |
2250 @table @code\n\ | |
2251 @item -all, -a\n\ | |
2252 Clears all local and global user-defined variables and all functions\n\ | |
2253 from the symbol table.\n\ | |
2254 \n\ | |
2255 @item -exclusive, -x\n\ | |
2256 Clears the variables that don't match the following pattern.\n\ | |
2257 \n\ | |
2258 @item -functions, -f\n\ | |
2259 Clears the function names and the built-in symbols names.\n\ | |
2260 @item -global, -g\n\ | |
2261 Clears the global symbol names.\n\ | |
2262 @item -variables, -v\n\ | |
2263 Clears the local variable names.\n\ | |
2264 @end table\n\ | |
2265 With the execption of @code{exclusive}, all long options can be used \n\ | |
2266 without the dash as well.\n\ | |
3361 | 2267 @end deffn") |
529 | 2268 { |
2086 | 2269 octave_value_list retval; |
593 | 2270 |
1755 | 2271 int argc = args.length () + 1; |
593 | 2272 |
1968 | 2273 string_vector argv = args.make_argv ("clear"); |
1755 | 2274 |
4009 | 2275 if (! error_state) |
529 | 2276 { |
4009 | 2277 if (argc == 1) |
593 | 2278 { |
7336 | 2279 symbol_table::clear_variables (); |
3681 | 2280 } |
2281 else | |
2282 { | |
4009 | 2283 int idx = 0; |
2284 | |
2285 bool clear_all = false; | |
2286 bool clear_functions = false; | |
2287 bool clear_globals = false; | |
2288 bool clear_variables = false; | |
2289 bool exclusive = false; | |
2290 bool have_dash_option = false; | |
3681 | 2291 |
4009 | 2292 while (++idx < argc) |
2293 { | |
4010 | 2294 if (argv[idx] == "-all" || argv[idx] == "-a") |
593 | 2295 { |
4009 | 2296 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681 | 2297 |
4009 | 2298 have_dash_option = true; |
2299 clear_all = true; | |
2300 } | |
4010 | 2301 else if (argv[idx] == "-exclusive" || argv[idx] == "-x") |
4009 | 2302 { |
2303 have_dash_option = true; | |
2304 exclusive = true; | |
2305 } | |
4010 | 2306 else if (argv[idx] == "-functions" || argv[idx] == "-f") |
4009 | 2307 { |
2308 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); | |
3681 | 2309 |
4009 | 2310 have_dash_option = true; |
2311 clear_functions = true; | |
2312 } | |
4010 | 2313 else if (argv[idx] == "-global" || argv[idx] == "-g") |
4009 | 2314 { |
2315 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); | |
2316 | |
2317 have_dash_option = true; | |
2318 clear_globals = true; | |
2319 } | |
4010 | 2320 else if (argv[idx] == "-variables" || argv[idx] == "-v") |
4009 | 2321 { |
2322 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); | |
3681 | 2323 |
4009 | 2324 have_dash_option = true; |
2325 clear_variables = true; | |
2326 } | |
2327 else | |
2328 break; | |
2329 } | |
3681 | 2330 |
4224 | 2331 if (idx <= argc) |
4009 | 2332 { |
2333 if (! have_dash_option) | |
2334 { | |
2335 do_matlab_compatible_clear (argv, argc, idx); | |
2336 } | |
2337 else | |
2338 { | |
2339 if (clear_all) | |
3681 | 2340 { |
4009 | 2341 maybe_warn_exclusive (exclusive); |
3681 | 2342 |
4009 | 2343 if (++idx < argc) |
2344 warning | |
4010 | 2345 ("clear: ignoring extra arguments after -all"); |
3681 | 2346 |
7336 | 2347 symbol_table::clear_all (); |
4009 | 2348 } |
2349 else if (clear_functions) | |
2350 { | |
2351 do_clear_functions (argv, argc, idx, exclusive); | |
2352 } | |
2353 else if (clear_globals) | |
593 | 2354 { |
4009 | 2355 do_clear_globals (argv, argc, idx, exclusive); |
2356 } | |
2357 else if (clear_variables) | |
2358 { | |
2359 do_clear_variables (argv, argc, idx, exclusive); | |
2360 } | |
2361 else | |
2362 { | |
2363 do_clear_symbols (argv, argc, idx, exclusive); | |
593 | 2364 } |
2365 } | |
2366 } | |
2367 } | |
2368 } | |
2369 | |
2370 return retval; | |
529 | 2371 } |
2372 | |
3933 | 2373 DEFUN (__print_symtab_info__, args, , |
3446 | 2374 "-*- texinfo -*-\n\ |
3933 | 2375 @deftypefn {Built-in Function} {} __print_symtab_info__ ()\n\ |
6945 | 2376 Undocumented internal function.\n\ |
3446 | 2377 @end deftypefn") |
3005 | 2378 { |
2379 octave_value_list retval; | |
2380 | |
7336 | 2381 // FIXME -- what should this function do now? Print a summary for |
2382 // each scope? Print the entire symbol table? Accept a scope | |
2383 // argument? | |
3005 | 2384 |
2385 return retval; | |
2386 } | |
2387 | |
3933 | 2388 DEFUN (__print_symbol_info__, args, , |
3446 | 2389 "-*- texinfo -*-\n\ |
2390 @deftypefn {Built-in Function} {} __dump_symbol_info__ (@var{name})\n\ | |
6945 | 2391 Undocumented internal function.\n\ |
3446 | 2392 @end deftypefn") |
3239 | 2393 { |
2394 octave_value_list retval; | |
2395 | |
7336 | 2396 // FIXME -- what should this function do now? |
3239 | 2397 |
2398 return retval; | |
2399 } | |
2400 | |
7336 | 2401 DEFUN (whos_line_format, args, nargout, |
2402 "-*- texinfo -*-\n\ | |
2403 @deftypefn {Built-in Function} {@var{val} =} whos_line_format ()\n\ | |
2404 @deftypefnx {Built-in Function} {@var{old_val} =} whos_line_format (@var{new_val})\n\ | |
2405 Query or set the format string used by the @code{whos}.\n\ | |
2406 \n\ | |
2407 The following escape sequences may be used in the format:\n\ | |
2408 @table @code\n\ | |
2409 @item %a\n\ | |
2410 Prints attributes of variables (g=global, p=persistent,\n\ | |
2411 f=formal parameter, a=automatic variable).\n\ | |
2412 @item %b\n\ | |
2413 Prints number of bytes occupied by variables.\n\ | |
2414 @item %c\n\ | |
2415 Prints class names of variables.\n\ | |
2416 @item %e\n\ | |
2417 Prints elements held by variables.\n\ | |
2418 @item %n\n\ | |
2419 Prints variable names.\n\ | |
2420 @item %s\n\ | |
2421 Prints dimensions of variables.\n\ | |
2422 @item %t\n\ | |
2423 Prints type names of variables.\n\ | |
2424 @end table\n\ | |
2425 \n\ | |
2426 Every command may also have a modifier:\n\ | |
2427 @table @code\n\ | |
2428 @item l\n\ | |
2429 Left alignment.\n\ | |
2430 @item r\n\ | |
2431 Right alignment (this is the default).\n\ | |
2432 @item c\n\ | |
2433 Centered (may only be applied to command %s).\n\ | |
2434 @end table\n\ | |
2435 \n\ | |
2436 A command is composed like this:\n\ | |
2437 \n\ | |
2438 @example\n\ | |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
2439 %[modifier]<command>[:size_of_parameter[:center-specific[:balance]]];\n\ |
7336 | 2440 @end example\n\ |
2441 \n\ | |
2442 Command and modifier is already explained. Size_of_parameter\n\ | |
2443 tells how many columns the parameter will need for printing.\n\ | |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
2444 The @code{center-specific} parameter may only be applied to command\n\ |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
2445 @samp{%s}.\n\ |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
2446 The @code{balance} parameter specifies the offset for printing\n\ |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
2447 the dimensions string.\n\ |
7336 | 2448 \n\ |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
2449 The default format is \" %a:4; %ln:6; %cs:16:6:1; %rb:12; %lc:-1;\\n\".\n\ |
5794 | 2450 @end deftypefn") |
2451 { | |
7336 | 2452 return SET_INTERNAL_VARIABLE (whos_line_format); |
3016 | 2453 } |
2454 | |
1 | 2455 /* |
2456 ;;; Local Variables: *** | |
2457 ;;; mode: C++ *** | |
2458 ;;; End: *** | |
2459 */ |