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