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