1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
240
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
1
|
25 #endif |
|
26 |
3716
|
27 #include <cerrno> |
1343
|
28 #include <climits> |
1346
|
29 #include <cstring> |
1343
|
30 |
3503
|
31 #include <fstream> |
|
32 #include <iostream> |
1728
|
33 #include <string> |
|
34 |
1350
|
35 #ifdef HAVE_UNISTD_H |
2442
|
36 #ifdef HAVE_SYS_TYPES_H |
1
|
37 #include <sys/types.h> |
2442
|
38 #endif |
1
|
39 #include <unistd.h> |
|
40 #endif |
367
|
41 |
3566
|
42 // Include setjmp.h, not csetjmp since the latter might only define |
|
43 // the ANSI standard C interface. |
|
44 |
|
45 #include <setjmp.h> |
|
46 |
3040
|
47 #include "dir-ops.h" |
|
48 #include "file-ops.h" |
2926
|
49 #include "file-stat.h" |
4051
|
50 #include "lo-sstream.h" |
1651
|
51 #include "oct-cmplx.h" |
2926
|
52 #include "oct-env.h" |
3040
|
53 #include "pathsearch.h" |
1755
|
54 #include "str-vec.h" |
1651
|
55 |
2492
|
56 #include <defaults.h> |
1352
|
57 #include "defun.h" |
|
58 #include "dirfns.h" |
|
59 #include "error.h" |
|
60 #include "gripes.h" |
|
61 #include "input.h" |
1742
|
62 #include "oct-hist.h" |
1750
|
63 #include "oct-obj.h" |
1352
|
64 #include "pager.h" |
1690
|
65 #include "sysdep.h" |
1750
|
66 #include "toplev.h" |
1
|
67 #include "unwind-prot.h" |
1352
|
68 #include "utils.h" |
|
69 #include "variables.h" |
1
|
70 |
3354
|
71 // Should expressions like ones (-1, 5) result in an empty matrix or |
|
72 // an error? A positive value means yes. A negative value means |
|
73 // yes, but print a warning message. Zero means it should be |
|
74 // considered an error. |
|
75 static int Vtreat_neg_dim_as_zero; |
|
76 |
4143
|
77 // Return TRUE if S is a valid identifier. |
|
78 |
|
79 bool |
|
80 valid_identifier (const char *s) |
|
81 { |
|
82 if (! s || ! (isalnum (*s) || *s == '_')) |
|
83 return false; |
|
84 |
|
85 while (*++s != '\0') |
|
86 if (! (isalnum (*s) || *s == '_')) |
|
87 return false; |
|
88 |
|
89 return true; |
|
90 } |
|
91 |
|
92 bool |
|
93 valid_identifier (const std::string& s) |
|
94 { |
|
95 return valid_identifier (s.c_str ()); |
|
96 } |
|
97 |
1
|
98 int |
3523
|
99 almost_match (const std::string& std, const std::string& s, int min_match_len, |
526
|
100 int case_sens) |
1
|
101 { |
1755
|
102 int stdlen = std.length (); |
|
103 int slen = s.length (); |
1
|
104 |
|
105 return (slen <= stdlen |
|
106 && slen >= min_match_len |
287
|
107 && (case_sens |
1755
|
108 ? (strncmp (std.c_str (), s.c_str (), slen) == 0) |
3350
|
109 : (octave_strncasecmp (std.c_str (), s.c_str (), slen) == 0))); |
287
|
110 } |
|
111 |
581
|
112 // Ugh. |
|
113 |
287
|
114 int |
3523
|
115 keyword_almost_match (const char * const *std, int *min_len, const std::string& s, |
287
|
116 int min_toks_to_match, int max_toks) |
|
117 { |
|
118 int status = 0; |
|
119 int tok_count = 0; |
|
120 int toks_matched = 0; |
|
121 |
1755
|
122 if (s.empty () || max_toks < 1) |
287
|
123 return status; |
|
124 |
1755
|
125 char *kw = strsave (s.c_str ()); |
287
|
126 |
|
127 char *t = kw; |
|
128 while (*t != '\0') |
|
129 { |
|
130 if (*t == '\t') |
|
131 *t = ' '; |
|
132 t++; |
|
133 } |
|
134 |
|
135 char *beg = kw; |
|
136 while (*beg == ' ') |
|
137 beg++; |
|
138 |
|
139 if (*beg == '\0') |
|
140 return status; |
|
141 |
|
142 |
3072
|
143 const char **to_match = new const char * [max_toks + 1]; |
|
144 const char * const *s1 = std; |
|
145 const char **s2 = to_match; |
287
|
146 |
526
|
147 if (! s1 || ! s2) |
287
|
148 goto done; |
|
149 |
|
150 s2[tok_count] = beg; |
|
151 char *end; |
526
|
152 while ((end = strchr (beg, ' ')) != 0) |
287
|
153 { |
|
154 *end = '\0'; |
|
155 beg = end + 1; |
|
156 |
|
157 while (*beg == ' ') |
|
158 beg++; |
|
159 |
|
160 if (*beg == '\0') |
|
161 break; |
|
162 |
|
163 tok_count++; |
|
164 if (tok_count >= max_toks) |
|
165 goto done; |
|
166 |
|
167 s2[tok_count] = beg; |
|
168 } |
526
|
169 s2[tok_count+1] = 0; |
287
|
170 |
|
171 s2 = to_match; |
|
172 |
|
173 for (;;) |
|
174 { |
|
175 if (! almost_match (*s1, *s2, min_len[toks_matched], 0)) |
|
176 goto done; |
|
177 |
|
178 toks_matched++; |
|
179 |
|
180 s1++; |
|
181 s2++; |
|
182 |
|
183 if (! *s2) |
|
184 { |
|
185 status = (toks_matched >= min_toks_to_match); |
|
186 goto done; |
|
187 } |
|
188 |
|
189 if (! *s1) |
|
190 goto done; |
|
191 } |
|
192 |
|
193 done: |
|
194 |
|
195 delete [] kw; |
|
196 delete [] to_match; |
|
197 |
|
198 return status; |
1
|
199 } |
|
200 |
2234
|
201 // Return non-zero if either NR or NC is zero. Return -1 if this |
|
202 // should be considered fatal; return 1 if this is ok. |
|
203 |
|
204 int |
|
205 empty_arg (const char *name, int nr, int nc) |
|
206 { |
|
207 int is_empty = 0; |
|
208 |
|
209 if (nr == 0 || nc == 0) |
|
210 { |
|
211 int flag = Vpropagate_empty_matrices; |
|
212 |
|
213 if (flag < 0) |
|
214 { |
|
215 gripe_empty_arg (name, 0); |
|
216 is_empty = 1; |
|
217 } |
|
218 else if (flag == 0) |
|
219 { |
|
220 gripe_empty_arg (name, 1); |
|
221 is_empty = -1; |
|
222 } |
|
223 else |
|
224 is_empty = 1; |
|
225 } |
|
226 |
|
227 return is_empty; |
|
228 } |
|
229 |
581
|
230 // See if the given file is in the path. |
|
231 |
3536
|
232 std::string |
3523
|
233 search_path_for_file (const std::string& path, const std::string& name) |
686
|
234 { |
3174
|
235 dir_path p (path); |
686
|
236 |
2926
|
237 return octave_env::make_absolute (p.find (name), octave_env::getcwd ()); |
686
|
238 } |
|
239 |
3195
|
240 DEFUN (file_in_loadpath, args, , |
3446
|
241 "-*- texinfo -*-\n\ |
|
242 @deftypefn {Built-in Function} {} file_in_loadpath (@var{name})\n\ |
3195
|
243 \n\ |
3446
|
244 Look up @var{name} in Octave's @code{LOADPATH}.\n\ |
|
245 @end deftypefn\n\ |
|
246 @seealso{file_in_path}") |
3195
|
247 { |
|
248 octave_value_list retval; |
|
249 |
|
250 int argc = args.length () + 1; |
|
251 |
|
252 string_vector argv = args.make_argv ("file_in_loadpath"); |
|
253 |
|
254 if (error_state) |
|
255 return retval; |
|
256 |
3225
|
257 if (argc == 2) |
3195
|
258 retval = octave_env::make_absolute (Vload_path_dir_path.find (argv[1]), |
|
259 octave_env::getcwd ()); |
|
260 else |
|
261 print_usage ("file_in_loadpath"); |
|
262 |
|
263 return retval; |
|
264 } |
|
265 |
1957
|
266 DEFUN (file_in_path, args, , |
3301
|
267 "-*- texinfo -*-\n\ |
|
268 @deftypefn {Built-in Function} {} file_in_path (@var{path}, @var{file})\n\ |
|
269 Return the absolute name name of @var{file} if it can be found in\n\ |
|
270 @var{path}. The value of @var{path} should be a colon-separated list of\n\ |
|
271 directories in the format described for the built-in variable\n\ |
|
272 @code{LOADPATH}.\n\ |
|
273 \n\ |
|
274 If the file cannot be found in the path, an empty matrix is returned.\n\ |
|
275 For example,\n\ |
|
276 \n\ |
|
277 @example\n\ |
|
278 file_in_path (LOADPATH, \"nargchk.m\")\n\ |
|
279 @result{} \"@value{OCTAVEHOME}/share/octave/2.0/m/general/nargchk.m\"\n\ |
|
280 @end example\n\ |
|
281 @end deftypefn") |
686
|
282 { |
2086
|
283 octave_value_list retval; |
686
|
284 |
1755
|
285 int argc = args.length () + 1; |
|
286 |
1968
|
287 string_vector argv = args.make_argv ("file_in_path"); |
1755
|
288 |
|
289 if (error_state) |
|
290 return retval; |
686
|
291 |
|
292 if (argc == 3) |
|
293 { |
3523
|
294 std::string fname = search_path_for_file (argv[1], argv[2]); |
686
|
295 |
1755
|
296 if (fname.empty ()) |
|
297 retval = Matrix (); |
|
298 else |
686
|
299 retval = fname; |
|
300 } |
|
301 else |
|
302 print_usage ("file_in_path"); |
|
303 |
|
304 return retval; |
|
305 } |
|
306 |
3536
|
307 std::string |
3523
|
308 file_in_path (const std::string& name, const std::string& suffix) |
526
|
309 { |
3523
|
310 std::string nm = name; |
526
|
311 |
1755
|
312 if (! suffix.empty ()) |
|
313 nm.append (suffix); |
686
|
314 |
3174
|
315 return octave_env::make_absolute (Vload_path_dir_path.find (nm), |
|
316 octave_env::getcwd ()); |
526
|
317 } |
|
318 |
581
|
319 // See if there is an function file in the path. If so, return the |
|
320 // full path to the file. |
|
321 |
3536
|
322 std::string |
3523
|
323 fcn_file_in_path (const std::string& name) |
526
|
324 { |
3523
|
325 std::string retval; |
908
|
326 |
1755
|
327 int len = name.length (); |
|
328 |
|
329 if (len > 0) |
|
330 { |
|
331 if (len > 2 && name [len - 2] == '.' && name [len - 1] == 'm') |
|
332 retval = file_in_path (name, ""); |
908
|
333 else |
1755
|
334 retval = file_in_path (name, ".m"); |
908
|
335 } |
1755
|
336 |
|
337 return retval; |
526
|
338 } |
|
339 |
581
|
340 // See if there is an octave file in the path. If so, return the |
|
341 // full path to the file. |
|
342 |
3536
|
343 std::string |
3523
|
344 oct_file_in_path (const std::string& name) |
572
|
345 { |
3523
|
346 std::string retval; |
908
|
347 |
1755
|
348 int len = name.length (); |
|
349 |
|
350 if (len > 0) |
|
351 { |
|
352 if (len > 2 && name [len - 4] == '.' && name [len - 3] == 'o' |
908
|
353 && name [len - 2] == 'c' && name [len - 1] == 't') |
1755
|
354 retval = file_in_path (name, ""); |
908
|
355 else |
1755
|
356 retval = file_in_path (name, ".oct"); |
908
|
357 } |
1755
|
358 |
|
359 return retval; |
572
|
360 } |
|
361 |
3103
|
362 // Replace backslash escapes in a string with the real values. |
|
363 |
3536
|
364 std::string |
3523
|
365 do_string_escapes (const std::string& s) |
3103
|
366 { |
3523
|
367 std::string retval; |
3103
|
368 |
|
369 size_t i = 0; |
|
370 size_t j = 0; |
|
371 size_t len = s.length (); |
|
372 |
|
373 retval.resize (len); |
|
374 |
|
375 while (j < len) |
|
376 { |
|
377 if (s[j] == '\\' && j+1 < len) |
|
378 { |
|
379 switch (s[++j]) |
|
380 { |
3893
|
381 case '0': |
|
382 retval[i] = '\0'; |
|
383 break; |
|
384 |
3103
|
385 case 'a': |
|
386 retval[i] = '\a'; |
|
387 break; |
|
388 |
|
389 case 'b': // backspace |
|
390 retval[i] = '\b'; |
|
391 break; |
|
392 |
|
393 case 'f': // formfeed |
|
394 retval[i] = '\f'; |
|
395 break; |
|
396 |
|
397 case 'n': // newline |
|
398 retval[i] = '\n'; |
|
399 break; |
|
400 |
|
401 case 'r': // carriage return |
|
402 retval[i] = '\r'; |
|
403 break; |
|
404 |
|
405 case 't': // horizontal tab |
|
406 retval[i] = '\t'; |
|
407 break; |
|
408 |
|
409 case 'v': // vertical tab |
|
410 retval[i] = '\v'; |
|
411 break; |
|
412 |
|
413 case '\\': // backslash |
|
414 retval[i] = '\\'; |
|
415 break; |
|
416 |
|
417 case '\'': // quote |
|
418 retval[i] = '\''; |
|
419 break; |
|
420 |
|
421 case '"': // double quote |
|
422 retval[i] = '"'; |
|
423 break; |
|
424 |
|
425 default: |
|
426 warning ("unrecognized escape sequence `\\%c' --\ |
|
427 converting to `%c'", s[j], s[j]); |
|
428 retval[i] = s[j]; |
|
429 break; |
|
430 } |
|
431 } |
|
432 else |
|
433 { |
|
434 retval[i] = s[j]; |
|
435 } |
|
436 |
|
437 i++; |
|
438 j++; |
|
439 } |
|
440 |
3105
|
441 retval.resize (i); |
3103
|
442 |
|
443 return retval; |
|
444 } |
|
445 |
|
446 DEFUN (do_string_escapes, args, , |
3446
|
447 "-*- texinfo -*-\n\ |
|
448 @deftypefn {Built-in Function} {} do_string_escapes (@var{string})\n\ |
|
449 Convert special characters in @var{string} to their escaped forms.\n\ |
|
450 @end deftypefn") |
3103
|
451 { |
|
452 octave_value retval; |
|
453 |
|
454 int nargin = args.length (); |
|
455 |
|
456 if (nargin == 1) |
|
457 { |
|
458 if (args(0).is_string ()) |
|
459 retval = do_string_escapes (args(0).string_value ()); |
|
460 else |
|
461 error ("do_string_escapes: argument must be a string"); |
|
462 } |
|
463 else |
|
464 print_usage ("do_string_escapes"); |
|
465 |
|
466 return retval; |
|
467 } |
|
468 |
1755
|
469 const char * |
801
|
470 undo_string_escape (char c) |
|
471 { |
|
472 if (! c) |
1755
|
473 return ""; |
801
|
474 |
|
475 switch (c) |
|
476 { |
3893
|
477 case '\0': |
|
478 return "\\0"; |
|
479 |
801
|
480 case '\a': |
|
481 return "\\a"; |
|
482 |
|
483 case '\b': // backspace |
|
484 return "\\b"; |
|
485 |
|
486 case '\f': // formfeed |
|
487 return "\\f"; |
|
488 |
|
489 case '\n': // newline |
|
490 return "\\n"; |
|
491 |
|
492 case '\r': // carriage return |
|
493 return "\\r"; |
|
494 |
|
495 case '\t': // horizontal tab |
|
496 return "\\t"; |
|
497 |
|
498 case '\v': // vertical tab |
|
499 return "\\v"; |
|
500 |
|
501 case '\\': // backslash |
|
502 return "\\\\"; |
|
503 |
|
504 case '"': // double quote |
|
505 return "\\\""; |
|
506 |
|
507 default: |
1755
|
508 { |
|
509 static char retval[2]; |
|
510 retval[0] = c; |
|
511 retval[1] = '\0'; |
|
512 return retval; |
|
513 } |
801
|
514 } |
|
515 } |
|
516 |
3536
|
517 std::string |
3523
|
518 undo_string_escapes (const std::string& s) |
801
|
519 { |
3523
|
520 std::string retval; |
801
|
521 |
1755
|
522 for (size_t i = 0; i < s.length (); i++) |
|
523 retval.append (undo_string_escape (s[i])); |
801
|
524 |
1755
|
525 return retval; |
801
|
526 } |
|
527 |
1957
|
528 DEFUN (undo_string_escapes, args, , |
3361
|
529 "-*- texinfo -*-\n\ |
|
530 @deftypefn {Built-in Function} {} undo_string_escapes (@var{s})\n\ |
|
531 Converts special characters in strings back to their escaped forms. For\n\ |
|
532 example, the expression\n\ |
|
533 \n\ |
|
534 @example\n\ |
|
535 bell = \"\\a\";\n\ |
|
536 @end example\n\ |
|
537 \n\ |
|
538 @noindent\n\ |
|
539 assigns the value of the alert character (control-g, ASCII code 7) to\n\ |
|
540 the string variable @code{bell}. If this string is printed, the\n\ |
|
541 system will ring the terminal bell (if it is possible). This is\n\ |
|
542 normally the desired outcome. However, sometimes it is useful to be\n\ |
|
543 able to print the original representation of the string, with the\n\ |
|
544 special characters replaced by their escape sequences. For example,\n\ |
|
545 \n\ |
|
546 @example\n\ |
|
547 octave:13> undo_string_escapes (bell)\n\ |
|
548 ans = \\a\n\ |
|
549 @end example\n\ |
|
550 \n\ |
|
551 @noindent\n\ |
|
552 replaces the unprintable alert character with its printable\n\ |
|
553 representation.\n\ |
|
554 @end deftypefn") |
801
|
555 { |
2086
|
556 octave_value retval; |
801
|
557 |
|
558 int nargin = args.length (); |
|
559 |
3103
|
560 if (nargin == 1) |
|
561 { |
|
562 if (args(0).is_string ()) |
|
563 retval = undo_string_escapes (args(0).string_value ()); |
|
564 else |
|
565 error ("undo_string_escapes: argument must be a string"); |
|
566 } |
801
|
567 else |
1023
|
568 print_usage ("undo_string_escapes"); |
801
|
569 |
|
570 return retval; |
|
571 } |
|
572 |
3879
|
573 // #if 0 |
3716
|
574 |
|
575 // Octave could use some way to access the value of ERRNO, but this is |
|
576 // probably not the best interface, so don't depend on it... |
|
577 |
|
578 DEFUN (ERRNO, args, , |
|
579 "-*- texinfo -*-\n\ |
|
580 @deftypefn {Built-in Function} {@var{system_error_number}} errno ()\n\ |
|
581 Return the current value of the system-dependent variable errno.\n\ |
|
582 @end deftypefn") |
|
583 { |
|
584 octave_value retval; |
|
585 |
|
586 if (args.length () == 0) |
|
587 retval = static_cast<double> (errno); |
|
588 else |
|
589 print_usage ("errno"); |
|
590 |
|
591 return retval; |
|
592 } |
|
593 |
3879
|
594 // #endif |
3716
|
595 |
2285
|
596 static void |
3523
|
597 warn_old_style_preference (bool val, const std::string& sval) |
2285
|
598 { |
|
599 warning |
|
600 ("preference of \"%s\" is obsolete -- use numeric value of %d instead", |
|
601 sval.c_str (), (val ? 1 : 0)); |
|
602 } |
|
603 |
2204
|
604 // Check the value of a string variable to see if it it's ok to do |
|
605 // something. |
|
606 // |
|
607 // return of 1 => always ok. |
|
608 // return of 0 => never ok. |
|
609 // return of -1 => ok, but give me warning (default). |
|
610 |
|
611 int |
3523
|
612 check_preference (const std::string& var) |
2204
|
613 { |
|
614 int pref = -1; |
|
615 |
3523
|
616 std::string val = builtin_string_variable (var); |
2204
|
617 |
|
618 if (val.empty ()) |
|
619 { |
|
620 double dval = 0; |
|
621 if (builtin_real_scalar_variable (var, dval)) |
|
622 pref = NINT (dval); |
|
623 } |
|
624 else |
|
625 { |
3565
|
626 if (val == "yes" || val == "true") |
2285
|
627 { |
|
628 warn_old_style_preference (true, val); |
|
629 pref = 1; |
|
630 } |
3565
|
631 else if (val == "never" || val == "no" || val == "false") |
2285
|
632 { |
|
633 warn_old_style_preference (false, val); |
|
634 pref = 0; |
|
635 } |
2204
|
636 } |
|
637 |
|
638 return pref; |
|
639 } |
|
640 |
3354
|
641 static void |
|
642 check_dimensions (int& nr, int& nc, const char *warnfor) |
|
643 { |
|
644 if (nr < 0 || nc < 0) |
|
645 { |
|
646 if (Vtreat_neg_dim_as_zero) |
|
647 { |
|
648 nr = (nr < 0) ? 0 : nr; |
|
649 nc = (nc < 0) ? 0 : nc; |
|
650 |
|
651 if (Vtreat_neg_dim_as_zero < 0) |
|
652 warning ("%s: converting negative dimension to zero", |
|
653 warnfor); |
|
654 } |
|
655 else |
|
656 error ("%s: can't create a matrix with negative dimensions", |
|
657 warnfor); |
|
658 } |
|
659 } |
|
660 |
|
661 void |
|
662 get_dimensions (const octave_value& a, const char *warn_for, |
|
663 int& nr, int& nc) |
|
664 { |
|
665 if (a.is_scalar_type ()) |
|
666 { |
|
667 nr = nc = a.nint_value (); |
|
668 } |
|
669 else |
|
670 { |
|
671 nr = a.rows (); |
|
672 nc = a.columns (); |
|
673 |
|
674 if ((nr == 1 && nc == 2) || (nr == 2 && nc == 1)) |
|
675 { |
3419
|
676 Array<double> v = a.vector_value (); |
3354
|
677 |
|
678 if (error_state) |
|
679 return; |
|
680 |
|
681 nr = NINT (v (0)); |
|
682 nc = NINT (v (1)); |
|
683 } |
|
684 else |
|
685 warning ("%s (A): use %s (size (A)) instead", warn_for, warn_for); |
|
686 } |
|
687 |
|
688 check_dimensions (nr, nc, warn_for); // May set error_state. |
|
689 } |
|
690 |
|
691 void |
|
692 get_dimensions (const octave_value& a, const octave_value& b, |
|
693 const char *warn_for, int& nr, int& nc) |
|
694 { |
|
695 nr = a.is_empty () ? 0 : a.nint_value (); |
|
696 nc = b.is_empty () ? 0 : b.nint_value (); |
|
697 |
|
698 if (error_state) |
|
699 error ("%s: expecting two scalar arguments", warn_for); |
|
700 else |
|
701 check_dimensions (nr, nc, warn_for); // May set error_state. |
|
702 } |
|
703 |
3620
|
704 extern int |
3622
|
705 octave_format (std::ostream& os, const char *fmt, ...) |
3620
|
706 { |
|
707 int retval = -1; |
|
708 |
|
709 va_list args; |
|
710 va_start (args, fmt); |
|
711 |
|
712 retval = octave_vformat (os, fmt, args); |
|
713 |
|
714 va_end (args); |
|
715 |
|
716 return retval; |
|
717 } |
|
718 |
|
719 extern int |
3622
|
720 octave_vformat (std::ostream& os, const char *fmt, va_list args) |
3620
|
721 { |
|
722 int retval = -1; |
|
723 |
3775
|
724 #if defined (__GNUG__) && !CXX_ISO_COMPLIANT_LIBRARY |
3620
|
725 |
4135
|
726 std::streambuf *sb = os.rdbuf (); |
|
727 |
|
728 if (sb) |
|
729 retval = sb->vform (fmt, args); |
3620
|
730 |
|
731 #else |
|
732 |
|
733 char *s = octave_vsnprintf (fmt, args); |
|
734 |
|
735 if (s) |
|
736 { |
|
737 os << s; |
|
738 |
|
739 retval = strlen (s); |
|
740 } |
|
741 |
|
742 #endif |
|
743 |
|
744 return retval; |
|
745 } |
|
746 |
4086
|
747 void |
|
748 octave_sleep (double seconds) |
|
749 { |
|
750 if (seconds > 0) |
|
751 { |
|
752 double t; |
|
753 |
4093
|
754 unsigned int usec |
|
755 = static_cast <unsigned int> (modf (seconds, &t) * 1000000); |
4086
|
756 |
4093
|
757 unsigned int sec |
|
758 = (t > UINT_MAX) ? UINT_MAX : static_cast <unsigned int> (t); |
4086
|
759 |
|
760 octave_sleep (sec); |
|
761 octave_usleep (usec); |
|
762 } |
|
763 } |
|
764 |
3354
|
765 static int |
|
766 treat_neg_dim_as_zero (void) |
|
767 { |
|
768 Vtreat_neg_dim_as_zero = check_preference ("treat_neg_dim_as_zero"); |
|
769 |
|
770 return 0; |
|
771 } |
|
772 |
|
773 void |
|
774 symbols_of_utils (void) |
|
775 { |
|
776 DEFVAR (treat_neg_dim_as_zero, 0.0, treat_neg_dim_as_zero, |
3369
|
777 "-*- texinfo -*-\n\ |
|
778 @defvr {Built-in Variable} treat_neg_dim_as_zero\n\ |
|
779 If the value of @code{treat_neg_dim_as_zero} is nonzero, expressions\n\ |
|
780 like\n\ |
|
781 \n\ |
|
782 @example\n\ |
|
783 eye (-1)\n\ |
|
784 @end example\n\ |
|
785 \n\ |
|
786 @noindent\n\ |
|
787 produce an empty matrix (i.e., row and column dimensions are zero).\n\ |
|
788 Otherwise, an error message is printed and control is returned to the\n\ |
|
789 top level. The default value is 0.\n\ |
|
790 @end defvr"); |
3354
|
791 } |
|
792 |
572
|
793 /* |
1
|
794 ;;; Local Variables: *** |
|
795 ;;; mode: C++ *** |
|
796 ;;; End: *** |
|
797 */ |