comparison src/file-io.cc @ 10315:57a59eae83cc

untabify src C++ source files
author John W. Eaton <jwe@octave.org>
date Thu, 11 Feb 2010 12:41:46 -0500
parents 65b41bc71f09
children 12884915a8e4
comparison
equal deleted inserted replaced
10314:07ebe522dac2 10315:57a59eae83cc
146 // but we don't know precisely what action that implies. 146 // but we don't know precisely what action that implies.
147 147
148 size_t pos = mode.find ('W'); 148 size_t pos = mode.find ('W');
149 149
150 if (pos != std::string::npos) 150 if (pos != std::string::npos)
151 { 151 {
152 warning ("fopen: treating mode \"W\" as equivalent to \"w\""); 152 warning ("fopen: treating mode \"W\" as equivalent to \"w\"");
153 mode[pos] = 'w'; 153 mode[pos] = 'w';
154 } 154 }
155 155
156 pos = mode.find ('R'); 156 pos = mode.find ('R');
157 157
158 if (pos != std::string::npos) 158 if (pos != std::string::npos)
159 { 159 {
160 warning ("fopen: treating mode \"R\" as equivalent to \"r\""); 160 warning ("fopen: treating mode \"R\" as equivalent to \"r\"");
161 mode[pos] = 'r'; 161 mode[pos] = 'r';
162 } 162 }
163 163
164 pos = mode.find ('z'); 164 pos = mode.find ('z');
165 165
166 if (pos != std::string::npos) 166 if (pos != std::string::npos)
167 { 167 {
168 #if defined (HAVE_ZLIB) 168 #if defined (HAVE_ZLIB)
169 mode.erase (pos, 1); 169 mode.erase (pos, 1);
170 #else 170 #else
171 error ("this version of Octave does not support gzipped files"); 171 error ("this version of Octave does not support gzipped files");
172 #endif 172 #endif
173 } 173 }
174 174
175 if (! error_state) 175 if (! error_state)
176 { 176 {
177 if (mode == "rt") 177 if (mode == "rt")
178 retval = std::ios::in; 178 retval = std::ios::in;
179 else if (mode == "wt") 179 else if (mode == "wt")
180 retval = std::ios::out | std::ios::trunc; 180 retval = std::ios::out | std::ios::trunc;
181 else if (mode == "at") 181 else if (mode == "at")
182 retval = std::ios::out | std::ios::app; 182 retval = std::ios::out | std::ios::app;
183 else if (mode == "r+t" || mode == "rt+") 183 else if (mode == "r+t" || mode == "rt+")
184 retval = std::ios::in | std::ios::out; 184 retval = std::ios::in | std::ios::out;
185 else if (mode == "w+t" || mode == "wt+") 185 else if (mode == "w+t" || mode == "wt+")
186 retval = std::ios::in | std::ios::out | std::ios::trunc; 186 retval = std::ios::in | std::ios::out | std::ios::trunc;
187 else if (mode == "a+t" || mode == "at+") 187 else if (mode == "a+t" || mode == "at+")
188 retval = std::ios::in | std::ios::out | std::ios::app; 188 retval = std::ios::in | std::ios::out | std::ios::app;
189 else if (mode == "rb" || mode == "r") 189 else if (mode == "rb" || mode == "r")
190 retval = std::ios::in | std::ios::binary; 190 retval = std::ios::in | std::ios::binary;
191 else if (mode == "wb" || mode == "w") 191 else if (mode == "wb" || mode == "w")
192 retval = std::ios::out | std::ios::trunc | std::ios::binary; 192 retval = std::ios::out | std::ios::trunc | std::ios::binary;
193 else if (mode == "ab" || mode == "a") 193 else if (mode == "ab" || mode == "a")
194 retval = std::ios::out | std::ios::app | std::ios::binary; 194 retval = std::ios::out | std::ios::app | std::ios::binary;
195 else if (mode == "r+b" || mode == "rb+" || mode == "r+") 195 else if (mode == "r+b" || mode == "rb+" || mode == "r+")
196 retval = std::ios::in | std::ios::out | std::ios::binary; 196 retval = std::ios::in | std::ios::out | std::ios::binary;
197 else if (mode == "w+b" || mode == "wb+" || mode == "w+") 197 else if (mode == "w+b" || mode == "wb+" || mode == "w+")
198 retval = (std::ios::in | std::ios::out | std::ios::trunc 198 retval = (std::ios::in | std::ios::out | std::ios::trunc
199 | std::ios::binary); 199 | std::ios::binary);
200 else if (mode == "a+b" || mode == "ab+" || mode == "a+") 200 else if (mode == "a+b" || mode == "ab+" || mode == "a+")
201 retval = (std::ios::in | std::ios::out | std::ios::app 201 retval = (std::ios::in | std::ios::out | std::ios::app
202 | std::ios::binary); 202 | std::ios::binary);
203 else 203 else
204 ::error ("invalid mode specified"); 204 ::error ("invalid mode specified");
205 } 205 }
206 } 206 }
207 207
208 return retval; 208 return retval;
209 } 209 }
210 210
243 int fid = octave_stream_list::get_file_number (args (0)); 243 int fid = octave_stream_list::get_file_number (args (0));
244 244
245 octave_stream os = octave_stream_list::lookup (fid, "fclear"); 245 octave_stream os = octave_stream_list::lookup (fid, "fclear");
246 246
247 if (! error_state) 247 if (! error_state)
248 os.clearerr (); 248 os.clearerr ();
249 } 249 }
250 else 250 else
251 print_usage (); 251 print_usage ();
252 252
253 return retval; 253 return retval;
275 // FIXME -- any way to avoid special case for stdout? 275 // FIXME -- any way to avoid special case for stdout?
276 276
277 int fid = octave_stream_list::get_file_number (args (0)); 277 int fid = octave_stream_list::get_file_number (args (0));
278 278
279 if (fid == 1) 279 if (fid == 1)
280 { 280 {
281 flush_octave_stdout (); 281 flush_octave_stdout ();
282 282
283 retval = 0; 283 retval = 0;
284 } 284 }
285 else 285 else
286 { 286 {
287 octave_stream os = octave_stream_list::lookup (fid, "fflush"); 287 octave_stream os = octave_stream_list::lookup (fid, "fflush");
288 288
289 if (! error_state) 289 if (! error_state)
290 retval = os.flush (); 290 retval = os.flush ();
291 } 291 }
292 } 292 }
293 else 293 else
294 print_usage (); 294 print_usage ();
295 295
296 return retval; 296 return retval;
322 if (nargin == 1 || nargin == 2) 322 if (nargin == 1 || nargin == 2)
323 { 323 {
324 octave_stream os = octave_stream_list::lookup (args(0), who); 324 octave_stream os = octave_stream_list::lookup (args(0), who);
325 325
326 if (! error_state) 326 if (! error_state)
327 { 327 {
328 octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); 328 octave_value len_arg = (nargin == 2) ? args(1) : octave_value ();
329 329
330 bool err = false; 330 bool err = false;
331 331
332 std::string tmp = os.getl (len_arg, err, who); 332 std::string tmp = os.getl (len_arg, err, who);
333 333
334 if (! (error_state || err)) 334 if (! (error_state || err))
335 { 335 {
336 retval(1) = tmp.length (); 336 retval(1) = tmp.length ();
337 retval(0) = tmp; 337 retval(0) = tmp;
338 } 338 }
339 } 339 }
340 } 340 }
341 else 341 else
342 print_usage (); 342 print_usage ();
343 343
344 return retval; 344 return retval;
370 if (nargin == 1 || nargin == 2) 370 if (nargin == 1 || nargin == 2)
371 { 371 {
372 octave_stream os = octave_stream_list::lookup (args(0), who); 372 octave_stream os = octave_stream_list::lookup (args(0), who);
373 373
374 if (! error_state) 374 if (! error_state)
375 { 375 {
376 octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); 376 octave_value len_arg = (nargin == 2) ? args(1) : octave_value ();
377 377
378 bool err = false; 378 bool err = false;
379 379
380 std::string tmp = os.gets (len_arg, err, who); 380 std::string tmp = os.gets (len_arg, err, who);
381 381
382 if (! (error_state || err)) 382 if (! (error_state || err))
383 { 383 {
384 retval(1) = tmp.length (); 384 retval(1) = tmp.length ();
385 retval(0) = tmp; 385 retval(0) = tmp;
386 } 386 }
387 } 387 }
388 } 388 }
389 else 389 else
390 print_usage (); 390 print_usage ();
391 391
392 return retval; 392 return retval;
413 if (nargin == 1 || nargin == 2) 413 if (nargin == 1 || nargin == 2)
414 { 414 {
415 octave_stream os = octave_stream_list::lookup (args(0), who); 415 octave_stream os = octave_stream_list::lookup (args(0), who);
416 416
417 if (! error_state) 417 if (! error_state)
418 { 418 {
419 octave_value count_arg = (nargin == 2) ? args(1) : octave_value (); 419 octave_value count_arg = (nargin == 2) ? args(1) : octave_value ();
420 420
421 bool err = false; 421 bool err = false;
422 422
423 long tmp = os.skipl (count_arg, err, who); 423 long tmp = os.skipl (count_arg, err, who);
424 424
425 if (! (error_state || err)) 425 if (! (error_state || err))
426 retval = tmp; 426 retval = tmp;
427 } 427 }
428 } 428 }
429 else 429 else
430 print_usage (); 430 print_usage ();
431 431
432 return retval; 432 return retval;
433 } 433 }
434 434
435 435
436 static octave_stream 436 static octave_stream
437 do_stream_open (const std::string& name, const std::string& mode, 437 do_stream_open (const std::string& name, const std::string& mode,
438 const std::string& arch, int& fid) 438 const std::string& arch, int& fid)
439 { 439 {
440 octave_stream retval; 440 octave_stream retval;
441 441
442 fid = -1; 442 fid = -1;
443 443
444 std::ios::openmode md = fopen_mode_to_ios_mode (mode); 444 std::ios::openmode md = fopen_mode_to_ios_mode (mode);
445 445
446 if (! error_state) 446 if (! error_state)
447 { 447 {
448 oct_mach_info::float_format flt_fmt = 448 oct_mach_info::float_format flt_fmt =
449 oct_mach_info::string_to_float_format (arch); 449 oct_mach_info::string_to_float_format (arch);
450 450
451 if (! error_state) 451 if (! error_state)
452 { 452 {
453 std::string fname = file_ops::tilde_expand (name); 453 std::string fname = file_ops::tilde_expand (name);
454 454
455 file_stat fs (fname); 455 file_stat fs (fname);
456 456
457 if (! (md & std::ios::out 457 if (! (md & std::ios::out
458 || octave_env::absolute_pathname (fname) 458 || octave_env::absolute_pathname (fname)
459 || octave_env::rooted_relative_pathname (fname))) 459 || octave_env::rooted_relative_pathname (fname)))
460 { 460 {
461 if (! fs.exists ()) 461 if (! fs.exists ())
462 { 462 {
463 std::string tmp 463 std::string tmp
464 = octave_env::make_absolute (load_path::find_file (fname)); 464 = octave_env::make_absolute (load_path::find_file (fname));
465 465
466 if (! tmp.empty ()) 466 if (! tmp.empty ())
467 { 467 {
468 warning_with_id ("Octave:fopen-file-in-path", 468 warning_with_id ("Octave:fopen-file-in-path",
469 "fopen: file found in load path"); 469 "fopen: file found in load path");
470 fname = tmp; 470 fname = tmp;
471 } 471 }
472 } 472 }
473 } 473 }
474 474
475 if (! fs.is_dir ()) 475 if (! fs.is_dir ())
476 { 476 {
477 std::string tmode = mode; 477 std::string tmode = mode;
478 478
479 // Use binary mode if 't' is not specified, but don't add 479 // Use binary mode if 't' is not specified, but don't add
480 // 'b' if it is already present. 480 // 'b' if it is already present.
481 481
482 size_t bpos = tmode.find ('b'); 482 size_t bpos = tmode.find ('b');
483 size_t tpos = tmode.find ('t'); 483 size_t tpos = tmode.find ('t');
484 484
485 if (bpos == std::string::npos && tpos == std::string::npos) 485 if (bpos == std::string::npos && tpos == std::string::npos)
486 tmode += 'b'; 486 tmode += 'b';
487 487
488 #if defined (HAVE_ZLIB) 488 #if defined (HAVE_ZLIB)
489 size_t pos = tmode.find ('z'); 489 size_t pos = tmode.find ('z');
490 490
491 if (pos != std::string::npos) 491 if (pos != std::string::npos)
492 { 492 {
493 tmode.erase (pos, 1); 493 tmode.erase (pos, 1);
494 494
495 gzFile fptr = ::gzopen (fname.c_str (), tmode.c_str ()); 495 gzFile fptr = ::gzopen (fname.c_str (), tmode.c_str ());
496 496
497 if (fptr) 497 if (fptr)
498 retval = octave_zstdiostream::create (fname, fptr, md, flt_fmt); 498 retval = octave_zstdiostream::create (fname, fptr, md, flt_fmt);
499 else 499 else
500 { 500 {
501 using namespace std; 501 using namespace std;
502 retval.error (::strerror (errno)); 502 retval.error (::strerror (errno));
503 } 503 }
504 } 504 }
505 else 505 else
506 #endif 506 #endif
507 { 507 {
508 FILE *fptr = ::fopen (fname.c_str (), tmode.c_str ()); 508 FILE *fptr = ::fopen (fname.c_str (), tmode.c_str ());
509 509
510 retval = octave_stdiostream::create (fname, fptr, md, flt_fmt); 510 retval = octave_stdiostream::create (fname, fptr, md, flt_fmt);
511 511
512 if (! fptr) 512 if (! fptr)
513 { 513 {
514 using namespace std; 514 using namespace std;
515 retval.error (::strerror (errno)); 515 retval.error (::strerror (errno));
516 } 516 }
517 } 517 }
518 518
519 } 519 }
520 } 520 }
521 } 521 }
522 522
523 return retval; 523 return retval;
524 } 524 }
525 525
526 static octave_stream 526 static octave_stream
527 do_stream_open (const octave_value& tc_name, const octave_value& tc_mode, 527 do_stream_open (const octave_value& tc_name, const octave_value& tc_mode,
528 const octave_value& tc_arch, const char *fcn, int& fid) 528 const octave_value& tc_arch, const char *fcn, int& fid)
529 { 529 {
530 octave_stream retval; 530 octave_stream retval;
531 531
532 fid = -1; 532 fid = -1;
533 533
536 if (! error_state) 536 if (! error_state)
537 { 537 {
538 std::string mode = tc_mode.string_value (); 538 std::string mode = tc_mode.string_value ();
539 539
540 if (! error_state) 540 if (! error_state)
541 { 541 {
542 std::string arch = tc_arch.string_value (); 542 std::string arch = tc_arch.string_value ();
543 543
544 if (! error_state) 544 if (! error_state)
545 retval = do_stream_open (name, mode, arch, fid); 545 retval = do_stream_open (name, mode, arch, fid);
546 else 546 else
547 ::error ("%s: architecture type must be a string", fcn); 547 ::error ("%s: architecture type must be a string", fcn);
548 } 548 }
549 else 549 else
550 ::error ("%s: file mode must be a string", fcn); 550 ::error ("%s: file mode must be a string", fcn);
551 } 551 }
552 else 552 else
553 ::error ("%s: file name must be a string", fcn); 553 ::error ("%s: file name must be a string", fcn);
554 554
555 return retval; 555 return retval;
664 int nargin = args.length (); 664 int nargin = args.length ();
665 665
666 if (nargin == 1) 666 if (nargin == 1)
667 { 667 {
668 if (args(0).is_string ()) 668 if (args(0).is_string ())
669 { 669 {
670 // If there is only one argument and it is a string but it 670 // If there is only one argument and it is a string but it
671 // is not the string "all", we assume it is a file to open 671 // is not the string "all", we assume it is a file to open
672 // with MODE = "r". To open a file called "all", you have 672 // with MODE = "r". To open a file called "all", you have
673 // to supply more than one argument. 673 // to supply more than one argument.
674 674
675 if (args(0).string_value () == "all") 675 if (args(0).string_value () == "all")
676 return octave_stream_list::open_file_numbers (); 676 return octave_stream_list::open_file_numbers ();
677 } 677 }
678 else 678 else
679 { 679 {
680 string_vector tmp = octave_stream_list::get_info (args(0)); 680 string_vector tmp = octave_stream_list::get_info (args(0));
681 681
682 if (! error_state) 682 if (! error_state)
683 { 683 {
684 retval(2) = tmp(2); 684 retval(2) = tmp(2);
685 retval(1) = tmp(1); 685 retval(1) = tmp(1);
686 retval(0) = tmp(0); 686 retval(0) = tmp(0);
687 } 687 }
688 688
689 return retval; 689 return retval;
690 } 690 }
691 } 691 }
692 692
693 if (nargin > 0 && nargin < 4) 693 if (nargin > 0 && nargin < 4)
694 { 694 {
695 octave_value mode = (nargin == 2 || nargin == 3) 695 octave_value mode = (nargin == 2 || nargin == 3)
696 ? args(1) : octave_value ("r"); 696 ? args(1) : octave_value ("r");
697 697
698 octave_value arch = (nargin == 3) 698 octave_value arch = (nargin == 3)
699 ? args(2) : octave_value ("native"); 699 ? args(2) : octave_value ("native");
700 700
701 int fid = -1; 701 int fid = -1;
702 702
703 octave_stream os = do_stream_open (args(0), mode, arch, "fopen", fid); 703 octave_stream os = do_stream_open (args(0), mode, arch, "fopen", fid);
704 704
705 if (os && ! error_state) 705 if (os && ! error_state)
706 { 706 {
707 retval(1) = ""; 707 retval(1) = "";
708 retval(0) = octave_stream_list::insert (os); 708 retval(0) = octave_stream_list::insert (os);
709 } 709 }
710 else 710 else
711 { 711 {
712 int error_number = 0; 712 int error_number = 0;
713 713
714 retval(1) = os.error (false, error_number); 714 retval(1) = os.error (false, error_number);
715 retval(0) = -1.0; 715 retval(0) = -1.0;
716 } 716 }
717 } 717 }
718 else 718 else
719 print_usage (); 719 print_usage ();
720 720
721 return retval; 721 return retval;
770 if (nargin == 1) 770 if (nargin == 1)
771 { 771 {
772 octave_stream os = octave_stream_list::lookup (args(0), "frewind"); 772 octave_stream os = octave_stream_list::lookup (args(0), "frewind");
773 773
774 if (! error_state) 774 if (! error_state)
775 result = os.rewind (); 775 result = os.rewind ();
776 } 776 }
777 else 777 else
778 print_usage (); 778 print_usage ();
779 779
780 if (nargout > 0) 780 if (nargout > 0)
806 if (nargin == 2 || nargin == 3) 806 if (nargin == 2 || nargin == 3)
807 { 807 {
808 octave_stream os = octave_stream_list::lookup (args(0), "fseek"); 808 octave_stream os = octave_stream_list::lookup (args(0), "fseek");
809 809
810 if (! error_state) 810 if (! error_state)
811 { 811 {
812 octave_value origin_arg = (nargin == 3) 812 octave_value origin_arg = (nargin == 3)
813 ? args(2) : octave_value (-1.0); 813 ? args(2) : octave_value (-1.0);
814 814
815 retval = os.seek (args(1), origin_arg); 815 retval = os.seek (args(1), origin_arg);
816 } 816 }
817 } 817 }
818 else 818 else
819 print_usage (); 819 print_usage ();
820 820
821 return retval; 821 return retval;
836 if (nargin == 1) 836 if (nargin == 1)
837 { 837 {
838 octave_stream os = octave_stream_list::lookup (args(0), "ftell"); 838 octave_stream os = octave_stream_list::lookup (args(0), "ftell");
839 839
840 if (! error_state) 840 if (! error_state)
841 retval = os.tell (); 841 retval = os.tell ();
842 } 842 }
843 else 843 else
844 print_usage (); 844 print_usage ();
845 845
846 return retval; 846 return retval;
867 { 867 {
868 octave_stream os; 868 octave_stream os;
869 int fmt_n = 0; 869 int fmt_n = 0;
870 870
871 if (args(0).is_string ()) 871 if (args(0).is_string ())
872 { 872 {
873 os = octave_stream_list::lookup (1, who); 873 os = octave_stream_list::lookup (1, who);
874 } 874 }
875 else 875 else
876 { 876 {
877 fmt_n = 1; 877 fmt_n = 1;
878 os = octave_stream_list::lookup (args(0), who); 878 os = octave_stream_list::lookup (args(0), who);
879 } 879 }
880 880
881 if (! error_state) 881 if (! error_state)
882 { 882 {
883 if (args(fmt_n).is_string ()) 883 if (args(fmt_n).is_string ())
884 { 884 {
885 octave_value_list tmp_args; 885 octave_value_list tmp_args;
886 886
887 if (nargin > 1 + fmt_n) 887 if (nargin > 1 + fmt_n)
888 { 888 {
889 tmp_args.resize (nargin-fmt_n-1, octave_value ()); 889 tmp_args.resize (nargin-fmt_n-1, octave_value ());
890 890
891 for (int i = fmt_n + 1; i < nargin; i++) 891 for (int i = fmt_n + 1; i < nargin; i++)
892 tmp_args(i-fmt_n-1) = args(i); 892 tmp_args(i-fmt_n-1) = args(i);
893 } 893 }
894 894
895 result = os.printf (args(fmt_n), tmp_args, who); 895 result = os.printf (args(fmt_n), tmp_args, who);
896 } 896 }
897 else 897 else
898 ::error ("%s: format must be a string", who.c_str ()); 898 ::error ("%s: format must be a string", who.c_str ());
899 } 899 }
900 } 900 }
901 else 901 else
902 print_usage (); 902 print_usage ();
903 903
904 if (nargout > 0) 904 if (nargout > 0)
930 int nargin = args.length (); 930 int nargin = args.length ();
931 931
932 if (nargin > 0) 932 if (nargin > 0)
933 { 933 {
934 if (args(0).is_string ()) 934 if (args(0).is_string ())
935 { 935 {
936 octave_value_list tmp_args; 936 octave_value_list tmp_args;
937 937
938 if (nargin > 1) 938 if (nargin > 1)
939 { 939 {
940 tmp_args.resize (nargin-1, octave_value ()); 940 tmp_args.resize (nargin-1, octave_value ());
941 941
942 for (int i = 1; i < nargin; i++) 942 for (int i = 1; i < nargin; i++)
943 tmp_args(i-1) = args(i); 943 tmp_args(i-1) = args(i);
944 } 944 }
945 945
946 result = stdout_stream.printf (args(0), tmp_args, who); 946 result = stdout_stream.printf (args(0), tmp_args, who);
947 } 947 }
948 else 948 else
949 ::error ("%s: format must be a string", who.c_str ()); 949 ::error ("%s: format must be a string", who.c_str ());
950 } 950 }
951 else 951 else
952 print_usage (); 952 print_usage ();
953 953
954 if (nargout > 0) 954 if (nargout > 0)
975 if (nargin == 2) 975 if (nargin == 2)
976 { 976 {
977 octave_stream os = octave_stream_list::lookup (args(0), who); 977 octave_stream os = octave_stream_list::lookup (args(0), who);
978 978
979 if (! error_state) 979 if (! error_state)
980 retval = os.puts (args(1), who); 980 retval = os.puts (args(1), who);
981 } 981 }
982 else 982 else
983 print_usage (); 983 print_usage ();
984 984
985 return retval; 985 return retval;
1031 octave_ostrstream *ostr = new octave_ostrstream (); 1031 octave_ostrstream *ostr = new octave_ostrstream ();
1032 1032
1033 octave_stream os (ostr); 1033 octave_stream os (ostr);
1034 1034
1035 if (os.is_valid ()) 1035 if (os.is_valid ())
1036 { 1036 {
1037 octave_value fmt_arg = args(0); 1037 octave_value fmt_arg = args(0);
1038 1038
1039 if (fmt_arg.is_string ()) 1039 if (fmt_arg.is_string ())
1040 { 1040 {
1041 octave_value_list tmp_args; 1041 octave_value_list tmp_args;
1042 1042
1043 if (nargin > 1) 1043 if (nargin > 1)
1044 { 1044 {
1045 tmp_args.resize (nargin-1, octave_value ()); 1045 tmp_args.resize (nargin-1, octave_value ());
1046 1046
1047 for (int i = 1; i < nargin; i++) 1047 for (int i = 1; i < nargin; i++)
1048 tmp_args(i-1) = args(i); 1048 tmp_args(i-1) = args(i);
1049 } 1049 }
1050 1050
1051 retval(2) = os.printf (fmt_arg, tmp_args, who); 1051 retval(2) = os.printf (fmt_arg, tmp_args, who);
1052 retval(1) = os.error (); 1052 retval(1) = os.error ();
1053 retval(0) = octave_value (ostr->str (), 1053 retval(0) = octave_value (ostr->str (),
1054 fmt_arg.is_sq_string () ? '\'' : '"'); 1054 fmt_arg.is_sq_string () ? '\'' : '"');
1055 } 1055 }
1056 else 1056 else
1057 ::error ("%s: format must be a string", who.c_str ()); 1057 ::error ("%s: format must be a string", who.c_str ());
1058 } 1058 }
1059 else 1059 else
1060 ::error ("%s: unable to create output buffer", who.c_str ()); 1060 ::error ("%s: unable to create output buffer", who.c_str ());
1061 } 1061 }
1062 else 1062 else
1063 print_usage (); 1063 print_usage ();
1064 1064
1065 return retval; 1065 return retval;
1123 if (nargin == 3 && args(2).is_string ()) 1123 if (nargin == 3 && args(2).is_string ())
1124 { 1124 {
1125 octave_stream os = octave_stream_list::lookup (args(0), who); 1125 octave_stream os = octave_stream_list::lookup (args(0), who);
1126 1126
1127 if (! error_state) 1127 if (! error_state)
1128 { 1128 {
1129 if (args(1).is_string ()) 1129 if (args(1).is_string ())
1130 retval = os.oscanf (args(1), who); 1130 retval = os.oscanf (args(1), who);
1131 else 1131 else
1132 ::error ("%s: format must be a string", who.c_str ()); 1132 ::error ("%s: format must be a string", who.c_str ());
1133 } 1133 }
1134 } 1134 }
1135 else 1135 else
1136 { 1136 {
1137 retval (1) = 0.0; 1137 retval (1) = 0.0;
1138 retval (0) = Matrix (); 1138 retval (0) = Matrix ();
1139 1139
1140 if (nargin == 2 || nargin == 3) 1140 if (nargin == 2 || nargin == 3)
1141 { 1141 {
1142 octave_stream os = octave_stream_list::lookup (args(0), who); 1142 octave_stream os = octave_stream_list::lookup (args(0), who);
1143 1143
1144 if (! error_state) 1144 if (! error_state)
1145 { 1145 {
1146 if (args(1).is_string ()) 1146 if (args(1).is_string ())
1147 { 1147 {
1148 octave_idx_type count = 0; 1148 octave_idx_type count = 0;
1149 1149
1150 Array<double> size = (nargin == 3) 1150 Array<double> size = (nargin == 3)
1151 ? args(2).vector_value () 1151 ? args(2).vector_value ()
1152 : Array<double> (1, lo_ieee_inf_value ()); 1152 : Array<double> (1, lo_ieee_inf_value ());
1153 1153
1154 if (! error_state) 1154 if (! error_state)
1155 { 1155 {
1156 octave_value tmp = os.scanf (args(1), size, count, who); 1156 octave_value tmp = os.scanf (args(1), size, count, who);
1157 1157
1158 if (! error_state) 1158 if (! error_state)
1159 { 1159 {
1160 retval(1) = count; 1160 retval(1) = count;
1161 retval(0) = tmp; 1161 retval(0) = tmp;
1162 } 1162 }
1163 } 1163 }
1164 } 1164 }
1165 else 1165 else
1166 ::error ("%s: format must be a string", who.c_str ()); 1166 ::error ("%s: format must be a string", who.c_str ());
1167 } 1167 }
1168 } 1168 }
1169 else 1169 else
1170 print_usage (); 1170 print_usage ();
1171 } 1171 }
1172 1172
1173 return retval; 1173 return retval;
1174 } 1174 }
1175 1175
1190 int nargin = args.length (); 1190 int nargin = args.length ();
1191 1191
1192 if (nargin == 3 && args(2).is_string ()) 1192 if (nargin == 3 && args(2).is_string ())
1193 { 1193 {
1194 if (args(0).is_string ()) 1194 if (args(0).is_string ())
1195 { 1195 {
1196 std::string data = args(0).string_value (); 1196 std::string data = args(0).string_value ();
1197 1197
1198 octave_stream os = octave_istrstream::create (data); 1198 octave_stream os = octave_istrstream::create (data);
1199 1199
1200 if (os.is_valid ()) 1200 if (os.is_valid ())
1201 { 1201 {
1202 if (args(1).is_string ()) 1202 if (args(1).is_string ())
1203 retval = os.oscanf (args(1), who); 1203 retval = os.oscanf (args(1), who);
1204 else 1204 else
1205 ::error ("%s: format must be a string", who.c_str ()); 1205 ::error ("%s: format must be a string", who.c_str ());
1206 } 1206 }
1207 else 1207 else
1208 ::error ("%s: unable to create temporary input buffer", 1208 ::error ("%s: unable to create temporary input buffer",
1209 who.c_str ()); 1209 who.c_str ());
1210 } 1210 }
1211 else 1211 else
1212 ::error ("%s: first argument must be a string", who.c_str ()); 1212 ::error ("%s: first argument must be a string", who.c_str ());
1213 } 1213 }
1214 else 1214 else
1215 { 1215 {
1216 if (nargin == 2 || nargin == 3) 1216 if (nargin == 2 || nargin == 3)
1217 { 1217 {
1218 retval(3) = -1.0; 1218 retval(3) = -1.0;
1219 retval(2) = "unknown error"; 1219 retval(2) = "unknown error";
1220 retval(1) = 0.0; 1220 retval(1) = 0.0;
1221 retval(0) = Matrix (); 1221 retval(0) = Matrix ();
1222 1222
1223 if (args(0).is_string ()) 1223 if (args(0).is_string ())
1224 { 1224 {
1225 std::string data = args(0).string_value (); 1225 std::string data = args(0).string_value ();
1226 1226
1227 octave_stream os = octave_istrstream::create (data); 1227 octave_stream os = octave_istrstream::create (data);
1228 1228
1229 if (os.is_valid ()) 1229 if (os.is_valid ())
1230 { 1230 {
1231 if (args(1).is_string ()) 1231 if (args(1).is_string ())
1232 { 1232 {
1233 octave_idx_type count = 0; 1233 octave_idx_type count = 0;
1234 1234
1235 Array<double> size = (nargin == 3) 1235 Array<double> size = (nargin == 3)
1236 ? args(2).vector_value () 1236 ? args(2).vector_value ()
1237 : Array<double> (1, lo_ieee_inf_value ()); 1237 : Array<double> (1, lo_ieee_inf_value ());
1238 1238
1239 octave_value tmp = os.scanf (args(1), size, count, who); 1239 octave_value tmp = os.scanf (args(1), size, count, who);
1240 1240
1241 if (! error_state) 1241 if (! error_state)
1242 { 1242 {
1243 // FIXME -- is this the right thing to do? 1243 // FIXME -- is this the right thing to do?
1244 // Extract error message first, because getting 1244 // Extract error message first, because getting
1245 // position will clear it. 1245 // position will clear it.
1246 std::string errmsg = os.error (); 1246 std::string errmsg = os.error ();
1247 1247
1248 retval(3) = os.tell () + 1; 1248 retval(3) = os.tell () + 1;
1249 retval(2) = errmsg; 1249 retval(2) = errmsg;
1250 retval(1) = count; 1250 retval(1) = count;
1251 retval(0) = tmp; 1251 retval(0) = tmp;
1252 } 1252 }
1253 } 1253 }
1254 else 1254 else
1255 ::error ("%s: format must be a string", who.c_str ()); 1255 ::error ("%s: format must be a string", who.c_str ());
1256 } 1256 }
1257 else 1257 else
1258 ::error ("%s: unable to create temporary input buffer", 1258 ::error ("%s: unable to create temporary input buffer",
1259 who.c_str ()); 1259 who.c_str ());
1260 } 1260 }
1261 else 1261 else
1262 ::error ("%s: first argument must be a string", who.c_str ()); 1262 ::error ("%s: first argument must be a string", who.c_str ());
1263 } 1263 }
1264 else 1264 else
1265 print_usage (); 1265 print_usage ();
1266 } 1266 }
1267 1267
1268 return retval; 1268 return retval;
1269 } 1269 }
1270 1270
1290 return Ffscanf (tmp_args, nargout); 1290 return Ffscanf (tmp_args, nargout);
1291 } 1291 }
1292 1292
1293 static octave_value 1293 static octave_value
1294 do_fread (octave_stream& os, const octave_value& size_arg, 1294 do_fread (octave_stream& os, const octave_value& size_arg,
1295 const octave_value& prec_arg, const octave_value& skip_arg, 1295 const octave_value& prec_arg, const octave_value& skip_arg,
1296 const octave_value& arch_arg, octave_idx_type& count) 1296 const octave_value& arch_arg, octave_idx_type& count)
1297 { 1297 {
1298 octave_value retval; 1298 octave_value retval;
1299 1299
1300 count = -1; 1300 count = -1;
1301 1301
1304 if (! error_state) 1304 if (! error_state)
1305 { 1305 {
1306 std::string prec = prec_arg.string_value (); 1306 std::string prec = prec_arg.string_value ();
1307 1307
1308 if (! error_state) 1308 if (! error_state)
1309 { 1309 {
1310 int block_size = 1; 1310 int block_size = 1;
1311 oct_data_conv::data_type input_type; 1311 oct_data_conv::data_type input_type;
1312 oct_data_conv::data_type output_type; 1312 oct_data_conv::data_type output_type;
1313 1313
1314 oct_data_conv::string_to_data_type (prec, block_size, 1314 oct_data_conv::string_to_data_type (prec, block_size,
1315 input_type, output_type); 1315 input_type, output_type);
1316 1316
1317 if (! error_state) 1317 if (! error_state)
1318 { 1318 {
1319 int skip = skip_arg.int_value (true); 1319 int skip = skip_arg.int_value (true);
1320 1320
1321 if (! error_state) 1321 if (! error_state)
1322 { 1322 {
1323 std::string arch = arch_arg.string_value (); 1323 std::string arch = arch_arg.string_value ();
1324 1324
1325 if (! error_state) 1325 if (! error_state)
1326 { 1326 {
1327 oct_mach_info::float_format flt_fmt 1327 oct_mach_info::float_format flt_fmt
1328 = oct_mach_info::string_to_float_format (arch); 1328 = oct_mach_info::string_to_float_format (arch);
1329 1329
1330 if (! error_state) 1330 if (! error_state)
1331 retval = os.read (size, block_size, input_type, 1331 retval = os.read (size, block_size, input_type,
1332 output_type, skip, flt_fmt, count); 1332 output_type, skip, flt_fmt, count);
1333 } 1333 }
1334 else 1334 else
1335 ::error ("fread: architecture type must be a string"); 1335 ::error ("fread: architecture type must be a string");
1336 } 1336 }
1337 else 1337 else
1338 ::error ("fread: skip must be an integer"); 1338 ::error ("fread: skip must be an integer");
1339 } 1339 }
1340 else 1340 else
1341 ::error ("fread: invalid data type specified"); 1341 ::error ("fread: invalid data type specified");
1342 } 1342 }
1343 else 1343 else
1344 ::error ("fread: precision must be a string"); 1344 ::error ("fread: precision must be a string");
1345 } 1345 }
1346 else 1346 else
1347 ::error ("fread: invalid size specified"); 1347 ::error ("fread: invalid size specified");
1348 1348
1349 return retval; 1349 return retval;
1534 retval(0) = Matrix (); 1534 retval(0) = Matrix ();
1535 1535
1536 octave_stream os = octave_stream_list::lookup (args(0), "fread"); 1536 octave_stream os = octave_stream_list::lookup (args(0), "fread");
1537 1537
1538 if (! error_state) 1538 if (! error_state)
1539 { 1539 {
1540 octave_value size = lo_ieee_inf_value (); 1540 octave_value size = lo_ieee_inf_value ();
1541 octave_value prec = "uchar"; 1541 octave_value prec = "uchar";
1542 octave_value skip = 0; 1542 octave_value skip = 0;
1543 octave_value arch = "unknown"; 1543 octave_value arch = "unknown";
1544 1544
1545 int idx = 1; 1545 int idx = 1;
1546 1546
1547 if (nargin > idx && ! args(idx).is_string ()) 1547 if (nargin > idx && ! args(idx).is_string ())
1548 size = args(idx++); 1548 size = args(idx++);
1549 1549
1550 if (nargin > idx) 1550 if (nargin > idx)
1551 prec = args(idx++); 1551 prec = args(idx++);
1552 1552
1553 if (nargin > idx) 1553 if (nargin > idx)
1554 skip = args(idx++); 1554 skip = args(idx++);
1555 1555
1556 if (nargin > idx) 1556 if (nargin > idx)
1557 arch = args(idx++); 1557 arch = args(idx++);
1558 else if (skip.is_string ()) 1558 else if (skip.is_string ())
1559 { 1559 {
1560 arch = skip; 1560 arch = skip;
1561 skip = 0; 1561 skip = 0;
1562 } 1562 }
1563 1563
1564 octave_idx_type count = -1; 1564 octave_idx_type count = -1;
1565 1565
1566 octave_value tmp = do_fread (os, size, prec, skip, arch, count); 1566 octave_value tmp = do_fread (os, size, prec, skip, arch, count);
1567 1567
1568 retval(1) = count; 1568 retval(1) = count;
1569 retval(0) = tmp; 1569 retval(0) = tmp;
1570 } 1570 }
1571 } 1571 }
1572 else 1572 else
1573 print_usage (); 1573 print_usage ();
1574 1574
1575 return retval; 1575 return retval;
1576 } 1576 }
1577 1577
1578 static int 1578 static int
1579 do_fwrite (octave_stream& os, const octave_value& data, 1579 do_fwrite (octave_stream& os, const octave_value& data,
1580 const octave_value& prec_arg, const octave_value& skip_arg, 1580 const octave_value& prec_arg, const octave_value& skip_arg,
1581 const octave_value& arch_arg) 1581 const octave_value& arch_arg)
1582 { 1582 {
1583 int retval = -1; 1583 int retval = -1;
1584 1584
1585 std::string prec = prec_arg.string_value (); 1585 std::string prec = prec_arg.string_value ();
1586 1586
1590 oct_data_conv::data_type output_type; 1590 oct_data_conv::data_type output_type;
1591 1591
1592 oct_data_conv::string_to_data_type (prec, block_size, output_type); 1592 oct_data_conv::string_to_data_type (prec, block_size, output_type);
1593 1593
1594 if (! error_state) 1594 if (! error_state)
1595 { 1595 {
1596 int skip = skip_arg.int_value (true); 1596 int skip = skip_arg.int_value (true);
1597 1597
1598 if (! error_state) 1598 if (! error_state)
1599 { 1599 {
1600 std::string arch = arch_arg.string_value (); 1600 std::string arch = arch_arg.string_value ();
1601 1601
1602 if (! error_state) 1602 if (! error_state)
1603 { 1603 {
1604 oct_mach_info::float_format flt_fmt 1604 oct_mach_info::float_format flt_fmt
1605 = oct_mach_info::string_to_float_format (arch); 1605 = oct_mach_info::string_to_float_format (arch);
1606 1606
1607 if (! error_state) 1607 if (! error_state)
1608 retval = os.write (data, block_size, output_type, 1608 retval = os.write (data, block_size, output_type,
1609 skip, flt_fmt); 1609 skip, flt_fmt);
1610 } 1610 }
1611 else 1611 else
1612 ::error ("fwrite: architecture type must be a string"); 1612 ::error ("fwrite: architecture type must be a string");
1613 } 1613 }
1614 else 1614 else
1615 ::error ("fwrite: skip must be an integer"); 1615 ::error ("fwrite: skip must be an integer");
1616 } 1616 }
1617 else 1617 else
1618 ::error ("fwrite: invalid precision specified"); 1618 ::error ("fwrite: invalid precision specified");
1619 } 1619 }
1620 else 1620 else
1621 ::error ("fwrite: precision must be a string"); 1621 ::error ("fwrite: precision must be a string");
1622 1622
1623 return retval; 1623 return retval;
1648 if (nargin > 1 && nargin < 6) 1648 if (nargin > 1 && nargin < 6)
1649 { 1649 {
1650 octave_stream os = octave_stream_list::lookup (args(0), "fwrite"); 1650 octave_stream os = octave_stream_list::lookup (args(0), "fwrite");
1651 1651
1652 if (! error_state) 1652 if (! error_state)
1653 { 1653 {
1654 octave_value prec = "uchar"; 1654 octave_value prec = "uchar";
1655 octave_value skip = 0; 1655 octave_value skip = 0;
1656 octave_value arch = "unknown"; 1656 octave_value arch = "unknown";
1657 1657
1658 int idx = 1; 1658 int idx = 1;
1659 1659
1660 octave_value data = args(idx++); 1660 octave_value data = args(idx++);
1661 1661
1662 if (nargin > idx) 1662 if (nargin > idx)
1663 prec = args(idx++); 1663 prec = args(idx++);
1664 1664
1665 if (nargin > idx) 1665 if (nargin > idx)
1666 skip = args(idx++); 1666 skip = args(idx++);
1667 1667
1668 if (nargin > idx) 1668 if (nargin > idx)
1669 arch = args(idx++); 1669 arch = args(idx++);
1670 else if (skip.is_string ()) 1670 else if (skip.is_string ())
1671 { 1671 {
1672 arch = skip; 1672 arch = skip;
1673 skip = 0; 1673 skip = 0;
1674 } 1674 }
1675 1675
1676 double status = do_fwrite (os, data, prec, skip, arch); 1676 double status = do_fwrite (os, data, prec, skip, arch);
1677 1677
1678 retval = status; 1678 retval = status;
1679 } 1679 }
1680 } 1680 }
1681 else 1681 else
1682 print_usage (); 1682 print_usage ();
1683 1683
1684 return retval; 1684 return retval;
1701 if (nargin == 1) 1701 if (nargin == 1)
1702 { 1702 {
1703 octave_stream os = octave_stream_list::lookup (args(0), "feof"); 1703 octave_stream os = octave_stream_list::lookup (args(0), "feof");
1704 1704
1705 if (! error_state) 1705 if (! error_state)
1706 retval = os.eof () ? 1.0 : 0.0; 1706 retval = os.eof () ? 1.0 : 0.0;
1707 } 1707 }
1708 else 1708 else
1709 print_usage (); 1709 print_usage ();
1710 1710
1711 return retval; 1711 return retval;
1730 if (nargin == 1 || nargin == 2) 1730 if (nargin == 1 || nargin == 2)
1731 { 1731 {
1732 octave_stream os = octave_stream_list::lookup (args(0), "ferror"); 1732 octave_stream os = octave_stream_list::lookup (args(0), "ferror");
1733 1733
1734 if (! error_state) 1734 if (! error_state)
1735 { 1735 {
1736 bool clear = false; 1736 bool clear = false;
1737 1737
1738 if (nargin == 2) 1738 if (nargin == 2)
1739 { 1739 {
1740 std::string opt = args(1).string_value (); 1740 std::string opt = args(1).string_value ();
1741 1741
1742 if (! error_state) 1742 if (! error_state)
1743 clear = (opt == "clear"); 1743 clear = (opt == "clear");
1744 else 1744 else
1745 return retval; 1745 return retval;
1746 } 1746 }
1747 1747
1748 int error_number = 0; 1748 int error_number = 0;
1749 1749
1750 std::string error_message = os.error (clear, error_number); 1750 std::string error_message = os.error (clear, error_number);
1751 1751
1752 retval(1) = error_number; 1752 retval(1) = error_number;
1753 retval(0) = error_message; 1753 retval(0) = error_message;
1754 } 1754 }
1755 } 1755 }
1756 else 1756 else
1757 print_usage (); 1757 print_usage ();
1758 1758
1759 return retval; 1759 return retval;
1799 if (nargin == 2) 1799 if (nargin == 2)
1800 { 1800 {
1801 std::string name = args(0).string_value (); 1801 std::string name = args(0).string_value ();
1802 1802
1803 if (! error_state) 1803 if (! error_state)
1804 { 1804 {
1805 std::string mode = args(1).string_value (); 1805 std::string mode = args(1).string_value ();
1806 1806
1807 if (! error_state) 1807 if (! error_state)
1808 { 1808 {
1809 if (mode == "r") 1809 if (mode == "r")
1810 { 1810 {
1811 octave_stream ips = octave_iprocstream::create (name); 1811 octave_stream ips = octave_iprocstream::create (name);
1812 1812
1813 retval = octave_stream_list::insert (ips); 1813 retval = octave_stream_list::insert (ips);
1814 } 1814 }
1815 else if (mode == "w") 1815 else if (mode == "w")
1816 { 1816 {
1817 octave_stream ops = octave_oprocstream::create (name); 1817 octave_stream ops = octave_oprocstream::create (name);
1818 1818
1819 retval = octave_stream_list::insert (ops); 1819 retval = octave_stream_list::insert (ops);
1820 } 1820 }
1821 else 1821 else
1822 ::error ("popen: invalid mode specified"); 1822 ::error ("popen: invalid mode specified");
1823 } 1823 }
1824 else 1824 else
1825 ::error ("popen: mode must be a string"); 1825 ::error ("popen: mode must be a string");
1826 } 1826 }
1827 else 1827 else
1828 ::error ("popen: name must be a string"); 1828 ::error ("popen: name must be a string");
1829 } 1829 }
1830 else 1830 else
1831 print_usage (); 1831 print_usage ();
1832 1832
1833 return retval; 1833 return retval;
1873 if (len < 3) 1873 if (len < 3)
1874 { 1874 {
1875 std::string dir = len > 0 ? args(0).string_value () : std::string (); 1875 std::string dir = len > 0 ? args(0).string_value () : std::string ();
1876 1876
1877 if (! error_state) 1877 if (! error_state)
1878 { 1878 {
1879 std::string pfx 1879 std::string pfx
1880 = len > 1 ? args(1).string_value () : std::string ("oct-"); 1880 = len > 1 ? args(1).string_value () : std::string ("oct-");
1881 1881
1882 if (! error_state) 1882 if (! error_state)
1883 retval = octave_tempnam (dir, pfx); 1883 retval = octave_tempnam (dir, pfx);
1884 else 1884 else
1885 ::error ("expecting second argument to be a string"); 1885 ::error ("expecting second argument to be a string");
1886 } 1886 }
1887 else 1887 else
1888 ::error ("expecting first argument to be a string"); 1888 ::error ("expecting first argument to be a string");
1889 } 1889 }
1890 else 1890 else
1891 print_usage (); 1891 print_usage ();
1892 1892
1893 return retval; 1893 return retval;
1919 if (nargin == 0) 1919 if (nargin == 0)
1920 { 1920 {
1921 FILE *fid = tmpfile (); 1921 FILE *fid = tmpfile ();
1922 1922
1923 if (fid) 1923 if (fid)
1924 { 1924 {
1925 std::string nm; 1925 std::string nm;
1926 1926
1927 std::ios::openmode md = fopen_mode_to_ios_mode ("w+b"); 1927 std::ios::openmode md = fopen_mode_to_ios_mode ("w+b");
1928 1928
1929 octave_stream s = octave_stdiostream::create (nm, fid, md); 1929 octave_stream s = octave_stdiostream::create (nm, fid, md);
1930 1930
1931 if (s) 1931 if (s)
1932 retval(0) = octave_stream_list::insert (s); 1932 retval(0) = octave_stream_list::insert (s);
1933 else 1933 else
1934 error ("tmpfile: failed to create octave_stdiostream object"); 1934 error ("tmpfile: failed to create octave_stdiostream object");
1935 1935
1936 } 1936 }
1937 else 1937 else
1938 { 1938 {
1939 using namespace std; 1939 using namespace std;
1940 retval(1) = ::strerror (errno); 1940 retval(1) = ::strerror (errno);
1941 retval(0) = -1; 1941 retval(0) = -1;
1942 } 1942 }
1943 } 1943 }
1944 else 1944 else
1945 print_usage (); 1945 print_usage ();
1946 1946
1947 return retval; 1947 return retval;
1958 int mkstemp (char *tmpl) 1958 int mkstemp (char *tmpl)
1959 { 1959 {
1960 int ret=-1; 1960 int ret=-1;
1961 mktemp (tmpl); 1961 mktemp (tmpl);
1962 ret = open (tmpl, O_RDWR | O_BINARY | O_CREAT | O_EXCL | _O_SHORT_LIVED, 1962 ret = open (tmpl, O_RDWR | O_BINARY | O_CREAT | O_EXCL | _O_SHORT_LIVED,
1963 _S_IREAD | _S_IWRITE); 1963 _S_IREAD | _S_IWRITE);
1964 return ret; 1964 return ret;
1965 } 1965 }
1966 #define HAVE_MKSTEMP 1 1966 #define HAVE_MKSTEMP 1
1967 #endif 1967 #endif
1968 1968
2001 if (nargin == 1 || nargin == 2) 2001 if (nargin == 1 || nargin == 2)
2002 { 2002 {
2003 std::string tmpl8 = args(0).string_value (); 2003 std::string tmpl8 = args(0).string_value ();
2004 2004
2005 if (! error_state) 2005 if (! error_state)
2006 { 2006 {
2007 OCTAVE_LOCAL_BUFFER (char, tmp, tmpl8.size () + 1); 2007 OCTAVE_LOCAL_BUFFER (char, tmp, tmpl8.size () + 1);
2008 strcpy (tmp, tmpl8.c_str ()); 2008 strcpy (tmp, tmpl8.c_str ());
2009 2009
2010 #if defined (HAVE_MKSTEMP) 2010 #if defined (HAVE_MKSTEMP)
2011 int fd = mkstemp (tmp); 2011 int fd = mkstemp (tmp);
2012 #else 2012 #else
2013 int fd = mkstemps (tmp, 0); 2013 int fd = mkstemps (tmp, 0);
2014 #endif 2014 #endif
2015 2015
2016 if (fd < 0) 2016 if (fd < 0)
2017 { 2017 {
2018 using namespace std; 2018 using namespace std;
2019 retval(2) = ::strerror (errno); 2019 retval(2) = ::strerror (errno);
2020 retval(0) = fd; 2020 retval(0) = fd;
2021 } 2021 }
2022 else 2022 else
2023 { 2023 {
2024 const char *fopen_mode = "w+"; 2024 const char *fopen_mode = "w+";
2025 2025
2026 FILE *fid = fdopen (fd, fopen_mode); 2026 FILE *fid = fdopen (fd, fopen_mode);
2027 2027
2028 if (fid) 2028 if (fid)
2029 { 2029 {
2030 std::string nm = tmp; 2030 std::string nm = tmp;
2031 2031
2032 std::ios::openmode md = fopen_mode_to_ios_mode (fopen_mode); 2032 std::ios::openmode md = fopen_mode_to_ios_mode (fopen_mode);
2033 2033
2034 octave_stream s = octave_stdiostream::create (nm, fid, md); 2034 octave_stream s = octave_stdiostream::create (nm, fid, md);
2035 2035
2036 if (s) 2036 if (s)
2037 { 2037 {
2038 retval(1) = nm; 2038 retval(1) = nm;
2039 retval(0) = octave_stream_list::insert (s); 2039 retval(0) = octave_stream_list::insert (s);
2040 2040
2041 if (nargin == 2 && args(1).is_true ()) 2041 if (nargin == 2 && args(1).is_true ())
2042 mark_for_deletion (nm); 2042 mark_for_deletion (nm);
2043 } 2043 }
2044 else 2044 else
2045 error ("mkstemp: failed to create octave_stdiostream object"); 2045 error ("mkstemp: failed to create octave_stdiostream object");
2046 } 2046 }
2047 else 2047 else
2048 { 2048 {
2049 using namespace std; 2049 using namespace std;
2050 retval(2) = ::strerror (errno); 2050 retval(2) = ::strerror (errno);
2051 retval(0) = -1; 2051 retval(0) = -1;
2052 } 2052 }
2053 } 2053 }
2054 } 2054 }
2055 else 2055 else
2056 error ("mkstemp: expecting string as first argument"); 2056 error ("mkstemp: expecting string as first argument");
2057 } 2057 }
2058 else 2058 else
2059 print_usage (); 2059 print_usage ();
2060 2060
2061 #else 2061 #else
2077 else 2077 else
2078 { 2078 {
2079 retval = tmp; 2079 retval = tmp;
2080 int mult = ibase; 2080 int mult = ibase;
2081 while ((x = (x - tmp) / obase)) 2081 while ((x = (x - tmp) / obase))
2082 { 2082 {
2083 tmp = x % obase; 2083 tmp = x % obase;
2084 if (tmp > ibase - 1) 2084 if (tmp > ibase - 1)
2085 { 2085 {
2086 ::error ("umask: invalid digit"); 2086 ::error ("umask: invalid digit");
2087 break; 2087 break;
2088 } 2088 }
2089 retval += mult * tmp; 2089 retval += mult * tmp;
2090 mult *= ibase; 2090 mult *= ibase;
2091 } 2091 }
2092 } 2092 }
2093 2093
2094 return retval; 2094 return retval;
2095 } 2095 }
2096 2096
2110 if (args.length () == 1) 2110 if (args.length () == 1)
2111 { 2111 {
2112 int mask = args(0).int_value (true); 2112 int mask = args(0).int_value (true);
2113 2113
2114 if (! error_state) 2114 if (! error_state)
2115 { 2115 {
2116 if (mask < 0) 2116 if (mask < 0)
2117 { 2117 {
2118 status = -1; 2118 status = -1;
2119 ::error ("umask: MASK must be a positive integer value"); 2119 ::error ("umask: MASK must be a positive integer value");
2120 } 2120 }
2121 else 2121 else
2122 { 2122 {
2123 int oct_mask = convert (mask, 8, 10); 2123 int oct_mask = convert (mask, 8, 10);
2124 2124
2125 if (! error_state) 2125 if (! error_state)
2126 status = convert (octave_umask (oct_mask), 10, 8); 2126 status = convert (octave_umask (oct_mask), 10, 8);
2127 } 2127 }
2128 } 2128 }
2129 else 2129 else
2130 { 2130 {
2131 status = -1; 2131 status = -1;
2132 ::error ("umask: expecting integer argument"); 2132 ::error ("umask: expecting integer argument");
2133 } 2133 }
2134 } 2134 }
2135 else 2135 else
2136 print_usage (); 2136 print_usage ();
2137 2137
2138 if (status >= 0) 2138 if (status >= 0)
2222 return const_value ("SEEK_END", args, 1); 2222 return const_value ("SEEK_END", args, 1);
2223 } 2223 }
2224 2224
2225 static octave_value 2225 static octave_value
2226 const_value (const char *, const octave_value_list& args, 2226 const_value (const char *, const octave_value_list& args,
2227 const octave_value& val) 2227 const octave_value& val)
2228 { 2228 {
2229 octave_value retval; 2229 octave_value retval;
2230 2230
2231 int nargin = args.length (); 2231 int nargin = args.length ();
2232 2232