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