comparison libinterp/corefcn/file-io.cc @ 29961:7d6709900da7

eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more Files affected: __betainc__.cc, __contourc__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc, __ichol__.cc, __ilu__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, balance.cc, besselj.cc, bsxfun.cc, call-stack.cc, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, defaults.cc, dirfns.cc, display.cc, dlmread.cc, dmperm.cc, dot.cc, eig.cc, ellipj.cc, environment.cc, error.cc, event-manager.cc, fft.cc, fft2.cc, fftn.cc, file-io.cc, find.cc, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, gsvd.cc, hash.cc, help.cc, hess.cc, hex2num.cc, input.cc, inv.cc, jsondecode.cc, jsonencode.cc, load-path.cc, load-save.cc, lookup.cc, lsode.cc, lu.cc, max.cc, mgorth.cc, oct-hist.cc, ordqz.cc, ordschur.cc, pager.cc, pr-output.cc, psi.cc, qr.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, regexp.cc, schur.cc, settings.cc, sighandlers.cc, sparse.cc, spparms.cc, sqrtm.cc, stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, symbfact.cc, symtab.cc, syscalls.cc, sysdep.cc, time.cc, toplev.cc, tril.cc, typecast.cc, urlwrite.cc, utils.cc, variables.cc, __delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc, audioread.cc, convhulln.cc, fftw.cc, gzip.cc, ov-cell.cc, ov-class.cc, ov-classdef.cc, ov-fcn-handle.cc, ov-struct.cc, ov-typeinfo.cc, ov-usr-fcn.cc, octave.cc, lex.ll, oct-parse.yy, profiler.cc, andpt-eval.cc.
author John W. Eaton <jwe@octave.org>
date Sat, 14 Aug 2021 22:48:52 -0400
parents 32c3a5805893
children 3988112c7116
comparison
equal deleted inserted replaced
29960:939bef0b66e0 29961:7d6709900da7
190 @end deftypefn */) 190 @end deftypefn */)
191 { 191 {
192 if (args.length () != 1) 192 if (args.length () != 1)
193 print_usage (); 193 print_usage ();
194 194
195 octave::stream_list& streams = interp.get_stream_list (); 195 stream_list& streams = interp.get_stream_list ();
196 196
197 return ovl (streams.remove (args(0), "fclose")); 197 return ovl (streams.remove (args(0), "fclose"));
198 } 198 }
199 199
200 DEFMETHOD (fclear, interp, args, , 200 DEFMETHOD (fclear, interp, args, ,
206 @end deftypefn */) 206 @end deftypefn */)
207 { 207 {
208 if (args.length () != 1) 208 if (args.length () != 1)
209 print_usage (); 209 print_usage ();
210 210
211 octave::stream_list& streams = interp.get_stream_list (); 211 stream_list& streams = interp.get_stream_list ();
212 212
213 int fid = streams.get_file_number (args(0)); 213 int fid = streams.get_file_number (args(0));
214 214
215 octave::stream os = streams.lookup (fid, "fclear"); 215 stream os = streams.lookup (fid, "fclear");
216 216
217 os.clearerr (); 217 os.clearerr ();
218 218
219 return ovl (); 219 return ovl ();
220 } 220 }
237 if (args.length () != 1) 237 if (args.length () != 1)
238 print_usage (); 238 print_usage ();
239 239
240 octave_value retval = -1; 240 octave_value retval = -1;
241 241
242 octave::stream_list& streams = interp.get_stream_list (); 242 stream_list& streams = interp.get_stream_list ();
243 243
244 // FIXME: any way to avoid special case for stdout? 244 // FIXME: any way to avoid special case for stdout?
245 int fid = streams.get_file_number (args(0)); 245 int fid = streams.get_file_number (args(0));
246 246
247 if (fid == 1) 247 if (fid == 1)
248 { 248 {
249 octave::flush_stdout (); 249 flush_stdout ();
250 250
251 retval = 0; 251 retval = 0;
252 } 252 }
253 else 253 else
254 { 254 {
255 octave::stream os = streams.lookup (fid, "fflush"); 255 stream os = streams.lookup (fid, "fflush");
256 256
257 retval = os.flush (); 257 retval = os.flush ();
258 } 258 }
259 259
260 return retval; 260 return retval;
285 int nargin = args.length (); 285 int nargin = args.length ();
286 286
287 if (nargin < 1 || nargin > 2) 287 if (nargin < 1 || nargin > 2)
288 print_usage (); 288 print_usage ();
289 289
290 octave::stream_list& streams = interp.get_stream_list (); 290 stream_list& streams = interp.get_stream_list ();
291 291
292 octave::stream os = streams.lookup (args(0), who); 292 stream os = streams.lookup (args(0), who);
293 293
294 octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); 294 octave_value len_arg = (nargin == 2) ? args(1) : octave_value ();
295 295
296 bool err = false; 296 bool err = false;
297 297
328 int nargin = args.length (); 328 int nargin = args.length ();
329 329
330 if (nargin < 1 || nargin > 2) 330 if (nargin < 1 || nargin > 2)
331 print_usage (); 331 print_usage ();
332 332
333 octave::stream_list& streams = interp.get_stream_list (); 333 stream_list& streams = interp.get_stream_list ();
334 334
335 octave::stream os = streams.lookup (args(0), who); 335 stream os = streams.lookup (args(0), who);
336 336
337 octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); 337 octave_value len_arg = (nargin == 2) ? args(1) : octave_value ();
338 338
339 bool err = false; 339 bool err = false;
340 340
370 int nargin = args.length (); 370 int nargin = args.length ();
371 371
372 if (nargin < 1 || nargin > 2) 372 if (nargin < 1 || nargin > 2)
373 print_usage (); 373 print_usage ();
374 374
375 octave::stream_list& streams = interp.get_stream_list (); 375 stream_list& streams = interp.get_stream_list ();
376 376
377 octave::stream os = streams.lookup (args(0), who); 377 stream os = streams.lookup (args(0), who);
378 378
379 octave_value count_arg = (nargin == 2) ? args(1) : octave_value (); 379 octave_value count_arg = (nargin == 2) ? args(1) : octave_value ();
380 380
381 bool err = false; 381 bool err = false;
382 382
386 return ovl (tmp); 386 return ovl (tmp);
387 else 387 else
388 return ovl (); 388 return ovl ();
389 } 389 }
390 390
391 static octave::stream 391 static stream
392 do_stream_open (const std::string& name, const std::string& mode_arg, 392 do_stream_open (const std::string& name, const std::string& mode_arg,
393 const std::string& arch, std::string encoding, int& fid) 393 const std::string& arch, std::string encoding, int& fid)
394 { 394 {
395 octave::stream retval; 395 stream retval;
396 396
397 fid = -1; 397 fid = -1;
398 398
399 // Valid names for encodings consist of ASCII characters only. 399 // Valid names for encodings consist of ASCII characters only.
400 std::transform (encoding.begin (), encoding.end (), encoding.begin (), 400 std::transform (encoding.begin (), encoding.end (), encoding.begin (),
417 bool use_zlib = false; 417 bool use_zlib = false;
418 normalize_fopen_mode (mode, use_zlib); 418 normalize_fopen_mode (mode, use_zlib);
419 419
420 std::ios::openmode md = fopen_mode_to_ios_mode (mode); 420 std::ios::openmode md = fopen_mode_to_ios_mode (mode);
421 421
422 octave::mach_info::float_format flt_fmt 422 mach_info::float_format flt_fmt
423 = octave::mach_info::string_to_float_format (arch); 423 = mach_info::string_to_float_format (arch);
424 424
425 std::string fname = octave::sys::file_ops::tilde_expand (name); 425 std::string fname = sys::file_ops::tilde_expand (name);
426 426
427 octave::sys::file_stat fs (fname); 427 sys::file_stat fs (fname);
428 428
429 if (! (md & std::ios::out)) 429 if (! (md & std::ios::out))
430 fname = octave::find_data_file_in_load_path ("fopen", fname); 430 fname = find_data_file_in_load_path ("fopen", fname);
431 431
432 if (! fs.is_dir ()) 432 if (! fs.is_dir ())
433 { 433 {
434 #if defined (HAVE_ZLIB) 434 #if defined (HAVE_ZLIB)
435 if (use_zlib) 435 if (use_zlib)
436 { 436 {
437 FILE *fptr = octave::sys::fopen (fname.c_str (), mode.c_str ()); 437 FILE *fptr = sys::fopen (fname.c_str (), mode.c_str ());
438 438
439 if (fptr) 439 if (fptr)
440 { 440 {
441 int fd = fileno (fptr); 441 int fd = fileno (fptr);
442 442
449 retval.error (std::strerror (errno)); 449 retval.error (std::strerror (errno));
450 } 450 }
451 else 451 else
452 #endif 452 #endif
453 { 453 {
454 FILE *fptr = octave::sys::fopen (fname, mode); 454 FILE *fptr = sys::fopen (fname, mode);
455 455
456 retval = octave_stdiostream::create (fname, fptr, md, flt_fmt, 456 retval = octave_stdiostream::create (fname, fptr, md, flt_fmt,
457 encoding); 457 encoding);
458 458
459 if (! fptr) 459 if (! fptr)
463 } 463 }
464 464
465 return retval; 465 return retval;
466 } 466 }
467 467
468 static octave::stream 468 static stream
469 do_stream_open (const octave_value& tc_name, const octave_value& tc_mode, 469 do_stream_open (const octave_value& tc_name, const octave_value& tc_mode,
470 const octave_value& tc_arch, const octave_value& tc_encoding, 470 const octave_value& tc_arch, const octave_value& tc_encoding,
471 const char *fcn, int& fid) 471 const char *fcn, int& fid)
472 { 472 {
473 octave::stream retval; 473 stream retval;
474 474
475 fid = -1; 475 fid = -1;
476 476
477 std::string name = tc_name.xstring_value ("%s: filename must be a string", fcn); 477 std::string name = tc_name.xstring_value ("%s: filename must be a string", fcn);
478 std::string mode = tc_mode.xstring_value ("%s: file mode must be a string", fcn); 478 std::string mode = tc_mode.xstring_value ("%s: file mode must be a string", fcn);
597 if (nargin < 1 || nargin > 4) 597 if (nargin < 1 || nargin > 4)
598 print_usage (); 598 print_usage ();
599 599
600 octave_value_list retval = ovl (-1.0); 600 octave_value_list retval = ovl (-1.0);
601 601
602 octave::stream_list& streams = interp.get_stream_list (); 602 stream_list& streams = interp.get_stream_list ();
603 603
604 if (nargin == 1) 604 if (nargin == 1)
605 { 605 {
606 if (args(0).is_string ()) 606 if (args(0).is_string ())
607 { 607 {
624 624
625 octave_value mode = (nargin > 1) ? args(1) : octave_value ("r"); 625 octave_value mode = (nargin > 1) ? args(1) : octave_value ("r");
626 626
627 octave_value arch = (nargin > 2) ? args(2) : octave_value ("native"); 627 octave_value arch = (nargin > 2) ? args(2) : octave_value ("native");
628 628
629 octave::input_system& input_sys = interp.get_input_system (); 629 input_system& input_sys = interp.get_input_system ();
630 octave_value encoding = (nargin > 3) ? args(3) 630 octave_value encoding = (nargin > 3) ? args(3)
631 : octave_value (input_sys.mfile_encoding ()); 631 : octave_value (input_sys.mfile_encoding ());
632 if (encoding.string_value () == "system") 632 if (encoding.string_value () == "system")
633 encoding = octave_value (octave_locale_charset_wrapper ()); 633 encoding = octave_value (octave_locale_charset_wrapper ());
634 634
635 int fid = -1; 635 int fid = -1;
636 636
637 octave::stream os = do_stream_open (args(0), mode, arch, encoding, "fopen", 637 stream os = do_stream_open (args(0), mode, arch, encoding, "fopen",
638 fid); 638 fid);
639 639
640 if (os) 640 if (os)
641 retval = ovl (streams.insert (os), ""); 641 retval = ovl (streams.insert (os), "");
642 else 642 else
688 @end deftypefn */) 688 @end deftypefn */)
689 { 689 {
690 if (args.length () > 0) 690 if (args.length () > 0)
691 warning ("freport: ignoring extra arguments"); 691 warning ("freport: ignoring extra arguments");
692 692
693 octave::stream_list& streams = interp.get_stream_list (); 693 stream_list& streams = interp.get_stream_list ();
694 694
695 octave_stdout << streams.list_open_files (); 695 octave_stdout << streams.list_open_files ();
696 696
697 return ovl (); 697 return ovl ();
698 } 698 }
712 if (args.length () != 1) 712 if (args.length () != 1)
713 print_usage (); 713 print_usage ();
714 714
715 int result = -1; 715 int result = -1;
716 716
717 octave::stream_list& streams = interp.get_stream_list (); 717 stream_list& streams = interp.get_stream_list ();
718 718
719 octave::stream os = streams.lookup (args(0), "frewind"); 719 stream os = streams.lookup (args(0), "frewind");
720 720
721 result = os.rewind (); 721 result = os.rewind ();
722 722
723 if (nargout > 0) 723 if (nargout > 0)
724 return ovl (result); 724 return ovl (result);
748 int nargin = args.length (); 748 int nargin = args.length ();
749 749
750 if (nargin < 2 || nargin > 3) 750 if (nargin < 2 || nargin > 3)
751 print_usage (); 751 print_usage ();
752 752
753 octave::stream_list& streams = interp.get_stream_list (); 753 stream_list& streams = interp.get_stream_list ();
754 754
755 octave::stream os = streams.lookup (args(0), "fseek"); 755 stream os = streams.lookup (args(0), "fseek");
756 756
757 octave_value origin_arg = (nargin == 3) ? args(2) : octave_value (-1.0); 757 octave_value origin_arg = (nargin == 3) ? args(2) : octave_value (-1.0);
758 758
759 return ovl (os.seek (args(1), origin_arg)); 759 return ovl (os.seek (args(1), origin_arg));
760 } 760 }
768 @end deftypefn */) 768 @end deftypefn */)
769 { 769 {
770 if (args.length () != 1) 770 if (args.length () != 1)
771 print_usage (); 771 print_usage ();
772 772
773 octave::stream_list& streams = interp.get_stream_list (); 773 stream_list& streams = interp.get_stream_list ();
774 774
775 octave::stream os = streams.lookup (args(0), "ftell"); 775 stream os = streams.lookup (args(0), "ftell");
776 776
777 return ovl (os.tell ()); 777 return ovl (os.tell ());
778 } 778 }
779 779
780 static octave_value_list 780 static octave_value_list
781 printf_internal (octave::interpreter& interp, const std::string& who, 781 printf_internal (interpreter& interp, const std::string& who,
782 const octave_value_list& args, int nargout) 782 const octave_value_list& args, int nargout)
783 { 783 {
784 int nargin = args.length (); 784 int nargin = args.length ();
785 785
786 if (! (nargin > 1 || (nargin > 0 && args(0).is_string ()))) 786 if (! (nargin > 1 || (nargin > 0 && args(0).is_string ())))
787 print_usage (); 787 print_usage ();
788 788
789 int result; 789 int result;
790 790
791 octave::stream os; 791 stream os;
792 int fmt_n = 0; 792 int fmt_n = 0;
793 793
794 octave::stream_list& streams = interp.get_stream_list (); 794 stream_list& streams = interp.get_stream_list ();
795 795
796 if (args(0).is_string ()) 796 if (args(0).is_string ())
797 os = streams.lookup (1, who); 797 os = streams.lookup (1, who);
798 else 798 else
799 { 799 {
871 return printf_internal (interp, who, tmp_args.prepend (octave_value (1)), 871 return printf_internal (interp, who, tmp_args.prepend (octave_value (1)),
872 nargout); 872 nargout);
873 } 873 }
874 874
875 static octave_value_list 875 static octave_value_list
876 puts_internal (octave::interpreter& interp, const std::string& who, 876 puts_internal (interpreter& interp, const std::string& who,
877 const octave_value_list& args) 877 const octave_value_list& args)
878 { 878 {
879 if (args.length () != 2) 879 if (args.length () != 2)
880 print_usage (); 880 print_usage ();
881 881
882 octave::stream_list& streams = interp.get_stream_list (); 882 stream_list& streams = interp.get_stream_list ();
883 883
884 octave::stream os = streams.lookup (args(0), who); 884 stream os = streams.lookup (args(0), who);
885 885
886 return ovl (os.puts (args(1), who)); 886 return ovl (os.puts (args(1), who));
887 } 887 }
888 888
889 DEFMETHOD (fputs, interp, args, , 889 DEFMETHOD (fputs, interp, args, ,
951 // We don't use octave_ostrstream::create here because need direct 951 // We don't use octave_ostrstream::create here because need direct
952 // access to the OSTR object so that we can extract a string object 952 // access to the OSTR object so that we can extract a string object
953 // from it to return. 953 // from it to return.
954 octave_ostrstream *ostr = new octave_ostrstream (); 954 octave_ostrstream *ostr = new octave_ostrstream ();
955 955
956 // The octave::stream destructor will delete OSTR for us. 956 // The stream destructor will delete OSTR for us.
957 octave::stream os (ostr); 957 stream os (ostr);
958 958
959 if (! os.is_valid ()) 959 if (! os.is_valid ())
960 error ("%s: unable to create output buffer", who.c_str ()); 960 error ("%s: unable to create output buffer", who.c_str ());
961 961
962 octave_value fmt_arg = args(0); 962 octave_value fmt_arg = args(0);
987 987
988 return retval; 988 return retval;
989 } 989 }
990 990
991 static octave_value_list 991 static octave_value_list
992 scanf_internal (octave::interpreter& interp, const std::string& who, 992 scanf_internal (interpreter& interp, const std::string& who,
993 const octave_value_list& args) 993 const octave_value_list& args)
994 { 994 {
995 int nargin = args.length (); 995 int nargin = args.length ();
996 996
997 if (nargin < 2 || nargin > 3) 997 if (nargin < 2 || nargin > 3)
998 print_usage (); 998 print_usage ();
999 999
1000 octave_value_list retval; 1000 octave_value_list retval;
1001 1001
1002 octave::stream_list& streams = interp.get_stream_list (); 1002 stream_list& streams = interp.get_stream_list ();
1003 1003
1004 octave::stream os = streams.lookup (args(0), who); 1004 stream os = streams.lookup (args(0), who);
1005 1005
1006 if (! args(1).is_string ()) 1006 if (! args(1).is_string ())
1007 error ("%s: format TEMPLATE must be a string", who.c_str ()); 1007 error ("%s: format TEMPLATE must be a string", who.c_str ());
1008 1008
1009 if (nargin == 3 && args(2).is_string ()) 1009 if (nargin == 3 && args(2).is_string ())
1119 1119
1120 octave_value_list retval; 1120 octave_value_list retval;
1121 1121
1122 std::string data = get_scan_string_data (args(0), who); 1122 std::string data = get_scan_string_data (args(0), who);
1123 1123
1124 octave::stream os = octave_istrstream::create (data); 1124 stream os = octave_istrstream::create (data);
1125 1125
1126 if (! os.is_valid ()) 1126 if (! os.is_valid ())
1127 error ("%s: unable to create temporary input buffer", who.c_str ()); 1127 error ("%s: unable to create temporary input buffer", who.c_str ());
1128 1128
1129 if (! args(1).is_string ()) 1129 if (! args(1).is_string ())
1180 1180
1181 return scanf_internal (interp, who, tmp_args.prepend (octave_value (0))); 1181 return scanf_internal (interp, who, tmp_args.prepend (octave_value (0)));
1182 } 1182 }
1183 1183
1184 static octave_value_list 1184 static octave_value_list
1185 textscan_internal (octave::interpreter& interp, const std::string& who, 1185 textscan_internal (interpreter& interp, const std::string& who,
1186 const octave_value_list& args) 1186 const octave_value_list& args)
1187 { 1187 {
1188 if (args.length () < 1) 1188 if (args.length () < 1)
1189 print_usage (who); 1189 print_usage (who);
1190 1190
1191 octave::stream os; 1191 stream os;
1192 1192
1193 if (args(0).is_string ()) 1193 if (args(0).is_string ())
1194 { 1194 {
1195 std::string data = get_scan_string_data (args(0), who); 1195 std::string data = get_scan_string_data (args(0), who);
1196 1196
1199 if (! os.is_valid ()) 1199 if (! os.is_valid ())
1200 error ("%s: unable to create temporary input buffer", who.c_str ()); 1200 error ("%s: unable to create temporary input buffer", who.c_str ());
1201 } 1201 }
1202 else 1202 else
1203 { 1203 {
1204 octave::stream_list& streams = interp.get_stream_list (); 1204 stream_list& streams = interp.get_stream_list ();
1205 1205
1206 os = streams.lookup (args(0), who); 1206 os = streams.lookup (args(0), who);
1207 } 1207 }
1208 1208
1209 int nskip = 1; 1209 int nskip = 1;
1218 else if (args(1).is_string ()) 1218 else if (args(1).is_string ())
1219 { 1219 {
1220 fmt = args(1).string_value (); 1220 fmt = args(1).string_value ();
1221 1221
1222 if (args(1).is_sq_string ()) 1222 if (args(1).is_sq_string ())
1223 fmt = octave::do_string_escapes (fmt); 1223 fmt = do_string_escapes (fmt);
1224 1224
1225 nskip++; 1225 nskip++;
1226 } 1226 }
1227 else 1227 else
1228 error ("%s: FORMAT must be a string", who.c_str ()); 1228 error ("%s: FORMAT must be a string", who.c_str ());
2365 %!error <'%z' is not a valid format specifier> textscan ("1.0", "%z") 2365 %!error <'%z' is not a valid format specifier> textscan ("1.0", "%z")
2366 %!error <no valid format conversion specifiers> textscan ("1.0", "foo") 2366 %!error <no valid format conversion specifiers> textscan ("1.0", "foo")
2367 */ 2367 */
2368 2368
2369 static octave_value 2369 static octave_value
2370 do_fread (octave::stream& os, const octave_value& size_arg, 2370 do_fread (stream& os, const octave_value& size_arg,
2371 const octave_value& prec_arg, const octave_value& skip_arg, 2371 const octave_value& prec_arg, const octave_value& skip_arg,
2372 const octave_value& arch_arg, octave_idx_type& count) 2372 const octave_value& arch_arg, octave_idx_type& count)
2373 { 2373 {
2374 count = -1; 2374 count = -1;
2375 2375
2384 try 2384 try
2385 { 2385 {
2386 oct_data_conv::string_to_data_type (prec, block_size, 2386 oct_data_conv::string_to_data_type (prec, block_size,
2387 input_type, output_type); 2387 input_type, output_type);
2388 } 2388 }
2389 catch (octave::execution_exception& ee) 2389 catch (execution_exception& ee)
2390 { 2390 {
2391 error (ee, "fread: invalid PRECISION specified"); 2391 error (ee, "fread: invalid PRECISION specified");
2392 } 2392 }
2393 2393
2394 int skip = 0; 2394 int skip = 0;
2395 2395
2396 try 2396 try
2397 { 2397 {
2398 skip = skip_arg.int_value (true); 2398 skip = skip_arg.int_value (true);
2399 } 2399 }
2400 catch (octave::execution_exception& ee) 2400 catch (execution_exception& ee)
2401 { 2401 {
2402 error (ee, "fread: SKIP must be an integer"); 2402 error (ee, "fread: SKIP must be an integer");
2403 } 2403 }
2404 2404
2405 std::string arch = arch_arg.xstring_value ("fread: ARCH architecture type must be a string"); 2405 std::string arch = arch_arg.xstring_value ("fread: ARCH architecture type must be a string");
2406 2406
2407 octave::mach_info::float_format flt_fmt 2407 mach_info::float_format flt_fmt
2408 = octave::mach_info::string_to_float_format (arch); 2408 = mach_info::string_to_float_format (arch);
2409 2409
2410 return os.read (size, block_size, input_type, output_type, skip, 2410 return os.read (size, block_size, input_type, output_type, skip,
2411 flt_fmt, count); 2411 flt_fmt, count);
2412 } 2412 }
2413 2413
2571 int nargin = args.length (); 2571 int nargin = args.length ();
2572 2572
2573 if (nargin < 1 || nargin > 5) 2573 if (nargin < 1 || nargin > 5)
2574 print_usage (); 2574 print_usage ();
2575 2575
2576 octave::stream_list& streams = interp.get_stream_list (); 2576 stream_list& streams = interp.get_stream_list ();
2577 2577
2578 octave::stream os = streams.lookup (args(0), "fread"); 2578 stream os = streams.lookup (args(0), "fread");
2579 2579
2580 octave_value size = lo_ieee_inf_value (); 2580 octave_value size = lo_ieee_inf_value ();
2581 octave_value prec = "uint8"; 2581 octave_value prec = "uint8";
2582 octave_value skip = 0; 2582 octave_value skip = 0;
2583 octave_value arch = "unknown"; 2583 octave_value arch = "unknown";
2607 2607
2608 return ovl (tmp, count); 2608 return ovl (tmp, count);
2609 } 2609 }
2610 2610
2611 static int 2611 static int
2612 do_fwrite (octave::stream& os, const octave_value& data, 2612 do_fwrite (stream& os, const octave_value& data,
2613 const octave_value& prec_arg, const octave_value& skip_arg, 2613 const octave_value& prec_arg, const octave_value& skip_arg,
2614 const octave_value& arch_arg) 2614 const octave_value& arch_arg)
2615 { 2615 {
2616 std::string prec = prec_arg.xstring_value ("fwrite: PRECISION must be a string"); 2616 std::string prec = prec_arg.xstring_value ("fwrite: PRECISION must be a string");
2617 2617
2620 2620
2621 try 2621 try
2622 { 2622 {
2623 oct_data_conv::string_to_data_type (prec, block_size, output_type); 2623 oct_data_conv::string_to_data_type (prec, block_size, output_type);
2624 } 2624 }
2625 catch (octave::execution_exception& ee) 2625 catch (execution_exception& ee)
2626 { 2626 {
2627 error (ee, "fwrite: invalid PRECISION specified"); 2627 error (ee, "fwrite: invalid PRECISION specified");
2628 } 2628 }
2629 2629
2630 int skip = 0; 2630 int skip = 0;
2631 2631
2632 try 2632 try
2633 { 2633 {
2634 skip = skip_arg.int_value (true); 2634 skip = skip_arg.int_value (true);
2635 } 2635 }
2636 catch (octave::execution_exception& ee) 2636 catch (execution_exception& ee)
2637 { 2637 {
2638 error (ee, "fwrite: SKIP must be an integer"); 2638 error (ee, "fwrite: SKIP must be an integer");
2639 } 2639 }
2640 2640
2641 std::string arch = arch_arg.xstring_value ("fwrite: ARCH architecture type must be a string"); 2641 std::string arch = arch_arg.xstring_value ("fwrite: ARCH architecture type must be a string");
2642 2642
2643 octave::mach_info::float_format flt_fmt 2643 mach_info::float_format flt_fmt
2644 = octave::mach_info::string_to_float_format (arch); 2644 = mach_info::string_to_float_format (arch);
2645 2645
2646 return os.write (data, block_size, output_type, skip, flt_fmt); 2646 return os.write (data, block_size, output_type, skip, flt_fmt);
2647 } 2647 }
2648 2648
2649 DEFMETHOD (fwrite, interp, args, , 2649 DEFMETHOD (fwrite, interp, args, ,
2671 int nargin = args.length (); 2671 int nargin = args.length ();
2672 2672
2673 if (nargin < 2 || nargin > 5) 2673 if (nargin < 2 || nargin > 5)
2674 print_usage (); 2674 print_usage ();
2675 2675
2676 octave::stream_list& streams = interp.get_stream_list (); 2676 stream_list& streams = interp.get_stream_list ();
2677 2677
2678 octave::stream os = streams.lookup (args(0), "fwrite"); 2678 stream os = streams.lookup (args(0), "fwrite");
2679 2679
2680 octave_value prec = "uchar"; 2680 octave_value prec = "uchar";
2681 octave_value skip = 0; 2681 octave_value skip = 0;
2682 octave_value arch = "unknown"; 2682 octave_value arch = "unknown";
2683 2683
2715 @end deftypefn */) 2715 @end deftypefn */)
2716 { 2716 {
2717 if (args.length () != 1) 2717 if (args.length () != 1)
2718 print_usage (); 2718 print_usage ();
2719 2719
2720 octave::stream_list& streams = interp.get_stream_list (); 2720 stream_list& streams = interp.get_stream_list ();
2721 2721
2722 octave::stream os = streams.lookup (args(0), "feof"); 2722 stream os = streams.lookup (args(0), "feof");
2723 2723
2724 return ovl (os.eof () ? 1.0 : 0.0); 2724 return ovl (os.eof () ? 1.0 : 0.0);
2725 } 2725 }
2726 2726
2727 DEFMETHODX ("ferror", Fferror, interp, args, , 2727 DEFMETHODX ("ferror", Fferror, interp, args, ,
2748 int nargin = args.length (); 2748 int nargin = args.length ();
2749 2749
2750 if (nargin < 1 || nargin > 2) 2750 if (nargin < 1 || nargin > 2)
2751 print_usage (); 2751 print_usage ();
2752 2752
2753 octave::stream_list& streams = interp.get_stream_list (); 2753 stream_list& streams = interp.get_stream_list ();
2754 2754
2755 octave::stream os = streams.lookup (args(0), "ferror"); 2755 stream os = streams.lookup (args(0), "ferror");
2756 2756
2757 bool clear = false; 2757 bool clear = false;
2758 2758
2759 if (nargin == 2) 2759 if (nargin == 2)
2760 { 2760 {
2814 std::string name = args(0).xstring_value ("popen: COMMAND must be a string"); 2814 std::string name = args(0).xstring_value ("popen: COMMAND must be a string");
2815 std::string mode = args(1).xstring_value ("popen: MODE must be a string"); 2815 std::string mode = args(1).xstring_value ("popen: MODE must be a string");
2816 2816
2817 octave_value retval; 2817 octave_value retval;
2818 2818
2819 octave::stream_list& streams = interp.get_stream_list (); 2819 stream_list& streams = interp.get_stream_list ();
2820 2820
2821 if (mode == "r") 2821 if (mode == "r")
2822 { 2822 {
2823 octave::stream ips = octave_iprocstream::create (name); 2823 stream ips = octave_iprocstream::create (name);
2824 2824
2825 retval = streams.insert (ips); 2825 retval = streams.insert (ips);
2826 } 2826 }
2827 else if (mode == "w") 2827 else if (mode == "w")
2828 { 2828 {
2829 octave::stream ops = octave_oprocstream::create (name); 2829 stream ops = octave_oprocstream::create (name);
2830 2830
2831 retval = streams.insert (ops); 2831 retval = streams.insert (ops);
2832 } 2832 }
2833 else 2833 else
2834 error ("popen: invalid MODE specified"); 2834 error ("popen: invalid MODE specified");
2846 @end deftypefn */) 2846 @end deftypefn */)
2847 { 2847 {
2848 if (args.length () != 1) 2848 if (args.length () != 1)
2849 print_usage (); 2849 print_usage ();
2850 2850
2851 octave::stream_list& streams = interp.get_stream_list (); 2851 stream_list& streams = interp.get_stream_list ();
2852 2852
2853 return ovl (streams.remove (args(0), "pclose")); 2853 return ovl (streams.remove (args(0), "pclose"));
2854 } 2854 }
2855 2855
2856 DEFUN (tempname, args, , 2856 DEFUN (tempname, args, ,
2881 std::string dir; 2881 std::string dir;
2882 2882
2883 if (nargin > 0) 2883 if (nargin > 0)
2884 dir = args(0).xstring_value ("tempname: DIR must be a string"); 2884 dir = args(0).xstring_value ("tempname: DIR must be a string");
2885 else 2885 else
2886 dir = octave::sys::env::getenv ("TMPDIR"); 2886 dir = sys::env::getenv ("TMPDIR");
2887 2887
2888 std::string pfx ("oct-"); 2888 std::string pfx ("oct-");
2889 2889
2890 if (nargin > 1) 2890 if (nargin > 1)
2891 pfx = args(1).xstring_value ("tempname: PREFIX must be a string"); 2891 pfx = args(1).xstring_value ("tempname: PREFIX must be a string");
2892 2892
2893 return ovl (octave::sys::tempnam (dir, pfx)); 2893 return ovl (sys::tempnam (dir, pfx));
2894 } 2894 }
2895 2895
2896 /* 2896 /*
2897 %!test 2897 %!test
2898 %! envvar = {"TMPDIR", "TMP"}; 2898 %! envvar = {"TMPDIR", "TMP"};
2972 { 2972 {
2973 std::string nm; 2973 std::string nm;
2974 2974
2975 std::ios::openmode md = fopen_mode_to_ios_mode ("w+b"); 2975 std::ios::openmode md = fopen_mode_to_ios_mode ("w+b");
2976 2976
2977 octave::stream s = octave_stdiostream::create (nm, fid, md); 2977 stream s = octave_stdiostream::create (nm, fid, md);
2978 2978
2979 if (! s) 2979 if (! s)
2980 { 2980 {
2981 fclose (fid); 2981 fclose (fid);
2982 2982
2983 error ("tmpfile: failed to create octave_stdiostream object"); 2983 error ("tmpfile: failed to create octave_stdiostream object");
2984 } 2984 }
2985 2985
2986 octave::stream_list& streams = interp.get_stream_list (); 2986 stream_list& streams = interp.get_stream_list ();
2987 2987
2988 retval = ovl (streams.insert (s), ""); 2988 retval = ovl (streams.insert (s), "");
2989 } 2989 }
2990 else 2990 else
2991 retval = ovl (-1, std::strerror (errno)); 2991 retval = ovl (-1, std::strerror (errno));
3051 { 3051 {
3052 std::string nm = tmp; 3052 std::string nm = tmp;
3053 3053
3054 std::ios::openmode md = fopen_mode_to_ios_mode (fopen_mode); 3054 std::ios::openmode md = fopen_mode_to_ios_mode (fopen_mode);
3055 3055
3056 octave::stream s = octave_stdiostream::create (nm, fid, md); 3056 stream s = octave_stdiostream::create (nm, fid, md);
3057 3057
3058 if (! s) 3058 if (! s)
3059 error ("mkstemp: failed to create octave_stdiostream object"); 3059 error ("mkstemp: failed to create octave_stdiostream object");
3060 3060
3061 octave::stream_list& streams = interp.get_stream_list (); 3061 stream_list& streams = interp.get_stream_list ();
3062 3062
3063 retval(0) = streams.insert (s); 3063 retval(0) = streams.insert (s);
3064 retval(1) = nm; 3064 retval(1) = nm;
3065 3065
3066 if (nargin == 2 && args(1).is_true ()) 3066 if (nargin == 2 && args(1).is_true ())
3125 if (mask < 0) 3125 if (mask < 0)
3126 error ("umask: MASK must be a positive integer value"); 3126 error ("umask: MASK must be a positive integer value");
3127 3127
3128 int oct_mask = convert (mask, 8, 10); 3128 int oct_mask = convert (mask, 8, 10);
3129 3129
3130 int status = convert (octave::sys::umask (oct_mask), 10, 8); 3130 int status = convert (sys::umask (oct_mask), 10, 8);
3131 3131
3132 if (status >= 0) 3132 if (status >= 0)
3133 return ovl (status); 3133 return ovl (status);
3134 else 3134 else
3135 return ovl (); 3135 return ovl ();
3158 @end deftypefn */) 3158 @end deftypefn */)
3159 { 3159 {
3160 if (args.length () != 0) 3160 if (args.length () != 0)
3161 print_usage (); 3161 print_usage ();
3162 3162
3163 return ovl (octave::get_P_tmpdir ()); 3163 return ovl (get_P_tmpdir ());
3164 } 3164 }
3165 3165
3166 // NOTE: the values of SEEK_SET, SEEK_CUR, and SEEK_END have to be 3166 // NOTE: the values of SEEK_SET, SEEK_CUR, and SEEK_END have to be
3167 // this way for Matlab compatibility. 3167 // this way for Matlab compatibility.
3168 3168
3217 When Octave is used interactively, stdin is filtered through the command 3217 When Octave is used interactively, stdin is filtered through the command
3218 line editing functions. 3218 line editing functions.
3219 @seealso{stdout, stderr} 3219 @seealso{stdout, stderr}
3220 @end deftypefn */) 3220 @end deftypefn */)
3221 { 3221 {
3222 octave::stream_list& streams = interp.get_stream_list (); 3222 stream_list& streams = interp.get_stream_list ();
3223 3223
3224 return const_value ("stdin", args, streams.stdin_file ()); 3224 return const_value ("stdin", args, streams.stdin_file ());
3225 } 3225 }
3226 3226
3227 DEFMETHODX ("stdout", Fstdout, interp, args, , 3227 DEFMETHODX ("stdout", Fstdout, interp, args, ,
3231 3231
3232 Data written to the standard output may be filtered through the pager. 3232 Data written to the standard output may be filtered through the pager.
3233 @seealso{stdin, stderr, page_screen_output} 3233 @seealso{stdin, stderr, page_screen_output}
3234 @end deftypefn */) 3234 @end deftypefn */)
3235 { 3235 {
3236 octave::stream_list& streams = interp.get_stream_list (); 3236 stream_list& streams = interp.get_stream_list ();
3237 3237
3238 return const_value ("stdout", args, streams.stdout_file ()); 3238 return const_value ("stdout", args, streams.stdout_file ());
3239 } 3239 }
3240 3240
3241 DEFMETHODX ("stderr", Fstderr, interp, args, , 3241 DEFMETHODX ("stderr", Fstderr, interp, args, ,
3246 Even if paging is turned on, the standard error is not sent to the pager. 3246 Even if paging is turned on, the standard error is not sent to the pager.
3247 It is useful for error messages and prompts. 3247 It is useful for error messages and prompts.
3248 @seealso{stdin, stdout} 3248 @seealso{stdin, stdout}
3249 @end deftypefn */) 3249 @end deftypefn */)
3250 { 3250 {
3251 octave::stream_list& streams = interp.get_stream_list (); 3251 stream_list& streams = interp.get_stream_list ();
3252 3252
3253 return const_value ("stderr", args, streams.stderr_file ()); 3253 return const_value ("stderr", args, streams.stderr_file ());
3254 } 3254 }
3255 3255
3256 OCTAVE_NAMESPACE_END 3256 OCTAVE_NAMESPACE_END