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