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