Mercurial > octave-nkf
annotate libinterp/corefcn/utils.cc @ 19437:03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
* data.cc (get_sort_mode_option, Fissorted): Use is_string() to check string
input.
* debug.cc (Fdbstep): use "string" rather than "character string" in error
messages.
* error.cc (Flasterr, Flastwarn): use "string" rather than "character string"
in error messages.
* file-io.cc (do_stream_open, do_fread, do_fwrite, Fpopen, Ftempname,
Fmkstemp): Use is_string() to check string input.
* graphics.cc (Fgraphics_toolkit): Use is_string() to check string input.
Rephrase error message.
* help.cc (F__list_functions): Use is_string() to check string input.
* input.cc (Fyes_or_no): Use is_string() to check string input. Rephrase
error message.
* input.cc (Fadd_input_event_hook): Rephrase error message.
* load-path.cc (Fgenpath, Faddpath): Rephrase error message.
* matrix_type.cc (Fmatrix_type): Use is_string() to check string input.
* qz.cc (Fqz): Follow Octave coding convention for space after '!'.
* regexp.cc (parse_options): Use is_string() to check string input.
Rephrase error message.
* schur.cc (Fschur): Use is_string() to check string input.
* strfns.cc (Flist_in_columns): Use is_string() to check string input.
Rephrase error message.
* symtab.cc (Fignore_function_time_stamp): Use is_string() to check string
input. Rephrase error message.
* syscalls.cc (Fexec, Fpopen2, Fcanonicalize_file_name): Use is_string() to
check string input. Rephrase error message.
* sysdep.cc (Fsetenv): Use is_string() to check string input.
* time.cc (Fstrftime, Fstrptime): Use is_string() to check string input.
* toplev.cc (Fsystem, Fatexit): Use is_string() to check string input.
* urlwrite.cc (Furlwrite, Furlread): Rephrase error message.
* utils.cc (Ffile_in_path): Use is_string() to check string input. Rephrase
error message.
* variables.cc (extract_function): Add FIXME about potentially using is_string.
* variables.cc (do_isglobal, Fmunlock, Fmislocked): Use is_string() to check
string input.
* variables.cc (set_internal_variable): Rephrase error message.
* ov-base.cc (make_idx_args): Rephrase error message.
* ov-class.cc (octave_class::all_strings, Fclass): Rephrase error message.
* ov-fcn-handle.cc (Fstr2func): Use is_string() to check string input
* ov-java.cc (FjavaObject, FjavaMethod, F__java_get__, F__java_set__):
Use is_string() to check string input.
* ov.cc (Fdecode_subscripts): Use is_string() to check string input.
Rephrase error message.
* pt-idx.cc (tree_index_expression::get_struct_index): Rephrase error message.
* io.tst: Change %!warning test to %!error test to match stricter checking.
* system.tst: Change %!warning test for setenv to %!error test to match
stricter checking.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 16 Dec 2014 09:21:29 -0800 |
parents | 65554f5847ac |
children | 4197fc428c7d |
rev | line source |
---|---|
1 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17290
diff
changeset
|
3 Copyright (C) 1993-2013 John W. Eaton |
11012 | 4 Copyright (C) 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 | |
3716 | 28 #include <cerrno> |
1346 | 29 #include <cstring> |
1343 | 30 |
3503 | 31 #include <fstream> |
32 #include <iostream> | |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
33 #include <limits> |
1728 | 34 #include <string> |
35 | |
1 | 36 #include <sys/types.h> |
37 #include <unistd.h> | |
367 | 38 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
39 #include "vasnprintf.h" |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
40 |
3040 | 41 #include "dir-ops.h" |
42 #include "file-ops.h" | |
2926 | 43 #include "file-stat.h" |
4732 | 44 #include "lo-mappers.h" |
11006
aca961a3f387
provide gethostname function
John W. Eaton <jwe@octave.org>
parents:
10987
diff
changeset
|
45 #include "lo-utils.h" |
1651 | 46 #include "oct-cmplx.h" |
2926 | 47 #include "oct-env.h" |
19303
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19186
diff
changeset
|
48 #include "oct-locbuf.h" |
3040 | 49 #include "pathsearch.h" |
19303
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19186
diff
changeset
|
50 #include "quit.h" |
1755 | 51 #include "str-vec.h" |
1651 | 52 |
4216 | 53 #include "Cell.h" |
2492 | 54 #include <defaults.h> |
1352 | 55 #include "defun.h" |
56 #include "dirfns.h" | |
57 #include "error.h" | |
58 #include "gripes.h" | |
59 #include "input.h" | |
10502
f13bf183a003
isvarname: keywords are not valid variable names
Judd Storrs <jstorrs@gmail.com>
parents:
10315
diff
changeset
|
60 #include "lex.h" |
5832 | 61 #include "load-path.h" |
5465 | 62 #include "oct-errno.h" |
1742 | 63 #include "oct-hist.h" |
1750 | 64 #include "oct-obj.h" |
10613
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10605
diff
changeset
|
65 #include "ov-range.h" |
1352 | 66 #include "pager.h" |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10502
diff
changeset
|
67 #include "parse.h" |
1690 | 68 #include "sysdep.h" |
1750 | 69 #include "toplev.h" |
1 | 70 #include "unwind-prot.h" |
1352 | 71 #include "utils.h" |
72 #include "variables.h" | |
1 | 73 |
4143 | 74 // Return TRUE if S is a valid identifier. |
75 | |
76 bool | |
77 valid_identifier (const char *s) | |
78 { | |
5290 | 79 if (! s || ! (isalpha (*s) || *s == '_' || *s == '$')) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
80 return false; |
4143 | 81 |
82 while (*++s != '\0') | |
5290 | 83 if (! (isalnum (*s) || *s == '_' || *s == '$')) |
4143 | 84 return false; |
85 | |
86 return true; | |
87 } | |
88 | |
89 bool | |
90 valid_identifier (const std::string& s) | |
91 { | |
92 return valid_identifier (s.c_str ()); | |
93 } | |
94 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8715
diff
changeset
|
95 DEFUN (isvarname, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
96 "-*- texinfo -*-\n\ |
5040 | 97 @deftypefn {Built-in Function} {} isvarname (@var{name})\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11066
diff
changeset
|
98 Return true if @var{name} is a valid variable name.\n\ |
12573
232a90612254
Add new section on parsing to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12546
diff
changeset
|
99 @seealso{iskeyword, exist, who}\n\ |
4264 | 100 @end deftypefn") |
101 { | |
15435
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
102 octave_value retval = false; |
4264 | 103 |
15435
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
104 int nargin = args.length (); |
4264 | 105 |
15435
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
106 if (nargin != 1) |
5823 | 107 print_usage (); |
15435
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
108 else if (args(0).is_string ()) |
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
109 { |
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
110 std::string varname = args(0).string_value (); |
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
111 retval = valid_identifier (varname) && ! is_keyword (varname); |
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
112 } |
4264 | 113 |
114 return retval; | |
115 } | |
116 | |
13094 | 117 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
118 %!assert (isvarname ("foo"), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
119 %!assert (isvarname ("_foo"), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
120 %!assert (isvarname ("_1"), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
121 %!assert (isvarname ("1foo"), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
122 %!assert (isvarname (""), false) |
15435
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
123 %!assert (isvarname (12), false) |
19172
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
124 %!assert (isvarname ("foo+bar"), false) |
13094 | 125 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
126 %!error isvarname () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
127 %!error isvarname ("foo", "bar"); |
13094 | 128 */ |
129 | |
6323 | 130 // Return TRUE if F and G are both names for the same file. |
131 | |
132 bool | |
133 same_file (const std::string& f, const std::string& g) | |
134 { | |
6598 | 135 return same_file_internal (f, g); |
6323 | 136 } |
137 | |
1 | 138 int |
3523 | 139 almost_match (const std::string& std, const std::string& s, int min_match_len, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
140 int case_sens) |
1 | 141 { |
1755 | 142 int stdlen = std.length (); |
143 int slen = s.length (); | |
1 | 144 |
145 return (slen <= stdlen | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
146 && slen >= min_match_len |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
147 && (case_sens |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
148 ? (strncmp (std.c_str (), s.c_str (), slen) == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
149 : (octave_strncasecmp (std.c_str (), s.c_str (), slen) == 0))); |
287 | 150 } |
151 | |
581 | 152 // Ugh. |
153 | |
287 | 154 int |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
155 keyword_almost_match (const char * const *std, int *min_len, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
156 const std::string& s, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
157 int min_toks_to_match, int max_toks) |
287 | 158 { |
159 int status = 0; | |
160 int tok_count = 0; | |
161 int toks_matched = 0; | |
162 | |
1755 | 163 if (s.empty () || max_toks < 1) |
287 | 164 return status; |
165 | |
1755 | 166 char *kw = strsave (s.c_str ()); |
287 | 167 |
168 char *t = kw; | |
169 while (*t != '\0') | |
170 { | |
171 if (*t == '\t') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
172 *t = ' '; |
287 | 173 t++; |
174 } | |
175 | |
176 char *beg = kw; | |
177 while (*beg == ' ') | |
178 beg++; | |
179 | |
180 if (*beg == '\0') | |
181 return status; | |
182 | |
183 | |
3072 | 184 const char **to_match = new const char * [max_toks + 1]; |
185 const char * const *s1 = std; | |
186 const char **s2 = to_match; | |
287 | 187 |
526 | 188 if (! s1 || ! s2) |
287 | 189 goto done; |
190 | |
191 s2[tok_count] = beg; | |
192 char *end; | |
526 | 193 while ((end = strchr (beg, ' ')) != 0) |
287 | 194 { |
195 *end = '\0'; | |
196 beg = end + 1; | |
197 | |
198 while (*beg == ' ') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
199 beg++; |
287 | 200 |
201 if (*beg == '\0') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
202 break; |
287 | 203 |
204 tok_count++; | |
205 if (tok_count >= max_toks) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
206 goto done; |
287 | 207 |
208 s2[tok_count] = beg; | |
209 } | |
526 | 210 s2[tok_count+1] = 0; |
287 | 211 |
212 s2 = to_match; | |
213 | |
214 for (;;) | |
215 { | |
216 if (! almost_match (*s1, *s2, min_len[toks_matched], 0)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
217 goto done; |
287 | 218 |
219 toks_matched++; | |
220 | |
221 s1++; | |
222 s2++; | |
223 | |
224 if (! *s2) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
225 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
226 status = (toks_matched >= min_toks_to_match); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
227 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
228 } |
287 | 229 |
230 if (! *s1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
231 goto done; |
287 | 232 } |
233 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
234 done: |
287 | 235 |
236 delete [] kw; | |
237 delete [] to_match; | |
238 | |
239 return status; | |
1 | 240 } |
241 | |
18851
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18131
diff
changeset
|
242 // Return nonzero if either NR or NC is zero. Return -1 if this |
2234 | 243 // should be considered fatal; return 1 if this is ok. |
244 | |
245 int | |
5275 | 246 empty_arg (const char * /* name */, octave_idx_type nr, octave_idx_type nc) |
2234 | 247 { |
4478 | 248 return (nr == 0 || nc == 0); |
2234 | 249 } |
250 | |
581 | 251 // See if the given file is in the path. |
252 | |
3536 | 253 std::string |
4243 | 254 search_path_for_file (const std::string& path, const string_vector& names) |
686 | 255 { |
3174 | 256 dir_path p (path); |
686 | 257 |
10250 | 258 return octave_env::make_absolute (p.find_first_of (names)); |
686 | 259 } |
260 | |
4216 | 261 // Find all locations of the given file in the path. |
262 | |
263 string_vector | |
4243 | 264 search_path_for_all_files (const std::string& path, const string_vector& names) |
4216 | 265 { |
266 dir_path p (path); | |
267 | |
4243 | 268 string_vector sv = p.find_all_first_of (names); |
4216 | 269 |
6379 | 270 octave_idx_type len = sv.length (); |
4216 | 271 |
6379 | 272 for (octave_idx_type i = 0; i < len; i++) |
10250 | 273 sv[i] = octave_env::make_absolute (sv[i]); |
4216 | 274 |
275 return sv; | |
276 } | |
277 | |
278 static string_vector | |
279 make_absolute (const string_vector& sv) | |
280 { | |
6379 | 281 octave_idx_type len = sv.length (); |
282 | |
283 string_vector retval (len); | |
4216 | 284 |
6379 | 285 for (octave_idx_type i = 0; i < len; i++) |
10250 | 286 retval[i] = octave_env::make_absolute (sv[i]); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
287 |
6379 | 288 return retval; |
4216 | 289 } |
290 | |
3195 | 291 DEFUN (file_in_loadpath, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
292 "-*- texinfo -*-\n\ |
10840 | 293 @deftypefn {Built-in Function} {} file_in_loadpath (@var{file})\n\ |
4216 | 294 @deftypefnx {Built-in Function} {} file_in_loadpath (@var{file}, \"all\")\n\ |
3195 | 295 \n\ |
5448 | 296 Return the absolute name of @var{file} if it can be found in\n\ |
5814 | 297 the list of directories specified by @code{path}.\n\ |
10646
6c50b56824aa
file_in_path, file_in_loadpath: return empty string instead of empty matrix if file not found
John W. Eaton <jwe@octave.org>
parents:
10613
diff
changeset
|
298 If no file is found, return an empty character string.\n\ |
4216 | 299 \n\ |
5448 | 300 If the first argument is a cell array of strings, search each\n\ |
4243 | 301 directory of the loadpath for element of the cell array and return\n\ |
302 the first that matches.\n\ | |
303 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
304 If the second optional argument @qcode{\"all\"} is supplied, return\n\ |
4216 | 305 a cell array containing the list of all files that have the same\n\ |
306 name in the path. If no files are found, return an empty cell array.\n\ | |
18109
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18104
diff
changeset
|
307 @seealso{file_in_path, dir_in_loadpath, path}\n\ |
5642 | 308 @end deftypefn") |
3195 | 309 { |
4216 | 310 octave_value retval; |
3195 | 311 |
4243 | 312 int nargin = args.length (); |
3195 | 313 |
4243 | 314 if (nargin == 1 || nargin == 2) |
4216 | 315 { |
4243 | 316 string_vector names = args(0).all_strings (); |
317 | |
318 if (! error_state && names.length () > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
319 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
320 if (nargin == 1) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
321 retval = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
322 octave_env::make_absolute (load_path::find_first_of (names)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
323 else if (nargin == 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
324 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
325 std::string opt = args(1).string_value (); |
4243 | 326 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
327 if (! error_state && opt == "all") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
328 retval = Cell (make_absolute |
10250 | 329 (load_path::find_all_first_of (names))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
330 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
331 error ("file_in_loadpath: invalid option"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
332 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
333 } |
4216 | 334 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
335 error ("file_in_loadpath: FILE argument must be a string"); |
4216 | 336 } |
3195 | 337 else |
5823 | 338 print_usage (); |
3195 | 339 |
340 return retval; | |
341 } | |
342 | |
13094 | 343 /* |
344 %!test | |
345 %! f = file_in_loadpath ("plot.m"); | |
346 %! assert (ischar (f)); | |
347 %! assert (! isempty (f)); | |
348 | |
349 %!test | |
350 %! f = file_in_loadpath ("$$probably_!!_not_&&_a_!!_file$$"); | |
351 %! assert (f, ""); | |
352 | |
353 %!test | |
354 %! lst = file_in_loadpath ("$$probably_!!_not_&&_a_!!_file$$", "all"); | |
355 %! assert (lst, {}); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
356 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
357 %!error file_in_loadpath () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
358 %!error file_in_loadpath ("foo", "bar", 1) |
19172
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
359 %!error file_in_loadpath ([]) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
360 %!error file_in_loadpath ("plot.m", "bar") |
13094 | 361 */ |
362 | |
1957 | 363 DEFUN (file_in_path, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
364 "-*- texinfo -*-\n\ |
10840 | 365 @deftypefn {Built-in Function} {} file_in_path (@var{path}, @var{file})\n\ |
4216 | 366 @deftypefnx {Built-in Function} {} file_in_path (@var{path}, @var{file}, \"all\")\n\ |
5448 | 367 Return the absolute name of @var{file} if it can be found in\n\ |
3301 | 368 @var{path}. The value of @var{path} should be a colon-separated list of\n\ |
5814 | 369 directories in the format described for @code{path}. If no file\n\ |
10840 | 370 is found, return an empty character string. For example:\n\ |
3301 | 371 \n\ |
372 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8929
diff
changeset
|
373 @group\n\ |
5456 | 374 file_in_path (EXEC_PATH, \"sh\")\n\ |
375 @result{} \"/bin/sh\"\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8929
diff
changeset
|
376 @end group\n\ |
3301 | 377 @end example\n\ |
4216 | 378 \n\ |
5448 | 379 If the second argument is a cell array of strings, search each\n\ |
4243 | 380 directory of the path for element of the cell array and return\n\ |
381 the first that matches.\n\ | |
382 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
383 If the third optional argument @qcode{\"all\"} is supplied, return\n\ |
4216 | 384 a cell array containing the list of all files that have the same\n\ |
385 name in the path. If no files are found, return an empty cell array.\n\ | |
18109
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18104
diff
changeset
|
386 @seealso{file_in_loadpath, dir_in_loadpath, path}\n\ |
3301 | 387 @end deftypefn") |
686 | 388 { |
4216 | 389 octave_value retval; |
686 | 390 |
4243 | 391 int nargin = args.length (); |
1755 | 392 |
4243 | 393 if (nargin == 2 || nargin == 3) |
686 | 394 { |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19303
diff
changeset
|
395 if (args(0).is_string ()) |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19303
diff
changeset
|
396 { |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19303
diff
changeset
|
397 std::string path = args(0).string_value (); |
4243 | 398 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
399 string_vector names = args(1).all_strings (); |
4243 | 400 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
401 if (! error_state && names.length () > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
402 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
403 if (nargin == 2) |
10646
6c50b56824aa
file_in_path, file_in_loadpath: return empty string instead of empty matrix if file not found
John W. Eaton <jwe@octave.org>
parents:
10613
diff
changeset
|
404 retval = search_path_for_file (path, names); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
405 else if (nargin == 3) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
406 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
407 std::string opt = args(2).string_value (); |
4243 | 408 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
409 if (! error_state && opt == "all") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
410 retval = Cell (make_absolute |
10250 | 411 (search_path_for_all_files (path, names))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
412 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
413 error ("file_in_path: invalid option"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
414 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
415 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
416 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
417 error ("file_in_path: all arguments must be strings"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
418 } |
1755 | 419 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
420 error ("file_in_path: PATH must be a string"); |
686 | 421 } |
422 else | |
5823 | 423 print_usage (); |
686 | 424 |
425 return retval; | |
426 } | |
427 | |
13094 | 428 /* |
429 %!test | |
430 %! f = file_in_path (path (), "plot.m"); | |
431 %! assert (ischar (f)); | |
432 %! assert (! isempty (f)); | |
433 | |
434 %!test | |
435 %! f = file_in_path (path (), "$$probably_!!_not_&&_a_!!_file$$"); | |
436 %! assert (f, ""); | |
437 | |
438 %!test | |
439 %! lst = file_in_path (path (), "$$probably_!!_not_&&_a_!!_file$$", "all"); | |
440 %! assert (lst, {}); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
441 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
442 %!error file_in_path () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
443 %!error file_in_path ("foo") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
444 %!error file_in_path ("foo", "bar", "baz", 1) |
19172
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
445 %!error file_in_path ([]) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
446 %!error file_in_path (path (), []) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
447 %!error file_in_path (path (), "plot.m", "bar") |
13094 | 448 */ |
449 | |
3536 | 450 std::string |
3523 | 451 file_in_path (const std::string& name, const std::string& suffix) |
526 | 452 { |
3523 | 453 std::string nm = name; |
526 | 454 |
1755 | 455 if (! suffix.empty ()) |
456 nm.append (suffix); | |
686 | 457 |
10250 | 458 return octave_env::make_absolute (load_path::find_file (nm)); |
526 | 459 } |
460 | |
19064
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
461 std::string |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
462 find_data_file_in_load_path (const std::string& fcn, |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
463 const std::string& file, |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
464 bool require_regular_file) |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
465 { |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
466 std::string fname = file; |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
467 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
468 if (! (octave_env::absolute_pathname (fname) |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
469 || octave_env::rooted_relative_pathname (fname))) |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
470 { |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
471 // Load path will also search "." first, but we don't want to |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
472 // issue a warning if the file is found in the current directory, |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
473 // so do an explicit check for that. |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
474 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
475 file_stat fs (fname); |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
476 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
477 bool local_file_ok |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
478 = fs.exists () && (fs.is_reg () || ! require_regular_file); |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
479 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
480 if (! local_file_ok) |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
481 { |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
482 // Not directly found; search load path. |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
483 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
484 std::string tmp |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
485 = octave_env::make_absolute (load_path::find_file (fname)); |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
486 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
487 if (! tmp.empty ()) |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
488 { |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
489 gripe_data_file_in_path (fcn, tmp); |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
490 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
491 fname = tmp; |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
492 } |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
493 } |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
494 } |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
495 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
496 return fname; |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
497 } |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18851
diff
changeset
|
498 |
581 | 499 // See if there is an function file in the path. If so, return the |
500 // full path to the file. | |
501 | |
3536 | 502 std::string |
3523 | 503 fcn_file_in_path (const std::string& name) |
526 | 504 { |
3523 | 505 std::string retval; |
908 | 506 |
1755 | 507 int len = name.length (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
508 |
1755 | 509 if (len > 0) |
510 { | |
5832 | 511 if (octave_env::absolute_pathname (name)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
512 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
513 file_stat fs (name); |
5832 | 514 |
17955
9fc0836cb69b
Fix "get_help_text('\')" in Windows.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17818
diff
changeset
|
515 if (fs.exists () && ! fs.is_dir ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
516 retval = name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
517 } |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
14819
diff
changeset
|
518 else if (len > 2 && name[len - 2] == '.' && name[len - 1] == 'm') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
519 retval = load_path::find_fcn_file (name.substr (0, len-2)); |
908 | 520 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
521 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
522 std::string fname = name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
523 size_t pos = name.find_first_of (Vfilemarker); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
524 if (pos != std::string::npos) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
525 fname = name.substr (0, pos); |
7818
5640a70cbab1
Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
526 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
527 retval = load_path::find_fcn_file (fname); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
528 } |
908 | 529 } |
1755 | 530 |
531 return retval; | |
526 | 532 } |
533 | |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
534 // See if there is a directory called "name" in the path and if it |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
535 // contains a Contents.m file return the full path to this file. |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
536 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
537 std::string |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
538 contents_file_in_path (const std::string& dir) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
539 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
540 std::string retval; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
541 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
542 if (dir.length () > 0) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
543 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
544 std::string tcontents = file_ops::concat (load_path::find_dir (dir), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
545 std::string ("Contents.m")); |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
546 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
547 file_stat fs (tcontents); |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
548 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
549 if (fs.exists ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
550 retval = octave_env::make_absolute (tcontents); |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
551 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
552 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
553 return retval; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
554 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
555 |
5864 | 556 // See if there is a .oct file in the path. If so, return the |
581 | 557 // full path to the file. |
558 | |
3536 | 559 std::string |
3523 | 560 oct_file_in_path (const std::string& name) |
572 | 561 { |
3523 | 562 std::string retval; |
908 | 563 |
1755 | 564 int len = name.length (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
565 |
1755 | 566 if (len > 0) |
567 { | |
5832 | 568 if (octave_env::absolute_pathname (name)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
569 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
570 file_stat fs (name); |
5832 | 571 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
572 if (fs.exists ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
573 retval = name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
574 } |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
14819
diff
changeset
|
575 else if (len > 4 && name[len - 4] == '.' && name[len - 3] == 'o' |
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
14819
diff
changeset
|
576 && name[len - 2] == 'c' && name[len - 1] == 't') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
577 retval = load_path::find_oct_file (name.substr (0, len-4)); |
908 | 578 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
579 retval = load_path::find_oct_file (name); |
908 | 580 } |
1755 | 581 |
582 return retval; | |
572 | 583 } |
584 | |
5864 | 585 // See if there is a .mex file in the path. If so, return the |
586 // full path to the file. | |
587 | |
588 std::string | |
589 mex_file_in_path (const std::string& name) | |
590 { | |
591 std::string retval; | |
592 | |
593 int len = name.length (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
594 |
5864 | 595 if (len > 0) |
596 { | |
597 if (octave_env::absolute_pathname (name)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
598 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
599 file_stat fs (name); |
5864 | 600 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
601 if (fs.exists ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
602 retval = name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
603 } |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
14819
diff
changeset
|
604 else if (len > 4 && name[len - 4] == '.' && name[len - 3] == 'm' |
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
14819
diff
changeset
|
605 && name[len - 2] == 'e' && name[len - 1] == 'x') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
606 retval = load_path::find_mex_file (name.substr (0, len-4)); |
5864 | 607 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
608 retval = load_path::find_mex_file (name); |
5864 | 609 } |
610 | |
611 return retval; | |
612 } | |
613 | |
3103 | 614 // Replace backslash escapes in a string with the real values. |
615 | |
3536 | 616 std::string |
3523 | 617 do_string_escapes (const std::string& s) |
3103 | 618 { |
3523 | 619 std::string retval; |
3103 | 620 |
621 size_t i = 0; | |
622 size_t j = 0; | |
623 size_t len = s.length (); | |
624 | |
625 retval.resize (len); | |
626 | |
627 while (j < len) | |
628 { | |
629 if (s[j] == '\\' && j+1 < len) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
630 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
631 switch (s[++j]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
632 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
633 case '0': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
634 retval[i] = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
635 break; |
3893 | 636 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
637 case 'a': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
638 retval[i] = '\a'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
639 break; |
3103 | 640 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
641 case 'b': // backspace |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
642 retval[i] = '\b'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
643 break; |
3103 | 644 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
645 case 'f': // formfeed |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
646 retval[i] = '\f'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
647 break; |
3103 | 648 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
649 case 'n': // newline |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
650 retval[i] = '\n'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
651 break; |
3103 | 652 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
653 case 'r': // carriage return |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
654 retval[i] = '\r'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
655 break; |
3103 | 656 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
657 case 't': // horizontal tab |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
658 retval[i] = '\t'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
659 break; |
3103 | 660 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
661 case 'v': // vertical tab |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
662 retval[i] = '\v'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
663 break; |
3103 | 664 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
665 case '\\': // backslash |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
666 retval[i] = '\\'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
667 break; |
3103 | 668 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
669 case '\'': // quote |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
670 retval[i] = '\''; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
671 break; |
3103 | 672 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
673 case '"': // double quote |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
674 retval[i] = '"'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
675 break; |
3103 | 676 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
677 default: |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
678 warning ("unrecognized escape sequence '\\%c' --\ |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
679 converting to '%c'", s[j], s[j]); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
680 retval[i] = s[j]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
681 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
682 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
683 } |
3103 | 684 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
685 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
686 retval[i] = s[j]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
687 } |
3103 | 688 |
689 i++; | |
690 j++; | |
691 } | |
692 | |
3105 | 693 retval.resize (i); |
3103 | 694 |
695 return retval; | |
696 } | |
697 | |
698 DEFUN (do_string_escapes, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
699 "-*- texinfo -*-\n\ |
3446 | 700 @deftypefn {Built-in Function} {} do_string_escapes (@var{string})\n\ |
701 Convert special characters in @var{string} to their escaped forms.\n\ | |
702 @end deftypefn") | |
3103 | 703 { |
704 octave_value retval; | |
705 | |
706 int nargin = args.length (); | |
707 | |
708 if (nargin == 1) | |
709 { | |
710 if (args(0).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
711 retval = do_string_escapes (args(0).string_value ()); |
3103 | 712 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
713 error ("do_string_escapes: STRING argument must be of type string"); |
3103 | 714 } |
715 else | |
5823 | 716 print_usage (); |
3103 | 717 |
718 return retval; | |
719 } | |
720 | |
13094 | 721 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
722 %!assert (do_string_escapes ('foo\nbar'), "foo\nbar") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
723 %!assert (do_string_escapes ("foo\\nbar"), "foo\nbar") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
724 %!assert (do_string_escapes ("foo\\nbar"), ["foo", char(10), "bar"]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
725 %!assert ("foo\nbar", ["foo", char(10), "bar"]) |
13094 | 726 |
19172
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
727 %!assert (do_string_escapes ('\0\a\b\f\n\r\t\v'), "\0\a\b\f\n\r\t\v") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
728 %!assert (do_string_escapes ("\\0\\a\\b\\f\\n\\r\\t\\v"), "\0\a\b\f\n\r\t\v") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
729 %!assert (do_string_escapes ("\\0\\a\\b\\f\\n\\r\\t\\v"), |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
730 %! char ([0, 7, 8, 12, 10, 13, 9, 11])) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
731 %!assert ("\0\a\b\f\n\r\t\v", char ([0, 7, 8, 12, 10, 13, 9, 11])) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
732 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
733 %!assert (do_string_escapes ('\\'), "\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
734 %!assert (do_string_escapes ("\\\\"), "\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
735 %!assert (do_string_escapes ("\\\\"), char (92)) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
736 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
737 %!assert (do_string_escapes ('\''single-quoted\'''), "'single-quoted'") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
738 %!assert (do_string_escapes ("\\'single-quoted\\'"), "'single-quoted'") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
739 %!assert (do_string_escapes ('\"double-quoted\"'), "\"double-quoted\"") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
740 %!assert (do_string_escapes ("\\\"double-quoted\\\""), "\"double-quoted\"") |
13094 | 741 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
742 %!error do_string_escapes () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
743 %!error do_string_escapes ("foo", "bar") |
19172
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
744 %!error do_string_escapes (3) |
13094 | 745 */ |
746 | |
1755 | 747 const char * |
801 | 748 undo_string_escape (char c) |
749 { | |
750 if (! c) | |
1755 | 751 return ""; |
801 | 752 |
753 switch (c) | |
754 { | |
3893 | 755 case '\0': |
756 return "\\0"; | |
757 | |
801 | 758 case '\a': |
759 return "\\a"; | |
760 | |
761 case '\b': // backspace | |
762 return "\\b"; | |
763 | |
764 case '\f': // formfeed | |
765 return "\\f"; | |
766 | |
767 case '\n': // newline | |
768 return "\\n"; | |
769 | |
770 case '\r': // carriage return | |
771 return "\\r"; | |
772 | |
773 case '\t': // horizontal tab | |
774 return "\\t"; | |
775 | |
776 case '\v': // vertical tab | |
777 return "\\v"; | |
778 | |
779 case '\\': // backslash | |
780 return "\\\\"; | |
781 | |
782 case '"': // double quote | |
783 return "\\\""; | |
784 | |
785 default: | |
1755 | 786 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
787 static char retval[2]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
788 retval[0] = c; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
789 retval[1] = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
790 return retval; |
1755 | 791 } |
801 | 792 } |
793 } | |
794 | |
3536 | 795 std::string |
3523 | 796 undo_string_escapes (const std::string& s) |
801 | 797 { |
3523 | 798 std::string retval; |
801 | 799 |
1755 | 800 for (size_t i = 0; i < s.length (); i++) |
801 retval.append (undo_string_escape (s[i])); | |
801 | 802 |
1755 | 803 return retval; |
801 | 804 } |
805 | |
1957 | 806 DEFUN (undo_string_escapes, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
807 "-*- texinfo -*-\n\ |
3361 | 808 @deftypefn {Built-in Function} {} undo_string_escapes (@var{s})\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
809 Convert special characters in strings back to their escaped forms. For\n\ |
3361 | 810 example, the expression\n\ |
811 \n\ | |
812 @example\n\ | |
813 bell = \"\\a\";\n\ | |
814 @end example\n\ | |
815 \n\ | |
816 @noindent\n\ | |
817 assigns the value of the alert character (control-g, ASCII code 7) to\n\ | |
818 the string variable @code{bell}. If this string is printed, the\n\ | |
819 system will ring the terminal bell (if it is possible). This is\n\ | |
820 normally the desired outcome. However, sometimes it is useful to be\n\ | |
821 able to print the original representation of the string, with the\n\ | |
822 special characters replaced by their escape sequences. For example,\n\ | |
823 \n\ | |
824 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8929
diff
changeset
|
825 @group\n\ |
3361 | 826 octave:13> undo_string_escapes (bell)\n\ |
827 ans = \\a\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8929
diff
changeset
|
828 @end group\n\ |
3361 | 829 @end example\n\ |
830 \n\ | |
831 @noindent\n\ | |
832 replaces the unprintable alert character with its printable\n\ | |
833 representation.\n\ | |
834 @end deftypefn") | |
801 | 835 { |
2086 | 836 octave_value retval; |
801 | 837 |
838 int nargin = args.length (); | |
839 | |
3103 | 840 if (nargin == 1) |
841 { | |
842 if (args(0).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
843 retval = undo_string_escapes (args(0).string_value ()); |
3103 | 844 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
845 error ("undo_string_escapes: S argument must be a string"); |
3103 | 846 } |
801 | 847 else |
5823 | 848 print_usage (); |
801 | 849 |
850 return retval; | |
851 } | |
852 | |
13094 | 853 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
854 %!assert (undo_string_escapes ("foo\nbar"), 'foo\nbar') |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
855 %!assert (undo_string_escapes ("foo\nbar"), "foo\\nbar") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
856 %!assert (undo_string_escapes (["foo", char(10), "bar"]), "foo\\nbar") |
13094 | 857 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
858 %!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), '\a\b\f\n\r\t\v') |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
859 %!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), "\\a\\b\\f\\n\\r\\t\\v") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
860 %!assert (undo_string_escapes (char ([7, 8, 12, 10, 13, 9, 11])), |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
861 %! "\\a\\b\\f\\n\\r\\t\\v") |
13094 | 862 |
19172
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
863 %!assert (undo_string_escapes ("\\"), '\\') |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
864 %!assert (undo_string_escapes ("\\"), "\\\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
865 %!assert (undo_string_escapes (char (92)), "\\\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
866 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
867 %!assert (undo_string_escapes ("\"double-quoted\""), '\"double-quoted\"') |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
868 %!assert (undo_string_escapes ("\"double-quoted\""), "\\\"double-quoted\\\"") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
869 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
870 %!error undo_string_escapes () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
871 %!error undo_string_escapes ("foo", "bar") |
19172
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
872 %!error undo_string_escapes (3) |
13094 | 873 */ |
874 | |
8229 | 875 DEFUN (is_absolute_filename, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
876 "-*- texinfo -*-\n\ |
8229 | 877 @deftypefn {Built-in Function} {} is_absolute_filename (@var{file})\n\ |
878 Return true if @var{file} is an absolute filename.\n\ | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11066
diff
changeset
|
879 @seealso{is_rooted_relative_filename, make_absolute_filename, isdir}\n\ |
8229 | 880 @end deftypefn") |
881 { | |
882 octave_value retval = false; | |
883 | |
884 if (args.length () == 1) | |
885 retval = (args(0).is_string () | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
886 && octave_env::absolute_pathname (args(0).string_value ())); |
8229 | 887 else |
888 print_usage (); | |
889 | |
890 return retval; | |
891 } | |
892 | |
13094 | 893 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
894 ## FIXME: We need system-dependent tests here. |
13094 | 895 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
896 %!error is_absolute_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
897 %!error is_absolute_filename ("foo", "bar") |
13094 | 898 */ |
899 | |
8229 | 900 DEFUN (is_rooted_relative_filename, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
901 "-*- texinfo -*-\n\ |
8229 | 902 @deftypefn {Built-in Function} {} is_rooted_relative_filename (@var{file})\n\ |
903 Return true if @var{file} is a rooted-relative filename.\n\ | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11066
diff
changeset
|
904 @seealso{is_absolute_filename, make_absolute_filename, isdir}\n\ |
8229 | 905 @end deftypefn") |
906 { | |
907 octave_value retval = false; | |
908 | |
909 if (args.length () == 1) | |
910 retval = (args(0).is_string () | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
911 && octave_env::rooted_relative_pathname (args(0).string_value ())); |
8229 | 912 else |
913 print_usage (); | |
914 | |
915 return retval; | |
916 } | |
917 | |
13094 | 918 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
919 ## FIXME: We need system-dependent tests here. |
13094 | 920 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
921 %!error is_rooted_relative_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
922 %!error is_rooted_relative_filename ("foo", "bar") |
13094 | 923 */ |
924 | |
8229 | 925 DEFUN (make_absolute_filename, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
926 "-*- texinfo -*-\n\ |
8229 | 927 @deftypefn {Built-in Function} {} make_absolute_filename (@var{file})\n\ |
14819
67b6b47a22f6
doc: Clarify docstrings for canonicalize_file_name, make_absolute_filename
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
928 Return the full name of @var{file} beginning from the root of the file\n\ |
67b6b47a22f6
doc: Clarify docstrings for canonicalize_file_name, make_absolute_filename
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
929 system. No check is done for the existence of @var{file}.\n\ |
67b6b47a22f6
doc: Clarify docstrings for canonicalize_file_name, make_absolute_filename
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
930 @seealso{canonicalize_file_name, is_absolute_filename, is_rooted_relative_filename, isdir}\n\ |
8229 | 931 @end deftypefn") |
932 { | |
933 octave_value retval = std::string (); | |
934 | |
935 if (args.length () == 1) | |
936 { | |
937 std::string nm = args(0).string_value (); | |
938 | |
939 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
940 retval = octave_env::make_absolute (nm); |
8229 | 941 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
942 error ("make_absolute_filename: FILE argument must be a file name"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
943 } |
8229 | 944 else |
945 print_usage (); | |
946 | |
947 return retval; | |
948 } | |
949 | |
13094 | 950 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
951 ## FIXME: We need system-dependent tests here. |
13094 | 952 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
953 %!error make_absolute_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
954 %!error make_absolute_filename ("foo", "bar") |
13094 | 955 */ |
956 | |
18109
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18104
diff
changeset
|
957 DEFUN (dir_in_loadpath, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
958 "-*- texinfo -*-\n\ |
18109
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18104
diff
changeset
|
959 @deftypefn {Built-in Function} {} dir_in_loadpath (@var{dir})\n\ |
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18104
diff
changeset
|
960 @deftypefnx {Built-in Function} {} dir_in_loadpath (@var{dir}, \"all\")\n\ |
8229 | 961 Return the full name of the path element matching @var{dir}. The\n\ |
962 match is performed at the end of each path element. For example, if\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
963 @var{dir} is @qcode{\"foo/bar\"}, it matches the path element\n\ |
17290
17be601bc783
doc: Periodic spellchecking of documentation.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
964 @nospell{@qcode{\"/some/dir/foo/bar\"}}, but not\n\ |
17be601bc783
doc: Periodic spellchecking of documentation.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
965 @nospell{@qcode{\"/some/dir/foo/bar/baz\"}}\n\ |
17be601bc783
doc: Periodic spellchecking of documentation.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
966 @nospell{@qcode{\"/some/dir/allfoo/bar\"}}.\n\ |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
967 \n\ |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
968 The second argument is optional. If it is supplied, return a cell array\n\ |
12668
e3dc23f7dd54
doc: Improve a few docstrings related to test functions and directories.
Rik <octave@nomad.inbox5.com>
parents:
12573
diff
changeset
|
969 containing all name matches rather than just the first.\n\ |
18062
aca545afdf25
doc: Add seealso links to find_dir_in_path function.
Rik <rik@octave.org>
parents:
17955
diff
changeset
|
970 @seealso{file_in_path, file_in_loadpath, path}\n\ |
8229 | 971 @end deftypefn") |
972 { | |
973 octave_value retval = std::string (); | |
974 | |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
975 int nargin = args.length (); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
976 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
977 std::string dir; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
978 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
979 if (nargin == 1 || nargin == 2) |
8229 | 980 { |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
981 dir = args(0).string_value (); |
8229 | 982 |
983 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
984 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
985 if (nargin == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
986 retval = load_path::find_dir (dir); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
987 else if (nargin == 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
988 retval = Cell (load_path::find_matching_dirs (dir)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
989 } |
8229 | 990 else |
18109
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18104
diff
changeset
|
991 error ("dir_in_loadpath: DIR must be a directory name"); |
8229 | 992 } |
993 else | |
994 print_usage (); | |
995 | |
996 return retval; | |
997 } | |
998 | |
13094 | 999 /* |
19172
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
1000 %!test |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
1001 %! f = dir_in_loadpath ("plot"); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
1002 %! assert (ischar (f)); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
1003 %! assert (! isempty (f)); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
1004 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
1005 %!test |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
1006 %! f = dir_in_loadpath ("$$probably_!!_not_&&_a_!!_dir$$"); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
1007 %! assert (f, ""); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
1008 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
1009 %!test |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
1010 %! lst = dir_in_loadpath ("$$probably_!!_not_&&_a_!!_dir$$", "all"); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
1011 %! assert (lst, {}); |
13094 | 1012 |
18109
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18104
diff
changeset
|
1013 %!error dir_in_loadpath () |
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18104
diff
changeset
|
1014 %!error dir_in_loadpath ("foo", "bar", 1) |
13094 | 1015 */ |
1016 | |
5465 | 1017 DEFUNX ("errno", Ferrno, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1018 "-*- texinfo -*-\n\ |
10840 | 1019 @deftypefn {Built-in Function} {@var{err} =} errno ()\n\ |
5465 | 1020 @deftypefnx {Built-in Function} {@var{err} =} errno (@var{val})\n\ |
1021 @deftypefnx {Built-in Function} {@var{err} =} errno (@var{name})\n\ | |
1022 Return the current value of the system-dependent variable errno,\n\ | |
1023 set its value to @var{val} and return the previous value, or return\n\ | |
1024 the named error code given @var{name} as a character string, or -1\n\ | |
1025 if @var{name} is not found.\n\ | |
3716 | 1026 @end deftypefn") |
1027 { | |
1028 octave_value retval; | |
1029 | |
5465 | 1030 int nargin = args.length (); |
1031 | |
1032 if (nargin == 1) | |
1033 { | |
1034 if (args(0).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1035 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1036 std::string nm = args(0).string_value (); |
5465 | 1037 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1038 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1039 retval = octave_errno::lookup (nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1040 else |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19303
diff
changeset
|
1041 error ("errno: expecting string argument"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1042 } |
5465 | 1043 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1044 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1045 int val = args(0).int_value (); |
5465 | 1046 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1047 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1048 retval = octave_errno::set (val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1049 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1050 error ("errno: expecting integer argument"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1051 } |
5465 | 1052 } |
1053 else if (nargin == 0) | |
1054 retval = octave_errno::get (); | |
3716 | 1055 else |
5823 | 1056 print_usage (); |
3716 | 1057 |
1058 return retval; | |
1059 } | |
1060 | |
13094 | 1061 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1062 %!assert (isnumeric (errno ())) |
13094 | 1063 |
1064 %!test | |
1065 %! lst = errno_list (); | |
1066 %! fns = fieldnames (lst); | |
1067 %! oldval = errno (fns{1}); | |
1068 %! assert (isnumeric (oldval)); | |
1069 %! errno (oldval); | |
1070 %! newval = errno (); | |
1071 %! assert (oldval, newval); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1072 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1073 %!error errno ("foo", 1) |
13094 | 1074 */ |
1075 | |
5465 | 1076 DEFUN (errno_list, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1077 "-*- texinfo -*-\n\ |
5465 | 1078 @deftypefn {Built-in Function} {} errno_list ()\n\ |
1079 Return a structure containing the system-dependent errno values.\n\ | |
1080 @end deftypefn") | |
1081 { | |
1082 octave_value retval; | |
1083 | |
1084 if (args.length () == 0) | |
1085 retval = octave_errno::list (); | |
1086 else | |
5823 | 1087 print_usage (); |
5465 | 1088 |
1089 return retval; | |
1090 } | |
3716 | 1091 |
13094 | 1092 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1093 %!assert (isstruct (errno_list ())) |
13094 | 1094 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1095 %!error errno_list ("foo") |
13094 | 1096 */ |
1097 | |
2285 | 1098 static void |
5275 | 1099 check_dimensions (octave_idx_type& nr, octave_idx_type& nc, const char *warnfor) |
3354 | 1100 { |
1101 if (nr < 0 || nc < 0) | |
1102 { | |
5781 | 1103 warning_with_id ("Octave:neg-dim-as-zero", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1104 "%s: converting negative dimension to zero", warnfor); |
3354 | 1105 |
4457 | 1106 nr = (nr < 0) ? 0 : nr; |
1107 nc = (nc < 0) ? 0 : nc; | |
3354 | 1108 } |
1109 } | |
1110 | |
1111 void | |
4513 | 1112 check_dimensions (dim_vector& dim, const char *warnfor) |
4481 | 1113 { |
1114 bool neg = false; | |
1115 | |
1116 for (int i = 0; i < dim.length (); i++) | |
1117 { | |
1118 if (dim(i) < 0) | |
1119 { | |
1120 dim(i) = 0; | |
1121 neg = true; | |
1122 } | |
1123 } | |
1124 | |
5781 | 1125 if (neg) |
1126 warning_with_id ("Octave:neg-dim-as-zero", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1127 "%s: converting negative dimension to zero", warnfor); |
4481 | 1128 } |
1129 | |
1130 | |
1131 void | |
1132 get_dimensions (const octave_value& a, const char *warn_for, | |
4513 | 1133 dim_vector& dim) |
4481 | 1134 { |
1135 if (a.is_scalar_type ()) | |
1136 { | |
1137 dim.resize (2); | |
4732 | 1138 dim(0) = a.int_value (); |
4481 | 1139 dim(1) = dim(0); |
1140 } | |
1141 else | |
1142 { | |
5275 | 1143 octave_idx_type nr = a.rows (); |
1144 octave_idx_type nc = a.columns (); | |
4481 | 1145 |
1146 if (nr == 1 || nc == 1) | |
1147 { | |
1148 Array<double> v = a.vector_value (); | |
1149 | |
1150 if (error_state) | |
1151 return; | |
1152 | |
5275 | 1153 octave_idx_type n = v.length (); |
4481 | 1154 dim.resize (n); |
5275 | 1155 for (octave_idx_type i = 0; i < n; i++) |
4783 | 1156 dim(i) = static_cast<int> (fix (v(i))); |
4481 | 1157 } |
1158 else | |
5257 | 1159 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); |
4481 | 1160 } |
1161 | |
5258 | 1162 if (! error_state) |
1163 check_dimensions (dim, warn_for); // May set error_state. | |
4481 | 1164 } |
1165 | |
1166 | |
1167 void | |
3354 | 1168 get_dimensions (const octave_value& a, const char *warn_for, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1169 octave_idx_type& nr, octave_idx_type& nc) |
3354 | 1170 { |
1171 if (a.is_scalar_type ()) | |
1172 { | |
4732 | 1173 nr = nc = a.int_value (); |
3354 | 1174 } |
1175 else | |
1176 { | |
1177 nr = a.rows (); | |
1178 nc = a.columns (); | |
1179 | |
1180 if ((nr == 1 && nc == 2) || (nr == 2 && nc == 1)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1181 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1182 Array<double> v = a.vector_value (); |
3354 | 1183 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1184 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1185 return; |
3354 | 1186 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1187 nr = static_cast<octave_idx_type> (fix (v (0))); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1188 nc = static_cast<octave_idx_type> (fix (v (1))); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1189 } |
3354 | 1190 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1191 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); |
3354 | 1192 } |
1193 | |
5258 | 1194 if (! error_state) |
1195 check_dimensions (nr, nc, warn_for); // May set error_state. | |
3354 | 1196 } |
1197 | |
1198 void | |
1199 get_dimensions (const octave_value& a, const octave_value& b, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1200 const char *warn_for, octave_idx_type& nr, octave_idx_type& nc) |
3354 | 1201 { |
4732 | 1202 nr = a.is_empty () ? 0 : a.int_value (); |
1203 nc = b.is_empty () ? 0 : b.int_value (); | |
3354 | 1204 |
1205 if (error_state) | |
1206 error ("%s: expecting two scalar arguments", warn_for); | |
1207 else | |
1208 check_dimensions (nr, nc, warn_for); // May set error_state. | |
1209 } | |
1210 | |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1211 octave_idx_type |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1212 dims_to_numel (const dim_vector& dims, const octave_value_list& idx) |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1213 { |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1214 octave_idx_type retval; |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1215 |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1216 octave_idx_type len = idx.length (); |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1217 |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1218 if (len == 0) |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1219 retval = dims.numel (); |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1220 else |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1221 { |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1222 const dim_vector dv = dims.redim (len); |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1223 retval = 1; |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1224 for (octave_idx_type i = 0; i < len; i++) |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1225 { |
9842
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1226 octave_value idxi = idx(i); |
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1227 if (idxi.is_magic_colon ()) |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1228 retval *= dv(i); |
9842
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1229 else if (idxi.is_numeric_type ()) |
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1230 retval *= idxi.numel (); |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1231 else |
9842
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1232 { |
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1233 idx_vector jdx = idxi.index_vector (); |
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1234 if (error_state) |
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1235 break; |
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1236 retval *= jdx.length (dv(i)); |
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1237 } |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1238 } |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1239 } |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1240 |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1241 return retval; |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1242 } |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1243 |
4478 | 1244 Matrix |
5275 | 1245 identity_matrix (octave_idx_type nr, octave_idx_type nc) |
4478 | 1246 { |
1247 Matrix m (nr, nc, 0.0); | |
1248 | |
1249 if (nr > 0 && nc > 0) | |
1250 { | |
5275 | 1251 octave_idx_type n = std::min (nr, nc); |
4478 | 1252 |
5275 | 1253 for (octave_idx_type i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1254 m (i, i) = 1.0; |
4478 | 1255 } |
1256 | |
1257 return m; | |
1258 } | |
1259 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1260 FloatMatrix |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1261 float_identity_matrix (octave_idx_type nr, octave_idx_type nc) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1262 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1263 FloatMatrix m (nr, nc, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1264 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1265 if (nr > 0 && nc > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1266 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1267 octave_idx_type n = std::min (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1268 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1269 for (octave_idx_type i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1270 m (i, i) = 1.0; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1271 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1272 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1273 return m; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1274 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1275 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1276 size_t |
3622 | 1277 octave_format (std::ostream& os, const char *fmt, ...) |
3620 | 1278 { |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1279 size_t retval; |
3620 | 1280 |
1281 va_list args; | |
1282 va_start (args, fmt); | |
1283 | |
1284 retval = octave_vformat (os, fmt, args); | |
1285 | |
1286 va_end (args); | |
1287 | |
1288 return retval; | |
1289 } | |
1290 | |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1291 size_t |
3622 | 1292 octave_vformat (std::ostream& os, const char *fmt, va_list args) |
3620 | 1293 { |
14005
f8556baf1949
rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents:
13991
diff
changeset
|
1294 std::string s = octave_vasprintf (fmt, args); |
3620 | 1295 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1296 os << s; |
3620 | 1297 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1298 return s.length (); |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1299 } |
4135 | 1300 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1301 std::string |
14005
f8556baf1949
rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents:
13991
diff
changeset
|
1302 octave_vasprintf (const char *fmt, va_list args) |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1303 { |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1304 std::string retval; |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1305 |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1306 char *result; |
4302 | 1307 |
14005
f8556baf1949
rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents:
13991
diff
changeset
|
1308 int status = gnulib::vasprintf (&result, fmt, args); |
4302 | 1309 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1310 if (status >= 0) |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1311 { |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1312 retval = result; |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1313 ::free (result); |
4302 | 1314 } |
3620 | 1315 |
1316 return retval; | |
1317 } | |
1318 | |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1319 std::string |
14005
f8556baf1949
rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents:
13991
diff
changeset
|
1320 octave_asprintf (const char *fmt, ...) |
4302 | 1321 { |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1322 std::string retval; |
4302 | 1323 |
1324 va_list args; | |
1325 va_start (args, fmt); | |
1326 | |
14005
f8556baf1949
rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents:
13991
diff
changeset
|
1327 retval = octave_vasprintf (fmt, args); |
4302 | 1328 |
1329 va_end (args); | |
1330 | |
1331 return retval; | |
1332 } | |
1333 | |
4086 | 1334 void |
1335 octave_sleep (double seconds) | |
1336 { | |
1337 if (seconds > 0) | |
1338 { | |
1339 double t; | |
1340 | |
4093 | 1341 unsigned int usec |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1342 = static_cast<unsigned int> (modf (seconds, &t) * 1000000); |
4086 | 1343 |
4093 | 1344 unsigned int sec |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1345 = ((t > std::numeric_limits<unsigned int>::max ()) |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1346 ? std::numeric_limits<unsigned int>::max () |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1347 : static_cast<unsigned int> (t)); |
4086 | 1348 |
5770 | 1349 // Versions of these functions that accept unsigned int args are |
1350 // defined in cutils.c. | |
4086 | 1351 octave_sleep (sec); |
1352 octave_usleep (usec); | |
10070
897e62651c0a
correctly handle interrupts in pause()
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
1353 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10086
diff
changeset
|
1354 octave_quit (); |
4086 | 1355 } |
1356 } | |
1357 | |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1358 DEFUN (isindex, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1359 "-*- texinfo -*-\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11066
diff
changeset
|
1360 @deftypefn {Built-in Function} {} isindex (@var{ind})\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11066
diff
changeset
|
1361 @deftypefnx {Built-in Function} {} isindex (@var{ind}, @var{n})\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11066
diff
changeset
|
1362 Return true if @var{ind} is a valid index. Valid indices are\n\ |
11575
d6619410e79c
Spellcheck documentation before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11572
diff
changeset
|
1363 either positive integers (although possibly of real data type), or logical\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11066
diff
changeset
|
1364 arrays. If present, @var{n} specifies the maximum extent of the dimension\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11066
diff
changeset
|
1365 to be indexed. When possible the internal result is cached so that\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11066
diff
changeset
|
1366 subsequent indexing using @var{ind} will not perform the check again.\n\ |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1367 @end deftypefn") |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1368 { |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1369 octave_value retval; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1370 int nargin = args.length (); |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1371 octave_idx_type n = 0; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1372 |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1373 if (nargin == 2) |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1374 n = args(1).idx_type_value (); |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1375 else if (nargin != 1) |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1376 print_usage (); |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1377 |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1378 if (! error_state) |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1379 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10033
diff
changeset
|
1380 unwind_protect frame; |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10502
diff
changeset
|
1381 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10033
diff
changeset
|
1382 frame.protect_var (error_state); |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10502
diff
changeset
|
1383 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10033
diff
changeset
|
1384 frame.protect_var (discard_error_messages); |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1385 discard_error_messages = true; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1386 |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1387 try |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1388 { |
18129
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
18104
diff
changeset
|
1389 idx_vector idx = args(0).index_vector (true); |
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
18104
diff
changeset
|
1390 |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1391 if (! error_state) |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1392 { |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1393 if (nargin == 2) |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1394 retval = idx.extent (n) <= n; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1395 else |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1396 retval = true; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1397 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1398 else |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1399 retval = false; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1400 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1401 catch (octave_execution_exception) |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1402 { |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1403 retval = false; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1404 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1405 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1406 |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1407 return retval; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1408 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1409 |
13094 | 1410 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1411 %!assert (isindex ([1, 2, 3])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1412 %!assert (isindex (1:3)) |
19172
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
1413 %!assert (isindex (1:3, 2), false) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1414 %!assert (isindex ([1, 2, -3]), false) |
13094 | 1415 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1416 %!error isindex () |
19172
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19162
diff
changeset
|
1417 %!error isindex (1:3, 2, 3) |
13094 | 1418 */ |
1419 | |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1420 octave_value_list |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1421 do_simple_cellfun (octave_value_list (*fun) (const octave_value_list&, int), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1422 const char *fun_name, const octave_value_list& args, |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1423 int nargout) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1424 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1425 octave_value_list new_args = args, retval; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1426 int nargin = args.length (); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1427 OCTAVE_LOCAL_BUFFER (bool, iscell, nargin); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1428 OCTAVE_LOCAL_BUFFER (Cell, cells, nargin); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1429 OCTAVE_LOCAL_BUFFER (Cell, rcells, nargout); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1430 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1431 const Cell *ccells = cells; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1432 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1433 octave_idx_type numel = 1; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1434 dim_vector dims (1, 1); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1435 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1436 for (int i = 0; i < nargin; i++) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1437 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1438 octave_value arg = new_args(i); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1439 iscell[i] = arg.is_cell (); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1440 if (iscell[i]) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1441 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1442 cells[i] = arg.cell_value (); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1443 octave_idx_type n = ccells[i].numel (); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1444 if (n == 1) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1445 { |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1446 iscell[i] = false; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1447 new_args(i) = ccells[i](0); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1448 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1449 else if (numel == 1) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1450 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1451 numel = n; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1452 dims = ccells[i].dims (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1453 } |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1454 else if (dims != ccells[i].dims ()) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1455 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1456 error ("%s: cell arguments must have matching sizes", fun_name); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1457 break; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1458 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1459 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1460 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1461 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1462 if (! error_state) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1463 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1464 for (int i = 0; i < nargout; i++) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1465 rcells[i].clear (dims); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1466 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1467 for (octave_idx_type j = 0; j < numel; j++) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1468 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1469 for (int i = 0; i < nargin; i++) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1470 if (iscell[i]) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1471 new_args(i) = ccells[i](j); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1472 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10086
diff
changeset
|
1473 octave_quit (); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1474 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1475 const octave_value_list tmp = fun (new_args, nargout); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1476 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1477 if (tmp.length () < nargout) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1478 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1479 error ("%s: do_simple_cellfun: internal error", fun_name); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1480 break; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1481 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1482 else |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1483 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1484 for (int i = 0; i < nargout; i++) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1485 rcells[i](j) = tmp(i); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1486 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1487 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1488 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1489 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1490 if (! error_state) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1491 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1492 retval.resize (nargout); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1493 for (int i = 0; i < nargout; i++) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1494 retval(i) = rcells[i]; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1495 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1496 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1497 return retval; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1498 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1499 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1500 octave_value |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1501 do_simple_cellfun (octave_value_list (*fun) (const octave_value_list&, int), |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1502 const char *fun_name, const octave_value_list& args) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1503 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1504 octave_value retval; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1505 const octave_value_list tmp = do_simple_cellfun (fun, fun_name, args, 1); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1506 if (tmp.length () > 0) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1507 retval = tmp(0); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1508 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1509 return retval; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1510 } |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1511 |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1512 octave_preserve_stream_state::~octave_preserve_stream_state (void) |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1513 { |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1514 stream.flags (oflags); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1515 stream.precision (oprecision); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1516 stream.width (owidth); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1517 stream.fill (ofill); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1518 } |
19162
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19064
diff
changeset
|
1519 |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19064
diff
changeset
|
1520 DEFUN (isstudent, args, , |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19064
diff
changeset
|
1521 "-*- texinfo -*-\n\ |
19186
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19172
diff
changeset
|
1522 @deftypefn {Built-in Function} {} isstudent ()\n\ |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19172
diff
changeset
|
1523 Return true if running in the student edition of @sc{matlab}.\n\ |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19172
diff
changeset
|
1524 \n\ |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19172
diff
changeset
|
1525 @code{isstudent} always returns false in Octave.\n\ |
19162
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19064
diff
changeset
|
1526 \n\ |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19064
diff
changeset
|
1527 @seealso{false}\n\ |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19064
diff
changeset
|
1528 @end deftypefn") |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19064
diff
changeset
|
1529 { |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19064
diff
changeset
|
1530 if (args.length () != 0) |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19064
diff
changeset
|
1531 print_usage (); |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19064
diff
changeset
|
1532 |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19064
diff
changeset
|
1533 return octave_value (false); |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19064
diff
changeset
|
1534 } |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19064
diff
changeset
|
1535 |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19064
diff
changeset
|
1536 /* |
19186
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19172
diff
changeset
|
1537 %!assert (isstudent (), false) |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19172
diff
changeset
|
1538 |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19172
diff
changeset
|
1539 %!error isstudent (1) |
19162
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19064
diff
changeset
|
1540 */ |