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