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