Mercurial > hg > octave-lyh
annotate src/utils.cc @ 8229:1bf51192fa1d
imported patch rundemos
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 16 Oct 2008 13:28:43 -0400 |
parents | a14bdf90be55 |
children | 954b6f69f51d |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
4 2002, 2003, 2004, 2005, 2006, 2007 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 | |
4264 | 93 DEFCMD (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\ | |
5456 | 345 file_in_path (EXEC_PATH, \"sh\")\n\ |
346 @result{} \"/bin/sh\"\n\ | |
3301 | 347 @end example\n\ |
4216 | 348 \n\ |
5448 | 349 If the second argument is a cell array of strings, search each\n\ |
4243 | 350 directory of the path for element of the cell array and return\n\ |
351 the first that matches.\n\ | |
352 \n\ | |
4216 | 353 If the third optional argument @code{\"all\"} is supplied, return\n\ |
354 a cell array containing the list of all files that have the same\n\ | |
355 name in the path. If no files are found, return an empty cell array.\n\ | |
4249 | 356 @seealso{file_in_loadpath}\n\ |
3301 | 357 @end deftypefn") |
686 | 358 { |
4216 | 359 octave_value retval; |
686 | 360 |
4243 | 361 int nargin = args.length (); |
1755 | 362 |
4243 | 363 if (nargin == 2 || nargin == 3) |
686 | 364 { |
4243 | 365 std::string path = args(0).string_value (); |
366 | |
367 if (! error_state) | |
368 { | |
4249 | 369 string_vector names = args(1).all_strings (); |
4243 | 370 |
371 if (! error_state && names.length () > 0) | |
372 { | |
373 if (nargin == 2) | |
374 { | |
375 std::string fname = search_path_for_file (path, names); | |
686 | 376 |
4243 | 377 if (fname.empty ()) |
378 retval = Matrix (); | |
379 else | |
380 retval = fname; | |
381 } | |
382 else if (nargin == 3) | |
383 { | |
4249 | 384 std::string opt = args(2).string_value (); |
4243 | 385 |
386 if (! error_state && opt == "all") | |
387 retval = Cell (make_absolute (search_path_for_all_files (path, names))); | |
388 else | |
4249 | 389 error ("file_in_path: invalid option"); |
4243 | 390 } |
391 } | |
392 else | |
393 error ("file_in_path: expecting string as second argument"); | |
394 } | |
1755 | 395 else |
4243 | 396 error ("file_in_path: expecting string as first argument"); |
686 | 397 } |
398 else | |
5823 | 399 print_usage (); |
686 | 400 |
401 return retval; | |
402 } | |
403 | |
3536 | 404 std::string |
3523 | 405 file_in_path (const std::string& name, const std::string& suffix) |
526 | 406 { |
3523 | 407 std::string nm = name; |
526 | 408 |
1755 | 409 if (! suffix.empty ()) |
410 nm.append (suffix); | |
686 | 411 |
5832 | 412 return octave_env::make_absolute |
413 (load_path::find_file (nm), octave_env::getcwd ()); | |
526 | 414 } |
415 | |
581 | 416 // See if there is an function file in the path. If so, return the |
417 // full path to the file. | |
418 | |
3536 | 419 std::string |
3523 | 420 fcn_file_in_path (const std::string& name) |
526 | 421 { |
3523 | 422 std::string retval; |
908 | 423 |
1755 | 424 int len = name.length (); |
425 | |
426 if (len > 0) | |
427 { | |
5832 | 428 if (octave_env::absolute_pathname (name)) |
429 { | |
430 file_stat fs (name); | |
431 | |
432 if (fs.exists ()) | |
433 retval = name; | |
434 } | |
435 else if (len > 2 && name [len - 2] == '.' && name [len - 1] == 'm') | |
436 retval = load_path::find_fcn_file (name.substr (0, len-2)); | |
908 | 437 else |
7818
5640a70cbab1
Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
438 { |
5640a70cbab1
Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
439 std::string fname = name; |
5640a70cbab1
Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
440 size_t pos = name.find_first_of (Vfilemarker); |
8021 | 441 if (pos != std::string::npos) |
7818
5640a70cbab1
Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
442 fname = name.substr (0, pos); |
5640a70cbab1
Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
443 |
5640a70cbab1
Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
444 retval = load_path::find_fcn_file (fname); |
5640a70cbab1
Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
445 } |
908 | 446 } |
1755 | 447 |
448 return retval; | |
526 | 449 } |
450 | |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
451 // 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
|
452 // 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
|
453 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
454 std::string |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
455 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
|
456 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
457 std::string retval; |
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 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
|
460 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
461 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
|
462 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
|
463 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
464 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
|
465 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
466 if (fs.exists ()) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
467 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
|
468 } |
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 return retval; |
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 |
5864 | 473 // See if there is a .oct file in the path. If so, return the |
581 | 474 // full path to the file. |
475 | |
3536 | 476 std::string |
3523 | 477 oct_file_in_path (const std::string& name) |
572 | 478 { |
3523 | 479 std::string retval; |
908 | 480 |
1755 | 481 int len = name.length (); |
482 | |
483 if (len > 0) | |
484 { | |
5832 | 485 if (octave_env::absolute_pathname (name)) |
486 { | |
487 file_stat fs (name); | |
488 | |
489 if (fs.exists ()) | |
490 retval = name; | |
491 } | |
492 else if (len > 4 && name [len - 4] == '.' && name [len - 3] == 'o' | |
493 && name [len - 2] == 'c' && name [len - 1] == 't') | |
494 retval = load_path::find_oct_file (name.substr (0, len-4)); | |
908 | 495 else |
5832 | 496 retval = load_path::find_oct_file (name); |
908 | 497 } |
1755 | 498 |
499 return retval; | |
572 | 500 } |
501 | |
5864 | 502 // See if there is a .mex file in the path. If so, return the |
503 // full path to the file. | |
504 | |
505 std::string | |
506 mex_file_in_path (const std::string& name) | |
507 { | |
508 std::string retval; | |
509 | |
510 int len = name.length (); | |
511 | |
512 if (len > 0) | |
513 { | |
514 if (octave_env::absolute_pathname (name)) | |
515 { | |
516 file_stat fs (name); | |
517 | |
518 if (fs.exists ()) | |
519 retval = name; | |
520 } | |
521 else if (len > 4 && name [len - 4] == '.' && name [len - 3] == 'm' | |
522 && name [len - 2] == 'e' && name [len - 1] == 'x') | |
523 retval = load_path::find_mex_file (name.substr (0, len-4)); | |
524 else | |
525 retval = load_path::find_mex_file (name); | |
526 } | |
527 | |
528 return retval; | |
529 } | |
530 | |
3103 | 531 // Replace backslash escapes in a string with the real values. |
532 | |
3536 | 533 std::string |
3523 | 534 do_string_escapes (const std::string& s) |
3103 | 535 { |
3523 | 536 std::string retval; |
3103 | 537 |
538 size_t i = 0; | |
539 size_t j = 0; | |
540 size_t len = s.length (); | |
541 | |
542 retval.resize (len); | |
543 | |
544 while (j < len) | |
545 { | |
546 if (s[j] == '\\' && j+1 < len) | |
547 { | |
548 switch (s[++j]) | |
549 { | |
3893 | 550 case '0': |
551 retval[i] = '\0'; | |
552 break; | |
553 | |
3103 | 554 case 'a': |
555 retval[i] = '\a'; | |
556 break; | |
557 | |
558 case 'b': // backspace | |
559 retval[i] = '\b'; | |
560 break; | |
561 | |
562 case 'f': // formfeed | |
563 retval[i] = '\f'; | |
564 break; | |
565 | |
566 case 'n': // newline | |
567 retval[i] = '\n'; | |
568 break; | |
569 | |
570 case 'r': // carriage return | |
571 retval[i] = '\r'; | |
572 break; | |
573 | |
574 case 't': // horizontal tab | |
575 retval[i] = '\t'; | |
576 break; | |
577 | |
578 case 'v': // vertical tab | |
579 retval[i] = '\v'; | |
580 break; | |
581 | |
582 case '\\': // backslash | |
583 retval[i] = '\\'; | |
584 break; | |
585 | |
586 case '\'': // quote | |
587 retval[i] = '\''; | |
588 break; | |
589 | |
590 case '"': // double quote | |
591 retval[i] = '"'; | |
592 break; | |
593 | |
594 default: | |
595 warning ("unrecognized escape sequence `\\%c' --\ | |
596 converting to `%c'", s[j], s[j]); | |
597 retval[i] = s[j]; | |
598 break; | |
599 } | |
600 } | |
601 else | |
602 { | |
603 retval[i] = s[j]; | |
604 } | |
605 | |
606 i++; | |
607 j++; | |
608 } | |
609 | |
3105 | 610 retval.resize (i); |
3103 | 611 |
612 return retval; | |
613 } | |
614 | |
615 DEFUN (do_string_escapes, args, , | |
3446 | 616 "-*- texinfo -*-\n\ |
617 @deftypefn {Built-in Function} {} do_string_escapes (@var{string})\n\ | |
618 Convert special characters in @var{string} to their escaped forms.\n\ | |
619 @end deftypefn") | |
3103 | 620 { |
621 octave_value retval; | |
622 | |
623 int nargin = args.length (); | |
624 | |
625 if (nargin == 1) | |
626 { | |
627 if (args(0).is_string ()) | |
628 retval = do_string_escapes (args(0).string_value ()); | |
629 else | |
630 error ("do_string_escapes: argument must be a string"); | |
631 } | |
632 else | |
5823 | 633 print_usage (); |
3103 | 634 |
635 return retval; | |
636 } | |
637 | |
1755 | 638 const char * |
801 | 639 undo_string_escape (char c) |
640 { | |
641 if (! c) | |
1755 | 642 return ""; |
801 | 643 |
644 switch (c) | |
645 { | |
3893 | 646 case '\0': |
647 return "\\0"; | |
648 | |
801 | 649 case '\a': |
650 return "\\a"; | |
651 | |
652 case '\b': // backspace | |
653 return "\\b"; | |
654 | |
655 case '\f': // formfeed | |
656 return "\\f"; | |
657 | |
658 case '\n': // newline | |
659 return "\\n"; | |
660 | |
661 case '\r': // carriage return | |
662 return "\\r"; | |
663 | |
664 case '\t': // horizontal tab | |
665 return "\\t"; | |
666 | |
667 case '\v': // vertical tab | |
668 return "\\v"; | |
669 | |
670 case '\\': // backslash | |
671 return "\\\\"; | |
672 | |
673 case '"': // double quote | |
674 return "\\\""; | |
675 | |
676 default: | |
1755 | 677 { |
678 static char retval[2]; | |
679 retval[0] = c; | |
680 retval[1] = '\0'; | |
681 return retval; | |
682 } | |
801 | 683 } |
684 } | |
685 | |
3536 | 686 std::string |
3523 | 687 undo_string_escapes (const std::string& s) |
801 | 688 { |
3523 | 689 std::string retval; |
801 | 690 |
1755 | 691 for (size_t i = 0; i < s.length (); i++) |
692 retval.append (undo_string_escape (s[i])); | |
801 | 693 |
1755 | 694 return retval; |
801 | 695 } |
696 | |
1957 | 697 DEFUN (undo_string_escapes, args, , |
3361 | 698 "-*- texinfo -*-\n\ |
699 @deftypefn {Built-in Function} {} undo_string_escapes (@var{s})\n\ | |
700 Converts special characters in strings back to their escaped forms. For\n\ | |
701 example, the expression\n\ | |
702 \n\ | |
703 @example\n\ | |
704 bell = \"\\a\";\n\ | |
705 @end example\n\ | |
706 \n\ | |
707 @noindent\n\ | |
708 assigns the value of the alert character (control-g, ASCII code 7) to\n\ | |
709 the string variable @code{bell}. If this string is printed, the\n\ | |
710 system will ring the terminal bell (if it is possible). This is\n\ | |
711 normally the desired outcome. However, sometimes it is useful to be\n\ | |
712 able to print the original representation of the string, with the\n\ | |
713 special characters replaced by their escape sequences. For example,\n\ | |
714 \n\ | |
715 @example\n\ | |
716 octave:13> undo_string_escapes (bell)\n\ | |
717 ans = \\a\n\ | |
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\ | |
801 @deftypefn {Built-in Function} {} find_dir_in_path (@var{dir})\n\ | |
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\ | |
806 or @code{\"/some/dir/allfoo/bar.\n\ | |
807 @end deftypefn") | |
808 { | |
809 octave_value retval = std::string (); | |
810 | |
811 if (args.length () == 1) | |
812 { | |
813 std::string dir = args(0).string_value (); | |
814 | |
815 if (! error_state) | |
816 retval = load_path::find_dir (dir); | |
817 else | |
818 error ("find_dir_in_path: expecting argument to be a directory name"); | |
819 } | |
820 else | |
821 print_usage (); | |
822 | |
823 return retval; | |
824 } | |
825 | |
5465 | 826 DEFUNX ("errno", Ferrno, args, , |
3716 | 827 "-*- texinfo -*-\n\ |
5465 | 828 @deftypefn {Built-in Function} {@var{err} =} errno ()\n\ |
829 @deftypefnx {Built-in Function} {@var{err} =} errno (@var{val})\n\ | |
830 @deftypefnx {Built-in Function} {@var{err} =} errno (@var{name})\n\ | |
831 Return the current value of the system-dependent variable errno,\n\ | |
832 set its value to @var{val} and return the previous value, or return\n\ | |
833 the named error code given @var{name} as a character string, or -1\n\ | |
834 if @var{name} is not found.\n\ | |
3716 | 835 @end deftypefn") |
836 { | |
837 octave_value retval; | |
838 | |
5465 | 839 int nargin = args.length (); |
840 | |
841 if (nargin == 1) | |
842 { | |
843 if (args(0).is_string ()) | |
844 { | |
845 std::string nm = args(0).string_value (); | |
846 | |
847 if (! error_state) | |
848 retval = octave_errno::lookup (nm); | |
849 else | |
850 error ("errno: expecting character string argument"); | |
851 } | |
852 else | |
853 { | |
854 int val = args(0).int_value (); | |
855 | |
856 if (! error_state) | |
857 retval = octave_errno::set (val); | |
858 else | |
859 error ("errno: expecting integer argument"); | |
860 } | |
861 } | |
862 else if (nargin == 0) | |
863 retval = octave_errno::get (); | |
3716 | 864 else |
5823 | 865 print_usage (); |
3716 | 866 |
867 return retval; | |
868 } | |
869 | |
5465 | 870 DEFUN (errno_list, args, , |
871 "-*- texinfo -*-\n\ | |
872 @deftypefn {Built-in Function} {} errno_list ()\n\ | |
873 Return a structure containing the system-dependent errno values.\n\ | |
874 @end deftypefn") | |
875 { | |
876 octave_value retval; | |
877 | |
878 if (args.length () == 0) | |
879 retval = octave_errno::list (); | |
880 else | |
5823 | 881 print_usage (); |
5465 | 882 |
883 return retval; | |
884 } | |
3716 | 885 |
2285 | 886 static void |
5275 | 887 check_dimensions (octave_idx_type& nr, octave_idx_type& nc, const char *warnfor) |
3354 | 888 { |
889 if (nr < 0 || nc < 0) | |
890 { | |
5781 | 891 warning_with_id ("Octave:neg-dim-as-zero", |
892 "%s: converting negative dimension to zero", warnfor); | |
3354 | 893 |
4457 | 894 nr = (nr < 0) ? 0 : nr; |
895 nc = (nc < 0) ? 0 : nc; | |
3354 | 896 } |
897 } | |
898 | |
899 void | |
4513 | 900 check_dimensions (dim_vector& dim, const char *warnfor) |
4481 | 901 { |
902 bool neg = false; | |
903 | |
904 for (int i = 0; i < dim.length (); i++) | |
905 { | |
906 if (dim(i) < 0) | |
907 { | |
908 dim(i) = 0; | |
909 neg = true; | |
910 } | |
911 } | |
912 | |
5781 | 913 if (neg) |
914 warning_with_id ("Octave:neg-dim-as-zero", | |
915 "%s: converting negative dimension to zero", warnfor); | |
4481 | 916 } |
917 | |
918 | |
919 void | |
920 get_dimensions (const octave_value& a, const char *warn_for, | |
4513 | 921 dim_vector& dim) |
4481 | 922 { |
923 if (a.is_scalar_type ()) | |
924 { | |
925 dim.resize (2); | |
4732 | 926 dim(0) = a.int_value (); |
4481 | 927 dim(1) = dim(0); |
928 } | |
929 else | |
930 { | |
5275 | 931 octave_idx_type nr = a.rows (); |
932 octave_idx_type nc = a.columns (); | |
4481 | 933 |
934 if (nr == 1 || nc == 1) | |
935 { | |
936 Array<double> v = a.vector_value (); | |
937 | |
938 if (error_state) | |
939 return; | |
940 | |
5275 | 941 octave_idx_type n = v.length (); |
4481 | 942 dim.resize (n); |
5275 | 943 for (octave_idx_type i = 0; i < n; i++) |
4783 | 944 dim(i) = static_cast<int> (fix (v(i))); |
4481 | 945 } |
946 else | |
5257 | 947 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); |
4481 | 948 } |
949 | |
5258 | 950 if (! error_state) |
951 check_dimensions (dim, warn_for); // May set error_state. | |
4481 | 952 } |
953 | |
954 | |
955 void | |
3354 | 956 get_dimensions (const octave_value& a, const char *warn_for, |
5275 | 957 octave_idx_type& nr, octave_idx_type& nc) |
3354 | 958 { |
959 if (a.is_scalar_type ()) | |
960 { | |
4732 | 961 nr = nc = a.int_value (); |
3354 | 962 } |
963 else | |
964 { | |
965 nr = a.rows (); | |
966 nc = a.columns (); | |
967 | |
968 if ((nr == 1 && nc == 2) || (nr == 2 && nc == 1)) | |
969 { | |
3419 | 970 Array<double> v = a.vector_value (); |
3354 | 971 |
972 if (error_state) | |
973 return; | |
974 | |
5275 | 975 nr = static_cast<octave_idx_type> (fix (v (0))); |
976 nc = static_cast<octave_idx_type> (fix (v (1))); | |
3354 | 977 } |
978 else | |
5257 | 979 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); |
3354 | 980 } |
981 | |
5258 | 982 if (! error_state) |
983 check_dimensions (nr, nc, warn_for); // May set error_state. | |
3354 | 984 } |
985 | |
986 void | |
987 get_dimensions (const octave_value& a, const octave_value& b, | |
5275 | 988 const char *warn_for, octave_idx_type& nr, octave_idx_type& nc) |
3354 | 989 { |
4732 | 990 nr = a.is_empty () ? 0 : a.int_value (); |
991 nc = b.is_empty () ? 0 : b.int_value (); | |
3354 | 992 |
993 if (error_state) | |
994 error ("%s: expecting two scalar arguments", warn_for); | |
995 else | |
996 check_dimensions (nr, nc, warn_for); // May set error_state. | |
997 } | |
998 | |
4478 | 999 Matrix |
5275 | 1000 identity_matrix (octave_idx_type nr, octave_idx_type nc) |
4478 | 1001 { |
1002 Matrix m (nr, nc, 0.0); | |
1003 | |
1004 if (nr > 0 && nc > 0) | |
1005 { | |
5275 | 1006 octave_idx_type n = std::min (nr, nc); |
4478 | 1007 |
5275 | 1008 for (octave_idx_type i = 0; i < n; i++) |
4478 | 1009 m (i, i) = 1.0; |
1010 } | |
1011 | |
1012 return m; | |
1013 } | |
1014 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1015 FloatMatrix |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1016 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
|
1017 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1018 FloatMatrix m (nr, nc, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1019 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1020 if (nr > 0 && nc > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1021 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1022 octave_idx_type n = std::min (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1023 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1024 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
|
1025 m (i, i) = 1.0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1026 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1027 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1028 return m; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1029 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1030 |
8012
63dbb85452cc
fix extern decls in .cc files
John W. Eaton <jwe@octave.org>
parents:
7818
diff
changeset
|
1031 int |
3622 | 1032 octave_format (std::ostream& os, const char *fmt, ...) |
3620 | 1033 { |
1034 int retval = -1; | |
1035 | |
1036 va_list args; | |
1037 va_start (args, fmt); | |
1038 | |
1039 retval = octave_vformat (os, fmt, args); | |
1040 | |
1041 va_end (args); | |
1042 | |
1043 return retval; | |
1044 } | |
1045 | |
8012
63dbb85452cc
fix extern decls in .cc files
John W. Eaton <jwe@octave.org>
parents:
7818
diff
changeset
|
1046 int |
3622 | 1047 octave_vformat (std::ostream& os, const char *fmt, va_list args) |
3620 | 1048 { |
1049 int retval = -1; | |
1050 | |
3775 | 1051 #if defined (__GNUG__) && !CXX_ISO_COMPLIANT_LIBRARY |
3620 | 1052 |
4135 | 1053 std::streambuf *sb = os.rdbuf (); |
1054 | |
1055 if (sb) | |
4302 | 1056 { |
1057 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; | |
1058 | |
1059 retval = sb->vform (fmt, args); | |
1060 | |
1061 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; | |
1062 } | |
3620 | 1063 |
1064 #else | |
1065 | |
1066 char *s = octave_vsnprintf (fmt, args); | |
1067 | |
1068 if (s) | |
1069 { | |
1070 os << s; | |
1071 | |
1072 retval = strlen (s); | |
1073 } | |
1074 | |
1075 #endif | |
1076 | |
1077 return retval; | |
1078 } | |
1079 | |
5775 | 1080 /* FIXME -- we really need a configure test for this. */ |
4302 | 1081 |
6694 | 1082 #if defined __GNUC__ && __GNUC__ >= 3 && ! defined __MINGW32__ |
4302 | 1083 #define HAVE_C99_VSNPRINTF 1 |
1084 #endif | |
1085 | |
1086 // We manage storage. User should not free it, and its contents are | |
1087 // only valid until next call to vsnprintf. | |
1088 | |
1089 // Interrupts might happen if someone makes a call with something that | |
1090 // will require a very large buffer. If we are interrupted in that | |
1091 // case, we should make the buffer size smaller for the next call. | |
1092 | |
1093 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_FOR_VSNPRINTF \ | |
1094 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_1; \ | |
1095 delete [] buf; \ | |
1096 buf = 0; \ | |
1097 size = initial_size; \ | |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1098 octave_rethrow_exception (); \ |
4302 | 1099 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_2 |
1100 | |
4485 | 1101 #if defined __GNUC__ && defined __va_copy |
1102 #define SAVE_ARGS(saved_args, args) __va_copy (saved_args, args) | |
1103 #elif defined va_copy | |
1104 #define SAVE_ARGS(saved_args, args) va_copy (saved_args, args) | |
1105 #else | |
1106 #define SAVE_ARGS(saved_args, args) saved_args = args | |
1107 #endif | |
1108 | |
4302 | 1109 char * |
1110 octave_vsnprintf (const char *fmt, va_list args) | |
1111 { | |
1112 static const size_t initial_size = 100; | |
1113 | |
1114 static size_t size = initial_size; | |
1115 | |
1116 static char *buf = 0; | |
1117 | |
4482 | 1118 #if defined (HAVE_C99_VSNPRINTF) |
1119 size_t nchars; | |
1120 #else | |
4351 | 1121 int nchars; |
4482 | 1122 #endif |
4302 | 1123 |
1124 if (! buf) | |
1125 buf = new char [size]; | |
1126 | |
1127 if (! buf) | |
1128 return 0; | |
1129 | |
1130 #if defined (HAVE_C99_VSNPRINTF) | |
1131 | |
4485 | 1132 // Note that the caller is responsible for calling va_end on args. |
1133 // We will do it for saved_args. | |
1134 | |
1135 va_list saved_args; | |
1136 | |
1137 SAVE_ARGS (saved_args, args); | |
1138 | |
4302 | 1139 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_FOR_VSNPRINTF; |
1140 | |
1141 nchars = octave_raw_vsnprintf (buf, size, fmt, args); | |
1142 | |
1143 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; | |
1144 | |
1145 if (nchars >= size) | |
1146 { | |
1147 size = nchars + 1; | |
1148 | |
1149 delete [] buf; | |
1150 | |
1151 buf = new char [size]; | |
1152 | |
1153 if (buf) | |
1154 { | |
1155 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_FOR_VSNPRINTF; | |
1156 | |
4485 | 1157 octave_raw_vsnprintf (buf, size, fmt, saved_args); |
4302 | 1158 |
1159 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; | |
1160 } | |
1161 } | |
1162 | |
4485 | 1163 va_end (saved_args); |
1164 | |
4302 | 1165 #else |
1166 | |
1167 while (1) | |
1168 { | |
4485 | 1169 va_list saved_args; |
1170 | |
1171 SAVE_ARGS (saved_args, args); | |
1172 | |
4302 | 1173 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_FOR_VSNPRINTF; |
1174 | |
4485 | 1175 nchars = octave_raw_vsnprintf (buf, size, fmt, saved_args); |
1176 | |
1177 va_end (saved_args); | |
4302 | 1178 |
1179 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; | |
1180 | |
4351 | 1181 if (nchars > -1 && nchars < size-1) |
4302 | 1182 return buf; |
1183 else | |
1184 { | |
1185 delete [] buf; | |
1186 | |
1187 size *= 2; | |
1188 | |
1189 buf = new char [size]; | |
1190 | |
1191 if (! buf) | |
1192 return 0; | |
1193 } | |
1194 } | |
1195 | |
1196 #endif | |
1197 | |
1198 return buf; | |
1199 } | |
1200 | |
1201 char * | |
1202 octave_snprintf (const char *fmt, ...) | |
1203 { | |
1204 char *retval = 0; | |
1205 | |
1206 va_list args; | |
1207 va_start (args, fmt); | |
1208 | |
1209 retval = octave_vsnprintf (fmt, args); | |
1210 | |
1211 va_end (args); | |
1212 | |
1213 return retval; | |
1214 } | |
1215 | |
4086 | 1216 void |
1217 octave_sleep (double seconds) | |
1218 { | |
1219 if (seconds > 0) | |
1220 { | |
1221 double t; | |
1222 | |
4093 | 1223 unsigned int usec |
4783 | 1224 = static_cast<unsigned int> (modf (seconds, &t) * 1000000); |
4086 | 1225 |
4093 | 1226 unsigned int sec |
4783 | 1227 = (t > UINT_MAX) ? UINT_MAX : static_cast<unsigned int> (t); |
4086 | 1228 |
5770 | 1229 // Versions of these functions that accept unsigned int args are |
1230 // defined in cutils.c. | |
4086 | 1231 octave_sleep (sec); |
1232 octave_usleep (usec); | |
1233 } | |
1234 } | |
1235 | |
572 | 1236 /* |
1 | 1237 ;;; Local Variables: *** |
1238 ;;; mode: C++ *** | |
1239 ;;; End: *** | |
1240 */ |