Mercurial > octave-libgccjit
annotate libinterp/corefcn/variables.cc @ 18856:de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
* variables.cc (symbol_exist): Simplify code by removing obsolete code testing for
structures in the input name. Re-order testing blocks so that built-in code (5) is
returned before generic file code (2).
* variables.cc (Fexist): Add more comprehensive %!tests for exist.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 25 Jun 2014 12:51:55 -0700 |
parents | 87381dbbe25e |
children | a1dde4d4c45c |
rev | line source |
---|---|
1 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17516
diff
changeset
|
3 Copyright (C) 1993-2013 John W. Eaton |
11523 | 4 Copyright (C) 2009-2010 VZLU Prague |
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" |
16940
99122191d3dd
maint: Rename regexp.h to lo-regexp.h, regexp.cc to lo-regexp.cc in liboctave.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
39 #include "lo-regexp.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" |
16523
62d8aaf6ba8f
force update of GUI workspace viewer from clear function
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
52 #include "octave-link.h" |
2926 | 53 #include "oct-map.h" |
54 #include "oct-obj.h" | |
55 #include "ov.h" | |
9240
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9180
diff
changeset
|
56 #include "ov-class.h" |
3933 | 57 #include "ov-usr-fcn.h" |
605 | 58 #include "pager.h" |
1352 | 59 #include "parse.h" |
2926 | 60 #include "symtab.h" |
2205 | 61 #include "toplev.h" |
1352 | 62 #include "unwind-prot.h" |
1 | 63 #include "utils.h" |
1352 | 64 #include "variables.h" |
2205 | 65 |
7336 | 66 // Defines layout for the whos/who -long command |
67 static std::string Vwhos_line_format | |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
68 = " %a:4; %ln:6; %cs:16:6:1; %rb:12; %lc:-1;\n"; |
195 | 69 |
6068 | 70 void |
6072 | 71 clear_mex_functions (void) |
6068 | 72 { |
7336 | 73 symbol_table::clear_mex_functions (); |
74 } | |
75 | |
76 void | |
77 clear_function (const std::string& nm) | |
78 { | |
79 symbol_table::clear_function (nm); | |
80 } | |
81 | |
82 void | |
83 clear_variable (const std::string& nm) | |
84 { | |
85 symbol_table::clear_variable (nm); | |
86 } | |
87 | |
88 void | |
89 clear_symbol (const std::string& nm) | |
90 { | |
91 symbol_table::clear_symbol (nm); | |
6068 | 92 } |
93 | |
593 | 94 // Attributes of variables and functions. |
95 | |
2086 | 96 // Is this octave_value a valid function? |
593 | 97 |
2975 | 98 octave_function * |
4345 | 99 is_valid_function (const std::string& fcn_name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
100 const std::string& warn_for, bool warn) |
593 | 101 { |
2975 | 102 octave_function *ans = 0; |
593 | 103 |
1755 | 104 if (! fcn_name.empty ()) |
3618 | 105 { |
7336 | 106 octave_value val = symbol_table::find_function (fcn_name); |
107 | |
108 if (val.is_defined ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
109 ans = val.function_value (true); |
3618 | 110 } |
593 | 111 |
7336 | 112 if (! ans && warn) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
113 error ("%s: the symbol '%s' is not valid as a function", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
114 warn_for.c_str (), fcn_name.c_str ()); |
593 | 115 |
116 return ans; | |
117 } | |
118 | |
2975 | 119 octave_function * |
4345 | 120 is_valid_function (const octave_value& arg, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
121 const std::string& warn_for, bool warn) |
3178 | 122 { |
123 octave_function *ans = 0; | |
124 | |
3523 | 125 std::string fcn_name; |
3178 | 126 |
127 if (arg.is_string ()) | |
4700 | 128 { |
129 fcn_name = arg.string_value (); | |
3178 | 130 |
4700 | 131 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
132 ans = is_valid_function (fcn_name, warn_for, warn); |
4700 | 133 else if (warn) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
134 error ("%s: expecting function name as argument", warn_for.c_str ()); |
4700 | 135 } |
3178 | 136 else if (warn) |
137 error ("%s: expecting function name as argument", warn_for.c_str ()); | |
138 | |
139 return ans; | |
140 } | |
141 | |
142 octave_function * | |
3523 | 143 extract_function (const octave_value& arg, const std::string& warn_for, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
144 const std::string& fname, const std::string& header, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
145 const std::string& trailer) |
2796 | 146 { |
2975 | 147 octave_function *retval = 0; |
2796 | 148 |
149 retval = is_valid_function (arg, warn_for, 0); | |
150 | |
151 if (! retval) | |
152 { | |
3523 | 153 std::string s = arg.string_value (); |
2796 | 154 |
3523 | 155 std::string cmd = header; |
2796 | 156 cmd.append (s); |
157 cmd.append (trailer); | |
158 | |
159 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
160 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
161 int parse_status; |
2796 | 162 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
163 eval_string (cmd, true, parse_status, 0); |
2796 | 164 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
165 if (parse_status == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
166 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
167 retval = is_valid_function (fname, warn_for, 0); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11558
diff
changeset
|
168 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
169 if (! retval) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
170 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
171 error ("%s: '%s' is not valid as a function", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
172 warn_for.c_str (), fname.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
173 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
174 } |
9727
04386b72d3df
fix extract_function & add obsoleteness warning
Jaroslav Hajek <highegg@gmail.com>
parents:
9724
diff
changeset
|
175 |
11590
4ced6b90fffb
style fixes for warning and error messages in source files
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
176 warning ("%s: passing function body as a string is obsolete; please use anonymous functions", |
4ced6b90fffb
style fixes for warning and error messages in source files
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
177 warn_for.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
178 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
179 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
180 error ("%s: '%s' is not valid as a function", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
181 warn_for.c_str (), fname.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
182 } |
2796 | 183 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
184 error ("%s: expecting first argument to be a string", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
185 warn_for.c_str ()); |
2796 | 186 } |
187 | |
188 return retval; | |
189 } | |
190 | |
2921 | 191 string_vector |
3523 | 192 get_struct_elts (const std::string& text) |
2921 | 193 { |
194 int n = 1; | |
195 | |
196 size_t pos = 0; | |
197 | |
198 size_t len = text.length (); | |
199 | |
8021 | 200 while ((pos = text.find ('.', pos)) != std::string::npos) |
2921 | 201 { |
202 if (++pos == len) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
203 break; |
2921 | 204 |
205 n++; | |
206 } | |
207 | |
208 string_vector retval (n); | |
209 | |
210 pos = 0; | |
211 | |
212 for (int i = 0; i < n; i++) | |
213 { | |
4587 | 214 len = text.find ('.', pos); |
2921 | 215 |
8021 | 216 if (len != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
217 len -= pos; |
2921 | 218 |
219 retval[i] = text.substr (pos, len); | |
220 | |
8021 | 221 if (len != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
222 pos += len + 1; |
2921 | 223 } |
224 | |
225 return retval; | |
226 } | |
227 | |
4179 | 228 static inline bool |
229 is_variable (const std::string& name) | |
230 { | |
231 bool retval = false; | |
232 | |
233 if (! name.empty ()) | |
234 { | |
7336 | 235 octave_value val = symbol_table::varval (name); |
236 | |
237 retval = val.is_defined (); | |
4179 | 238 } |
239 | |
240 return retval; | |
241 } | |
242 | |
2921 | 243 string_vector |
3933 | 244 generate_struct_completions (const std::string& text, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
245 std::string& prefix, std::string& hint) |
2921 | 246 { |
247 string_vector names; | |
248 | |
249 size_t pos = text.rfind ('.'); | |
250 | |
8021 | 251 if (pos != std::string::npos) |
2921 | 252 { |
253 if (pos == text.length ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
254 hint = ""; |
2921 | 255 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
256 hint = text.substr (pos+1); |
2921 | 257 |
258 prefix = text.substr (0, pos); | |
259 | |
4179 | 260 std::string base_name = prefix; |
261 | |
262 pos = base_name.find_first_of ("{(."); | |
2921 | 263 |
8021 | 264 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
265 base_name = base_name.substr (0, pos); |
4143 | 266 |
4179 | 267 if (is_variable (base_name)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
268 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
269 int parse_status; |
4179 | 270 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
271 unwind_protect frame; |
3935 | 272 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
273 frame.protect_var (error_state); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
274 frame.protect_var (warning_state); |
4452 | 275 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
276 frame.protect_var (discard_error_messages); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
277 frame.protect_var (discard_warning_messages); |
3935 | 278 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
279 discard_error_messages = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
280 discard_warning_messages = true; |
2921 | 281 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
282 octave_value tmp = eval_string (prefix, true, parse_status); |
4179 | 283 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
284 frame.run (); |
3935 | 285 |
15807
37104cd70d0f
Add command-line completion for method names of Java object.
Rik <rik@octave.org>
parents:
15562
diff
changeset
|
286 if (tmp.is_defined () && (tmp.is_map () || tmp.is_java ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
287 names = tmp.map_keys (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
288 } |
4179 | 289 } |
2921 | 290 |
291 return names; | |
292 } | |
293 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
294 // FIXME: this will have to be much smarter to work "correctly". |
4179 | 295 |
2921 | 296 bool |
3523 | 297 looks_like_struct (const std::string& text) |
2921 | 298 { |
4604 | 299 bool retval = (! text.empty () |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
300 && text != "." |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
301 && text.find_first_of (file_ops::dir_sep_chars ()) == std::string::npos |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
302 && text.find ("..") == std::string::npos |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
303 && text.rfind ('.') != std::string::npos); |
3968 | 304 |
4179 | 305 #if 0 |
3968 | 306 symbol_record *sr = curr_sym_tab->lookup (text); |
2963 | 307 |
3968 | 308 if (sr && ! sr->is_function ()) |
309 { | |
310 int parse_status; | |
2921 | 311 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9750
diff
changeset
|
312 unwind_protect frame; |
4143 | 313 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9750
diff
changeset
|
314 frame.protect_var (discard_error_messages); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9750
diff
changeset
|
315 frame.protect_var (error_state); |
4143 | 316 |
317 discard_error_messages = true; | |
318 | |
3968 | 319 octave_value tmp = eval_string (text, true, parse_status); |
320 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9750
diff
changeset
|
321 frame.run (); |
4143 | 322 |
3968 | 323 retval = (tmp.is_defined () && tmp.is_map ()); |
324 } | |
4179 | 325 #endif |
3968 | 326 |
327 return retval; | |
2921 | 328 } |
2796 | 329 |
5930 | 330 static octave_value |
331 do_isglobal (const octave_value_list& args) | |
593 | 332 { |
4233 | 333 octave_value retval = false; |
593 | 334 |
712 | 335 int nargin = args.length (); |
336 | |
337 if (nargin != 1) | |
593 | 338 { |
5823 | 339 print_usage (); |
593 | 340 return retval; |
341 } | |
342 | |
3523 | 343 std::string name = args(0).string_value (); |
593 | 344 |
636 | 345 if (error_state) |
346 { | |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11595
diff
changeset
|
347 error ("isglobal: NAME must be a string"); |
636 | 348 return retval; |
349 } | |
350 | |
7336 | 351 return symbol_table::is_global (name); |
593 | 352 } |
353 | |
5930 | 354 DEFUN (isglobal, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
355 "-*- texinfo -*-\n\ |
5930 | 356 @deftypefn {Built-in Function} {} isglobal (@var{name})\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11151
diff
changeset
|
357 Return true if @var{name} is a globally visible variable.\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11151
diff
changeset
|
358 For example:\n\ |
5930 | 359 \n\ |
360 @example\n\ | |
361 @group\n\ | |
362 global x\n\ | |
363 isglobal (\"x\")\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
364 @result{} 1\n\ |
5930 | 365 @end group\n\ |
366 @end example\n\ | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11151
diff
changeset
|
367 @seealso{isvarname, exist}\n\ |
5930 | 368 @end deftypefn") |
369 { | |
370 return do_isglobal (args); | |
371 } | |
372 | |
9454
c58b8960c7d0
variables.cc (symbol_exist): ignore errors when parsing functions
John W. Eaton <jwe@octave.org>
parents:
9445
diff
changeset
|
373 static octave_value |
c58b8960c7d0
variables.cc (symbol_exist): ignore errors when parsing functions
John W. Eaton <jwe@octave.org>
parents:
9445
diff
changeset
|
374 safe_symbol_lookup (const std::string& symbol_name) |
c58b8960c7d0
variables.cc (symbol_exist): ignore errors when parsing functions
John W. Eaton <jwe@octave.org>
parents:
9445
diff
changeset
|
375 { |
c58b8960c7d0
variables.cc (symbol_exist): ignore errors when parsing functions
John W. Eaton <jwe@octave.org>
parents:
9445
diff
changeset
|
376 octave_value retval; |
c58b8960c7d0
variables.cc (symbol_exist): ignore errors when parsing functions
John W. Eaton <jwe@octave.org>
parents:
9445
diff
changeset
|
377 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9750
diff
changeset
|
378 unwind_protect frame; |
11029
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10975
diff
changeset
|
379 interpreter_try (frame); |
9454
c58b8960c7d0
variables.cc (symbol_exist): ignore errors when parsing functions
John W. Eaton <jwe@octave.org>
parents:
9445
diff
changeset
|
380 |
c58b8960c7d0
variables.cc (symbol_exist): ignore errors when parsing functions
John W. Eaton <jwe@octave.org>
parents:
9445
diff
changeset
|
381 retval = symbol_table::find (symbol_name); |
c58b8960c7d0
variables.cc (symbol_exist): ignore errors when parsing functions
John W. Eaton <jwe@octave.org>
parents:
9445
diff
changeset
|
382 |
c58b8960c7d0
variables.cc (symbol_exist): ignore errors when parsing functions
John W. Eaton <jwe@octave.org>
parents:
9445
diff
changeset
|
383 error_state = 0; |
c58b8960c7d0
variables.cc (symbol_exist): ignore errors when parsing functions
John W. Eaton <jwe@octave.org>
parents:
9445
diff
changeset
|
384 |
c58b8960c7d0
variables.cc (symbol_exist): ignore errors when parsing functions
John W. Eaton <jwe@octave.org>
parents:
9445
diff
changeset
|
385 return retval; |
c58b8960c7d0
variables.cc (symbol_exist): ignore errors when parsing functions
John W. Eaton <jwe@octave.org>
parents:
9445
diff
changeset
|
386 } |
c58b8960c7d0
variables.cc (symbol_exist): ignore errors when parsing functions
John W. Eaton <jwe@octave.org>
parents:
9445
diff
changeset
|
387 |
4016 | 388 int |
389 symbol_exist (const std::string& name, const std::string& type) | |
593 | 390 { |
18856
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
391 if (is_keyword (name)) |
17963
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
392 return 0; |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
393 |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
394 bool search_any = type == "any"; |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
395 bool search_var = type == "var"; |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
396 bool search_dir = type == "dir"; |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
397 bool search_file = type == "file"; |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
398 bool search_builtin = type == "builtin"; |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
399 |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
400 if (search_any || search_var) |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
401 { |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
402 octave_value val = symbol_table::varval (name); |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
403 |
18856
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
404 if (val.is_constant () || val.is_object () |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
405 || val.is_function_handle () |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
406 || val.is_anonymous_function () |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
407 || val.is_inline_function ()) |
17963
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
408 return 1; |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
409 |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
410 if (search_var) |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
411 return 0; |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
412 } |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
413 |
18856
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
414 // We shouldn't need to look in the global symbol table, since any name |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
415 // that is visible in the current scope will be in the local symbol table. |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
416 |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
417 octave_value val = safe_symbol_lookup (name); |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
418 |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
419 if (val.is_defined ()) |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
420 { |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
421 if ((search_any || search_builtin) |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
422 && val.is_builtin_function ()) |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
423 return 5; |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
424 } |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
425 |
17963
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
426 if (search_any || search_file || search_dir) |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
427 { |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
428 std::string file_name = lookup_autoload (name); |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
429 |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
430 if (file_name.empty ()) |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
431 file_name = load_path::find_fcn (name); |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
432 |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
433 size_t len = file_name.length (); |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
434 |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
435 if (len > 0) |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
436 { |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
437 if (search_any || search_file) |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
438 { |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
439 if (len > 4 && (file_name.substr (len-4) == ".oct" |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
440 || file_name.substr (len-4) == ".mex")) |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
441 return 3; |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
442 else |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
443 return 2; |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
444 } |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
445 } |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
446 |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
447 file_name = file_in_path (name, ""); |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
448 |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
449 if (file_name.empty ()) |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
450 file_name = name; |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
451 |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
452 file_stat fs (file_name); |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
453 |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
454 if (fs) |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
455 { |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
456 if (search_any || search_file) |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
457 return fs.is_dir () ? 7 : 2; |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
458 else if (search_dir && fs.is_dir ()) |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
459 return 7; |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
460 } |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
461 |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
462 if (search_file || search_dir) |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
463 return 0; |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
464 } |
1277 | 465 |
18856
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
466 if (val.is_defined ()) |
1277 | 467 { |
17963
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
468 if ((search_any || search_file) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
469 && (val.is_user_function () || val.is_dld_function ())) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
470 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
471 octave_function *f = val.function_value (true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
472 std::string s = f ? f->fcn_file_name () : std::string (); |
4016 | 473 |
18856
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
474 // FIXME: I believe that by this point in the code the only |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
475 // return value is 103. User functions should have |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
476 // been located above. Maybe replace entire if block |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
477 // code with "return 103;" |
17963
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
478 return s.empty () ? 103 : (val.is_user_function () ? 2 : 3); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
479 } |
1421 | 480 } |
4016 | 481 |
17963
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
482 return 0; |
593 | 483 } |
484 | |
4962 | 485 #define GET_IDX(LEN) \ |
486 static_cast<int> ((LEN-1) * static_cast<double> (rand ()) / RAND_MAX) | |
487 | |
4954 | 488 std::string |
489 unique_symbol_name (const std::string& basename) | |
490 { | |
4962 | 491 static const std::string alpha |
492 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
493 | |
494 static size_t len = alpha.length (); | |
495 | |
496 std::string nm = basename + alpha[GET_IDX (len)]; | |
497 | |
498 size_t pos = nm.length (); | |
499 | |
500 if (nm.substr (0, 2) == "__") | |
501 nm.append ("__"); | |
502 | |
503 while (symbol_exist (nm, "any")) | |
504 nm.insert (pos++, 1, alpha[GET_IDX (len)]); | |
505 | |
506 return nm; | |
4954 | 507 } |
508 | |
4016 | 509 DEFUN (exist, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
510 "-*- texinfo -*-\n\ |
4016 | 511 @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
|
512 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
|
513 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
|
514 appending @samp{.m}) a function file in Octave's @code{path}, 3 if the\n\ |
5864 | 515 name is a @samp{.oct} or @samp{.mex} file in Octave's @code{path},\n\ |
516 5 if the name is a built-in function, 7 if the name is a directory, or 103\n\ | |
4016 | 517 if the name is a function not associated with a file (entered on\n\ |
518 the command line).\n\ | |
519 \n\ | |
520 Otherwise, return 0.\n\ | |
521 \n\ | |
522 This function also returns 2 if a regular file called @var{name}\n\ | |
5814 | 523 exists in Octave's search path. If you want information about\n\ |
4016 | 524 other types of files, you should use some combination of the functions\n\ |
525 @code{file_in_path} and @code{stat} instead.\n\ | |
526 \n\ | |
527 If the optional argument @var{type} is supplied, check only for\n\ | |
528 symbols of the specified type. Valid types are\n\ | |
529 \n\ | |
11595
5ec6aa05638d
Prevent doubled quotes around @table items in Info.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
530 @table @asis\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16940
diff
changeset
|
531 @item @qcode{\"var\"}\n\ |
4016 | 532 Check only for variables.\n\ |
10840 | 533 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16940
diff
changeset
|
534 @item @qcode{\"builtin\"}\n\ |
4016 | 535 Check only for built-in functions.\n\ |
10840 | 536 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16940
diff
changeset
|
537 @item @qcode{\"file\"}\n\ |
15508
cea08e743c2c
doc: Clarify that exist (name, "file") also includes directories (bug #37512).
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
538 Check only for files and directories.\n\ |
10840 | 539 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16940
diff
changeset
|
540 @item @qcode{\"dir\"}\n\ |
4016 | 541 Check only for directories.\n\ |
542 @end table\n\ | |
15007
8f0e3c5bfa5f
doc: Periodic grammarcheck of documentation
Rik <rik@octave.org>
parents:
14861
diff
changeset
|
543 \n\ |
18074
1e27079409bf
Rename function dir_in_path to dir_in_loadpath.
Rik <rik@octave.org>
parents:
18070
diff
changeset
|
544 @seealso{file_in_loadpath, file_in_path, dir_in_loadpath, stat}\n\ |
4016 | 545 @end deftypefn") |
546 { | |
4233 | 547 octave_value retval = false; |
4016 | 548 |
549 int nargin = args.length (); | |
550 | |
551 if (nargin == 1 || nargin == 2) | |
552 { | |
553 std::string name = args(0).string_value (); | |
554 | |
555 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
556 { |
17963
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
557 if (nargin == 2) |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
558 { |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
559 std::string type = args(1).string_value (); |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
560 |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
561 if (! error_state) |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
562 retval = symbol_exist (name, type); |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
563 else |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
564 error ("exist: TYPE must be a string"); |
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
565 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
566 else |
17963
2ca3a2f46d93
improve performance of exist when searching for specific items
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
567 retval = symbol_exist (name); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
568 } |
4016 | 569 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11595
diff
changeset
|
570 error ("exist: NAME must be a string"); |
4016 | 571 } |
572 else | |
5823 | 573 print_usage (); |
4016 | 574 |
575 return retval; | |
576 } | |
577 | |
10975
2d14817353a6
allow exist to work correctly for special files; recognize directories when searching for files
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
578 /* |
18856
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
579 %!shared dirtmp, __var1 |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
580 %! dirtmp = P_tmpdir (); |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
581 %! __var1 = 1; |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
582 |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
583 %!assert (exist ("__%Highly_unlikely_name%__"), 0) |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
584 %!assert (exist ("__var1"), 1) |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
585 %!assert (exist ("__var1", "var"), 1) |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
586 %!assert (exist ("__var1", "builtin"), 0) |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
587 %!assert (exist ("__var1", "dir"), 0) |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
588 %!assert (exist ("__var1", "file"), 0) |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
589 |
10975
2d14817353a6
allow exist to work correctly for special files; recognize directories when searching for files
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
590 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
591 %! if (isunix ()) |
18856
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
592 %! assert (exist ("/bin/sh"), 2); |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
593 %! assert (exist ("/bin/sh", "file"), 2); |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
594 %! assert (exist ("/bin/sh", "dir"), 0); |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
595 %! assert (exist ("/dev/null"), 2); |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
596 %! assert (exist ("/dev/null", "file"), 2); |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
597 %! assert (exist ("/dev/null", "dir"), 0); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
598 %! endif |
18856
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
599 |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
600 %!assert (exist ("colon"), 2) |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
601 %!assert (exist ("colon.m"), 2) |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
602 |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
603 %!testif HAVE_CHOLMOD |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
604 %! assert (exist ("chol"), 3); |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
605 %! assert (exist ("chol", "file"), 3); |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
606 %! assert (exist ("chol", "builtin"), 0); |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
607 |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
608 %!assert (exist ("sin"), 5) |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
609 |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
610 %!assert (exist (dirtmp), 7) |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
611 %!assert (exist (dirtmp, "dir"), 7) |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
612 %!assert (exist (dirtmp, "file"), 7) |
de8c67ba7ac4
Use Matlab return hierarchy for exist() codes when no type is specified.
Rik <rik@octave.org>
parents:
18282
diff
changeset
|
613 |
10975
2d14817353a6
allow exist to work correctly for special files; recognize directories when searching for files
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
614 */ |
2d14817353a6
allow exist to work correctly for special files; recognize directories when searching for files
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
615 |
2849 | 616 octave_value |
4988 | 617 lookup_function_handle (const std::string& nm) |
618 { | |
7336 | 619 octave_value val = symbol_table::varval (nm); |
620 | |
621 return val.is_function_handle () ? val : octave_value (); | |
4988 | 622 } |
623 | |
624 octave_value | |
5027 | 625 get_global_value (const std::string& nm, bool silent) |
2849 | 626 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
627 octave_value val = symbol_table::global_varval (nm); |
7336 | 628 |
629 if (val.is_undefined () && ! silent) | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
630 error ("get_global_value: undefined symbol '%s'", nm.c_str ()); |
7336 | 631 |
632 return val; | |
2849 | 633 } |
634 | |
635 void | |
3523 | 636 set_global_value (const std::string& nm, const octave_value& val) |
2849 | 637 { |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15807
diff
changeset
|
638 symbol_table::global_assign (nm, val); |
2849 | 639 } |
640 | |
10071
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
641 octave_value |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
642 get_top_level_value (const std::string& nm, bool silent) |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
643 { |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
644 octave_value val = symbol_table::top_level_varval (nm); |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
645 |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
646 if (val.is_undefined () && ! silent) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
647 error ("get_top_level_value: undefined symbol '%s'", nm.c_str ()); |
10071
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
648 |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
649 return val; |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
650 } |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
651 |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
652 void |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
653 set_top_level_value (const std::string& nm, const octave_value& val) |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
654 { |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15807
diff
changeset
|
655 symbol_table::top_level_assign (nm, val); |
10071
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
656 } |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
10066
diff
changeset
|
657 |
593 | 658 // Variable values. |
195 | 659 |
10637
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
660 static bool |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
661 wants_local_change (const octave_value_list& args, int& nargin) |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
662 { |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
663 bool retval = false; |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
664 |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
665 if (nargin == 2) |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
666 { |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
667 if (args(1).is_string () && args(1).string_value () == "local") |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
668 { |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
669 nargin = 1; |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
670 retval = true; |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
671 } |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
672 else |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
673 { |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
674 error_with_cfn ("expecting second argument to be \"local\""); |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
675 nargin = 0; |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
676 } |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
677 } |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
678 |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
679 return retval; |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
680 } |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
681 |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
682 template <class T> |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
683 bool try_local_protect (T& var) |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
684 { |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
685 octave_user_code *curr_usr_code = octave_call_stack::caller_user_code (); |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
686 octave_user_function *curr_usr_fcn = 0; |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
687 if (curr_usr_code && curr_usr_code->is_user_function ()) |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
688 curr_usr_fcn = dynamic_cast<octave_user_function *> (curr_usr_code); |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
689 |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
690 if (curr_usr_fcn && curr_usr_fcn->local_protect (var)) |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
691 return true; |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
692 else |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
693 return false; |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
694 } |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
695 |
5791 | 696 octave_value |
697 set_internal_variable (bool& var, const octave_value_list& args, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
698 int nargout, const char *nm) |
5791 | 699 { |
5794 | 700 octave_value retval; |
701 | |
5800 | 702 int nargin = args.length (); |
703 | |
704 if (nargout > 0 || nargin == 0) | |
5794 | 705 retval = var; |
5791 | 706 |
10637
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
707 if (wants_local_change (args, nargin)) |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
708 { |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
709 if (! try_local_protect (var)) |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
710 warning ("\"local\" has no effect outside a function"); |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
711 } |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
712 |
5791 | 713 if (nargin == 1) |
714 { | |
715 bool bval = args(0).bool_value (); | |
716 | |
717 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
718 var = bval; |
5791 | 719 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
720 error ("%s: expecting arg to be a logical value", nm); |
5791 | 721 } |
722 else if (nargin > 1) | |
5823 | 723 print_usage (); |
5791 | 724 |
725 return retval; | |
726 } | |
727 | |
728 octave_value | |
5794 | 729 set_internal_variable (char& var, const octave_value_list& args, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
730 int nargout, const char *nm) |
5791 | 731 { |
5794 | 732 octave_value retval; |
733 | |
5800 | 734 int nargin = args.length (); |
735 | |
736 if (nargout > 0 || nargin == 0) | |
5794 | 737 retval = var; |
5791 | 738 |
10637
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
739 if (wants_local_change (args, nargin)) |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
740 { |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
741 if (! try_local_protect (var)) |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
742 warning ("\"local\" has no effect outside a function"); |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
743 } |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
744 |
5791 | 745 if (nargin == 1) |
746 { | |
747 std::string sval = args(0).string_value (); | |
748 | |
749 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
750 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
751 switch (sval.length ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
752 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
753 case 1: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
754 var = sval[0]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
755 break; |
5794 | 756 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
757 case 0: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
758 var = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
759 break; |
5794 | 760 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
761 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
762 error ("%s: argument must be a single character", nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
763 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
764 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
765 } |
5794 | 766 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
767 error ("%s: argument must be a single character", nm); |
5794 | 768 } |
769 else if (nargin > 1) | |
5823 | 770 print_usage (); |
5794 | 771 |
772 return retval; | |
773 } | |
774 | |
775 octave_value | |
776 set_internal_variable (int& var, const octave_value_list& args, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
777 int nargout, const char *nm, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
778 int minval, int maxval) |
5794 | 779 { |
780 octave_value retval; | |
781 | |
5800 | 782 int nargin = args.length (); |
783 | |
784 if (nargout > 0 || nargin == 0) | |
5794 | 785 retval = var; |
786 | |
10637
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
787 if (wants_local_change (args, nargin)) |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
788 { |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
789 if (! try_local_protect (var)) |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
790 warning ("\"local\" has no effect outside a function"); |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
791 } |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
792 |
5794 | 793 if (nargin == 1) |
794 { | |
795 int ival = args(0).int_value (); | |
796 | |
797 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
798 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
799 if (ival < minval) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
800 error ("%s: expecting arg to be greater than %d", nm, minval); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
801 else if (ival > maxval) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
802 error ("%s: expecting arg to be less than or equal to %d", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
803 nm, maxval); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
804 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
805 var = ival; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
806 } |
5794 | 807 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
808 error ("%s: expecting arg to be an integer value", nm); |
5794 | 809 } |
810 else if (nargin > 1) | |
5823 | 811 print_usage (); |
5794 | 812 |
813 return retval; | |
814 } | |
815 | |
816 octave_value | |
817 set_internal_variable (double& var, const octave_value_list& args, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
818 int nargout, const char *nm, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
819 double minval, double maxval) |
5794 | 820 { |
821 octave_value retval; | |
822 | |
5800 | 823 int nargin = args.length (); |
824 | |
825 if (nargout > 0 || nargin == 0) | |
5794 | 826 retval = var; |
827 | |
10637
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
828 if (wants_local_change (args, nargin)) |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
829 { |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
830 if (! try_local_protect (var)) |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
831 warning ("\"local\" has no effect outside a function"); |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
832 } |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
833 |
5794 | 834 if (nargin == 1) |
835 { | |
836 double dval = args(0).scalar_value (); | |
837 | |
838 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
839 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
840 if (dval < minval) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
841 error ("%s: expecting arg to be greater than %g", minval); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
842 else if (dval > maxval) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
843 error ("%s: expecting arg to be less than or equal to %g", maxval); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
844 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
845 var = dval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
846 } |
5794 | 847 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
848 error ("%s: expecting arg to be a scalar value", nm); |
5794 | 849 } |
850 else if (nargin > 1) | |
5823 | 851 print_usage (); |
5794 | 852 |
853 return retval; | |
854 } | |
855 | |
856 octave_value | |
857 set_internal_variable (std::string& var, const octave_value_list& args, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
858 int nargout, const char *nm, bool empty_ok) |
5794 | 859 { |
860 octave_value retval; | |
861 | |
5800 | 862 int nargin = args.length (); |
863 | |
864 if (nargout > 0 || nargin == 0) | |
5794 | 865 retval = var; |
866 | |
10637
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
867 if (wants_local_change (args, nargin)) |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
868 { |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
869 if (! try_local_protect (var)) |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
870 warning ("\"local\" has no effect outside a function"); |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
871 } |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
872 |
5794 | 873 if (nargin == 1) |
874 { | |
875 std::string sval = args(0).string_value (); | |
876 | |
877 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
878 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
879 if (empty_ok || ! sval.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
880 var = sval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
881 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
882 error ("%s: value must not be empty", nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
883 } |
5791 | 884 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
885 error ("%s: expecting arg to be a character string", nm); |
5791 | 886 } |
887 else if (nargin > 1) | |
5823 | 888 print_usage (); |
1 | 889 |
890 return retval; | |
891 } | |
892 | |
10638
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
893 octave_value |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
894 set_internal_variable (int& var, const octave_value_list& args, |
10640
5c594472f75e
determine string enum length by trailing null rather than sizeof
Jaroslav Hajek <highegg@gmail.com>
parents:
10638
diff
changeset
|
895 int nargout, const char *nm, const char **choices) |
10638
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
896 { |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
897 octave_value retval; |
10640
5c594472f75e
determine string enum length by trailing null rather than sizeof
Jaroslav Hajek <highegg@gmail.com>
parents:
10638
diff
changeset
|
898 int nchoices = 0; |
5c594472f75e
determine string enum length by trailing null rather than sizeof
Jaroslav Hajek <highegg@gmail.com>
parents:
10638
diff
changeset
|
899 while (choices[nchoices] != 0) |
5c594472f75e
determine string enum length by trailing null rather than sizeof
Jaroslav Hajek <highegg@gmail.com>
parents:
10638
diff
changeset
|
900 nchoices++; |
10638
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
901 |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
902 int nargin = args.length (); |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
903 assert (var < nchoices); |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
904 |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
905 if (nargout > 0 || nargin == 0) |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
906 retval = choices[var]; |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
907 |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
908 if (wants_local_change (args, nargin)) |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
909 { |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
910 if (! try_local_protect (var)) |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
911 warning ("\"local\" has no effect outside a function"); |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
912 } |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
913 |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
914 if (nargin == 1) |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
915 { |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
916 std::string sval = args(0).string_value (); |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
917 |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
918 if (! error_state) |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
919 { |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
920 int i = 0; |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
921 for (; i < nchoices; i++) |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
922 { |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
923 if (sval == choices[i]) |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
924 { |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
925 var = i; |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
926 break; |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
927 } |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
928 } |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
929 if (i == nchoices) |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
930 error ("%s: value not allowed (\"%s\")", nm, sval.c_str ()); |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
931 } |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
932 else |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
933 error ("%s: expecting arg to be a character string", nm); |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
934 } |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
935 else if (nargin > 1) |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
936 print_usage (); |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
937 |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
938 return retval; |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
939 } |
e1559a8a60b4
general mechanism for string enum variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
940 |
7336 | 941 struct |
942 whos_parameter | |
195 | 943 { |
7336 | 944 char command; |
945 char modifier; | |
946 int parameter_length; | |
947 int first_parameter_length; | |
948 int balance; | |
949 std::string text; | |
950 std::string line; | |
951 }; | |
952 | |
953 static void | |
954 print_descriptor (std::ostream& os, std::list<whos_parameter> params) | |
955 { | |
956 // This method prints a line of information on a given symbol | |
957 std::list<whos_parameter>::iterator i = params.begin (); | |
958 std::ostringstream param_buf; | |
959 | |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
960 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
961 |
7336 | 962 while (i != params.end ()) |
195 | 963 { |
7336 | 964 whos_parameter param = *i; |
965 | |
966 if (param.command != '\0') | |
967 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
968 // Do the actual printing |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
969 switch (param.modifier) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
970 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
971 case 'l': |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
972 os << std::setiosflags (std::ios::left) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
973 << std::setw (param.parameter_length); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
974 param_buf << std::setiosflags (std::ios::left) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
975 << std::setw (param.parameter_length); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
976 break; |
7336 | 977 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
978 case 'r': |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
979 os << std::setiosflags (std::ios::right) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
980 << std::setw (param.parameter_length); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
981 param_buf << std::setiosflags (std::ios::right) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
982 << std::setw (param.parameter_length); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
983 break; |
7336 | 984 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
985 case 'c': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
986 if (param.command != 's') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
987 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
988 os << std::setiosflags (std::ios::left) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
989 << std::setw (param.parameter_length); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
990 param_buf << std::setiosflags (std::ios::left) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
991 << std::setw (param.parameter_length); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
992 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
993 break; |
7336 | 994 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
995 default: |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
996 os << std::setiosflags (std::ios::left) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
997 << std::setw (param.parameter_length); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
998 param_buf << std::setiosflags (std::ios::left) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
999 << std::setw (param.parameter_length); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1000 } |
7336 | 1001 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1002 if (param.command == 's' && param.modifier == 'c') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1003 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1004 int a, b; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11558
diff
changeset
|
1005 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1006 if (param.modifier == 'c') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1007 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1008 a = param.first_parameter_length - param.balance; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1009 a = (a < 0 ? 0 : a); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1010 b = param.parameter_length - a - param.text . length (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1011 b = (b < 0 ? 0 : b); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1012 os << std::setiosflags (std::ios::left) << std::setw (a) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1013 << "" << std::resetiosflags (std::ios::left) << param.text |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1014 << std::setiosflags (std::ios::left) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1015 << std::setw (b) << "" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1016 << std::resetiosflags (std::ios::left); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1017 param_buf << std::setiosflags (std::ios::left) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1018 << std::setw (a) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1019 << "" << std::resetiosflags (std::ios::left) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1020 << param.line |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1021 << std::setiosflags (std::ios::left) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1022 << std::setw (b) << "" |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1023 << std::resetiosflags (std::ios::left); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1024 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1025 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1026 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1027 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1028 os << param.text; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1029 param_buf << param.line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1030 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1031 os << std::resetiosflags (std::ios::left) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1032 << std::resetiosflags (std::ios::right); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1033 param_buf << std::resetiosflags (std::ios::left) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1034 << std::resetiosflags (std::ios::right); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1035 i++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1036 } |
7336 | 1037 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1038 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1039 os << param.text; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1040 param_buf << param.line; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1041 i++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1042 } |
195 | 1043 } |
7336 | 1044 |
1045 os << param_buf.str (); | |
195 | 1046 } |
1047 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1048 // FIXME: This is a bit of a kluge. We'd like to just use val.dims() |
9704
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1049 // and if val is an object, expect that dims will call size if it is |
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1050 // overloaded by a user-defined method. But there are currently some |
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1051 // unresolved const issues that prevent that solution from working. |
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1052 |
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1053 std::string |
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1054 get_dims_str (const octave_value& val) |
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1055 { |
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1056 octave_value tmp = val; |
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1057 |
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1058 Matrix sz = tmp.size (); |
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1059 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1060 dim_vector dv = dim_vector::alloc (sz.numel ()); |
9704
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1061 |
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1062 for (octave_idx_type i = 0; i < dv.length (); i++) |
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1063 dv(i) = sz(i); |
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1064 |
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1065 return dv.str (); |
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1066 } |
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1067 |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1068 class |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1069 symbol_info_list |
593 | 1070 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1071 private: |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1072 struct symbol_info |
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 symbol_info (const symbol_table::symbol_record& sr, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1075 const std::string& expr_str = std::string (), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1076 const octave_value& expr_val = octave_value ()) |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1077 : name (expr_str.empty () ? sr.name () : expr_str), |
12651
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1078 varval (expr_val.is_undefined () ? sr.varval () : expr_val), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1079 is_automatic (sr.is_automatic ()), |
12651
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1080 is_complex (varval.is_complex_type ()), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1081 is_formal (sr.is_formal ()), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1082 is_global (sr.is_global ()), |
12651
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1083 is_persistent (sr.is_persistent ()) |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1084 { } |
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 void display_line (std::ostream& os, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1087 const std::list<whos_parameter>& params) const |
593 | 1088 { |
9704
bb413c0d0d6d
whos: kluge fix to get size right for objects
John W. Eaton <jwe@octave.org>
parents:
9454
diff
changeset
|
1089 std::string dims_str = get_dims_str (varval); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1090 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1091 std::list<whos_parameter>::const_iterator i = params.begin (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1092 |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1093 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1094 |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1095 while (i != params.end ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1096 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1097 whos_parameter param = *i; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1098 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1099 if (param.command != '\0') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1100 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1101 // Do the actual printing. |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1102 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1103 switch (param.modifier) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1104 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1105 case 'l': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1106 os << std::setiosflags (std::ios::left) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1107 << std::setw (param.parameter_length); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1108 break; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1109 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1110 case 'r': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1111 os << std::setiosflags (std::ios::right) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1112 << std::setw (param.parameter_length); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1113 break; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1114 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1115 case 'c': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1116 if (param.command == 's') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1117 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1118 int front = param.first_parameter_length |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1119 - dims_str.find ('x'); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1120 int back = param.parameter_length |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1121 - dims_str.length () |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1122 - front; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1123 front = (front > 0) ? front : 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1124 back = (back > 0) ? back : 0; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1125 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1126 os << std::setiosflags (std::ios::left) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1127 << std::setw (front) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1128 << "" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1129 << std::resetiosflags (std::ios::left) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1130 << dims_str |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1131 << std::setiosflags (std::ios::left) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1132 << std::setw (back) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1133 << "" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1134 << std::resetiosflags (std::ios::left); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1135 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1136 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1137 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1138 os << std::setiosflags (std::ios::left) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1139 << std::setw (param.parameter_length); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1140 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1141 break; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1142 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1143 default: |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1144 error ("whos_line_format: modifier '%c' unknown", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1145 param.modifier); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1146 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1147 os << std::setiosflags (std::ios::right) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1148 << std::setw (param.parameter_length); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1149 } |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1150 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1151 switch (param.command) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1152 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1153 case 'a': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1154 { |
12651
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1155 char tmp[6]; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1156 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1157 tmp[0] = (is_automatic ? 'a' : ' '); |
12651
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1158 tmp[1] = (is_complex ? 'c' : ' '); |
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1159 tmp[2] = (is_formal ? 'f' : ' '); |
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1160 tmp[3] = (is_global ? 'g' : ' '); |
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1161 tmp[4] = (is_persistent ? 'p' : ' '); |
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1162 tmp[5] = 0; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1163 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1164 os << tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1165 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1166 break; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1167 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1168 case 'b': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1169 os << varval.byte_size (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1170 break; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1171 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1172 case 'c': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1173 os << varval.class_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1174 break; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1175 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1176 case 'e': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1177 os << varval.capacity (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1178 break; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1179 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1180 case 'n': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1181 os << name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1182 break; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1183 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1184 case 's': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1185 if (param.modifier != 'c') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1186 os << dims_str; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1187 break; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1188 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1189 case 't': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1190 os << varval.type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1191 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11558
diff
changeset
|
1192 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1193 default: |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1194 error ("whos_line_format: command '%c' unknown", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1195 param.command); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1196 } |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1197 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1198 os << std::resetiosflags (std::ios::left) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1199 << std::resetiosflags (std::ios::right); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1200 i++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1201 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1202 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1203 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1204 os << param.text; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1205 i++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1206 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1207 } |
593 | 1208 } |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1209 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1210 std::string name; |
12651
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1211 octave_value varval; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1212 bool is_automatic; |
12651
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1213 bool is_complex; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1214 bool is_formal; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1215 bool is_global; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1216 bool is_persistent; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1217 }; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1218 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1219 public: |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1220 symbol_info_list (void) : lst () { } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1221 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1222 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
|
1223 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1224 symbol_info_list& operator = (const symbol_info_list& sil) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1225 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1226 if (this != &sil) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1227 lst = sil.lst; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1228 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1229 return *this; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1230 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1231 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1232 ~symbol_info_list (void) { } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1233 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1234 void append (const symbol_table::symbol_record& sr) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1235 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1236 lst.push_back (symbol_info (sr)); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1237 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1238 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1239 void append (const symbol_table::symbol_record& sr, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1240 const std::string& expr_str, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1241 const octave_value& expr_val) |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1242 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1243 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
|
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 size_t size (void) const { return lst.size (); } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1247 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1248 bool empty (void) const { return lst.empty (); } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1249 |
11069
e40e19761d06
variables.cc: Octave_map to octave_map and octave_scalar_map conversion
John W. Eaton <jwe@octave.org>
parents:
11029
diff
changeset
|
1250 octave_map |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1251 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
|
1252 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1253 size_t len = lst.size (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1254 |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9727
diff
changeset
|
1255 Cell name_info (len, 1); |
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9727
diff
changeset
|
1256 Cell size_info (len, 1); |
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9727
diff
changeset
|
1257 Cell bytes_info (len, 1); |
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9727
diff
changeset
|
1258 Cell class_info (len, 1); |
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9727
diff
changeset
|
1259 Cell global_info (len, 1); |
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9727
diff
changeset
|
1260 Cell sparse_info (len, 1); |
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9727
diff
changeset
|
1261 Cell complex_info (len, 1); |
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9727
diff
changeset
|
1262 Cell nesting_info (len, 1); |
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9727
diff
changeset
|
1263 Cell persistent_info (len, 1); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1264 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1265 std::list<symbol_info>::const_iterator p = lst.begin (); |
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 for (size_t j = 0; j < len; j++) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1268 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1269 const symbol_info& si = *p++; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1270 |
11069
e40e19761d06
variables.cc: Octave_map to octave_map and octave_scalar_map conversion
John W. Eaton <jwe@octave.org>
parents:
11029
diff
changeset
|
1271 octave_scalar_map ni; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1272 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1273 ni.assign ("function", caller_function_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1274 ni.assign ("level", nesting_level); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1275 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1276 name_info(j) = si.name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1277 global_info(j) = si.is_global; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1278 persistent_info(j) = si.is_persistent; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1279 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1280 octave_value val = si.varval; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1281 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1282 size_info(j) = val.size (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1283 bytes_info(j) = val.byte_size (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1284 class_info(j) = val.class_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1285 sparse_info(j) = val.is_sparse_type (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1286 complex_info(j) = val.is_complex_type (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1287 nesting_info(j) = ni; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1288 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1289 |
11069
e40e19761d06
variables.cc: Octave_map to octave_map and octave_scalar_map conversion
John W. Eaton <jwe@octave.org>
parents:
11029
diff
changeset
|
1290 octave_map info; |
7586
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 info.assign ("name", name_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1293 info.assign ("size", size_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1294 info.assign ("bytes", bytes_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1295 info.assign ("class", class_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1296 info.assign ("global", global_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1297 info.assign ("sparse", sparse_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1298 info.assign ("complex", complex_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1299 info.assign ("nesting", nesting_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1300 info.assign ("persistent", persistent_info); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1301 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1302 return info; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1303 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1304 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1305 void display (std::ostream& os) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1306 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1307 if (! lst.empty ()) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1308 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1309 size_t bytes = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1310 size_t elements = 0; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1311 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1312 std::list<whos_parameter> params = parse_whos_line_format (); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1313 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1314 print_descriptor (os, params); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1315 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1316 octave_stdout << "\n"; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1317 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1318 for (std::list<symbol_info>::const_iterator p = lst.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1319 p != lst.end (); p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1320 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1321 p->display_line (os, params); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1322 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1323 octave_value val = p->varval; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1324 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1325 elements += val.capacity (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1326 bytes += val.byte_size (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1327 } |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1328 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1329 os << "\nTotal is " << elements |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1330 << (elements == 1 ? " element" : " elements") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1331 << " using " << bytes << (bytes == 1 ? " byte" : " bytes") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1332 << "\n"; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1333 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1334 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1335 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1336 // 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
|
1337 // containing all information needed to print the given |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1338 // attributtes of the symbols. |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1339 std::list<whos_parameter> parse_whos_line_format (void) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1340 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1341 int idx; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1342 size_t format_len = Vwhos_line_format.length (); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1343 char garbage; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1344 std::list<whos_parameter> params; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1345 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1346 size_t bytes1; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1347 int elements1; |
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 std::string param_string = "abcenst"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1350 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
|
1351 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
|
1352 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
|
1353 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1354 pos_a = param_string.find ('a'); // Attributes |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1355 pos_b = param_string.find ('b'); // Bytes |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1356 pos_c = param_string.find ('c'); // Class |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1357 pos_e = param_string.find ('e'); // Elements |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1358 pos_n = param_string.find ('n'); // Name |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1359 pos_s = param_string.find ('s'); // Size |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1360 pos_t = param_string.find ('t'); // Type |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1361 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1362 param_names(pos_a) = "Attr"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1363 param_names(pos_b) = "Bytes"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1364 param_names(pos_c) = "Class"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1365 param_names(pos_e) = "Elements"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1366 param_names(pos_n) = "Name"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1367 param_names(pos_s) = "Size"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1368 param_names(pos_t) = "Type"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1369 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1370 for (size_t i = 0; i < param_string.length (); i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1371 param_length(i) = param_names(i).length (); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1372 |
12651
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1373 // The attribute column needs size 5. |
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1374 param_length(pos_a) = 5; |
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1375 |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1376 // Calculating necessary spacing for name column, |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1377 // bytes column, elements column and class column |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1378 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1379 for (std::list<symbol_info>::const_iterator p = lst.begin (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1380 p != lst.end (); p++) |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1381 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1382 std::stringstream ss1, ss2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1383 std::string str; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1384 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1385 str = p->name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1386 param_length(pos_n) = ((str.length () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1387 > static_cast<size_t> (param_length(pos_n))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1388 ? str.length () : param_length(pos_n)); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1389 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1390 octave_value val = p->varval; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1391 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1392 str = val.type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1393 param_length(pos_t) = ((str.length () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1394 > static_cast<size_t> (param_length(pos_t))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1395 ? str.length () : param_length(pos_t)); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1396 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1397 elements1 = val.capacity (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1398 ss1 << elements1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1399 str = ss1.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1400 param_length(pos_e) = ((str.length () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1401 > static_cast<size_t> (param_length(pos_e))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1402 ? str.length () : param_length(pos_e)); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1403 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1404 bytes1 = val.byte_size (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1405 ss2 << bytes1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1406 str = ss2.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1407 param_length(pos_b) = ((str.length () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1408 > static_cast<size_t> (param_length(pos_b))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1409 ? str.length () : param_length (pos_b)); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1410 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1411 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1412 idx = 0; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1413 while (static_cast<size_t> (idx) < format_len) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1414 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1415 whos_parameter param; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1416 param.command = '\0'; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1417 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1418 if (Vwhos_line_format[idx] == '%') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1419 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1420 bool error_encountered = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1421 param.modifier = 'r'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1422 param.parameter_length = 0; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1423 |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
18074
diff
changeset
|
1424 int a = 0; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
18074
diff
changeset
|
1425 int b = -1; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
18074
diff
changeset
|
1426 int balance = 1; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1427 unsigned int items; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1428 size_t pos; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1429 std::string cmd; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1430 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1431 // Parse one command from whos_line_format |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1432 cmd = Vwhos_line_format.substr (idx, Vwhos_line_format.length ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1433 pos = cmd.find (';'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1434 if (pos != std::string::npos) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1435 cmd = cmd.substr (0, pos+1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1436 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1437 error ("parameter without ; in whos_line_format"); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1438 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1439 idx += cmd.length (); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1440 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1441 // FIXME: use iostream functions instead of sscanf! |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1442 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1443 if (cmd.find_first_of ("crl") != 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1444 items = sscanf (cmd.c_str (), "%c%c:%d:%d:%d;", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1445 &garbage, ¶m.command, &a, &b, &balance); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1446 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1447 items = sscanf (cmd.c_str (), "%c%c%c:%d:%d:%d;", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1448 &garbage, ¶m.modifier, ¶m.command, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1449 &a, &b, &balance) - 1; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1450 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1451 if (items < 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1452 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1453 error ("whos_line_format: parameter structure without command in whos_line_format"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1454 error_encountered = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1455 } |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1456 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1457 // Insert data into parameter |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1458 param.first_parameter_length = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1459 pos = param_string.find (param.command); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1460 if (pos != std::string::npos) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1461 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1462 param.parameter_length = param_length(pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1463 param.text = param_names(pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1464 param.line.assign (param_names(pos).length (), '='); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1465 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1466 param.parameter_length = (a > param.parameter_length |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1467 ? a : param.parameter_length); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1468 if (param.command == 's' && param.modifier == 'c' && b > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1469 param.first_parameter_length = b; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1470 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1471 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1472 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1473 error ("whos_line_format: '%c' is not a command", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1474 param.command); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1475 error_encountered = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1476 } |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1477 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1478 if (param.command == 's') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1479 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1480 // Have to calculate space needed for printing |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1481 // matrix dimensions Space needed for Size column is |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1482 // hard to determine in prior, because it depends on |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1483 // dimensions to be shown. That is why it is |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1484 // recalculated for each Size-command int first, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1485 // rest = 0, total; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1486 int rest = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1487 int first = param.first_parameter_length; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1488 int total = param.parameter_length; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1489 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1490 for (std::list<symbol_info>::const_iterator p = lst.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1491 p != lst.end (); p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1492 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1493 octave_value val = p->varval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1494 std::string dims_str = get_dims_str (val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1495 int first1 = dims_str.find ('x'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1496 int total1 = dims_str.length (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1497 int rest1 = total1 - first1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1498 rest = (rest1 > rest ? rest1 : rest); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1499 first = (first1 > first ? first1 : first); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1500 total = (total1 > total ? total1 : total); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1501 } |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1502 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1503 if (param.modifier == 'c') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1504 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1505 if (first < balance) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1506 first += balance - first; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1507 if (rest + balance < param.parameter_length) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1508 rest += param.parameter_length - rest - balance; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1509 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1510 param.parameter_length = first + rest; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1511 param.first_parameter_length = first; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1512 param.balance = balance; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1513 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1514 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1515 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1516 param.parameter_length = total; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1517 param.first_parameter_length = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1518 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1519 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1520 else if (param.modifier == 'c') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1521 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1522 error ("whos_line_format: modifier 'c' not available for command '%c'", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1523 param.command); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1524 error_encountered = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1525 } |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1526 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1527 // What happens if whos_line_format contains negative numbers |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1528 // at param_length positions? |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1529 param.balance = (b < 0 ? 0 : param.balance); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1530 param.first_parameter_length = (b < 0 ? 0 : |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1531 param.first_parameter_length); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1532 param.parameter_length = (a < 0 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1533 ? 0 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1534 : (param.parameter_length |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1535 < param_length(pos_s) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1536 ? param_length(pos_s) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1537 : param.parameter_length)); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1538 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1539 // Parameter will not be pushed into parameter list if ... |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1540 if (! error_encountered) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1541 params.push_back (param); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1542 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1543 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1544 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1545 // Text string, to be printed as it is ... |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1546 std::string text; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1547 size_t pos; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1548 text = Vwhos_line_format.substr (idx, Vwhos_line_format.length ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1549 pos = text.find ('%'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1550 if (pos != std::string::npos) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1551 text = text.substr (0, pos); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1552 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1553 // Push parameter into list ... |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1554 idx += text.length (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1555 param.text=text; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
1556 param.line.assign (text.length (), ' '); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1557 params.push_back (param); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1558 } |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1559 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1560 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1561 return params; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1562 } |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1563 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1564 private: |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1565 std::list<symbol_info> lst; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1566 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1567 }; |
5659 | 1568 |
4435 | 1569 static octave_value |
7336 | 1570 do_who (int argc, const string_vector& argv, bool return_list, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1571 bool verbose = false, std::string msg = std::string ()) |
529 | 1572 { |
4435 | 1573 octave_value retval; |
529 | 1574 |
3523 | 1575 std::string my_name = argv[0]; |
584 | 1576 |
7336 | 1577 bool global_only = false; |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1578 bool have_regexp = false; |
7336 | 1579 |
1857 | 1580 int i; |
1581 for (i = 1; i < argc; i++) | |
529 | 1582 { |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1583 if (argv[i] == "-file") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1584 { |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17818
diff
changeset
|
1585 // FIXME: This is an inefficient manner to implement this as the |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1586 // variables are loaded in to a temporary context and then treated. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1587 // It would be better to refecat symbol_info_list to not store the |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1588 // symbol records and then use it in load-save.cc (do_load) to |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11558
diff
changeset
|
1589 // implement this option there so that the variables are never |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1590 // stored at all. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1591 if (i == argc - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1592 error ("whos: -file argument must be followed by a file name"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1593 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1594 { |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15007
diff
changeset
|
1595 std::string nm = argv[i + 1]; |
8131
10b63c4fd413
Add -file option to who/whos
David Bateman <dbateman@free.fr>
parents:
8083
diff
changeset
|
1596 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1597 unwind_protect frame; |
8131
10b63c4fd413
Add -file option to who/whos
David Bateman <dbateman@free.fr>
parents:
8083
diff
changeset
|
1598 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1599 // Set up temporary scope. |
8131
10b63c4fd413
Add -file option to who/whos
David Bateman <dbateman@free.fr>
parents:
8083
diff
changeset
|
1600 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1601 symbol_table::scope_id tmp_scope = symbol_table::alloc_scope (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1602 frame.add_fcn (symbol_table::erase_scope, tmp_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
9037
diff
changeset
|
1603 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1604 symbol_table::set_scope (tmp_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
9037
diff
changeset
|
1605 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1606 octave_call_stack::push (tmp_scope, 0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1607 frame.add_fcn (octave_call_stack::pop); |
8131
10b63c4fd413
Add -file option to who/whos
David Bateman <dbateman@free.fr>
parents:
8083
diff
changeset
|
1608 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1609 frame.add_fcn (symbol_table::clear_variables); |
8131
10b63c4fd413
Add -file option to who/whos
David Bateman <dbateman@free.fr>
parents:
8083
diff
changeset
|
1610 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1611 feval ("load", octave_value (nm), 0); |
8131
10b63c4fd413
Add -file option to who/whos
David Bateman <dbateman@free.fr>
parents:
8083
diff
changeset
|
1612 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1613 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1614 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11558
diff
changeset
|
1615 std::string newmsg = std::string ("Variables in the file ") + |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1616 nm + ":\n\n"; |
8131
10b63c4fd413
Add -file option to who/whos
David Bateman <dbateman@free.fr>
parents:
8083
diff
changeset
|
1617 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1618 retval = do_who (i, argv, return_list, verbose, newmsg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1619 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1620 } |
8131
10b63c4fd413
Add -file option to who/whos
David Bateman <dbateman@free.fr>
parents:
8083
diff
changeset
|
1621 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1622 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1623 } |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1624 else if (argv[i] == "-regexp") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1625 have_regexp = true; |
7336 | 1626 else if (argv[i] == "global") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1627 global_only = true; |
1755 | 1628 else if (argv[i][0] == '-') |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1629 warning ("%s: unrecognized option '%s'", my_name.c_str (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1630 argv[i].c_str ()); |
529 | 1631 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1632 break; |
529 | 1633 } |
1634 | |
7336 | 1635 int npats = argc - i; |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1636 string_vector pats; |
7336 | 1637 if (npats > 0) |
3248 | 1638 { |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1639 pats.resize (npats); |
7336 | 1640 for (int j = 0; j < npats; j++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1641 pats[j] = argv[i+j]; |
3248 | 1642 } |
7336 | 1643 else |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1644 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1645 pats.resize (++npats); |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1646 pats[0] = "*"; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1647 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11558
diff
changeset
|
1648 |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1649 symbol_info_list symbol_stats; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1650 std::list<std::string> symbol_names; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1651 |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1652 for (int j = 0; j < npats; j++) |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1653 { |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1654 std::string pat = pats[j]; |
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1655 |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1656 if (have_regexp) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1657 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1658 std::list<symbol_table::symbol_record> tmp = global_only |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1659 ? symbol_table::regexp_global_variables (pat) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1660 : symbol_table::regexp_variables (pat); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1661 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1662 for (std::list<symbol_table::symbol_record>::const_iterator |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1663 p = tmp.begin (); p != tmp.end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1664 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1665 if (p->is_variable ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1666 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1667 if (verbose) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1668 symbol_stats.append (*p); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1669 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1670 symbol_names.push_back (p->name ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1671 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1672 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1673 } |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1674 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1675 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1676 size_t pos = pat.find_first_of (".({"); |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1677 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1678 if (pos != std::string::npos && pos > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1679 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1680 if (verbose) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1681 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1682 // NOTE: we can only display information for |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1683 // expressions based on global values if the variable is |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1684 // global in the current scope because we currently have |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1685 // no way of looking up the base value in the global |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1686 // scope and then evaluating the arguments in the |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1687 // current scope. |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1688 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1689 std::string base_name = pat.substr (0, pos); |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1690 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1691 if (symbol_table::is_variable (base_name)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1692 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1693 symbol_table::symbol_record sr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1694 = symbol_table::find_symbol (base_name); |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1695 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1696 if (! global_only || sr.is_global ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1697 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1698 int parse_status; |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1699 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1700 octave_value expr_val |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1701 = eval_string (pat, true, parse_status); |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1702 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1703 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1704 symbol_stats.append (sr, pat, expr_val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1705 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1706 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1707 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1708 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1709 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1710 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1711 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1712 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1713 std::list<symbol_table::symbol_record> tmp = global_only |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1714 ? symbol_table::glob_global_variables (pat) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1715 : symbol_table::glob_variables (pat); |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1716 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1717 for (std::list<symbol_table::symbol_record>::const_iterator |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1718 p = tmp.begin (); p != tmp.end (); p++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1719 { |
9260
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9250
diff
changeset
|
1720 if (p->is_variable ()) |
9250
80c299c84796
don't print undefined symbols in who
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
1721 { |
80c299c84796
don't print undefined symbols in who
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
1722 if (verbose) |
80c299c84796
don't print undefined symbols in who
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
1723 symbol_stats.append (*p); |
80c299c84796
don't print undefined symbols in who
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
1724 else |
80c299c84796
don't print undefined symbols in who
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
1725 symbol_names.push_back (p->name ()); |
80c299c84796
don't print undefined symbols in who
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
1726 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1727 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1728 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1729 } |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1730 } |
529 | 1731 |
4435 | 1732 if (return_list) |
529 | 1733 { |
7336 | 1734 if (verbose) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1735 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1736 std::string caller_function_name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1737 octave_function *caller = octave_call_stack::caller (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1738 if (caller) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1739 caller_function_name = caller->name (); |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1740 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1741 retval = symbol_stats.map_value (caller_function_name, 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1742 } |
4435 | 1743 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1744 retval = Cell (string_vector (symbol_names)); |
529 | 1745 } |
7586
84122fb29c75
whos: handle index expressions
John W. Eaton <jwe@octave.org>
parents:
7531
diff
changeset
|
1746 else if (! (symbol_stats.empty () && symbol_names.empty ())) |
529 | 1747 { |
8131
10b63c4fd413
Add -file option to who/whos
David Bateman <dbateman@free.fr>
parents:
8083
diff
changeset
|
1748 if (msg.length () == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1749 if (global_only) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1750 octave_stdout << "Global variables:\n\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1751 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1752 octave_stdout << "Variables in the current scope:\n\n"; |
7336 | 1753 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1754 octave_stdout << msg; |
7336 | 1755 |
1756 if (verbose) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1757 symbol_stats.display (octave_stdout); |
7336 | 1758 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1759 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1760 string_vector names (symbol_names); |
7336 | 1761 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1762 names.list_in_columns (octave_stdout); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1763 } |
4435 | 1764 |
7336 | 1765 octave_stdout << "\n"; |
529 | 1766 } |
1767 | |
581 | 1768 return retval; |
1769 } | |
1770 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8677
diff
changeset
|
1771 DEFUN (who, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1772 "-*- texinfo -*-\n\ |
9724
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9704
diff
changeset
|
1773 @deftypefn {Command} {} who\n\ |
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9704
diff
changeset
|
1774 @deftypefnx {Command} {} who pattern @dots{}\n\ |
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9704
diff
changeset
|
1775 @deftypefnx {Command} {} who option pattern @dots{}\n\ |
9750
7bf4f3d64955
Fix unbalanced parentheses warning during creation of pdf documentation.
Rik <rdrider0-list@yahoo.com>
parents:
9732
diff
changeset
|
1776 @deftypefnx {Command} {C =} who (\"pattern\", @dots{})\n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1777 List currently defined variables matching the given patterns. Valid\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1778 pattern syntax is the same as described for the @code{clear} command.\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1779 If no patterns are supplied, all variables are listed.\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1780 By default, only variables visible in the local scope are displayed.\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1781 \n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1782 The following are valid options but may not be combined.\n\ |
3361 | 1783 \n\ |
1784 @table @code\n\ | |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1785 @item global\n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1786 List variables in the global scope rather than the current scope.\n\ |
10840 | 1787 \n\ |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1788 @item -regexp\n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1789 The patterns are considered to be regular expressions when matching the\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1790 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
|
1791 the @code{regexp} function is used.\n\ |
10840 | 1792 \n\ |
8131
10b63c4fd413
Add -file option to who/whos
David Bateman <dbateman@free.fr>
parents:
8083
diff
changeset
|
1793 @item -file\n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1794 The next argument is treated as a filename. All variables found within the\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1795 specified file are listed. No patterns are accepted when reading variables\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1796 from a file.\n\ |
3361 | 1797 @end table\n\ |
1798 \n\ | |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1799 If called as a function, return a cell array of defined variable names\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1800 matching the given patterns.\n\ |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1801 @seealso{whos, isglobal, isvarname, exist, regexp}\n\ |
9724
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9704
diff
changeset
|
1802 @end deftypefn") |
581 | 1803 { |
4435 | 1804 octave_value retval; |
581 | 1805 |
4435 | 1806 if (nargout < 2) |
1807 { | |
1808 int argc = args.length () + 1; | |
1809 | |
1810 string_vector argv = args.make_argv ("who"); | |
1755 | 1811 |
7336 | 1812 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1813 retval = do_who (argc, argv, nargout == 1); |
4435 | 1814 } |
1815 else | |
5823 | 1816 print_usage (); |
581 | 1817 |
529 | 1818 return retval; |
1819 } | |
1820 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8677
diff
changeset
|
1821 DEFUN (whos, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1822 "-*- texinfo -*-\n\ |
9724
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9704
diff
changeset
|
1823 @deftypefn {Command} {} whos\n\ |
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9704
diff
changeset
|
1824 @deftypefnx {Command} {} whos pattern @dots{}\n\ |
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9704
diff
changeset
|
1825 @deftypefnx {Command} {} whos option pattern @dots{}\n\ |
9750
7bf4f3d64955
Fix unbalanced parentheses warning during creation of pdf documentation.
Rik <rdrider0-list@yahoo.com>
parents:
9732
diff
changeset
|
1826 @deftypefnx {Command} {S =} whos (\"pattern\", @dots{})\n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1827 Provide detailed information on currently defined variables matching the\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1828 given patterns. Options and pattern syntax are the same as for the\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1829 @code{who} command. Extended information about each variable is\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1830 summarized in a table with the following default entries.\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1831 \n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1832 @table @asis\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1833 @item Attr\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1834 Attributes of the listed variable. Possible attributes are:\n\ |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1835 \n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1836 @table @asis\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1837 @item blank\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1838 Variable in local scope\n\ |
10840 | 1839 \n\ |
11556
e582adc89d55
update whos help text
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
11547
diff
changeset
|
1840 @item @code{a}\n\ |
e582adc89d55
update whos help text
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
11547
diff
changeset
|
1841 Automatic variable. An automatic variable is one created by the\n\ |
e582adc89d55
update whos help text
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
11547
diff
changeset
|
1842 interpreter, for example @code{argn}.\n\ |
e582adc89d55
update whos help text
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
11547
diff
changeset
|
1843 \n\ |
12651
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1844 @item @code{c}\n\ |
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1845 Variable of complex type.\n\ |
332bb3b9600e
interpreter: Add new attribute 'complex' in whos (bug #32053)
Daniel Kraft <d@domob.eu>
parents:
12632
diff
changeset
|
1846 \n\ |
11556
e582adc89d55
update whos help text
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
11547
diff
changeset
|
1847 @item @code{f}\n\ |
e582adc89d55
update whos help text
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
11547
diff
changeset
|
1848 Formal parameter (function argument).\n\ |
e582adc89d55
update whos help text
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
11547
diff
changeset
|
1849 \n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1850 @item @code{g}\n\ |
11556
e582adc89d55
update whos help text
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
11547
diff
changeset
|
1851 Variable with global scope.\n\ |
10840 | 1852 \n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1853 @item @code{p}\n\ |
11556
e582adc89d55
update whos help text
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
11547
diff
changeset
|
1854 Persistent variable.\n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1855 @end table\n\ |
10840 | 1856 \n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1857 @item Name\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1858 The name of the variable.\n\ |
10840 | 1859 \n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1860 @item Size\n\ |
11591
1d13679b587e
Use @nospell macro on certain words in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1861 The logical size of the variable. A scalar is 1x1, a vector is\n\ |
1d13679b587e
Use @nospell macro on certain words in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
1862 @nospell{1xN} or @nospell{Nx1}, a 2-D matrix is @nospell{MxN}.\n\ |
10840 | 1863 \n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1864 @item Bytes\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1865 The amount of memory currently used to store the variable.\n\ |
10840 | 1866 \n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1867 @item Class\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1868 The class of the variable. Examples include double, single, char, uint16,\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1869 cell, and struct.\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1870 @end table\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1871 \n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1872 The table can be customized to display more or less information through\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1873 the function @code{whos_line_format}.\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1874 \n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1875 If @code{whos} is called as a function, return a struct array of defined\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1876 variable names matching the given patterns. Fields in the structure\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
1877 describing each variable are: name, size, bytes, class, global, sparse,\n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1878 complex, nesting, persistent.\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
1879 @seealso{who, whos_line_format}\n\ |
9724
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9704
diff
changeset
|
1880 @end deftypefn") |
581 | 1881 { |
4435 | 1882 octave_value retval; |
712 | 1883 |
4435 | 1884 if (nargout < 2) |
1885 { | |
7336 | 1886 int argc = args.length () + 1; |
1887 | |
1888 string_vector argv = args.make_argv ("whos"); | |
1889 | |
1890 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1891 retval = do_who (argc, argv, nargout == 1, true); |
4435 | 1892 } |
1893 else | |
5823 | 1894 print_usage (); |
581 | 1895 |
1896 return retval; | |
1897 } | |
1898 | |
593 | 1899 // Defining variables. |
1900 | |
1162 | 1901 void |
2856 | 1902 bind_ans (const octave_value& val, bool print) |
1162 | 1903 { |
7336 | 1904 static std::string ans = "ans"; |
1162 | 1905 |
2978 | 1906 if (val.is_defined ()) |
1907 { | |
7531
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1908 if (val.is_cs_list ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1909 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1910 octave_value_list lst = val.list_value (); |
7531
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1911 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1912 for (octave_idx_type i = 0; i < lst.length (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1913 bind_ans (lst(i), print); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1914 } |
7531
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1915 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1916 { |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15807
diff
changeset
|
1917 symbol_table::force_assign (ans, val); |
7531
c9a476b1e664
correctly set ans for cs-lists and simplify printing them
John W. Eaton <jwe@octave.org>
parents:
7347
diff
changeset
|
1918 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1919 if (print) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1920 val.print_with_name (octave_stdout, ans); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1921 } |
2978 | 1922 } |
1162 | 1923 } |
1924 | |
593 | 1925 void |
5794 | 1926 bind_internal_variable (const std::string& fname, const octave_value& val) |
593 | 1927 { |
5794 | 1928 octave_value_list args; |
1929 | |
1930 args(0) = val; | |
1931 | |
1932 feval (fname, args, 0); | |
529 | 1933 } |
1934 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11558
diff
changeset
|
1935 void |
7336 | 1936 mlock (void) |
4319 | 1937 { |
8083
16ab78b816bc
variables.cc (mlock): lock current function
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
1938 octave_function *fcn = octave_call_stack::current (); |
7336 | 1939 |
1940 if (fcn) | |
1941 fcn->lock (); | |
1942 else | |
1943 error ("mlock: invalid use outside a function"); | |
4319 | 1944 } |
1945 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11558
diff
changeset
|
1946 void |
4319 | 1947 munlock (const std::string& nm) |
1948 { | |
7336 | 1949 octave_value val = symbol_table::find_function (nm); |
1950 | |
1951 if (val.is_defined ()) | |
1952 { | |
1953 octave_function *fcn = val.function_value (); | |
1954 | |
1955 if (fcn) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1956 fcn->unlock (); |
7336 | 1957 } |
4319 | 1958 } |
1959 | |
1960 bool | |
1961 mislocked (const std::string& nm) | |
1962 { | |
7336 | 1963 bool retval = false; |
1964 | |
1965 octave_value val = symbol_table::find_function (nm); | |
1966 | |
1967 if (val.is_defined ()) | |
1968 { | |
1969 octave_function *fcn = val.function_value (); | |
1970 | |
1971 if (fcn) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1972 retval = fcn->islocked (); |
7336 | 1973 } |
1974 | |
1975 return retval; | |
4319 | 1976 } |
1977 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8677
diff
changeset
|
1978 DEFUN (mlock, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
1979 "-*- texinfo -*-\n\ |
7875 | 1980 @deftypefn {Built-in Function} {} mlock ()\n\ |
7336 | 1981 Lock the current function into memory so that it can't be cleared.\n\ |
5642 | 1982 @seealso{munlock, mislocked, persistent}\n\ |
1983 @end deftypefn") | |
4319 | 1984 { |
1985 octave_value_list retval; | |
1986 | |
7336 | 1987 if (args.length () == 0) |
8083
16ab78b816bc
variables.cc (mlock): lock current function
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
1988 { |
16ab78b816bc
variables.cc (mlock): lock current function
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
1989 octave_function *fcn = octave_call_stack::caller (); |
16ab78b816bc
variables.cc (mlock): lock current function
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
1990 |
16ab78b816bc
variables.cc (mlock): lock current function
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
1991 if (fcn) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1992 fcn->lock (); |
8083
16ab78b816bc
variables.cc (mlock): lock current function
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
1993 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1994 error ("mlock: invalid use outside a function"); |
8083
16ab78b816bc
variables.cc (mlock): lock current function
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
1995 } |
4319 | 1996 else |
5823 | 1997 print_usage (); |
4319 | 1998 |
1999 return retval; | |
2000 } | |
2001 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8677
diff
changeset
|
2002 DEFUN (munlock, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
2003 "-*- texinfo -*-\n\ |
12692
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
2004 @deftypefn {Built-in Function} {} munlock ()\n\ |
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
2005 @deftypefnx {Built-in Function} {} munlock (@var{fcn})\n\ |
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
2006 Unlock the named function @var{fcn}. If no function is named\n\ |
4319 | 2007 then unlock the current function.\n\ |
5642 | 2008 @seealso{mlock, mislocked, persistent}\n\ |
2009 @end deftypefn") | |
4319 | 2010 { |
2011 octave_value_list retval; | |
2012 | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
2013 if (args.length () == 1) |
4319 | 2014 { |
2015 std::string name = args(0).string_value (); | |
2016 | |
2017 if (! error_state) | |
2018 munlock (name); | |
2019 else | |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11595
diff
changeset
|
2020 error ("munlock: FCN must be a string"); |
4319 | 2021 } |
2022 else if (args.length () == 0) | |
2023 { | |
7336 | 2024 octave_function *fcn = octave_call_stack::caller (); |
5743 | 2025 |
2026 if (fcn) | |
7336 | 2027 fcn->unlock (); |
4319 | 2028 else |
2029 error ("munlock: invalid use outside a function"); | |
2030 } | |
2031 else | |
5823 | 2032 print_usage (); |
4319 | 2033 |
2034 return retval; | |
2035 } | |
2036 | |
2037 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8677
diff
changeset
|
2038 DEFUN (mislocked, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
2039 "-*- texinfo -*-\n\ |
12692
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
2040 @deftypefn {Built-in Function} {} mislocked ()\n\ |
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
2041 @deftypefnx {Built-in Function} {} mislocked (@var{fcn})\n\ |
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
2042 Return true if the named function @var{fcn} is locked. If no function is\n\ |
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
2043 named then return true if the current function is locked.\n\ |
5642 | 2044 @seealso{mlock, munlock, persistent}\n\ |
2045 @end deftypefn") | |
4319 | 2046 { |
2047 octave_value retval; | |
2048 | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
2049 if (args.length () == 1) |
4319 | 2050 { |
2051 std::string name = args(0).string_value (); | |
2052 | |
2053 if (! error_state) | |
2054 retval = mislocked (name); | |
2055 else | |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11595
diff
changeset
|
2056 error ("mislocked: FCN must be a string"); |
4319 | 2057 } |
2058 else if (args.length () == 0) | |
2059 { | |
7336 | 2060 octave_function *fcn = octave_call_stack::caller (); |
5743 | 2061 |
2062 if (fcn) | |
7336 | 2063 retval = fcn->islocked (); |
4319 | 2064 else |
2065 error ("mislocked: invalid use outside a function"); | |
2066 } | |
2067 else | |
5823 | 2068 print_usage (); |
4319 | 2069 |
2070 return retval; | |
2071 } | |
2072 | |
593 | 2073 // Deleting names from the symbol tables. |
2074 | |
3681 | 2075 static inline bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11558
diff
changeset
|
2076 name_matches_any_pattern (const std::string& nm, const string_vector& argv, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2077 int argc, int idx, bool have_regexp = false) |
3681 | 2078 { |
2079 bool retval = false; | |
2080 | |
2081 for (int k = idx; k < argc; k++) | |
2082 { | |
2083 std::string patstr = argv[k]; | |
2084 if (! patstr.empty ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2085 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2086 if (have_regexp) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2087 { |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
2088 if (is_regexp_match (patstr, nm)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2089 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2090 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2091 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2092 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2093 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2094 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2095 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2096 glob_match pattern (patstr); |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2097 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2098 if (pattern.match (nm)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2099 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2100 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2101 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2102 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2103 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2104 } |
3681 | 2105 } |
2106 | |
2107 return retval; | |
2108 } | |
2109 | |
4009 | 2110 static inline void |
2111 maybe_warn_exclusive (bool exclusive) | |
2112 { | |
2113 if (exclusive) | |
2114 warning ("clear: ignoring --exclusive option"); | |
2115 } | |
2116 | |
7336 | 2117 static void |
4009 | 2118 do_clear_functions (const string_vector& argv, int argc, int idx, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2119 bool exclusive = false) |
4009 | 2120 { |
2121 if (idx == argc) | |
7336 | 2122 symbol_table::clear_functions (); |
4009 | 2123 else |
2124 { | |
2125 if (exclusive) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2126 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2127 string_vector fcns = symbol_table::user_function_names (); |
4009 | 2128 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2129 int fcount = fcns.length (); |
4009 | 2130 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2131 for (int i = 0; i < fcount; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2132 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2133 std::string nm = fcns[i]; |
4009 | 2134 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2135 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2136 symbol_table::clear_function (nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2137 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2138 } |
4009 | 2139 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2140 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2141 while (idx < argc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2142 symbol_table::clear_function_pattern (argv[idx++]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2143 } |
4009 | 2144 } |
2145 } | |
2146 | |
7336 | 2147 static void |
4009 | 2148 do_clear_globals (const string_vector& argv, int argc, int idx, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2149 bool exclusive = false) |
4009 | 2150 { |
2151 if (idx == argc) | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
2152 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
2153 string_vector gvars = symbol_table::global_variable_names (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
2154 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
2155 int gcount = gvars.length (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
2156 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
2157 for (int i = 0; i < gcount; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2158 symbol_table::clear_global (gvars[i]); |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7626
diff
changeset
|
2159 } |
4009 | 2160 else |
2161 { | |
2162 if (exclusive) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2163 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2164 string_vector gvars = symbol_table::global_variable_names (); |
4009 | 2165 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2166 int gcount = gvars.length (); |
4009 | 2167 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2168 for (int i = 0; i < gcount; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2169 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2170 std::string nm = gvars[i]; |
4009 | 2171 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2172 if (! name_matches_any_pattern (nm, argv, argc, idx)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2173 symbol_table::clear_global (nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2174 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2175 } |
4009 | 2176 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2177 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2178 while (idx < argc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2179 symbol_table::clear_global_pattern (argv[idx++]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2180 } |
4009 | 2181 } |
2182 } | |
2183 | |
7336 | 2184 static void |
4009 | 2185 do_clear_variables (const string_vector& argv, int argc, int idx, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2186 bool exclusive = false, bool have_regexp = false) |
4009 | 2187 { |
2188 if (idx == argc) | |
7336 | 2189 symbol_table::clear_variables (); |
4009 | 2190 else |
2191 { | |
2192 if (exclusive) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2193 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2194 string_vector lvars = symbol_table::variable_names (); |
4009 | 2195 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2196 int lcount = lvars.length (); |
4009 | 2197 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2198 for (int i = 0; i < lcount; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2199 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2200 std::string nm = lvars[i]; |
4009 | 2201 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2202 if (! name_matches_any_pattern (nm, argv, argc, idx, have_regexp)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2203 symbol_table::clear_variable (nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2204 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2205 } |
4009 | 2206 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2207 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2208 if (have_regexp) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2209 while (idx < argc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2210 symbol_table::clear_variable_regexp (argv[idx++]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2211 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2212 while (idx < argc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2213 symbol_table::clear_variable_pattern (argv[idx++]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2214 } |
4009 | 2215 } |
2216 } | |
2217 | |
7336 | 2218 static void |
4009 | 2219 do_clear_symbols (const string_vector& argv, int argc, int idx, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2220 bool exclusive = false) |
4009 | 2221 { |
2222 if (idx == argc) | |
7336 | 2223 symbol_table::clear_variables (); |
4009 | 2224 else |
2225 { | |
2226 if (exclusive) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2227 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
2228 // FIXME: is this really what we want, or do we |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2229 // somehow want to only clear the functions that are not |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2230 // shadowed by local variables? It seems that would be a |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2231 // bit harder to do. |
4009 | 2232 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2233 do_clear_variables (argv, argc, idx, exclusive); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2234 do_clear_functions (argv, argc, idx, exclusive); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2235 } |
4009 | 2236 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2237 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2238 while (idx < argc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2239 symbol_table::clear_symbol_pattern (argv[idx++]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2240 } |
4009 | 2241 } |
2242 } | |
2243 | |
2244 static void | |
2245 do_matlab_compatible_clear (const string_vector& argv, int argc, int idx) | |
2246 { | |
2247 // This is supposed to be mostly Matlab compatible. | |
2248 | |
2249 for (; idx < argc; idx++) | |
2250 { | |
7336 | 2251 if (argv[idx] == "all" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2252 && ! symbol_table::is_local_variable ("all")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2253 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2254 symbol_table::clear_all (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2255 } |
7336 | 2256 else if (argv[idx] == "functions" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2257 && ! symbol_table::is_local_variable ("functions")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2258 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2259 do_clear_functions (argv, argc, ++idx); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2260 } |
7336 | 2261 else if (argv[idx] == "global" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2262 && ! symbol_table::is_local_variable ("global")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2263 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2264 do_clear_globals (argv, argc, ++idx); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2265 } |
7336 | 2266 else if (argv[idx] == "variables" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2267 && ! symbol_table::is_local_variable ("variables")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2268 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2269 symbol_table::clear_variables (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2270 } |
9240
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9180
diff
changeset
|
2271 else if (argv[idx] == "classes" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2272 && ! symbol_table::is_local_variable ("classes")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2273 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2274 symbol_table::clear_objects (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2275 octave_class::clear_exemplar_map (); |
18282
87381dbbe25e
Clear all var, functions, globals when clearing classes (bug #41229)
Rik <rik@octave.org>
parents:
18110
diff
changeset
|
2276 symbol_table::clear_all (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2277 } |
4009 | 2278 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2279 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2280 symbol_table::clear_symbol_pattern (argv[idx]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2281 } |
4009 | 2282 } |
2283 } | |
2284 | |
2285 #define CLEAR_OPTION_ERROR(cond) \ | |
2286 do \ | |
2287 { \ | |
2288 if (cond) \ | |
2289 { \ | |
5823 | 2290 print_usage (); \ |
4009 | 2291 return retval; \ |
2292 } \ | |
2293 } \ | |
2294 while (0) | |
2295 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8677
diff
changeset
|
2296 DEFUN (clear, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
2297 "-*- texinfo -*-\n\ |
11547 | 2298 @deftypefn {Command} {} clear [options] pattern @dots{}\n\ |
3361 | 2299 Delete the names matching the given patterns from the symbol table. The\n\ |
2300 pattern may contain the following special characters:\n\ | |
4016 | 2301 \n\ |
3361 | 2302 @table @code\n\ |
2303 @item ?\n\ | |
2304 Match any single character.\n\ | |
668 | 2305 \n\ |
3361 | 2306 @item *\n\ |
2307 Match zero or more characters.\n\ | |
2308 \n\ | |
2309 @item [ @var{list} ]\n\ | |
2310 Match the list of characters specified by @var{list}. If the first\n\ | |
2311 character is @code{!} or @code{^}, match all characters except those\n\ | |
2312 specified by @var{list}. For example, the pattern @samp{[a-zA-Z]} will\n\ | |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
2313 match all lowercase and uppercase alphabetic characters.\n\ |
3361 | 2314 @end table\n\ |
2315 \n\ | |
2316 For example, the command\n\ | |
593 | 2317 \n\ |
3361 | 2318 @example\n\ |
2319 clear foo b*r\n\ | |
2320 @end example\n\ | |
2321 \n\ | |
2322 @noindent\n\ | |
2323 clears the name @code{foo} and all names that begin with the letter\n\ | |
2324 @code{b} and end with the letter @code{r}.\n\ | |
668 | 2325 \n\ |
3361 | 2326 If @code{clear} is called without any arguments, all user-defined\n\ |
2327 variables (local and global) are cleared from the symbol table. If\n\ | |
2328 @code{clear} is called with at least one argument, only the visible\n\ | |
2329 names matching the arguments are cleared. For example, suppose you have\n\ | |
2330 defined a function @code{foo}, and then hidden it by performing the\n\ | |
2331 assignment @code{foo = 2}. Executing the command @kbd{clear foo} once\n\ | |
2332 will clear the variable definition and restore the definition of\n\ | |
2333 @code{foo} as a function. Executing @kbd{clear foo} a second time will\n\ | |
2334 clear the function definition.\n\ | |
2335 \n\ | |
7347 | 2336 The following options are available in both long and short form\n\ |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
2337 \n\ |
7347 | 2338 @table @code\n\ |
2339 @item -all, -a\n\ | |
2340 Clears all local and global user-defined variables and all functions\n\ | |
2341 from the symbol table.\n\ | |
2342 \n\ | |
2343 @item -exclusive, -x\n\ | |
2344 Clears the variables that don't match the following pattern.\n\ | |
2345 \n\ | |
2346 @item -functions, -f\n\ | |
2347 Clears the function names and the built-in symbols names.\n\ | |
10840 | 2348 \n\ |
7347 | 2349 @item -global, -g\n\ |
2350 Clears the global symbol names.\n\ | |
10840 | 2351 \n\ |
7347 | 2352 @item -variables, -v\n\ |
2353 Clears the local variable names.\n\ | |
10840 | 2354 \n\ |
9240
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9180
diff
changeset
|
2355 @item -classes, -c\n\ |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9180
diff
changeset
|
2356 Clears the class structure table and clears all objects.\n\ |
10840 | 2357 \n\ |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2358 @item -regexp, -r\n\ |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2359 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
|
2360 match will be cleared.\n\ |
7347 | 2361 @end table\n\ |
15007
8f0e3c5bfa5f
doc: Periodic grammarcheck of documentation
Rik <rik@octave.org>
parents:
14861
diff
changeset
|
2362 \n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
2363 With the exception of @code{exclusive}, all long options can be used\n\ |
7347 | 2364 without the dash as well.\n\ |
11547 | 2365 @end deftypefn") |
529 | 2366 { |
2086 | 2367 octave_value_list retval; |
593 | 2368 |
1755 | 2369 int argc = args.length () + 1; |
593 | 2370 |
1968 | 2371 string_vector argv = args.make_argv ("clear"); |
1755 | 2372 |
4009 | 2373 if (! error_state) |
529 | 2374 { |
4009 | 2375 if (argc == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2376 { |
15399
66e17621f99a
* variables.h, variables.cc (clear_current_scope): New function.
John W. Eaton <jwe@octave.org>
parents:
15236
diff
changeset
|
2377 do_clear_globals (argv, argc, true); |
66e17621f99a
* variables.h, variables.cc (clear_current_scope): New function.
John W. Eaton <jwe@octave.org>
parents:
15236
diff
changeset
|
2378 do_clear_variables (argv, argc, true); |
16523
62d8aaf6ba8f
force update of GUI workspace viewer from clear function
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
2379 |
62d8aaf6ba8f
force update of GUI workspace viewer from clear function
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
2380 octave_link::clear_workspace (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2381 } |
3681 | 2382 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2383 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2384 int idx = 0; |
4009 | 2385 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2386 bool clear_all = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2387 bool clear_functions = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2388 bool clear_globals = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2389 bool clear_variables = false; |
9240
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9180
diff
changeset
|
2390 bool clear_objects = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2391 bool exclusive = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2392 bool have_regexp = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2393 bool have_dash_option = false; |
3681 | 2394 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2395 while (++idx < argc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2396 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2397 if (argv[idx] == "-all" || argv[idx] == "-a") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2398 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2399 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681 | 2400 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2401 have_dash_option = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2402 clear_all = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2403 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2404 else if (argv[idx] == "-exclusive" || argv[idx] == "-x") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2405 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2406 have_dash_option = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2407 exclusive = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2408 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2409 else if (argv[idx] == "-functions" || argv[idx] == "-f") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2410 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2411 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681 | 2412 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2413 have_dash_option = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2414 clear_functions = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2415 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2416 else if (argv[idx] == "-global" || argv[idx] == "-g") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2417 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2418 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
4009 | 2419 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2420 have_dash_option = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2421 clear_globals = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2422 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2423 else if (argv[idx] == "-variables" || argv[idx] == "-v") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2424 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2425 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
3681 | 2426 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2427 have_dash_option = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2428 clear_variables = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2429 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2430 else if (argv[idx] == "-classes" || argv[idx] == "-c") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2431 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2432 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
9240
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9180
diff
changeset
|
2433 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2434 have_dash_option = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2435 clear_objects = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2436 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2437 else if (argv[idx] == "-regexp" || argv[idx] == "-r") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2438 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2439 CLEAR_OPTION_ERROR (have_dash_option && ! exclusive); |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2440 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2441 have_dash_option = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2442 have_regexp = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2443 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2444 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2445 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2446 } |
3681 | 2447 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2448 if (idx <= argc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2449 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2450 if (! have_dash_option) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2451 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2452 do_matlab_compatible_clear (argv, argc, idx); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2453 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2454 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2455 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2456 if (clear_all) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2457 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2458 maybe_warn_exclusive (exclusive); |
3681 | 2459 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2460 if (++idx < argc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2461 warning |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2462 ("clear: ignoring extra arguments after -all"); |
3681 | 2463 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2464 symbol_table::clear_all (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2465 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2466 else if (have_regexp) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2467 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2468 do_clear_variables (argv, argc, idx, exclusive, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2469 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2470 else if (clear_functions) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2471 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2472 do_clear_functions (argv, argc, idx, exclusive); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2473 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2474 else if (clear_globals) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2475 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2476 do_clear_globals (argv, argc, idx, exclusive); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2477 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2478 else if (clear_variables) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2479 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2480 do_clear_variables (argv, argc, idx, exclusive); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2481 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2482 else if (clear_objects) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2483 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2484 symbol_table::clear_objects (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2485 octave_class::clear_exemplar_map (); |
18282
87381dbbe25e
Clear all var, functions, globals when clearing classes (bug #41229)
Rik <rik@octave.org>
parents:
18110
diff
changeset
|
2486 symbol_table::clear_all (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2487 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2488 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2489 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2490 do_clear_symbols (argv, argc, idx, exclusive); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2491 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2492 } |
16523
62d8aaf6ba8f
force update of GUI workspace viewer from clear function
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
2493 |
16524
6a8e63dadfad
provide octave_link::set_workspace function with default values
John W. Eaton <jwe@octave.org>
parents:
16523
diff
changeset
|
2494 octave_link::set_workspace (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2495 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2496 } |
593 | 2497 } |
2498 | |
2499 return retval; | |
529 | 2500 } |
2501 | |
7336 | 2502 DEFUN (whos_line_format, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
2503 "-*- texinfo -*-\n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2504 @deftypefn {Built-in Function} {@var{val} =} whos_line_format ()\n\ |
7336 | 2505 @deftypefnx {Built-in Function} {@var{old_val} =} whos_line_format (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13241
diff
changeset
|
2506 @deftypefnx {Built-in Function} {} whos_line_format (@var{new_val}, \"local\")\n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2507 Query or set the format string used by the command @code{whos}.\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2508 \n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2509 A full format string is:\n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
2510 @c Set example in small font to prevent overfull line\n\ |
7336 | 2511 \n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2512 @smallexample\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2513 %[modifier]<command>[:width[:left-min[:balance]]];\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2514 @end smallexample\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2515 \n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2516 The following command sequences are available:\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2517 \n\ |
7336 | 2518 @table @code\n\ |
2519 @item %a\n\ | |
2520 Prints attributes of variables (g=global, p=persistent,\n\ | |
2521 f=formal parameter, a=automatic variable).\n\ | |
10840 | 2522 \n\ |
7336 | 2523 @item %b\n\ |
2524 Prints number of bytes occupied by variables.\n\ | |
10840 | 2525 \n\ |
7336 | 2526 @item %c\n\ |
2527 Prints class names of variables.\n\ | |
10840 | 2528 \n\ |
7336 | 2529 @item %e\n\ |
2530 Prints elements held by variables.\n\ | |
10840 | 2531 \n\ |
7336 | 2532 @item %n\n\ |
2533 Prints variable names.\n\ | |
10840 | 2534 \n\ |
7336 | 2535 @item %s\n\ |
2536 Prints dimensions of variables.\n\ | |
10840 | 2537 \n\ |
7336 | 2538 @item %t\n\ |
2539 Prints type names of variables.\n\ | |
2540 @end table\n\ | |
2541 \n\ | |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2542 Every command may also have an alignment modifier:\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2543 \n\ |
7336 | 2544 @table @code\n\ |
2545 @item l\n\ | |
2546 Left alignment.\n\ | |
10840 | 2547 \n\ |
7336 | 2548 @item r\n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2549 Right alignment (default).\n\ |
10840 | 2550 \n\ |
7336 | 2551 @item c\n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2552 Column-aligned (only applicable to command %s).\n\ |
7336 | 2553 @end table\n\ |
2554 \n\ | |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2555 The @code{width} parameter is a positive integer specifying the minimum\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2556 number of columns used for printing. No maximum is needed as the field will\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2557 auto-expand as required.\n\ |
7336 | 2558 \n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2559 The parameters @code{left-min} and @code{balance} are only available when the\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2560 column-aligned modifier is used with the command @samp{%s}.\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2561 @code{balance} specifies the column number within the field width which will\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2562 be aligned between entries. Numbering starts from 0 which indicates the\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2563 leftmost column. @code{left-min} specifies the minimum field width to the\n\ |
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2564 left of the specified balance column.\n\ |
7336 | 2565 \n\ |
8516 | 2566 The default format is\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16940
diff
changeset
|
2567 @qcode{\" %a:4; %ln:6; %cs:16:6:1; %rb:12; %lc:-1;\\n\"}.\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13241
diff
changeset
|
2568 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16940
diff
changeset
|
2569 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16940
diff
changeset
|
2570 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16940
diff
changeset
|
2571 The original variable value is restored when exiting the function.\n\ |
9304
b6235c6cfb83
Update documentation for 'who' family of functions.
Rik <rdrider0-list@yahoo.com>
parents:
9260
diff
changeset
|
2572 @seealso{whos}\n\ |
5794 | 2573 @end deftypefn") |
2574 { | |
7336 | 2575 return SET_INTERNAL_VARIABLE (whos_line_format); |
3016 | 2576 } |
10443
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
2577 |
15562
8ed107220a3e
maint: Rename unimplemented.m to __unimplemented__.m.
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
15528
diff
changeset
|
2578 static std::string Vmissing_function_hook = "__unimplemented__"; |
10443
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
2579 |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
2580 DEFUN (missing_function_hook, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
2581 "-*- texinfo -*-\n\ |
10840 | 2582 @deftypefn {Built-in Function} {@var{val} =} missing_function_hook ()\n\ |
10443
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
2583 @deftypefnx {Built-in Function} {@var{old_val} =} missing_function_hook (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13241
diff
changeset
|
2584 @deftypefnx {Built-in Function} {} missing_function_hook (@var{new_val}, \"local\")\n\ |
12573
232a90612254
Add new section on parsing to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12546
diff
changeset
|
2585 Query or set the internal variable that specifies the function to call when\n\ |
232a90612254
Add new section on parsing to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12546
diff
changeset
|
2586 an unknown identifier is requested.\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13241
diff
changeset
|
2587 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16940
diff
changeset
|
2588 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16940
diff
changeset
|
2589 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16940
diff
changeset
|
2590 The original variable value is restored when exiting the function.\n\ |
17756
9aff1c9fd70f
doc: Add missing functions to manual.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2591 @seealso{missing_component_hook}\n\ |
10443
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
2592 @end deftypefn") |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
2593 { |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
2594 return SET_INTERNAL_VARIABLE (missing_function_hook); |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
2595 } |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
2596 |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
2597 void maybe_missing_function_hook (const std::string& name) |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
2598 { |
10444
537d9fbba9c0
don't call missing_function_hook inside try block
Jaroslav Hajek <highegg@gmail.com>
parents:
10443
diff
changeset
|
2599 // Don't do this if we're handling errors. |
537d9fbba9c0
don't call missing_function_hook inside try block
Jaroslav Hajek <highegg@gmail.com>
parents:
10443
diff
changeset
|
2600 if (buffer_error_messages == 0 && ! Vmissing_function_hook.empty ()) |
10467
13c1f15c67fa
guard against recursive calls of missing_function_hook
Jaroslav Hajek <highegg@gmail.com>
parents:
10444
diff
changeset
|
2601 { |
15528
8d2b3db8b5b0
Allow missing_function_hook to fail silently
Mike Miller <mtmiller@ieee.org>
parents:
15508
diff
changeset
|
2602 octave_value val = symbol_table::find_function (Vmissing_function_hook); |
8d2b3db8b5b0
Allow missing_function_hook to fail silently
Mike Miller <mtmiller@ieee.org>
parents:
15508
diff
changeset
|
2603 |
8d2b3db8b5b0
Allow missing_function_hook to fail silently
Mike Miller <mtmiller@ieee.org>
parents:
15508
diff
changeset
|
2604 if (val.is_defined ()) |
8d2b3db8b5b0
Allow missing_function_hook to fail silently
Mike Miller <mtmiller@ieee.org>
parents:
15508
diff
changeset
|
2605 { |
8d2b3db8b5b0
Allow missing_function_hook to fail silently
Mike Miller <mtmiller@ieee.org>
parents:
15508
diff
changeset
|
2606 // Ensure auto-restoration. |
8d2b3db8b5b0
Allow missing_function_hook to fail silently
Mike Miller <mtmiller@ieee.org>
parents:
15508
diff
changeset
|
2607 unwind_protect frame; |
8d2b3db8b5b0
Allow missing_function_hook to fail silently
Mike Miller <mtmiller@ieee.org>
parents:
15508
diff
changeset
|
2608 frame.protect_var (Vmissing_function_hook); |
8d2b3db8b5b0
Allow missing_function_hook to fail silently
Mike Miller <mtmiller@ieee.org>
parents:
15508
diff
changeset
|
2609 |
8d2b3db8b5b0
Allow missing_function_hook to fail silently
Mike Miller <mtmiller@ieee.org>
parents:
15508
diff
changeset
|
2610 // Clear the variable prior to calling the function. |
8d2b3db8b5b0
Allow missing_function_hook to fail silently
Mike Miller <mtmiller@ieee.org>
parents:
15508
diff
changeset
|
2611 const std::string func_name = Vmissing_function_hook; |
8d2b3db8b5b0
Allow missing_function_hook to fail silently
Mike Miller <mtmiller@ieee.org>
parents:
15508
diff
changeset
|
2612 Vmissing_function_hook.clear (); |
8d2b3db8b5b0
Allow missing_function_hook to fail silently
Mike Miller <mtmiller@ieee.org>
parents:
15508
diff
changeset
|
2613 |
8d2b3db8b5b0
Allow missing_function_hook to fail silently
Mike Miller <mtmiller@ieee.org>
parents:
15508
diff
changeset
|
2614 // Call. |
8d2b3db8b5b0
Allow missing_function_hook to fail silently
Mike Miller <mtmiller@ieee.org>
parents:
15508
diff
changeset
|
2615 feval (func_name, octave_value (name)); |
8d2b3db8b5b0
Allow missing_function_hook to fail silently
Mike Miller <mtmiller@ieee.org>
parents:
15508
diff
changeset
|
2616 } |
10467
13c1f15c67fa
guard against recursive calls of missing_function_hook
Jaroslav Hajek <highegg@gmail.com>
parents:
10444
diff
changeset
|
2617 } |
10443
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
2618 } |
11558
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2619 |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2620 DEFUN (__varval__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
2621 "-*- texinfo -*-\n\ |
11558
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2622 @deftypefn {Built-in Function} {} __varval__ (@var{name})\n\ |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2623 Undocumented internal function.\n\ |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2624 @end deftypefn") |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2625 { |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2626 octave_value retval; |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2627 |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2628 if (args.length () == 1) |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2629 { |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2630 std::string name = args(0).string_value (); |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2631 |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2632 if (! error_state) |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2633 retval = symbol_table::varval (args(0).string_value ()); |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2634 else |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2635 error ("__varval__: expecting argument to be variable name"); |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2636 } |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2637 else |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2638 print_usage (); |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2639 |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2640 return retval; |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11556
diff
changeset
|
2641 } |
17516
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2642 |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2643 static std::string Vmissing_component_hook; |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2644 |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2645 DEFUN (missing_component_hook, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17756
diff
changeset
|
2646 "-*- texinfo -*-\n\ |
17516
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2647 @deftypefn {Built-in Function} {@var{val} =} missing_component_hook ()\n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2648 @deftypefnx {Built-in Function} {@var{old_val} =} missing_component_hook (@var{new_val})\n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2649 @deftypefnx {Built-in Function} {} missing_component_hook (@var{new_val}, \"local\")\n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2650 Query or set the internal variable that specifies the function to call when\n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2651 a component of Octave is missing. This can be useful for packagers that\n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2652 may split the Octave installation into multiple sub-packages, for example,\n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2653 to provide a hint to users for how to install the missing components.\n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2654 \n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2655 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2656 variable is changed locally for the function and any subroutines it calls. \n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2657 The original variable value is restored when exiting the function.\n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2658 \n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2659 The hook function is expected to be of the form\n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2660 \n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2661 @example\n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2662 @var{fcn} (@var{component})\n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2663 @end example\n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2664 \n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2665 Octave will call @var{fcn} with the name of the function that requires the\n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2666 component and a string describing the missing component. The hook function\n\ |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2667 should return an error message to be displayed.\n\ |
17756
9aff1c9fd70f
doc: Add missing functions to manual.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2668 @seealso{missing_function_hook}\n\ |
17516
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2669 @end deftypefn") |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2670 { |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2671 return SET_INTERNAL_VARIABLE (missing_component_hook); |
21656a949661
Add hook function to handle missing Octave components
Mike Miller <mtmiller@ieee.org>
parents:
17355
diff
changeset
|
2672 } |