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