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