Mercurial > hg > octave-nkf
annotate libinterp/corefcn/utils.cc @ 20527:2ec049e50ed8 stable
doc: Fix backslash characters in docstrings
* utils.cc (Fisindex), beep.m: Use @xbackslashchar to produce backslashes in
docstrings consistently and be compatible with Texinfo 6.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Thu, 09 Jul 2015 21:44:09 -0400 |
parents | b0f7ee81d974 |
children | 421e3ebfca8d |
rev | line source |
---|---|
1 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19600
diff
changeset
|
3 Copyright (C) 1993-2015 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" |
19461
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19344
diff
changeset
|
48 #include "oct-locbuf.h" |
3040 | 49 #include "pathsearch.h" |
19461
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19344
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) |
19330
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
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 | |
19007
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\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
298 \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
|
299 If no file is found, return an empty character string.\n\ |
4216 | 300 \n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
301 If the first argument is a cell array of strings, search each directory of\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
302 the loadpath for element of the cell array and return the first that\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
303 matches.\n\ |
4243 | 304 \n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
305 If the second optional argument @qcode{\"all\"} is supplied, return a cell\n\ |
20391
aa36fb998a4d
maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents:
20382
diff
changeset
|
306 array containing the list of all files that have the same name in the path.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
307 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
|
308 @seealso{file_in_path, dir_in_loadpath, path}\n\ |
5642 | 309 @end deftypefn") |
3195 | 310 { |
4216 | 311 octave_value retval; |
3195 | 312 |
4243 | 313 int nargin = args.length (); |
3195 | 314 |
4243 | 315 if (nargin == 1 || nargin == 2) |
4216 | 316 { |
4243 | 317 string_vector names = args(0).all_strings (); |
318 | |
319 if (! error_state && names.length () > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
320 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
321 if (nargin == 1) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
322 retval = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
323 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
|
324 else if (nargin == 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
325 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
326 std::string opt = args(1).string_value (); |
4243 | 327 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
328 if (! error_state && opt == "all") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
329 retval = Cell (make_absolute |
10250 | 330 (load_path::find_all_first_of (names))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
331 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
332 error ("file_in_loadpath: invalid option"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
333 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
334 } |
4216 | 335 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
336 error ("file_in_loadpath: FILE argument must be a string"); |
4216 | 337 } |
3195 | 338 else |
5823 | 339 print_usage (); |
3195 | 340 |
341 return retval; | |
342 } | |
343 | |
13094 | 344 /* |
345 %!test | |
346 %! f = file_in_loadpath ("plot.m"); | |
347 %! assert (ischar (f)); | |
348 %! assert (! isempty (f)); | |
349 | |
350 %!test | |
351 %! f = file_in_loadpath ("$$probably_!!_not_&&_a_!!_file$$"); | |
352 %! assert (f, ""); | |
353 | |
354 %!test | |
355 %! lst = file_in_loadpath ("$$probably_!!_not_&&_a_!!_file$$", "all"); | |
356 %! assert (lst, {}); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
357 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
358 %!error file_in_loadpath () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
359 %!error file_in_loadpath ("foo", "bar", 1) |
19330
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
360 %!error file_in_loadpath ([]) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
361 %!error file_in_loadpath ("plot.m", "bar") |
13094 | 362 */ |
363 | |
1957 | 364 DEFUN (file_in_path, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
365 "-*- texinfo -*-\n\ |
10840 | 366 @deftypefn {Built-in Function} {} file_in_path (@var{path}, @var{file})\n\ |
4216 | 367 @deftypefnx {Built-in Function} {} file_in_path (@var{path}, @var{file}, \"all\")\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
368 Return the absolute name of @var{file} if it can be found in @var{path}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
369 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
370 The value of @var{path} should be a colon-separated list of directories in\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
371 the format described for @code{path}. If no file is found, return an empty\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
372 character string. For example:\n\ |
3301 | 373 \n\ |
374 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8929
diff
changeset
|
375 @group\n\ |
5456 | 376 file_in_path (EXEC_PATH, \"sh\")\n\ |
377 @result{} \"/bin/sh\"\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8929
diff
changeset
|
378 @end group\n\ |
3301 | 379 @end example\n\ |
4216 | 380 \n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
381 If the second argument is a cell array of strings, search each directory of\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
382 the path for element of the cell array and return the first that matches.\n\ |
4243 | 383 \n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
384 If the third optional argument @qcode{\"all\"} is supplied, return a cell\n\ |
20391
aa36fb998a4d
maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents:
20382
diff
changeset
|
385 array containing the list of all files that have the same name in the path.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
386 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
|
387 @seealso{file_in_loadpath, dir_in_loadpath, path}\n\ |
3301 | 388 @end deftypefn") |
686 | 389 { |
4216 | 390 octave_value retval; |
686 | 391 |
4243 | 392 int nargin = args.length (); |
1755 | 393 |
4243 | 394 if (nargin == 2 || nargin == 3) |
686 | 395 { |
19600
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19461
diff
changeset
|
396 if (args(0).is_string ()) |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19461
diff
changeset
|
397 { |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19461
diff
changeset
|
398 std::string path = args(0).string_value (); |
4243 | 399 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
400 string_vector names = args(1).all_strings (); |
4243 | 401 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
402 if (! error_state && names.length () > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
403 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
404 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
|
405 retval = search_path_for_file (path, names); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
406 else if (nargin == 3) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
407 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
408 std::string opt = args(2).string_value (); |
4243 | 409 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
410 if (! error_state && opt == "all") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
411 retval = Cell (make_absolute |
10250 | 412 (search_path_for_all_files (path, names))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
413 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
414 error ("file_in_path: invalid option"); |
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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
417 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
418 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
|
419 } |
1755 | 420 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
421 error ("file_in_path: PATH must be a string"); |
686 | 422 } |
423 else | |
5823 | 424 print_usage (); |
686 | 425 |
426 return retval; | |
427 } | |
428 | |
13094 | 429 /* |
430 %!test | |
431 %! f = file_in_path (path (), "plot.m"); | |
432 %! assert (ischar (f)); | |
433 %! assert (! isempty (f)); | |
434 | |
435 %!test | |
436 %! f = file_in_path (path (), "$$probably_!!_not_&&_a_!!_file$$"); | |
437 %! assert (f, ""); | |
438 | |
439 %!test | |
440 %! lst = file_in_path (path (), "$$probably_!!_not_&&_a_!!_file$$", "all"); | |
441 %! assert (lst, {}); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
442 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
443 %!error file_in_path () |
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") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
445 %!error file_in_path ("foo", "bar", "baz", 1) |
19330
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
446 %!error file_in_path ([]) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
447 %!error file_in_path (path (), []) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
448 %!error file_in_path (path (), "plot.m", "bar") |
13094 | 449 */ |
450 | |
3536 | 451 std::string |
3523 | 452 file_in_path (const std::string& name, const std::string& suffix) |
526 | 453 { |
3523 | 454 std::string nm = name; |
526 | 455 |
1755 | 456 if (! suffix.empty ()) |
457 nm.append (suffix); | |
686 | 458 |
10250 | 459 return octave_env::make_absolute (load_path::find_file (nm)); |
526 | 460 } |
461 | |
19222
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
462 std::string |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
463 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:
19007
diff
changeset
|
464 const std::string& file, |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
465 bool require_regular_file) |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
466 { |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
467 std::string fname = file; |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
468 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
469 if (! (octave_env::absolute_pathname (fname) |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
470 || octave_env::rooted_relative_pathname (fname))) |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
471 { |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
472 // 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:
19007
diff
changeset
|
473 // 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:
19007
diff
changeset
|
474 // so do an explicit check for that. |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
475 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
476 file_stat fs (fname); |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
477 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
478 bool local_file_ok |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
479 = fs.exists () && (fs.is_reg () || ! require_regular_file); |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
480 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
481 if (! local_file_ok) |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
482 { |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
483 // Not directly found; search load path. |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
484 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
485 std::string tmp |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
486 = octave_env::make_absolute (load_path::find_file (fname)); |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
487 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
488 if (! tmp.empty ()) |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
489 { |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
490 gripe_data_file_in_path (fcn, tmp); |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
491 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
492 fname = tmp; |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
493 } |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
494 } |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
495 } |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
496 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
497 return fname; |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
498 } |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
19007
diff
changeset
|
499 |
581 | 500 // See if there is an function file in the path. If so, return the |
501 // full path to the file. | |
502 | |
3536 | 503 std::string |
3523 | 504 fcn_file_in_path (const std::string& name) |
526 | 505 { |
3523 | 506 std::string retval; |
908 | 507 |
1755 | 508 int len = name.length (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
509 |
1755 | 510 if (len > 0) |
511 { | |
5832 | 512 if (octave_env::absolute_pathname (name)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
513 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
514 file_stat fs (name); |
5832 | 515 |
17955
9fc0836cb69b
Fix "get_help_text('\')" in Windows.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17818
diff
changeset
|
516 if (fs.exists () && ! fs.is_dir ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
517 retval = name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
518 } |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
14819
diff
changeset
|
519 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
|
520 retval = load_path::find_fcn_file (name.substr (0, len-2)); |
908 | 521 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
522 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
523 std::string fname = name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
524 size_t pos = name.find_first_of (Vfilemarker); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
525 if (pos != std::string::npos) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
526 fname = name.substr (0, pos); |
7818
5640a70cbab1
Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
527 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
528 retval = load_path::find_fcn_file (fname); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
529 } |
908 | 530 } |
1755 | 531 |
532 return retval; | |
526 | 533 } |
534 | |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
535 // 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
|
536 // 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
|
537 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
538 std::string |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
539 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
|
540 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
541 std::string retval; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
542 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
543 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
|
544 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
545 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
|
546 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
|
547 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
548 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
|
549 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
550 if (fs.exists ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
551 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
|
552 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
553 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
554 return retval; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
555 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
556 |
5864 | 557 // See if there is a .oct file in the path. If so, return the |
581 | 558 // full path to the file. |
559 | |
3536 | 560 std::string |
3523 | 561 oct_file_in_path (const std::string& name) |
572 | 562 { |
3523 | 563 std::string retval; |
908 | 564 |
1755 | 565 int len = name.length (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
566 |
1755 | 567 if (len > 0) |
568 { | |
5832 | 569 if (octave_env::absolute_pathname (name)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
570 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
571 file_stat fs (name); |
5832 | 572 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
573 if (fs.exists ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
574 retval = name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
575 } |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
14819
diff
changeset
|
576 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
|
577 && 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
|
578 retval = load_path::find_oct_file (name.substr (0, len-4)); |
908 | 579 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
580 retval = load_path::find_oct_file (name); |
908 | 581 } |
1755 | 582 |
583 return retval; | |
572 | 584 } |
585 | |
5864 | 586 // See if there is a .mex file in the path. If so, return the |
587 // full path to the file. | |
588 | |
589 std::string | |
590 mex_file_in_path (const std::string& name) | |
591 { | |
592 std::string retval; | |
593 | |
594 int len = name.length (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
595 |
5864 | 596 if (len > 0) |
597 { | |
598 if (octave_env::absolute_pathname (name)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
599 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
600 file_stat fs (name); |
5864 | 601 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
602 if (fs.exists ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
603 retval = name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
604 } |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
14819
diff
changeset
|
605 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
|
606 && 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
|
607 retval = load_path::find_mex_file (name.substr (0, len-4)); |
5864 | 608 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
609 retval = load_path::find_mex_file (name); |
5864 | 610 } |
611 | |
612 return retval; | |
613 } | |
614 | |
3103 | 615 // Replace backslash escapes in a string with the real values. |
616 | |
3536 | 617 std::string |
3523 | 618 do_string_escapes (const std::string& s) |
3103 | 619 { |
3523 | 620 std::string retval; |
3103 | 621 |
622 size_t i = 0; | |
623 size_t j = 0; | |
624 size_t len = s.length (); | |
625 | |
626 retval.resize (len); | |
627 | |
628 while (j < len) | |
629 { | |
630 if (s[j] == '\\' && j+1 < len) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
631 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
632 switch (s[++j]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
633 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
634 case '0': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
635 retval[i] = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
636 break; |
3893 | 637 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
638 case 'a': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
639 retval[i] = '\a'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
640 break; |
3103 | 641 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
642 case 'b': // backspace |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
643 retval[i] = '\b'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
644 break; |
3103 | 645 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
646 case 'f': // formfeed |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
647 retval[i] = '\f'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
648 break; |
3103 | 649 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
650 case 'n': // newline |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
651 retval[i] = '\n'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
652 break; |
3103 | 653 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
654 case 'r': // carriage return |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
655 retval[i] = '\r'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
656 break; |
3103 | 657 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
658 case 't': // horizontal tab |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
659 retval[i] = '\t'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
660 break; |
3103 | 661 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
662 case 'v': // vertical tab |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
663 retval[i] = '\v'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
664 break; |
3103 | 665 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
666 case '\\': // backslash |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
667 retval[i] = '\\'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
668 break; |
3103 | 669 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
670 case '\'': // quote |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
671 retval[i] = '\''; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
672 break; |
3103 | 673 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
674 case '"': // double quote |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
675 retval[i] = '"'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
676 break; |
3103 | 677 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
678 default: |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
679 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
|
680 converting to '%c'", s[j], s[j]); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
681 retval[i] = s[j]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
682 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
683 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
684 } |
3103 | 685 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
686 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
687 retval[i] = s[j]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
688 } |
3103 | 689 |
690 i++; | |
691 j++; | |
692 } | |
693 | |
3105 | 694 retval.resize (i); |
3103 | 695 |
696 return retval; | |
697 } | |
698 | |
699 DEFUN (do_string_escapes, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
700 "-*- texinfo -*-\n\ |
3446 | 701 @deftypefn {Built-in Function} {} do_string_escapes (@var{string})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
702 Convert escape sequences in @var{string} to the characters they represent.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
703 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
704 Escape sequences begin with a leading backslash\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
705 (@qcode{'@xbackslashchar{}'}) followed by 1--3 characters\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
706 (.e.g., @qcode{\"@xbackslashchar{}n\"} => newline).\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
707 @seealso{undo_string_escapes}\n\ |
3446 | 708 @end deftypefn") |
3103 | 709 { |
710 octave_value retval; | |
711 | |
712 int nargin = args.length (); | |
713 | |
714 if (nargin == 1) | |
715 { | |
716 if (args(0).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
717 retval = do_string_escapes (args(0).string_value ()); |
3103 | 718 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
719 error ("do_string_escapes: STRING argument must be of type string"); |
3103 | 720 } |
721 else | |
5823 | 722 print_usage (); |
3103 | 723 |
724 return retval; | |
725 } | |
726 | |
13094 | 727 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
728 %!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
|
729 %!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
|
730 %!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
|
731 %!assert ("foo\nbar", ["foo", char(10), "bar"]) |
13094 | 732 |
19330
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
733 %!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:
19320
diff
changeset
|
734 %!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:
19320
diff
changeset
|
735 %!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:
19320
diff
changeset
|
736 %! char ([0, 7, 8, 12, 10, 13, 9, 11])) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
737 %!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:
19320
diff
changeset
|
738 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
739 %!assert (do_string_escapes ('\\'), "\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
740 %!assert (do_string_escapes ("\\\\"), "\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
741 %!assert (do_string_escapes ("\\\\"), char (92)) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
742 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
743 %!assert (do_string_escapes ('\''single-quoted\'''), "'single-quoted'") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
744 %!assert (do_string_escapes ("\\'single-quoted\\'"), "'single-quoted'") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
745 %!assert (do_string_escapes ('\"double-quoted\"'), "\"double-quoted\"") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
746 %!assert (do_string_escapes ("\\\"double-quoted\\\""), "\"double-quoted\"") |
13094 | 747 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
748 %!error do_string_escapes () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
749 %!error do_string_escapes ("foo", "bar") |
19330
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
750 %!error do_string_escapes (3) |
13094 | 751 */ |
752 | |
1755 | 753 const char * |
801 | 754 undo_string_escape (char c) |
755 { | |
756 if (! c) | |
1755 | 757 return ""; |
801 | 758 |
759 switch (c) | |
760 { | |
3893 | 761 case '\0': |
762 return "\\0"; | |
763 | |
801 | 764 case '\a': |
765 return "\\a"; | |
766 | |
767 case '\b': // backspace | |
768 return "\\b"; | |
769 | |
770 case '\f': // formfeed | |
771 return "\\f"; | |
772 | |
773 case '\n': // newline | |
774 return "\\n"; | |
775 | |
776 case '\r': // carriage return | |
777 return "\\r"; | |
778 | |
779 case '\t': // horizontal tab | |
780 return "\\t"; | |
781 | |
782 case '\v': // vertical tab | |
783 return "\\v"; | |
784 | |
785 case '\\': // backslash | |
786 return "\\\\"; | |
787 | |
788 case '"': // double quote | |
789 return "\\\""; | |
790 | |
791 default: | |
1755 | 792 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
793 static char retval[2]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
794 retval[0] = c; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
795 retval[1] = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
796 return retval; |
1755 | 797 } |
801 | 798 } |
799 } | |
800 | |
3536 | 801 std::string |
3523 | 802 undo_string_escapes (const std::string& s) |
801 | 803 { |
3523 | 804 std::string retval; |
801 | 805 |
1755 | 806 for (size_t i = 0; i < s.length (); i++) |
807 retval.append (undo_string_escape (s[i])); | |
801 | 808 |
1755 | 809 return retval; |
801 | 810 } |
811 | |
1957 | 812 DEFUN (undo_string_escapes, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
813 "-*- texinfo -*-\n\ |
3361 | 814 @deftypefn {Built-in Function} {} undo_string_escapes (@var{s})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
815 Convert special characters in strings back to their escaped forms.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
816 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
817 For example, the expression\n\ |
3361 | 818 \n\ |
819 @example\n\ | |
820 bell = \"\\a\";\n\ | |
821 @end example\n\ | |
822 \n\ | |
823 @noindent\n\ | |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
824 assigns the value of the alert character (control-g, ASCII code 7) to the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
825 string variable @code{bell}. If this string is printed, the system will\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
826 ring the terminal bell (if it is possible). This is normally the desired\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
827 outcome. However, sometimes it is useful to be able to print the original\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
828 representation of the string, with the special characters replaced by their\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
829 escape sequences. For example,\n\ |
3361 | 830 \n\ |
831 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8929
diff
changeset
|
832 @group\n\ |
3361 | 833 octave:13> undo_string_escapes (bell)\n\ |
834 ans = \\a\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8929
diff
changeset
|
835 @end group\n\ |
3361 | 836 @end example\n\ |
837 \n\ | |
838 @noindent\n\ | |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
839 replaces the unprintable alert character with its printable representation.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
840 @seealso{do_string_escapes}\n\ |
3361 | 841 @end deftypefn") |
801 | 842 { |
2086 | 843 octave_value retval; |
801 | 844 |
845 int nargin = args.length (); | |
846 | |
3103 | 847 if (nargin == 1) |
848 { | |
849 if (args(0).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
850 retval = undo_string_escapes (args(0).string_value ()); |
3103 | 851 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
852 error ("undo_string_escapes: S argument must be a string"); |
3103 | 853 } |
801 | 854 else |
5823 | 855 print_usage (); |
801 | 856 |
857 return retval; | |
858 } | |
859 | |
13094 | 860 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
861 %!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
|
862 %!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
|
863 %!assert (undo_string_escapes (["foo", char(10), "bar"]), "foo\\nbar") |
13094 | 864 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
865 %!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
|
866 %!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
|
867 %!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
|
868 %! "\\a\\b\\f\\n\\r\\t\\v") |
13094 | 869 |
19330
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
870 %!assert (undo_string_escapes ("\\"), '\\') |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
871 %!assert (undo_string_escapes ("\\"), "\\\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
872 %!assert (undo_string_escapes (char (92)), "\\\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
873 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
874 %!assert (undo_string_escapes ("\"double-quoted\""), '\"double-quoted\"') |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
875 %!assert (undo_string_escapes ("\"double-quoted\""), "\\\"double-quoted\\\"") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
876 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
877 %!error undo_string_escapes () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
878 %!error undo_string_escapes ("foo", "bar") |
19330
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
879 %!error undo_string_escapes (3) |
13094 | 880 */ |
881 | |
8229 | 882 DEFUN (is_absolute_filename, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
883 "-*- texinfo -*-\n\ |
8229 | 884 @deftypefn {Built-in Function} {} is_absolute_filename (@var{file})\n\ |
885 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
|
886 @seealso{is_rooted_relative_filename, make_absolute_filename, isdir}\n\ |
8229 | 887 @end deftypefn") |
888 { | |
889 octave_value retval = false; | |
890 | |
891 if (args.length () == 1) | |
892 retval = (args(0).is_string () | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
893 && octave_env::absolute_pathname (args(0).string_value ())); |
8229 | 894 else |
895 print_usage (); | |
896 | |
897 return retval; | |
898 } | |
899 | |
13094 | 900 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
901 ## FIXME: We need system-dependent tests here. |
13094 | 902 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
903 %!error is_absolute_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
904 %!error is_absolute_filename ("foo", "bar") |
13094 | 905 */ |
906 | |
8229 | 907 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
|
908 "-*- texinfo -*-\n\ |
8229 | 909 @deftypefn {Built-in Function} {} is_rooted_relative_filename (@var{file})\n\ |
910 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
|
911 @seealso{is_absolute_filename, make_absolute_filename, isdir}\n\ |
8229 | 912 @end deftypefn") |
913 { | |
914 octave_value retval = false; | |
915 | |
916 if (args.length () == 1) | |
917 retval = (args(0).is_string () | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
918 && octave_env::rooted_relative_pathname (args(0).string_value ())); |
8229 | 919 else |
920 print_usage (); | |
921 | |
922 return retval; | |
923 } | |
924 | |
13094 | 925 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
926 ## FIXME: We need system-dependent tests here. |
13094 | 927 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
928 %!error is_rooted_relative_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
929 %!error is_rooted_relative_filename ("foo", "bar") |
13094 | 930 */ |
931 | |
8229 | 932 DEFUN (make_absolute_filename, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
933 "-*- texinfo -*-\n\ |
8229 | 934 @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
|
935 Return the full name of @var{file} beginning from the root of the file\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
936 system.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
937 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
938 No check is done for the existence of @var{file}.\n\ |
14819
67b6b47a22f6
doc: Clarify docstrings for canonicalize_file_name, make_absolute_filename
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
939 @seealso{canonicalize_file_name, is_absolute_filename, is_rooted_relative_filename, isdir}\n\ |
8229 | 940 @end deftypefn") |
941 { | |
942 octave_value retval = std::string (); | |
943 | |
944 if (args.length () == 1) | |
945 { | |
946 std::string nm = args(0).string_value (); | |
947 | |
948 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
949 retval = octave_env::make_absolute (nm); |
8229 | 950 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
951 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
|
952 } |
8229 | 953 else |
954 print_usage (); | |
955 | |
956 return retval; | |
957 } | |
958 | |
13094 | 959 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
960 ## FIXME: We need system-dependent tests here. |
13094 | 961 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
962 %!error make_absolute_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
963 %!error make_absolute_filename ("foo", "bar") |
13094 | 964 */ |
965 | |
18109
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18104
diff
changeset
|
966 DEFUN (dir_in_loadpath, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
967 "-*- 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
|
968 @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
|
969 @deftypefnx {Built-in Function} {} dir_in_loadpath (@var{dir}, \"all\")\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
970 Return the full name of the path element matching @var{dir}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
971 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
972 The 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
|
973 @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
|
974 @nospell{@qcode{\"/some/dir/foo/bar\"}}, but not\n\ |
17be601bc783
doc: Periodic spellchecking of documentation.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
975 @nospell{@qcode{\"/some/dir/foo/bar/baz\"}}\n\ |
17be601bc783
doc: Periodic spellchecking of documentation.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
976 @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
|
977 \n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
978 If the optional second argument is supplied, return a cell array containing\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
979 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
|
980 @seealso{file_in_path, file_in_loadpath, path}\n\ |
8229 | 981 @end deftypefn") |
982 { | |
983 octave_value retval = std::string (); | |
984 | |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
985 int nargin = args.length (); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
986 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
987 std::string dir; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
988 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
989 if (nargin == 1 || nargin == 2) |
8229 | 990 { |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
991 dir = args(0).string_value (); |
8229 | 992 |
993 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
994 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
995 if (nargin == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
996 retval = load_path::find_dir (dir); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
997 else if (nargin == 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
998 retval = Cell (load_path::find_matching_dirs (dir)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
999 } |
8229 | 1000 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
|
1001 error ("dir_in_loadpath: DIR must be a directory name"); |
8229 | 1002 } |
1003 else | |
1004 print_usage (); | |
1005 | |
1006 return retval; | |
1007 } | |
1008 | |
13094 | 1009 /* |
19330
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
1010 %!test |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
1011 %! f = dir_in_loadpath ("plot"); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
1012 %! assert (ischar (f)); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
1013 %! assert (! isempty (f)); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
1014 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
1015 %!test |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
1016 %! f = dir_in_loadpath ("$$probably_!!_not_&&_a_!!_dir$$"); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
1017 %! assert (f, ""); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
1018 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
1019 %!test |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
1020 %! lst = dir_in_loadpath ("$$probably_!!_not_&&_a_!!_dir$$", "all"); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
1021 %! assert (lst, {}); |
13094 | 1022 |
18109
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18104
diff
changeset
|
1023 %!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
|
1024 %!error dir_in_loadpath ("foo", "bar", 1) |
13094 | 1025 */ |
1026 | |
5465 | 1027 DEFUNX ("errno", Ferrno, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1028 "-*- texinfo -*-\n\ |
10840 | 1029 @deftypefn {Built-in Function} {@var{err} =} errno ()\n\ |
5465 | 1030 @deftypefnx {Built-in Function} {@var{err} =} errno (@var{val})\n\ |
1031 @deftypefnx {Built-in Function} {@var{err} =} errno (@var{name})\n\ | |
1032 Return the current value of the system-dependent variable errno,\n\ | |
1033 set its value to @var{val} and return the previous value, or return\n\ | |
1034 the named error code given @var{name} as a character string, or -1\n\ | |
1035 if @var{name} is not found.\n\ | |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
1036 @seealso{errno_list}\n\ |
3716 | 1037 @end deftypefn") |
1038 { | |
1039 octave_value retval; | |
1040 | |
5465 | 1041 int nargin = args.length (); |
1042 | |
1043 if (nargin == 1) | |
1044 { | |
1045 if (args(0).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1046 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1047 std::string nm = args(0).string_value (); |
5465 | 1048 |
19948
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
1049 retval = octave_errno::lookup (nm); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1050 } |
5465 | 1051 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1052 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1053 int val = args(0).int_value (); |
5465 | 1054 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1055 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1056 retval = octave_errno::set (val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1057 else |
19948
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
1058 error ("errno: argument must be string or integer"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1059 } |
5465 | 1060 } |
1061 else if (nargin == 0) | |
1062 retval = octave_errno::get (); | |
3716 | 1063 else |
5823 | 1064 print_usage (); |
3716 | 1065 |
1066 return retval; | |
1067 } | |
1068 | |
13094 | 1069 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1070 %!assert (isnumeric (errno ())) |
13094 | 1071 |
1072 %!test | |
1073 %! lst = errno_list (); | |
1074 %! fns = fieldnames (lst); | |
1075 %! oldval = errno (fns{1}); | |
1076 %! assert (isnumeric (oldval)); | |
1077 %! errno (oldval); | |
1078 %! newval = errno (); | |
1079 %! assert (oldval, newval); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1080 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1081 %!error errno ("foo", 1) |
13094 | 1082 */ |
1083 | |
5465 | 1084 DEFUN (errno_list, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1085 "-*- texinfo -*-\n\ |
5465 | 1086 @deftypefn {Built-in Function} {} errno_list ()\n\ |
1087 Return a structure containing the system-dependent errno values.\n\ | |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
1088 @seealso{errno}\n\ |
5465 | 1089 @end deftypefn") |
1090 { | |
1091 octave_value retval; | |
1092 | |
1093 if (args.length () == 0) | |
1094 retval = octave_errno::list (); | |
1095 else | |
5823 | 1096 print_usage (); |
5465 | 1097 |
1098 return retval; | |
1099 } | |
3716 | 1100 |
13094 | 1101 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1102 %!assert (isstruct (errno_list ())) |
13094 | 1103 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1104 %!error errno_list ("foo") |
13094 | 1105 */ |
1106 | |
2285 | 1107 static void |
5275 | 1108 check_dimensions (octave_idx_type& nr, octave_idx_type& nc, const char *warnfor) |
3354 | 1109 { |
1110 if (nr < 0 || nc < 0) | |
1111 { | |
5781 | 1112 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
|
1113 "%s: converting negative dimension to zero", warnfor); |
3354 | 1114 |
4457 | 1115 nr = (nr < 0) ? 0 : nr; |
1116 nc = (nc < 0) ? 0 : nc; | |
3354 | 1117 } |
1118 } | |
1119 | |
1120 void | |
4513 | 1121 check_dimensions (dim_vector& dim, const char *warnfor) |
4481 | 1122 { |
1123 bool neg = false; | |
1124 | |
1125 for (int i = 0; i < dim.length (); i++) | |
1126 { | |
1127 if (dim(i) < 0) | |
1128 { | |
1129 dim(i) = 0; | |
1130 neg = true; | |
1131 } | |
1132 } | |
1133 | |
5781 | 1134 if (neg) |
1135 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
|
1136 "%s: converting negative dimension to zero", warnfor); |
4481 | 1137 } |
1138 | |
1139 | |
1140 void | |
1141 get_dimensions (const octave_value& a, const char *warn_for, | |
4513 | 1142 dim_vector& dim) |
4481 | 1143 { |
1144 if (a.is_scalar_type ()) | |
1145 { | |
1146 dim.resize (2); | |
4732 | 1147 dim(0) = a.int_value (); |
4481 | 1148 dim(1) = dim(0); |
1149 } | |
1150 else | |
1151 { | |
5275 | 1152 octave_idx_type nr = a.rows (); |
1153 octave_idx_type nc = a.columns (); | |
4481 | 1154 |
1155 if (nr == 1 || nc == 1) | |
1156 { | |
1157 Array<double> v = a.vector_value (); | |
1158 | |
1159 if (error_state) | |
1160 return; | |
1161 | |
5275 | 1162 octave_idx_type n = v.length (); |
4481 | 1163 dim.resize (n); |
5275 | 1164 for (octave_idx_type i = 0; i < n; i++) |
4783 | 1165 dim(i) = static_cast<int> (fix (v(i))); |
4481 | 1166 } |
1167 else | |
5257 | 1168 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); |
4481 | 1169 } |
1170 | |
5258 | 1171 if (! error_state) |
1172 check_dimensions (dim, warn_for); // May set error_state. | |
4481 | 1173 } |
1174 | |
1175 | |
1176 void | |
3354 | 1177 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
|
1178 octave_idx_type& nr, octave_idx_type& nc) |
3354 | 1179 { |
1180 if (a.is_scalar_type ()) | |
1181 { | |
4732 | 1182 nr = nc = a.int_value (); |
3354 | 1183 } |
1184 else | |
1185 { | |
1186 nr = a.rows (); | |
1187 nc = a.columns (); | |
1188 | |
1189 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
|
1190 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1191 Array<double> v = a.vector_value (); |
3354 | 1192 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1193 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1194 return; |
3354 | 1195 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1196 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
|
1197 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
|
1198 } |
3354 | 1199 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1200 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); |
3354 | 1201 } |
1202 | |
5258 | 1203 if (! error_state) |
1204 check_dimensions (nr, nc, warn_for); // May set error_state. | |
3354 | 1205 } |
1206 | |
1207 void | |
1208 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
|
1209 const char *warn_for, octave_idx_type& nr, octave_idx_type& nc) |
3354 | 1210 { |
4732 | 1211 nr = a.is_empty () ? 0 : a.int_value (); |
1212 nc = b.is_empty () ? 0 : b.int_value (); | |
3354 | 1213 |
1214 if (error_state) | |
1215 error ("%s: expecting two scalar arguments", warn_for); | |
1216 else | |
1217 check_dimensions (nr, nc, warn_for); // May set error_state. | |
1218 } | |
1219 | |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1220 octave_idx_type |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1221 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
|
1222 { |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1223 octave_idx_type retval; |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1224 |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1225 octave_idx_type len = idx.length (); |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1226 |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1227 if (len == 0) |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1228 retval = dims.numel (); |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1229 else |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1230 { |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1231 const dim_vector dv = dims.redim (len); |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1232 retval = 1; |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1233 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
|
1234 { |
9842
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1235 octave_value idxi = idx(i); |
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1236 if (idxi.is_magic_colon ()) |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1237 retval *= dv(i); |
9842
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1238 else if (idxi.is_numeric_type ()) |
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1239 retval *= idxi.numel (); |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1240 else |
9842
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1241 { |
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1242 idx_vector jdx = idxi.index_vector (); |
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1243 if (error_state) |
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1244 break; |
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1245 retval *= jdx.length (dv(i)); |
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1246 } |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1247 } |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1248 } |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1249 |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1250 return retval; |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1251 } |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1252 |
4478 | 1253 Matrix |
5275 | 1254 identity_matrix (octave_idx_type nr, octave_idx_type nc) |
4478 | 1255 { |
1256 Matrix m (nr, nc, 0.0); | |
1257 | |
1258 if (nr > 0 && nc > 0) | |
1259 { | |
5275 | 1260 octave_idx_type n = std::min (nr, nc); |
4478 | 1261 |
5275 | 1262 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
|
1263 m (i, i) = 1.0; |
4478 | 1264 } |
1265 | |
1266 return m; | |
1267 } | |
1268 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1269 FloatMatrix |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1270 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
|
1271 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1272 FloatMatrix m (nr, nc, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1273 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1274 if (nr > 0 && nc > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1275 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1276 octave_idx_type n = std::min (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1277 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1278 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
|
1279 m (i, i) = 1.0; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1280 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1281 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1282 return m; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1283 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1284 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1285 size_t |
3622 | 1286 octave_format (std::ostream& os, const char *fmt, ...) |
3620 | 1287 { |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1288 size_t retval; |
3620 | 1289 |
1290 va_list args; | |
1291 va_start (args, fmt); | |
1292 | |
1293 retval = octave_vformat (os, fmt, args); | |
1294 | |
1295 va_end (args); | |
1296 | |
1297 return retval; | |
1298 } | |
1299 | |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1300 size_t |
3622 | 1301 octave_vformat (std::ostream& os, const char *fmt, va_list args) |
3620 | 1302 { |
14005
f8556baf1949
rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents:
13991
diff
changeset
|
1303 std::string s = octave_vasprintf (fmt, args); |
3620 | 1304 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1305 os << s; |
3620 | 1306 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1307 return s.length (); |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1308 } |
4135 | 1309 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1310 std::string |
14005
f8556baf1949
rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents:
13991
diff
changeset
|
1311 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
|
1312 { |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1313 std::string retval; |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1314 |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1315 char *result; |
4302 | 1316 |
14005
f8556baf1949
rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents:
13991
diff
changeset
|
1317 int status = gnulib::vasprintf (&result, fmt, args); |
4302 | 1318 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1319 if (status >= 0) |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1320 { |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1321 retval = result; |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1322 ::free (result); |
4302 | 1323 } |
3620 | 1324 |
1325 return retval; | |
1326 } | |
1327 | |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1328 std::string |
14005
f8556baf1949
rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents:
13991
diff
changeset
|
1329 octave_asprintf (const char *fmt, ...) |
4302 | 1330 { |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1331 std::string retval; |
4302 | 1332 |
1333 va_list args; | |
1334 va_start (args, fmt); | |
1335 | |
14005
f8556baf1949
rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents:
13991
diff
changeset
|
1336 retval = octave_vasprintf (fmt, args); |
4302 | 1337 |
1338 va_end (args); | |
1339 | |
1340 return retval; | |
1341 } | |
1342 | |
4086 | 1343 void |
1344 octave_sleep (double seconds) | |
1345 { | |
1346 if (seconds > 0) | |
1347 { | |
1348 double t; | |
1349 | |
4093 | 1350 unsigned int usec |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1351 = static_cast<unsigned int> (modf (seconds, &t) * 1000000); |
4086 | 1352 |
4093 | 1353 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
|
1354 = ((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
|
1355 ? 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
|
1356 : static_cast<unsigned int> (t)); |
4086 | 1357 |
5770 | 1358 // Versions of these functions that accept unsigned int args are |
1359 // defined in cutils.c. | |
4086 | 1360 octave_sleep (sec); |
1361 octave_usleep (usec); | |
10070
897e62651c0a
correctly handle interrupts in pause()
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
1362 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10086
diff
changeset
|
1363 octave_quit (); |
4086 | 1364 } |
1365 } | |
1366 | |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1367 DEFUN (isindex, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1368 "-*- texinfo -*-\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11066
diff
changeset
|
1369 @deftypefn {Built-in Function} {} isindex (@var{ind})\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11066
diff
changeset
|
1370 @deftypefnx {Built-in Function} {} isindex (@var{ind}, @var{n})\n\ |
20294
4d0c7fec0a31
doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents:
19948
diff
changeset
|
1371 Return true if @var{ind} is a valid index.\n\ |
4d0c7fec0a31
doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents:
19948
diff
changeset
|
1372 \n\ |
4d0c7fec0a31
doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents:
19948
diff
changeset
|
1373 Valid indices are either positive integers (although possibly of real data\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
1374 type), or logical arrays.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
1375 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
1376 If present, @var{n} specifies the maximum extent of the dimension to be\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
1377 indexed. When possible the internal result is cached so that subsequent\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20311
diff
changeset
|
1378 indexing using @var{ind} will not perform the check again.\n\ |
20294
4d0c7fec0a31
doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents:
19948
diff
changeset
|
1379 \n\ |
4d0c7fec0a31
doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents:
19948
diff
changeset
|
1380 Implementation Note: Strings are first converted to double values before the\n\ |
4d0c7fec0a31
doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents:
19948
diff
changeset
|
1381 checks for valid indices are made. Unless a string contains the NULL\n\ |
20527
2ec049e50ed8
doc: Fix backslash characters in docstrings
Mike Miller <mtmiller@octave.org>
parents:
20404
diff
changeset
|
1382 character @nospell{\"@xbackslashchar{}0\"}, it will always be a valid index.\n\ |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1383 @end deftypefn") |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1384 { |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1385 octave_value retval; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1386 int nargin = args.length (); |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1387 octave_idx_type n = 0; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1388 |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1389 if (nargin == 2) |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1390 n = args(1).idx_type_value (); |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1391 else if (nargin != 1) |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1392 print_usage (); |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1393 |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1394 if (! error_state) |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1395 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10033
diff
changeset
|
1396 unwind_protect frame; |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10502
diff
changeset
|
1397 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10033
diff
changeset
|
1398 frame.protect_var (error_state); |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10502
diff
changeset
|
1399 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10033
diff
changeset
|
1400 frame.protect_var (discard_error_messages); |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1401 discard_error_messages = true; |
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 try |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1404 { |
18129
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
18104
diff
changeset
|
1405 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
|
1406 |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1407 if (! error_state) |
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 if (nargin == 2) |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1410 retval = idx.extent (n) <= n; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1411 else |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1412 retval = true; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1413 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1414 else |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1415 retval = false; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1416 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1417 catch (octave_execution_exception) |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1418 { |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1419 retval = false; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1420 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1421 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1422 |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1423 return retval; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1424 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1425 |
13094 | 1426 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1427 %!assert (isindex ([1, 2, 3])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1428 %!assert (isindex (1:3)) |
19330
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
1429 %!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
|
1430 %!assert (isindex ([1, 2, -3]), false) |
13094 | 1431 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1432 %!error isindex () |
19330
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19320
diff
changeset
|
1433 %!error isindex (1:3, 2, 3) |
13094 | 1434 */ |
1435 | |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1436 octave_value_list |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1437 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
|
1438 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
|
1439 int nargout) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1440 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1441 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
|
1442 int nargin = args.length (); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1443 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
|
1444 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
|
1445 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
|
1446 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1447 const Cell *ccells = cells; |
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 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
|
1450 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
|
1451 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1452 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
|
1453 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1454 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
|
1455 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
|
1456 if (iscell[i]) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1457 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1458 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
|
1459 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
|
1460 if (n == 1) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1461 { |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1462 iscell[i] = false; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1463 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
|
1464 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1465 else if (numel == 1) |
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 numel = n; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1468 dims = ccells[i].dims (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1469 } |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1470 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
|
1471 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1472 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
|
1473 break; |
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 } |
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 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1478 if (! error_state) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1479 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1480 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
|
1481 rcells[i].clear (dims); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1482 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1483 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
|
1484 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1485 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
|
1486 if (iscell[i]) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1487 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
|
1488 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10086
diff
changeset
|
1489 octave_quit (); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1490 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1491 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
|
1492 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1493 if (tmp.length () < nargout) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1494 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1495 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
|
1496 break; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1497 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1498 else |
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 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
|
1501 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
|
1502 } |
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 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1505 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1506 if (! error_state) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1507 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1508 retval.resize (nargout); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1509 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
|
1510 retval(i) = rcells[i]; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1511 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1512 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1513 return retval; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1514 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1515 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1516 octave_value |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1517 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
|
1518 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
|
1519 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1520 octave_value retval; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1521 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
|
1522 if (tmp.length () > 0) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1523 retval = tmp(0); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1524 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1525 return retval; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1526 } |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1527 |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1528 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
|
1529 { |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1530 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
|
1531 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
|
1532 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
|
1533 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
|
1534 } |
19320
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19222
diff
changeset
|
1535 |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19222
diff
changeset
|
1536 DEFUN (isstudent, args, , |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19222
diff
changeset
|
1537 "-*- texinfo -*-\n\ |
19344
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19330
diff
changeset
|
1538 @deftypefn {Built-in Function} {} isstudent ()\n\ |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19330
diff
changeset
|
1539 Return true if running in the student edition of @sc{matlab}.\n\ |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19330
diff
changeset
|
1540 \n\ |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19330
diff
changeset
|
1541 @code{isstudent} always returns false in Octave.\n\ |
19320
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19222
diff
changeset
|
1542 @seealso{false}\n\ |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19222
diff
changeset
|
1543 @end deftypefn") |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19222
diff
changeset
|
1544 { |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19222
diff
changeset
|
1545 if (args.length () != 0) |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19222
diff
changeset
|
1546 print_usage (); |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19222
diff
changeset
|
1547 |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19222
diff
changeset
|
1548 return octave_value (false); |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19222
diff
changeset
|
1549 } |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19222
diff
changeset
|
1550 |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19222
diff
changeset
|
1551 /* |
19344
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19330
diff
changeset
|
1552 %!assert (isstudent (), false) |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19330
diff
changeset
|
1553 |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19330
diff
changeset
|
1554 %!error isstudent (1) |
19320
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19222
diff
changeset
|
1555 */ |