Mercurial > hg > octave-nkf
annotate src/variables.cc @ 7752:40c428ea3408
initial implementation of dbup and dbdown
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 04 May 2008 03:42:19 -0400 |
parents | ec78d83a7fde |
children | e76a4a6e3c47 |
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\ | |
7626
ec78d83a7fde
variables.cc (exist): Clarify help.
Ben Abbott <bpabbott@mac.com>
parents:
7586
diff
changeset
|
791 Return 1 if the name exists as a variable, 2 if the name is an\n\ |
ec78d83a7fde
variables.cc (exist): Clarify help.
Ben Abbott <bpabbott@mac.com>
parents:
7586
diff
changeset
|
792 absolute file name, an ordinary file in Octave's @code{path}, or (after\n\ |
ec78d83a7fde
variables.cc (exist): Clarify help.
Ben Abbott <bpabbott@mac.com>
parents:
7586
diff
changeset
|
793 appending @samp{.m}) a function file in Octave's @code{path}, 3 if the\n\ |
5864 | 794 name is a @samp{.oct} or @samp{.mex} file in Octave's @code{path},\n\ |
795 5 if the name is a built-in function, 7 if the name is a directory, or 103\n\ | |
4016 | 796 if the name is a function not associated with a file (entered on\n\ |
797 the command line).\n\ | |
798 \n\ | |
799 Otherwise, return 0.\n\ | |
800 \n\ | |
801 This function also returns 2 if a regular file called @var{name}\n\ | |
5814 | 802 exists in Octave's search path. If you want information about\n\ |
4016 | 803 other types of files, you should use some combination of the functions\n\ |
804 @code{file_in_path} and @code{stat} instead.\n\ | |
805 \n\ | |
806 If the optional argument @var{type} is supplied, check only for\n\ | |
807 symbols of the specified type. Valid types are\n\ | |
808 \n\ | |
809 @table @samp\n\ | |
810 @item \"var\"\n\ | |
811 Check only for variables.\n\ | |
812 @item \"builtin\"\n\ | |
813 Check only for built-in functions.\n\ | |
814 @item \"file\"\n\ | |
815 Check only for files.\n\ | |
816 @item \"dir\"\n\ | |
817 Check only for directories.\n\ | |
818 @end table\n\ | |
819 @end deftypefn") | |
820 { | |
4233 | 821 octave_value retval = false; |
4016 | 822 |
823 int nargin = args.length (); | |
824 | |
825 if (nargin == 1 || nargin == 2) | |
826 { | |
827 std::string name = args(0).string_value (); | |
828 | |
829 if (! error_state) | |
830 { | |
831 std::string type | |
832 = (nargin == 2) ? args(1).string_value () : std::string ("any"); | |
833 | |
834 if (! error_state) | |
4233 | 835 retval = symbol_exist (name, type); |
4016 | 836 else |
837 error ("exist: expecting second argument to be a string"); | |
838 } | |
839 else | |
840 error ("exist: expecting first argument to be a string"); | |
841 } | |
842 else | |
5823 | 843 print_usage (); |
4016 | 844 |
845 return retval; | |
846 } | |
847 | |
2849 | 848 octave_value |
4988 | 849 lookup_function_handle (const std::string& nm) |
850 { | |
7336 | 851 octave_value val = symbol_table::varval (nm); |
852 | |
853 return val.is_function_handle () ? val : octave_value (); | |
4988 | 854 } |
855 | |
856 octave_value | |
5027 | 857 get_global_value (const std::string& nm, bool silent) |
2849 | 858 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
859 octave_value val = symbol_table::global_varval (nm); |
7336 | 860 |
861 if (val.is_undefined () && ! silent) | |
862 error ("get_global_by_name: undefined symbol `%s'", nm.c_str ()); | |
863 | |
864 return val; | |
2849 | 865 } |
866 | |
867 void | |
3523 | 868 set_global_value (const std::string& nm, const octave_value& val) |
2849 | 869 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
870 symbol_table::global_varref (nm) = val; |
2849 | 871 } |
872 | |
593 | 873 // Variable values. |
195 | 874 |
5791 | 875 octave_value |
876 set_internal_variable (bool& var, const octave_value_list& args, | |
5794 | 877 int nargout, const char *nm) |
5791 | 878 { |
5794 | 879 octave_value retval; |
880 | |
5800 | 881 int nargin = args.length (); |
882 | |
883 if (nargout > 0 || nargin == 0) | |
5794 | 884 retval = var; |
5791 | 885 |
886 if (nargin == 1) | |
887 { | |
888 bool bval = args(0).bool_value (); | |
889 | |
890 if (! error_state) | |
891 var = bval; | |
892 else | |
893 error ("%s: expecting arg to be a logical value", nm); | |
894 } | |
895 else if (nargin > 1) | |
5823 | 896 print_usage (); |
5791 | 897 |
898 return retval; | |
899 } | |
900 | |
901 octave_value | |
5794 | 902 set_internal_variable (char& var, const octave_value_list& args, |
903 int nargout, const char *nm) | |
5791 | 904 { |
5794 | 905 octave_value retval; |
906 | |
5800 | 907 int nargin = args.length (); |
908 | |
909 if (nargout > 0 || nargin == 0) | |
5794 | 910 retval = var; |
5791 | 911 |
912 if (nargin == 1) | |
913 { | |
914 std::string sval = args(0).string_value (); | |
915 | |
916 if (! error_state) | |
5794 | 917 { |
918 switch (sval.length ()) | |
919 { | |
920 case 1: | |
921 var = sval[0]; | |
922 break; | |
923 | |
924 case 0: | |
925 var = '\0'; | |
926 break; | |
927 | |
928 default: | |
929 error ("%s: argument must be a single character", nm); | |
930 break; | |
931 } | |
932 } | |
933 else | |
934 error ("%s: argument must be a single character", nm); | |
935 } | |
936 else if (nargin > 1) | |
5823 | 937 print_usage (); |
5794 | 938 |
939 return retval; | |
940 } | |
941 | |
942 octave_value | |
943 set_internal_variable (int& var, const octave_value_list& args, | |
944 int nargout, const char *nm, | |
945 int minval, int maxval) | |
946 { | |
947 octave_value retval; | |
948 | |
5800 | 949 int nargin = args.length (); |
950 | |
951 if (nargout > 0 || nargin == 0) | |
5794 | 952 retval = var; |
953 | |
954 if (nargin == 1) | |
955 { | |
956 int ival = args(0).int_value (); | |
957 | |
958 if (! error_state) | |
959 { | |
960 if (ival < minval) | |
961 error ("%s: expecting arg to be greater than %d", minval); | |
962 else if (ival > maxval) | |
963 error ("%s: expecting arg to be less than or equal to %d", maxval); | |
964 else | |
965 var = ival; | |
966 } | |
967 else | |
968 error ("%s: expecting arg to be an integer value", nm); | |
969 } | |
970 else if (nargin > 1) | |
5823 | 971 print_usage (); |
5794 | 972 |
973 return retval; | |
974 } | |
975 | |
976 octave_value | |
977 set_internal_variable (double& var, const octave_value_list& args, | |
978 int nargout, const char *nm, | |
979 double minval, double maxval) | |
980 { | |
981 octave_value retval; | |
982 | |
5800 | 983 int nargin = args.length (); |
984 | |
985 if (nargout > 0 || nargin == 0) | |
5794 | 986 retval = var; |
987 | |
988 if (nargin == 1) | |
989 { | |
990 double dval = args(0).scalar_value (); | |
991 | |
992 if (! error_state) | |
993 { | |
994 if (dval < minval) | |
995 error ("%s: expecting arg to be greater than %g", minval); | |
996 else if (dval > maxval) | |
997 error ("%s: expecting arg to be less than or equal to %g", maxval); | |
998 else | |
999 var = dval; | |
1000 } | |
1001 else | |
1002 error ("%s: expecting arg to be a scalar value", nm); | |
1003 } | |
1004 else if (nargin > 1) | |
5823 | 1005 print_usage (); |
5794 | 1006 |
1007 return retval; | |
1008 } | |
1009 | |
1010 octave_value | |
1011 set_internal_variable (std::string& var, const octave_value_list& args, | |
1012 int nargout, const char *nm, bool empty_ok) | |
1013 { | |
1014 octave_value retval; | |
1015 | |
5800 | 1016 int nargin = args.length (); |
1017 | |
1018 if (nargout > 0 || nargin == 0) | |
5794 | 1019 retval = var; |
1020 | |
1021 if (nargin == 1) | |
1022 { | |
1023 std::string sval = args(0).string_value (); | |
1024 | |
1025 if (! error_state) | |
1026 { | |
1027 if (empty_ok || ! sval.empty ()) | |
1028 var = sval; | |
1029 else | |
1030 error ("%s: value must not be empty", nm); | |
1031 } | |
5791 | 1032 else |
1033 error ("%s: expecting arg to be a character string", nm); | |
1034 } | |
1035 else if (nargin > 1) | |
5823 | 1036 print_usage (); |
1 | 1037 |
1038 return retval; | |
1039 } | |
1040 | |
7336 | 1041 struct |
1042 whos_parameter | |
195 | 1043 { |
7336 | 1044 char command; |
1045 char modifier; | |
1046 int parameter_length; | |
1047 int first_parameter_length; | |
1048 int balance; | |
1049 std::string text; | |
1050 std::string line; | |
1051 }; | |
1052 | |
1053 static void | |
1054 print_descriptor (std::ostream& os, std::list<whos_parameter> params) | |
1055 { | |
1056 // This method prints a line of information on a given symbol | |
1057 std::list<whos_parameter>::iterator i = params.begin (); | |
1058 std::ostringstream param_buf; | |
1059 | |
1060 while (i != params.end ()) | |
195 | 1061 { |
7336 | 1062 whos_parameter param = *i; |
1063 | |
1064 if (param.command != '\0') | |
1065 { | |
1066 // Do the actual printing | |
1067 switch (param.modifier) | |
1068 { | |
1069 case 'l': | |
1070 os << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); | |
1071 param_buf << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); | |
1072 break; | |
1073 | |
1074 case 'r': | |
1075 os << std::setiosflags (std::ios::right) << std::setw (param.parameter_length); | |
1076 param_buf << std::setiosflags (std::ios::right) << std::setw (param.parameter_length); | |
1077 break; | |
1078 | |
1079 case 'c': | |
1080 if (param.command != 's') | |
1081 { | |
1082 os << std::setiosflags (std::ios::left) | |
1083 << std::setw (param.parameter_length); | |
1084 param_buf << std::setiosflags (std::ios::left) | |
1085 << std::setw (param.parameter_length); | |
1086 } | |
1087 break; | |
1088 | |
1089 default: | |
1090 os << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); | |
1091 param_buf << std::setiosflags (std::ios::left) << std::setw (param.parameter_length); | |
1092 } | |
1093 | |
1094 if (param.command == 's' && param.modifier == 'c') | |
1095 { | |
1096 int a, b; | |
1097 | |
1098 if (param.modifier == 'c') | |
1099 { | |
1100 a = param.first_parameter_length - param.balance; | |
1101 a = (a < 0 ? 0 : a); | |
1102 b = param.parameter_length - a - param.text . length (); | |
1103 b = (b < 0 ? 0 : b); | |
1104 os << std::setiosflags (std::ios::left) << std::setw (a) | |
1105 << "" << std::resetiosflags (std::ios::left) << param.text | |
1106 << std::setiosflags (std::ios::left) | |
1107 << std::setw (b) << "" | |
1108 << std::resetiosflags (std::ios::left); | |
1109 param_buf << std::setiosflags (std::ios::left) << std::setw (a) | |
1110 << "" << std::resetiosflags (std::ios::left) << param.line | |
1111 << std::setiosflags (std::ios::left) | |
1112 << std::setw (b) << "" | |
1113 << std::resetiosflags (std::ios::left); | |
1114 } | |
1115 } | |
1116 else | |
1117 { | |
1118 os << param.text; | |
1119 param_buf << param.line; | |
1120 } | |
1121 os << std::resetiosflags (std::ios::left) | |
1122 << std::resetiosflags (std::ios::right); | |
1123 param_buf << std::resetiosflags (std::ios::left) | |
1124 << std::resetiosflags (std::ios::right); | |
1125 i++; | |
1126 } | |
1127 else | |
2975 | 1128 { |
7336 | 1129 os << param.text; |
1130 param_buf << param.line; | |
1131 i++; | |
2975 | 1132 } |
195 | 1133 } |
7336 | 1134 |
1135 os << param_buf.str (); | |
195 | 1136 } |
1137 | |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1138 class |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1139 symbol_info_list |
593 | 1140 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1141 private: |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1142 struct symbol_info |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1143 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1144 symbol_info (const symbol_table::symbol_record& sr, |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1145 const std::string& expr_str = std::string (), |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1146 const octave_value& expr_val = octave_value ()) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1147 : name (expr_str.empty () ? sr.name () : expr_str), |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1148 is_automatic (sr.is_automatic ()), |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1149 is_formal (sr.is_formal ()), |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1150 is_global (sr.is_global ()), |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1151 is_persistent (sr.is_persistent ()), |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1152 varval (expr_val.is_undefined () ? sr.varval () : expr_val) |
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 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1155 void display_line (std::ostream& os, |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1156 const std::list<whos_parameter>& params) const |
593 | 1157 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1158 dim_vector dims = varval.dims (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1159 std::string dims_str = dims.str (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1160 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1161 std::list<whos_parameter>::const_iterator i = params.begin (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1162 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1163 while (i != params.end ()) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1164 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1165 whos_parameter param = *i; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1166 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1167 if (param.command != '\0') |
2294 | 1168 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1169 // Do the actual printing. |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1170 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1171 switch (param.modifier) |
2294 | 1172 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1173 case 'l': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1174 os << std::setiosflags (std::ios::left) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1175 << std::setw (param.parameter_length); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1176 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1177 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1178 case 'r': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1179 os << std::setiosflags (std::ios::right) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1180 << std::setw (param.parameter_length); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1181 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1182 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1183 case 'c': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1184 if (param.command == 's') |
7336 | 1185 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1186 int front = param.first_parameter_length |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1187 - dims_str.find ('x'); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1188 int back = param.parameter_length |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1189 - dims_str.length () |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1190 - front; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1191 front = (front > 0) ? front : 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1192 back = (back > 0) ? back : 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1193 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1194 os << std::setiosflags (std::ios::left) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1195 << std::setw (front) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1196 << "" |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1197 << std::resetiosflags (std::ios::left) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1198 << dims_str |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1199 << std::setiosflags (std::ios::left) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1200 << std::setw (back) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1201 << "" |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1202 << std::resetiosflags (std::ios::left); |
7336 | 1203 } |
2294 | 1204 else |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1205 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1206 os << std::setiosflags (std::ios::left) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1207 << std::setw (param.parameter_length); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1208 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1209 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1210 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1211 default: |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1212 error ("whos_line_format: modifier `%c' unknown", |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1213 param.modifier); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1214 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1215 os << std::setiosflags (std::ios::right) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1216 << std::setw (param.parameter_length); |
2294 | 1217 } |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1218 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1219 switch (param.command) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1220 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1221 case 'a': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1222 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1223 char tmp[5]; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1224 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1225 tmp[0] = (is_automatic ? 'a' : ' '); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1226 tmp[1] = (is_formal ? 'f' : ' '); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1227 tmp[2] = (is_global ? 'g' : ' '); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1228 tmp[3] = (is_persistent ? 'p' : ' '); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1229 tmp[4] = 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1230 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1231 os << tmp; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1232 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1233 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1234 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1235 case 'b': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1236 os << varval.byte_size (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1237 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1238 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1239 case 'c': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1240 os << varval.class_name (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1241 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1242 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1243 case 'e': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1244 os << varval.capacity (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1245 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1246 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1247 case 'n': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1248 os << name; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1249 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1250 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1251 case 's': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1252 if (param.modifier != 'c') |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1253 os << dims_str; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1254 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1255 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1256 case 't': |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1257 os << varval.type_name (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1258 break; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1259 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1260 default: |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1261 error ("whos_line_format: command `%c' unknown", |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1262 param.command); |
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 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1265 os << std::resetiosflags (std::ios::left) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1266 << std::resetiosflags (std::ios::right); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1267 i++; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1268 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1269 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1270 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1271 os << param.text; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1272 i++; |
2294 | 1273 } |
593 | 1274 } |
1275 } | |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1276 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1277 std::string name; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1278 bool is_automatic; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1279 bool is_formal; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1280 bool is_global; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1281 bool is_persistent; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1282 octave_value varval; |
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 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1285 public: |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1286 symbol_info_list (void) : lst () { } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1287 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1288 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
|
1289 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1290 symbol_info_list& operator = (const symbol_info_list& sil) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1291 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1292 if (this != &sil) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1293 lst = sil.lst; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1294 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1295 return *this; |
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 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1298 ~symbol_info_list (void) { } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1299 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1300 void append (const symbol_table::symbol_record& sr) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1301 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1302 lst.push_back (symbol_info (sr)); |
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 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1305 void append (const symbol_table::symbol_record& sr, |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1306 const std::string& expr_str, |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1307 const octave_value& expr_val) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1308 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1309 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
|
1310 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1311 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1312 size_t size (void) const { return lst.size (); } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1313 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1314 bool empty (void) const { return lst.empty (); } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1315 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1316 Octave_map |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1317 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
|
1318 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1319 size_t len = lst.size (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1320 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1321 Array<octave_value> name_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1322 Array<octave_value> size_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1323 Array<octave_value> bytes_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1324 Array<octave_value> class_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1325 Array<octave_value> global_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1326 Array<octave_value> sparse_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1327 Array<octave_value> complex_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1328 Array<octave_value> nesting_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1329 Array<octave_value> persistent_info (len, 1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1330 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1331 std::list<symbol_info>::const_iterator p = lst.begin (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1332 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1333 for (size_t j = 0; j < len; j++) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1334 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1335 const symbol_info& si = *p++; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1336 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1337 Octave_map ni; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1338 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1339 ni.assign ("function", caller_function_name); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1340 ni.assign ("level", nesting_level); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1341 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1342 name_info(j) = si.name; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1343 global_info(j) = si.is_global; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1344 persistent_info(j) = si.is_persistent; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1345 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1346 octave_value val = si.varval; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1347 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1348 size_info(j) = val.size (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1349 bytes_info(j) = val.byte_size (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1350 class_info(j) = val.class_name (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1351 sparse_info(j) = val.is_sparse_type (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1352 complex_info(j) = val.is_complex_type (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1353 nesting_info(j) = ni; |
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 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1356 Octave_map info; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1357 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1358 info.assign ("name", name_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1359 info.assign ("size", size_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1360 info.assign ("bytes", bytes_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1361 info.assign ("class", class_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1362 info.assign ("global", global_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1363 info.assign ("sparse", sparse_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1364 info.assign ("complex", complex_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1365 info.assign ("nesting", nesting_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1366 info.assign ("persistent", persistent_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1367 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1368 return info; |
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 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1371 void display (std::ostream& os) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1372 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1373 if (! lst.empty ()) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1374 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1375 size_t bytes = 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1376 size_t elements = 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1377 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1378 std::list<whos_parameter> params = parse_whos_line_format (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1379 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1380 print_descriptor (os, params); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1381 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1382 octave_stdout << "\n"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1383 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1384 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
|
1385 p != lst.end (); p++) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1386 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1387 p->display_line (os, params); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1388 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1389 octave_value val = p->varval; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1390 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1391 elements += val.capacity (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1392 bytes += val.byte_size (); |
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 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1395 os << "\nTotal is " << elements |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1396 << (elements == 1 ? " element" : " elements") |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1397 << " using " << bytes << (bytes == 1 ? " byte" : " bytes") |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1398 << "\n"; |
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 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1402 // 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
|
1403 // containing all information needed to print the given |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1404 // attributtes of the symbols. |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1405 std::list<whos_parameter> parse_whos_line_format (void) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1406 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1407 int idx; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1408 size_t format_len = Vwhos_line_format.length (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1409 char garbage; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1410 std::list<whos_parameter> params; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1411 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1412 size_t bytes1; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1413 int elements1; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1414 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1415 std::string param_string = "abcenst"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1416 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
|
1417 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
|
1418 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
|
1419 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1420 pos_a = param_string.find ('a'); // Attributes |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1421 pos_b = param_string.find ('b'); // Bytes |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1422 pos_c = param_string.find ('c'); // Class |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1423 pos_e = param_string.find ('e'); // Elements |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1424 pos_n = param_string.find ('n'); // Name |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1425 pos_s = param_string.find ('s'); // Size |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1426 pos_t = param_string.find ('t'); // Type |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1427 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1428 param_names(pos_a) = "Attr"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1429 param_names(pos_b) = "Bytes"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1430 param_names(pos_c) = "Class"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1431 param_names(pos_e) = "Elements"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1432 param_names(pos_n) = "Name"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1433 param_names(pos_s) = "Size"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1434 param_names(pos_t) = "Type"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1435 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1436 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
|
1437 param_length(i) = param_names(i) . length (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1438 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1439 // Calculating necessary spacing for name column, |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1440 // bytes column, elements column and class column |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1441 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1442 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
|
1443 p != lst.end (); p++) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1444 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1445 std::stringstream ss1, ss2; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1446 std::string str; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1447 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1448 str = p->name; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1449 param_length(pos_n) = ((str.length () |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1450 > static_cast<size_t> (param_length(pos_n))) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1451 ? str.length () : param_length(pos_n)); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1452 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1453 octave_value val = p->varval; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1454 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1455 str = val.type_name (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1456 param_length(pos_t) = ((str.length () |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1457 > static_cast<size_t> (param_length(pos_t))) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1458 ? str.length () : param_length(pos_t)); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1459 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1460 elements1 = val.capacity (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1461 ss1 << elements1; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1462 str = ss1.str (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1463 param_length(pos_e) = ((str.length () |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1464 > static_cast<size_t> (param_length(pos_e))) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1465 ? str.length () : param_length(pos_e)); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1466 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1467 bytes1 = val.byte_size (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1468 ss2 << bytes1; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1469 str = ss2.str (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1470 param_length(pos_b) = ((str.length () |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1471 > static_cast<size_t> (param_length(pos_b))) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1472 ? str.length () : param_length (pos_b)); |
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 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1475 idx = 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1476 while (static_cast<size_t> (idx) < format_len) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1477 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1478 whos_parameter param; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1479 param.command = '\0'; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1480 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1481 if (Vwhos_line_format[idx] == '%') |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1482 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1483 bool error_encountered = false; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1484 param.modifier = 'r'; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1485 param.parameter_length = 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1486 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1487 int a = 0, b = -1, balance = 1; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1488 unsigned int items; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1489 size_t pos; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1490 std::string cmd; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1491 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1492 // Parse one command from whos_line_format |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1493 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
|
1494 pos = cmd.find (';'); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1495 if (pos != NPOS) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1496 cmd = cmd.substr (0, pos+1); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1497 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1498 error ("parameter without ; in whos_line_format"); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1499 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1500 idx += cmd.length (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1501 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1502 // FIXME -- use iostream functions instead of sscanf! |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1503 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1504 if (cmd.find_first_of ("crl") != 1) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1505 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
|
1506 &garbage, ¶m.command, &a, &b, &balance); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1507 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1508 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
|
1509 &garbage, ¶m.modifier, ¶m.command, |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1510 &a, &b, &balance) - 1; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1511 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1512 if (items < 2) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1513 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1514 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
|
1515 error_encountered = true; |
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 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1518 // Insert data into parameter |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1519 param.first_parameter_length = 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1520 pos = param_string.find (param.command); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1521 if (pos != NPOS) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1522 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1523 param.parameter_length = param_length(pos); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1524 param.text = param_names(pos); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1525 param.line.assign (param_names(pos).length (), '='); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1526 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1527 param.parameter_length = (a > param.parameter_length |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1528 ? a : param.parameter_length); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1529 if (param.command == 's' && param.modifier == 'c' && b > 0) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1530 param.first_parameter_length = b; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1531 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1532 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1533 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1534 error ("whos_line_format: '%c' is not a command", |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1535 param.command); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1536 error_encountered = true; |
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 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1539 if (param.command == 's') |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1540 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1541 // Have to calculate space needed for printing |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1542 // matrix dimensions Space needed for Size column is |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1543 // hard to determine in prior, because it depends on |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1544 // dimensions to be shown. That is why it is |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1545 // recalculated for each Size-command int first, |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1546 // rest = 0, total; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1547 int rest = 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1548 int first = param.first_parameter_length; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1549 int total = param.parameter_length; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1550 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1551 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
|
1552 p != lst.end (); p++) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1553 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1554 octave_value val = p->varval; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1555 dim_vector dims = val.dims (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1556 std::string dims_str = dims.str (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1557 int first1 = dims_str.find ('x'); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1558 int total1 = dims_str.length (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1559 int rest1 = total1 - first1; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1560 rest = (rest1 > rest ? rest1 : rest); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1561 first = (first1 > first ? first1 : first); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1562 total = (total1 > total ? total1 : total); |
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 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1565 if (param.modifier == 'c') |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1566 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1567 if (first < balance) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1568 first += balance - first; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1569 if (rest + balance < param.parameter_length) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1570 rest += param.parameter_length - rest - balance; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1571 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1572 param.parameter_length = first + rest; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1573 param.first_parameter_length = first; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1574 param.balance = balance; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1575 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1576 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1577 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1578 param.parameter_length = total; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1579 param.first_parameter_length = 0; |
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 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1582 else if (param.modifier == 'c') |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1583 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1584 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
|
1585 param.command); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1586 error_encountered = true; |
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 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1589 // What happens if whos_line_format contains negative numbers |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1590 // at param_length positions? |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1591 param.balance = (b < 0 ? 0 : param.balance); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1592 param.first_parameter_length = (b < 0 ? 0 : |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1593 param.first_parameter_length); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1594 param.parameter_length = (a < 0 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1595 ? 0 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1596 : (param.parameter_length |
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_length(pos_s) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1599 : param.parameter_length)); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1600 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1601 // Parameter will not be pushed into parameter list if ... |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1602 if (! error_encountered) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1603 params.push_back (param); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1604 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1605 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1606 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1607 // Text string, to be printed as it is ... |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1608 std::string text; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1609 size_t pos; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1610 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
|
1611 pos = text.find ('%'); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1612 if (pos != NPOS) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1613 text = text.substr (0, pos); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1614 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1615 // Push parameter into list ... |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1616 idx += text.length (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1617 param.text=text; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1618 param.line.assign (text.length(), ' '); |
7336 | 1619 params.push_back (param); |
7586
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 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1623 return params; |
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 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1626 private: |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1627 std::list<symbol_info> lst; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1628 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1629 }; |
5659 | 1630 |
4435 | 1631 static octave_value |
7336 | 1632 do_who (int argc, const string_vector& argv, bool return_list, |
1633 bool verbose = false) | |
529 | 1634 { |
4435 | 1635 octave_value retval; |
529 | 1636 |
3523 | 1637 std::string my_name = argv[0]; |
584 | 1638 |
7336 | 1639 bool global_only = false; |
1640 | |
1857 | 1641 int i; |
1642 for (i = 1; i < argc; i++) | |
529 | 1643 { |
7336 | 1644 if (argv[i] == "-regexp" || argv[i] == "-file") |
529 | 1645 { |
7336 | 1646 error ("%s: `%s' option not implemented", my_name.c_str (), |
1647 argv[i].c_str ()); | |
1648 | |
1649 return retval; | |
529 | 1650 } |
7336 | 1651 else if (argv[i] == "global") |
1652 global_only = true; | |
1755 | 1653 else if (argv[i][0] == '-') |
1654 warning ("%s: unrecognized option `%s'", my_name.c_str (), | |
1655 argv[i].c_str ()); | |
529 | 1656 else |
867 | 1657 break; |
529 | 1658 } |
1659 | |
7336 | 1660 int npats = argc - i; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1661 string_vector pats; |
7336 | 1662 if (npats > 0) |
3248 | 1663 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1664 pats.resize (npats); |
7336 | 1665 for (int j = 0; j < npats; j++) |
1666 pats[j] = argv[i+j]; | |
3248 | 1667 } |
7336 | 1668 else |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1669 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1670 pats.resize (++npats); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1671 pats[0] = "*"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1672 } |
7336 | 1673 |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1674 symbol_info_list symbol_stats; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1675 std::list<std::string> symbol_names; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1676 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1677 for (int j = 0; j < npats; j++) |
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 std::string pat = pats[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 size_t pos = pat.find_first_of (".({"); |
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 if (pos != NPOS && pos > 0) |
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 (verbose) |
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 // NOTE: we can only display information for |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1688 // expressions based on global values if the variable is |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1689 // global in the current scope because we currently have |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1690 // 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
|
1691 // scope and then evaluating the arguments in the |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1692 // current scope. |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1693 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1694 std::string base_name = pat.substr (0, pos); |
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 if (symbol_table::is_variable (base_name)) |
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 symbol_table::symbol_record sr |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1699 = symbol_table::find_symbol (base_name); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1700 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1701 if (! global_only || sr.is_global ()) |
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 int parse_status; |
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 octave_value expr_val |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1706 = eval_string (pat, true, parse_status); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1707 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1708 if (! error_state) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1709 symbol_stats.append (sr, pat, expr_val); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1710 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1711 return retval; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1712 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1713 } |
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 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1717 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
1718 std::list<symbol_table::symbol_record> tmp = global_only |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
1719 ? symbol_table::glob_global_variables (pats[j]) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
1720 : symbol_table::glob_variables (pats[j]); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1721 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1722 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
|
1723 p != tmp.end (); p++) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1724 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1725 if (verbose) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1726 symbol_stats.append (*p); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1727 else |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1728 symbol_names.push_back (p->name ()); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1729 } |
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 } |
529 | 1732 |
4435 | 1733 if (return_list) |
529 | 1734 { |
7336 | 1735 if (verbose) |
4435 | 1736 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1737 std::string caller_function_name; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1738 octave_function *caller = octave_call_stack::caller (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1739 if (caller) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1740 caller_function_name = caller->name (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1741 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1742 retval = symbol_stats.map_value (caller_function_name, 1); |
4435 | 1743 } |
1744 else | |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1745 retval = Cell (string_vector (symbol_names)); |
529 | 1746 } |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1747 else if (! (symbol_stats.empty () && symbol_names.empty ())) |
529 | 1748 { |
7336 | 1749 if (global_only) |
1750 octave_stdout << "Global variables:\n\n"; | |
1751 else | |
1752 octave_stdout << "Variables in the current scope:\n\n"; | |
1753 | |
1754 if (verbose) | |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1755 symbol_stats.display (octave_stdout); |
7336 | 1756 else |
4435 | 1757 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1758 string_vector names (symbol_names); |
7336 | 1759 |
1760 names.list_in_columns (octave_stdout); | |
4435 | 1761 } |
1762 | |
7336 | 1763 octave_stdout << "\n"; |
529 | 1764 } |
1765 | |
581 | 1766 return retval; |
1767 } | |
1768 | |
4435 | 1769 DEFCMD (who, args, nargout, |
3361 | 1770 "-*- texinfo -*-\n\ |
1771 @deffn {Command} who options pattern @dots{}\n\ | |
1772 @deffnx {Command} whos options pattern @dots{}\n\ | |
1773 List currently defined symbols matching the given patterns. The\n\ | |
1774 following are valid options. They may be shortened to one character but\n\ | |
1775 may not be combined.\n\ | |
1776 \n\ | |
1777 @table @code\n\ | |
1778 @item -all\n\ | |
1779 List all currently defined symbols.\n\ | |
1780 \n\ | |
1781 @item -builtins\n\ | |
5794 | 1782 List built-in functions. This includes all currently\n\ |
3361 | 1783 compiled function files, but does not include all function files that\n\ |
5814 | 1784 are in the search path.\n\ |
581 | 1785 \n\ |
3361 | 1786 @item -functions\n\ |
1787 List user-defined functions.\n\ | |
1788 \n\ | |
1789 @item -long\n\ | |
1790 Print a long listing including the type and dimensions of any symbols.\n\ | |
1791 The symbols in the first column of output indicate whether it is\n\ | |
1792 possible to redefine the symbol, and whether it is possible for it to be\n\ | |
1793 cleared.\n\ | |
1794 \n\ | |
1795 @item -variables\n\ | |
1796 List user-defined variables.\n\ | |
1797 @end table\n\ | |
1798 \n\ | |
1799 Valid patterns are the same as described for the @code{clear} command\n\ | |
1800 above. If no patterns are supplied, all symbols from the given category\n\ | |
1801 are listed. By default, only user defined functions and variables\n\ | |
1802 visible in the local scope are displayed.\n\ | |
1803 \n\ | |
1804 The command @kbd{whos} is equivalent to @kbd{who -long}.\n\ | |
1805 @end deffn") | |
581 | 1806 { |
4435 | 1807 octave_value retval; |
581 | 1808 |
4435 | 1809 if (nargout < 2) |
1810 { | |
1811 int argc = args.length () + 1; | |
1812 | |
1813 string_vector argv = args.make_argv ("who"); | |
1755 | 1814 |
7336 | 1815 if (! error_state) |
1816 retval = do_who (argc, argv, nargout == 1); | |
4435 | 1817 } |
1818 else | |
5823 | 1819 print_usage (); |
581 | 1820 |
529 | 1821 return retval; |
1822 } | |
1823 | |
4435 | 1824 DEFCMD (whos, args, nargout, |
3458 | 1825 "-*- texinfo -*-\n\ |
1826 @deffn {Command} whos options pattern @dots{}\n\ | |
1827 See who.\n\ | |
1828 @end deffn") | |
581 | 1829 { |
4435 | 1830 octave_value retval; |
712 | 1831 |
4435 | 1832 if (nargout < 2) |
1833 { | |
7336 | 1834 int argc = args.length () + 1; |
1835 | |
1836 string_vector argv = args.make_argv ("whos"); | |
1837 | |
1838 if (! error_state) | |
1839 retval = do_who (argc, argv, nargout == 1, true); | |
4435 | 1840 } |
1841 else | |
5823 | 1842 print_usage (); |
581 | 1843 |
1844 return retval; | |
1845 } | |
1846 | |
593 | 1847 // Defining variables. |
1848 | |
1162 | 1849 void |
2856 | 1850 bind_ans (const octave_value& val, bool print) |
1162 | 1851 { |
7336 | 1852 static std::string ans = "ans"; |
1162 | 1853 |
2978 | 1854 if (val.is_defined ()) |
1855 { | |
7531
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1856 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
|
1857 { |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1858 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
|
1859 |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1860 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
|
1861 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
|
1862 } |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1863 else |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1864 { |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1865 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
|
1866 |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1867 if (print) |
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1868 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
|
1869 } |
2978 | 1870 } |
1162 | 1871 } |
1872 | |
593 | 1873 void |
5794 | 1874 bind_internal_variable (const std::string& fname, const octave_value& val) |
593 | 1875 { |
5794 | 1876 octave_value_list args; |
1877 | |
1878 args(0) = val; | |
1879 | |
1880 feval (fname, args, 0); | |
529 | 1881 } |
1882 | |
4319 | 1883 void |
7336 | 1884 mlock (void) |
4319 | 1885 { |
7336 | 1886 octave_function *fcn = octave_call_stack::caller (); |
1887 | |
1888 if (fcn) | |
1889 fcn->lock (); | |
1890 else | |
1891 error ("mlock: invalid use outside a function"); | |
4319 | 1892 } |
1893 | |
1894 void | |
1895 munlock (const std::string& nm) | |
1896 { | |
7336 | 1897 octave_value val = symbol_table::find_function (nm); |
1898 | |
1899 if (val.is_defined ()) | |
1900 { | |
1901 octave_function *fcn = val.function_value (); | |
1902 | |
1903 if (fcn) | |
1904 fcn->unlock (); | |
1905 } | |
4319 | 1906 } |
1907 | |
1908 bool | |
1909 mislocked (const std::string& nm) | |
1910 { | |
7336 | 1911 bool retval = false; |
1912 | |
1913 octave_value val = symbol_table::find_function (nm); | |
1914 | |
1915 if (val.is_defined ()) | |
1916 { | |
1917 octave_function *fcn = val.function_value (); | |
1918 | |
1919 if (fcn) | |
1920 retval = fcn->islocked (); | |
1921 } | |
1922 | |
1923 return retval; | |
4319 | 1924 } |
1925 | |
1926 DEFCMD (mlock, args, , | |
1927 "-*- texinfo -*-\n\ | |
4526 | 1928 @deftypefn {Built-in Function} {} mlock (@var{name})\n\ |
7336 | 1929 Lock the current function into memory so that it can't be cleared.\n\ |
5642 | 1930 @seealso{munlock, mislocked, persistent}\n\ |
1931 @end deftypefn") | |
4319 | 1932 { |
1933 octave_value_list retval; | |
1934 | |
7336 | 1935 if (args.length () == 0) |
1936 mlock (); | |
4319 | 1937 else |
5823 | 1938 print_usage (); |
4319 | 1939 |
1940 return retval; | |
1941 } | |
1942 | |
1943 DEFCMD (munlock, args, , | |
1944 "-*- texinfo -*-\n\ | |
1945 @deftypefn {Built-in Function} {} munlock (@var{fcn})\n\ | |
1946 Unlock the named function. If no function is named\n\ | |
1947 then unlock the current function.\n\ | |
5642 | 1948 @seealso{mlock, mislocked, persistent}\n\ |
1949 @end deftypefn") | |
4319 | 1950 { |
1951 octave_value_list retval; | |
1952 | |
1953 if (args.length() == 1) | |
1954 { | |
1955 std::string name = args(0).string_value (); | |
1956 | |
1957 if (! error_state) | |
1958 munlock (name); | |
1959 else | |
1960 error ("munlock: expecting argument to be a function name"); | |
1961 } | |
1962 else if (args.length () == 0) | |
1963 { | |
7336 | 1964 octave_function *fcn = octave_call_stack::caller (); |
5743 | 1965 |
1966 if (fcn) | |
7336 | 1967 fcn->unlock (); |
4319 | 1968 else |
1969 error ("munlock: invalid use outside a function"); | |
1970 } | |
1971 else | |
5823 | 1972 print_usage (); |
4319 | 1973 |
1974 return retval; | |
1975 } | |
1976 | |
1977 | |
1978 DEFCMD (mislocked, args, , | |
1979 "-*- texinfo -*-\n\ | |
1980 @deftypefn {Built-in Function} {} mislocked (@var{fcn})\n\ | |
1981 Return true if the named function is locked. If no function is named\n\ | |
1982 then return true if the current function is locked.\n\ | |
5642 | 1983 @seealso{mlock, munlock, persistent}\n\ |
1984 @end deftypefn") | |
4319 | 1985 { |
1986 octave_value retval; | |
1987 | |
1988 if (args.length() == 1) | |
1989 { | |
1990 std::string name = args(0).string_value (); | |
1991 | |
1992 if (! error_state) | |
1993 retval = mislocked (name); | |
1994 else | |
1995 error ("mislocked: expecting argument to be a function name"); | |
1996 } | |
1997 else if (args.length () == 0) | |
1998 { | |
7336 | 1999 octave_function *fcn = octave_call_stack::caller (); |
5743 | 2000 |
2001 if (fcn) | |
7336 | 2002 retval = fcn->islocked (); |
4319 | 2003 else |
2004 error ("mislocked: invalid use outside a function"); | |
2005 } | |
2006 else | |
5823 | 2007 print_usage (); |
4319 | 2008 |
2009 return retval; | |
2010 } | |
2011 | |
593 | 2012 // Deleting names from the symbol tables. |
2013 | |
3681 | 2014 static inline bool |
4009 | 2015 name_matches_any_pattern (const std::string& nm, |
2016 const string_vector& argv, int argc, int idx) | |
3681 | 2017 { |
2018 bool retval = false; | |
2019 | |
2020 for (int k = idx; k < argc; k++) | |
2021 { | |
2022 std::string patstr = argv[k]; | |
2023 | |
2024 if (! patstr.empty ()) | |
2025 { | |
2026 glob_match pattern (patstr); | |
2027 | |
2028 if (pattern.match (nm)) | |
2029 { | |
2030 retval = true; | |
2031 break; | |
2032 } | |
2033 } | |
2034 } | |
2035 | |
2036 return retval; | |
2037 } | |
2038 | |
4009 | 2039 static inline void |
2040 maybe_warn_exclusive (bool exclusive) | |
2041 { | |
2042 if (exclusive) | |
2043 warning ("clear: ignoring --exclusive option"); | |
2044 } | |
2045 | |
7336 | 2046 static void |
4009 | 2047 do_clear_functions (const string_vector& argv, int argc, int idx, |
2048 bool exclusive = false) | |
2049 { | |
2050 if (idx == argc) | |
7336 | 2051 symbol_table::clear_functions (); |
4009 | 2052 else |
2053 { | |
2054 if (exclusive) | |
2055 { | |
7336 | 2056 string_vector fcns = symbol_table::user_function_names (); |
4009 | 2057 |
2058 int fcount = fcns.length (); | |
2059 | |
2060 for (int i = 0; i < fcount; i++) | |
2061 { | |
2062 std::string nm = fcns[i]; | |
2063 | |
2064 if (! name_matches_any_pattern (nm, argv, argc, idx)) | |
7336 | 2065 symbol_table::clear_function (nm); |
4009 | 2066 } |
2067 } | |
2068 else | |
2069 { | |
2070 while (idx < argc) | |
7336 | 2071 symbol_table::clear_function_pattern (argv[idx++]); |
4009 | 2072 } |
2073 } | |
2074 } | |
2075 | |
7336 | 2076 static void |
4009 | 2077 do_clear_globals (const string_vector& argv, int argc, int idx, |
2078 bool exclusive = false) | |
2079 { | |
2080 if (idx == argc) | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
2081 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
2082 string_vector gvars = symbol_table::global_variable_names (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
2083 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
2084 int gcount = gvars.length (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
2085 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
2086 for (int i = 0; i < gcount; i++) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
2087 symbol_table::clear_global (gvars[i]); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
2088 } |
4009 | 2089 else |
2090 { | |
2091 if (exclusive) | |
2092 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
2093 string_vector gvars = symbol_table::global_variable_names (); |
4009 | 2094 |
2095 int gcount = gvars.length (); | |
2096 | |
2097 for (int i = 0; i < gcount; i++) | |
2098 { | |
2099 std::string nm = gvars[i]; | |
2100 | |
2101 if (! name_matches_any_pattern (nm, argv, argc, idx)) | |
7336 | 2102 symbol_table::clear_global (nm); |
4009 | 2103 } |
2104 } | |
2105 else | |
2106 { | |
2107 while (idx < argc) | |
7336 | 2108 symbol_table::clear_global_pattern (argv[idx++]); |
4009 | 2109 } |
2110 } | |
2111 } | |
2112 | |
7336 | 2113 static void |
4009 | 2114 do_clear_variables (const string_vector& argv, int argc, int idx, |
2115 bool exclusive = false) | |
2116 { | |
2117 if (idx == argc) | |
7336 | 2118 symbol_table::clear_variables (); |
4009 | 2119 else |
2120 { | |
2121 if (exclusive) | |
2122 { | |
7336 | 2123 string_vector lvars = symbol_table::variable_names (); |
4009 | 2124 |
2125 int lcount = lvars.length (); | |
2126 | |
2127 for (int i = 0; i < lcount; i++) | |
2128 { | |
2129 std::string nm = lvars[i]; | |
2130 | |
2131 if (! name_matches_any_pattern (nm, argv, argc, idx)) | |
7336 | 2132 symbol_table::clear_variable (nm); |
4009 | 2133 } |
2134 } | |
2135 else | |
2136 { | |
2137 while (idx < argc) | |
7336 | 2138 symbol_table::clear_variable_pattern (argv[idx++]); |
4009 | 2139 } |
2140 } | |
2141 } | |
2142 | |
7336 | 2143 static void |
4009 | 2144 do_clear_symbols (const string_vector& argv, int argc, int idx, |
2145 bool exclusive = false) | |
2146 { | |
2147 if (idx == argc) | |
7336 | 2148 symbol_table::clear_variables (); |
4009 | 2149 else |
2150 { | |
2151 if (exclusive) | |
2152 { | |
5775 | 2153 // FIXME -- is this really what we want, or do we |
4009 | 2154 // somehow want to only clear the functions that are not |
2155 // shadowed by local variables? It seems that would be a | |
2156 // bit harder to do. | |
2157 | |
2158 do_clear_variables (argv, argc, idx, exclusive); | |
2159 do_clear_functions (argv, argc, idx, exclusive); | |
2160 } | |
2161 else | |
2162 { | |
2163 while (idx < argc) | |
7336 | 2164 symbol_table::clear_symbol_pattern (argv[idx++]); |
4009 | 2165 } |
2166 } | |
2167 } | |
2168 | |
2169 static void | |
2170 do_matlab_compatible_clear (const string_vector& argv, int argc, int idx) | |
2171 { | |
2172 // This is supposed to be mostly Matlab compatible. | |
2173 | |
2174 for (; idx < argc; idx++) | |
2175 { | |
7336 | 2176 if (argv[idx] == "all" |
2177 && ! symbol_table::is_local_variable ("all")) | |
4009 | 2178 { |
7336 | 2179 symbol_table::clear_all (); |
4009 | 2180 } |
7336 | 2181 else if (argv[idx] == "functions" |
2182 && ! symbol_table::is_local_variable ("functions")) | |
4009 | 2183 { |
2184 do_clear_functions (argv, argc, ++idx); | |
2185 } | |
7336 | 2186 else if (argv[idx] == "global" |
2187 && ! symbol_table::is_local_variable ("global")) | |
4009 | 2188 { |
2189 do_clear_globals (argv, argc, ++idx); | |
2190 } | |
7336 | 2191 else if (argv[idx] == "variables" |
2192 && ! symbol_table::is_local_variable ("variables")) | |
4009 | 2193 { |
7336 | 2194 symbol_table::clear_variables (); |
4009 | 2195 } |
2196 else | |
2197 { | |
7336 | 2198 symbol_table::clear_symbol_pattern (argv[idx]); |
4009 | 2199 } |
2200 } | |
2201 } | |
2202 | |
2203 #define CLEAR_OPTION_ERROR(cond) \ | |
2204 do \ | |
2205 { \ | |
2206 if (cond) \ | |
2207 { \ | |
5823 | 2208 print_usage (); \ |
4009 | 2209 return retval; \ |
2210 } \ | |
2211 } \ | |
2212 while (0) | |
2213 | |
4208 | 2214 DEFCMD (clear, args, , |
3361 | 2215 "-*- texinfo -*-\n\ |
7347 | 2216 @deffn {Command} clear [options] pattern @dots{}\n\ |
3361 | 2217 Delete the names matching the given patterns from the symbol table. The\n\ |
2218 pattern may contain the following special characters:\n\ | |
4016 | 2219 \n\ |
3361 | 2220 @table @code\n\ |
2221 @item ?\n\ | |
2222 Match any single character.\n\ | |
668 | 2223 \n\ |
3361 | 2224 @item *\n\ |
2225 Match zero or more characters.\n\ | |
2226 \n\ | |
2227 @item [ @var{list} ]\n\ | |
2228 Match the list of characters specified by @var{list}. If the first\n\ | |
2229 character is @code{!} or @code{^}, match all characters except those\n\ | |
2230 specified by @var{list}. For example, the pattern @samp{[a-zA-Z]} will\n\ | |
2231 match all lower and upper case alphabetic characters.\n\ | |
2232 @end table\n\ | |
2233 \n\ | |
2234 For example, the command\n\ | |
593 | 2235 \n\ |
3361 | 2236 @example\n\ |
2237 clear foo b*r\n\ | |
2238 @end example\n\ | |
2239 \n\ | |
2240 @noindent\n\ | |
2241 clears the name @code{foo} and all names that begin with the letter\n\ | |
2242 @code{b} and end with the letter @code{r}.\n\ | |
668 | 2243 \n\ |
3361 | 2244 If @code{clear} is called without any arguments, all user-defined\n\ |
2245 variables (local and global) are cleared from the symbol table. If\n\ | |
2246 @code{clear} is called with at least one argument, only the visible\n\ | |
2247 names matching the arguments are cleared. For example, suppose you have\n\ | |
2248 defined a function @code{foo}, and then hidden it by performing the\n\ | |
2249 assignment @code{foo = 2}. Executing the command @kbd{clear foo} once\n\ | |
2250 will clear the variable definition and restore the definition of\n\ | |
2251 @code{foo} as a function. Executing @kbd{clear foo} a second time will\n\ | |
2252 clear the function definition.\n\ | |
2253 \n\ | |
7347 | 2254 The following options are available in both long and short form\n\ |
2255 @table @code\n\ | |
2256 @item -all, -a\n\ | |
2257 Clears all local and global user-defined variables and all functions\n\ | |
2258 from the symbol table.\n\ | |
2259 \n\ | |
2260 @item -exclusive, -x\n\ | |
2261 Clears the variables that don't match the following pattern.\n\ | |
2262 \n\ | |
2263 @item -functions, -f\n\ | |
2264 Clears the function names and the built-in symbols names.\n\ | |
2265 @item -global, -g\n\ | |
2266 Clears the global symbol names.\n\ | |
2267 @item -variables, -v\n\ | |
2268 Clears the local variable names.\n\ | |
2269 @end table\n\ | |
2270 With the execption of @code{exclusive}, all long options can be used \n\ | |
2271 without the dash as well.\n\ | |
3361 | 2272 @end deffn") |
529 | 2273 { |
2086 | 2274 octave_value_list retval; |
593 | 2275 |
1755 | 2276 int argc = args.length () + 1; |
593 | 2277 |
1968 | 2278 string_vector argv = args.make_argv ("clear"); |
1755 | 2279 |
4009 | 2280 if (! error_state) |
529 | 2281 { |
4009 | 2282 if (argc == 1) |
593 | 2283 { |
7336 | 2284 symbol_table::clear_variables (); |
3681 | 2285 } |
2286 else | |
2287 { | |
4009 | 2288 int idx = 0; |
2289 | |
2290 bool clear_all = false; | |
2291 bool clear_functions = false; | |
2292 bool clear_globals = false; | |
2293 bool clear_variables = false; | |
2294 bool exclusive = false; | |
2295 bool have_dash_option = false; | |
3681 | 2296 |
4009 | 2297 while (++idx < argc) |
2298 { | |
4010 | 2299 if (argv[idx] == "-all" || argv[idx] == "-a") |
593 | 2300 { |
4009 | 2301 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681 | 2302 |
4009 | 2303 have_dash_option = true; |
2304 clear_all = true; | |
2305 } | |
4010 | 2306 else if (argv[idx] == "-exclusive" || argv[idx] == "-x") |
4009 | 2307 { |
2308 have_dash_option = true; | |
2309 exclusive = true; | |
2310 } | |
4010 | 2311 else if (argv[idx] == "-functions" || argv[idx] == "-f") |
4009 | 2312 { |
2313 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); | |
3681 | 2314 |
4009 | 2315 have_dash_option = true; |
2316 clear_functions = true; | |
2317 } | |
4010 | 2318 else if (argv[idx] == "-global" || argv[idx] == "-g") |
4009 | 2319 { |
2320 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); | |
2321 | |
2322 have_dash_option = true; | |
2323 clear_globals = true; | |
2324 } | |
4010 | 2325 else if (argv[idx] == "-variables" || argv[idx] == "-v") |
4009 | 2326 { |
2327 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); | |
3681 | 2328 |
4009 | 2329 have_dash_option = true; |
2330 clear_variables = true; | |
2331 } | |
2332 else | |
2333 break; | |
2334 } | |
3681 | 2335 |
4224 | 2336 if (idx <= argc) |
4009 | 2337 { |
2338 if (! have_dash_option) | |
2339 { | |
2340 do_matlab_compatible_clear (argv, argc, idx); | |
2341 } | |
2342 else | |
2343 { | |
2344 if (clear_all) | |
3681 | 2345 { |
4009 | 2346 maybe_warn_exclusive (exclusive); |
3681 | 2347 |
4009 | 2348 if (++idx < argc) |
2349 warning | |
4010 | 2350 ("clear: ignoring extra arguments after -all"); |
3681 | 2351 |
7336 | 2352 symbol_table::clear_all (); |
4009 | 2353 } |
2354 else if (clear_functions) | |
2355 { | |
2356 do_clear_functions (argv, argc, idx, exclusive); | |
2357 } | |
2358 else if (clear_globals) | |
593 | 2359 { |
4009 | 2360 do_clear_globals (argv, argc, idx, exclusive); |
2361 } | |
2362 else if (clear_variables) | |
2363 { | |
2364 do_clear_variables (argv, argc, idx, exclusive); | |
2365 } | |
2366 else | |
2367 { | |
2368 do_clear_symbols (argv, argc, idx, exclusive); | |
593 | 2369 } |
2370 } | |
2371 } | |
2372 } | |
2373 } | |
2374 | |
2375 return retval; | |
529 | 2376 } |
2377 | |
3933 | 2378 DEFUN (__print_symtab_info__, args, , |
3446 | 2379 "-*- texinfo -*-\n\ |
3933 | 2380 @deftypefn {Built-in Function} {} __print_symtab_info__ ()\n\ |
6945 | 2381 Undocumented internal function.\n\ |
3446 | 2382 @end deftypefn") |
3005 | 2383 { |
2384 octave_value_list retval; | |
2385 | |
7336 | 2386 // FIXME -- what should this function do now? Print a summary for |
2387 // each scope? Print the entire symbol table? Accept a scope | |
2388 // argument? | |
3005 | 2389 |
2390 return retval; | |
2391 } | |
2392 | |
3933 | 2393 DEFUN (__print_symbol_info__, args, , |
3446 | 2394 "-*- texinfo -*-\n\ |
2395 @deftypefn {Built-in Function} {} __dump_symbol_info__ (@var{name})\n\ | |
6945 | 2396 Undocumented internal function.\n\ |
3446 | 2397 @end deftypefn") |
3239 | 2398 { |
2399 octave_value_list retval; | |
2400 | |
7336 | 2401 // FIXME -- what should this function do now? |
3239 | 2402 |
2403 return retval; | |
2404 } | |
2405 | |
7336 | 2406 DEFUN (whos_line_format, args, nargout, |
2407 "-*- texinfo -*-\n\ | |
2408 @deftypefn {Built-in Function} {@var{val} =} whos_line_format ()\n\ | |
2409 @deftypefnx {Built-in Function} {@var{old_val} =} whos_line_format (@var{new_val})\n\ | |
2410 Query or set the format string used by the @code{whos}.\n\ | |
2411 \n\ | |
2412 The following escape sequences may be used in the format:\n\ | |
2413 @table @code\n\ | |
2414 @item %a\n\ | |
2415 Prints attributes of variables (g=global, p=persistent,\n\ | |
2416 f=formal parameter, a=automatic variable).\n\ | |
2417 @item %b\n\ | |
2418 Prints number of bytes occupied by variables.\n\ | |
2419 @item %c\n\ | |
2420 Prints class names of variables.\n\ | |
2421 @item %e\n\ | |
2422 Prints elements held by variables.\n\ | |
2423 @item %n\n\ | |
2424 Prints variable names.\n\ | |
2425 @item %s\n\ | |
2426 Prints dimensions of variables.\n\ | |
2427 @item %t\n\ | |
2428 Prints type names of variables.\n\ | |
2429 @end table\n\ | |
2430 \n\ | |
2431 Every command may also have a modifier:\n\ | |
2432 @table @code\n\ | |
2433 @item l\n\ | |
2434 Left alignment.\n\ | |
2435 @item r\n\ | |
2436 Right alignment (this is the default).\n\ | |
2437 @item c\n\ | |
2438 Centered (may only be applied to command %s).\n\ | |
2439 @end table\n\ | |
2440 \n\ | |
2441 A command is composed like this:\n\ | |
2442 \n\ | |
2443 @example\n\ | |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
2444 %[modifier]<command>[:size_of_parameter[:center-specific[:balance]]];\n\ |
7336 | 2445 @end example\n\ |
2446 \n\ | |
2447 Command and modifier is already explained. Size_of_parameter\n\ | |
2448 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
|
2449 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
|
2450 @samp{%s}.\n\ |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
2451 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
|
2452 the dimensions string.\n\ |
7336 | 2453 \n\ |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
2454 The default format is \" %a:4; %ln:6; %cs:16:6:1; %rb:12; %lc:-1;\\n\".\n\ |
5794 | 2455 @end deftypefn") |
2456 { | |
7336 | 2457 return SET_INTERNAL_VARIABLE (whos_line_format); |
3016 | 2458 } |
2459 | |
1 | 2460 /* |
2461 ;;; Local Variables: *** | |
2462 ;;; mode: C++ *** | |
2463 ;;; End: *** | |
2464 */ |