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