comparison libinterp/corefcn/file-io.cc @ 20593:c41595061186

eliminate more simple uses of error_state * betainc.cc, file-io.cc, ov-class.cc, ov-struct.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Mon, 05 Oct 2015 23:09:54 -0400
parents 642ce72cf1ab
children fd0efcdb3718
comparison
equal deleted inserted replaced
20592:56fee8f84fe7 20593:c41595061186
180 #else 180 #else
181 error ("this version of Octave does not support gzipped files"); 181 error ("this version of Octave does not support gzipped files");
182 #endif 182 #endif
183 } 183 }
184 184
185 if (! error_state) 185 // Use binary mode if 't' is not specified, but don't add
186 { 186 // 'b' if it is already present.
187 // Use binary mode if 't' is not specified, but don't add 187
188 // 'b' if it is already present. 188 size_t bpos = mode.find ('b');
189 189 size_t tpos = mode.find ('t');
190 size_t bpos = mode.find ('b'); 190
191 size_t tpos = mode.find ('t'); 191 if (bpos == std::string::npos && tpos == std::string::npos)
192 192 mode += 'b';
193 if (bpos == std::string::npos && tpos == std::string::npos)
194 mode += 'b';
195 }
196 } 193 }
197 } 194 }
198 195
199 static std::ios::openmode 196 static std::ios::openmode
200 fopen_mode_to_ios_mode (const std::string& mode) 197 fopen_mode_to_ios_mode (const std::string& mode)
201 { 198 {
202 std::ios::openmode retval = std::ios::in; 199 std::ios::openmode retval = std::ios::in;
203 200
204 if (! error_state) 201 if (mode == "rt")
205 { 202 retval = std::ios::in;
206 if (mode == "rt") 203 else if (mode == "wt")
207 retval = std::ios::in; 204 retval = std::ios::out | std::ios::trunc;
208 else if (mode == "wt") 205 else if (mode == "at")
209 retval = std::ios::out | std::ios::trunc; 206 retval = std::ios::out | std::ios::app;
210 else if (mode == "at") 207 else if (mode == "r+t" || mode == "rt+")
211 retval = std::ios::out | std::ios::app; 208 retval = std::ios::in | std::ios::out;
212 else if (mode == "r+t" || mode == "rt+") 209 else if (mode == "w+t" || mode == "wt+")
213 retval = std::ios::in | std::ios::out; 210 retval = std::ios::in | std::ios::out | std::ios::trunc;
214 else if (mode == "w+t" || mode == "wt+") 211 else if (mode == "a+t" || mode == "at+")
215 retval = std::ios::in | std::ios::out | std::ios::trunc; 212 retval = std::ios::in | std::ios::out | std::ios::app;
216 else if (mode == "a+t" || mode == "at+") 213 else if (mode == "rb" || mode == "r")
217 retval = std::ios::in | std::ios::out | std::ios::app; 214 retval = std::ios::in | std::ios::binary;
218 else if (mode == "rb" || mode == "r") 215 else if (mode == "wb" || mode == "w")
219 retval = std::ios::in | std::ios::binary; 216 retval = std::ios::out | std::ios::trunc | std::ios::binary;
220 else if (mode == "wb" || mode == "w") 217 else if (mode == "ab" || mode == "a")
221 retval = std::ios::out | std::ios::trunc | std::ios::binary; 218 retval = std::ios::out | std::ios::app | std::ios::binary;
222 else if (mode == "ab" || mode == "a") 219 else if (mode == "r+b" || mode == "rb+" || mode == "r+")
223 retval = std::ios::out | std::ios::app | std::ios::binary; 220 retval = std::ios::in | std::ios::out | std::ios::binary;
224 else if (mode == "r+b" || mode == "rb+" || mode == "r+") 221 else if (mode == "w+b" || mode == "wb+" || mode == "w+")
225 retval = std::ios::in | std::ios::out | std::ios::binary; 222 retval = (std::ios::in | std::ios::out | std::ios::trunc
226 else if (mode == "w+b" || mode == "wb+" || mode == "w+") 223 | std::ios::binary);
227 retval = (std::ios::in | std::ios::out | std::ios::trunc 224 else if (mode == "a+b" || mode == "ab+" || mode == "a+")
228 | std::ios::binary); 225 retval = (std::ios::in | std::ios::out | std::ios::app
229 else if (mode == "a+b" || mode == "ab+" || mode == "a+") 226 | std::ios::binary);
230 retval = (std::ios::in | std::ios::out | std::ios::app 227 else
231 | std::ios::binary); 228 error ("invalid mode specified");
232 else
233 error ("invalid mode specified");
234 }
235 229
236 return retval; 230 return retval;
237 } 231 }
238 232
239 DEFUN (fclose, args, , 233 DEFUN (fclose, args, ,
281 { 275 {
282 int fid = octave_stream_list::get_file_number (args(0)); 276 int fid = octave_stream_list::get_file_number (args(0));
283 277
284 octave_stream os = octave_stream_list::lookup (fid, "fclear"); 278 octave_stream os = octave_stream_list::lookup (fid, "fclear");
285 279
286 if (! error_state) 280 os.clearerr ();
287 os.clearerr ();
288 } 281 }
289 else 282 else
290 print_usage (); 283 print_usage ();
291 284
292 return retval; 285 return retval;
325 } 318 }
326 else 319 else
327 { 320 {
328 octave_stream os = octave_stream_list::lookup (fid, "fflush"); 321 octave_stream os = octave_stream_list::lookup (fid, "fflush");
329 322
330 if (! error_state) 323 retval = os.flush ();
331 retval = os.flush ();
332 } 324 }
333 } 325 }
334 else 326 else
335 print_usage (); 327 print_usage ();
336 328
366 358
367 if (nargin == 1 || nargin == 2) 359 if (nargin == 1 || nargin == 2)
368 { 360 {
369 octave_stream os = octave_stream_list::lookup (args(0), who); 361 octave_stream os = octave_stream_list::lookup (args(0), who);
370 362
371 if (! error_state) 363 octave_value len_arg = (nargin == 2) ? args(1) : octave_value ();
372 { 364
373 octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); 365 bool err = false;
374 366
375 bool err = false; 367 std::string tmp = os.getl (len_arg, err, who);
376 368
377 std::string tmp = os.getl (len_arg, err, who); 369 if (! err)
378 370 {
379 if (! (error_state || err)) 371 retval(1) = tmp.length ();
380 { 372 retval(0) = tmp;
381 retval(1) = tmp.length ();
382 retval(0) = tmp;
383 }
384 } 373 }
385 } 374 }
386 else 375 else
387 print_usage (); 376 print_usage ();
388 377
418 407
419 if (nargin == 1 || nargin == 2) 408 if (nargin == 1 || nargin == 2)
420 { 409 {
421 octave_stream os = octave_stream_list::lookup (args(0), who); 410 octave_stream os = octave_stream_list::lookup (args(0), who);
422 411
423 if (! error_state) 412 octave_value len_arg = (nargin == 2) ? args(1) : octave_value ();
424 { 413
425 octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); 414 bool err = false;
426 415
427 bool err = false; 416 std::string tmp = os.gets (len_arg, err, who);
428 417
429 std::string tmp = os.gets (len_arg, err, who); 418 if (! err)
430 419 {
431 if (! (error_state || err)) 420 retval(1) = tmp.length ();
432 { 421 retval(0) = tmp;
433 retval(1) = tmp.length ();
434 retval(0) = tmp;
435 }
436 } 422 }
437 } 423 }
438 else 424 else
439 print_usage (); 425 print_usage ();
440 426
468 454
469 if (nargin == 1 || nargin == 2) 455 if (nargin == 1 || nargin == 2)
470 { 456 {
471 octave_stream os = octave_stream_list::lookup (args(0), who); 457 octave_stream os = octave_stream_list::lookup (args(0), who);
472 458
473 if (! error_state) 459 octave_value count_arg = (nargin == 2) ? args(1) : octave_value ();
474 { 460
475 octave_value count_arg = (nargin == 2) ? args(1) : octave_value (); 461 bool err = false;
476 462
477 bool err = false; 463 off_t tmp = os.skipl (count_arg, err, who);
478 464
479 off_t tmp = os.skipl (count_arg, err, who); 465 if (! err)
480 466 retval = tmp;
481 if (! (error_state || err))
482 retval = tmp;
483 }
484 } 467 }
485 else 468 else
486 print_usage (); 469 print_usage ();
487 470
488 return retval; 471 return retval;
501 bool use_zlib = false; 484 bool use_zlib = false;
502 normalize_fopen_mode (mode, use_zlib); 485 normalize_fopen_mode (mode, use_zlib);
503 486
504 std::ios::openmode md = fopen_mode_to_ios_mode (mode); 487 std::ios::openmode md = fopen_mode_to_ios_mode (mode);
505 488
506 if (! error_state) 489 oct_mach_info::float_format flt_fmt =
507 { 490 oct_mach_info::string_to_float_format (arch);
508 oct_mach_info::float_format flt_fmt = 491
509 oct_mach_info::string_to_float_format (arch); 492 std::string fname = file_ops::tilde_expand (name);
510 493
511 if (! error_state) 494 file_stat fs (fname);
512 { 495
513 std::string fname = file_ops::tilde_expand (name); 496 if (! (md & std::ios::out))
514 497 fname = find_data_file_in_load_path ("fopen", fname);
515 file_stat fs (fname); 498
516 499 if (! fs.is_dir ())
517 if (! (md & std::ios::out)) 500 {
518 fname = find_data_file_in_load_path ("fopen", fname);
519
520 if (! fs.is_dir ())
521 {
522 #if defined (HAVE_ZLIB) 501 #if defined (HAVE_ZLIB)
523 if (use_zlib) 502 if (use_zlib)
524 { 503 {
525 FILE *fptr = gnulib::fopen (fname.c_str (), mode.c_str ()); 504 FILE *fptr = gnulib::fopen (fname.c_str (), mode.c_str ());
526 505
527 int fd = fileno (fptr); 506 int fd = fileno (fptr);
528 507
529 gzFile gzf = ::gzdopen (fd, mode.c_str ()); 508 gzFile gzf = ::gzdopen (fd, mode.c_str ());
530 509
531 if (fptr) 510 if (fptr)
532 retval = octave_zstdiostream::create (fname, gzf, fd, 511 retval = octave_zstdiostream::create (fname, gzf, fd,
533 md, flt_fmt); 512 md, flt_fmt);
534 else 513 else
535 retval.error (gnulib::strerror (errno)); 514 retval.error (gnulib::strerror (errno));
536 } 515 }
537 else 516 else
538 #endif 517 #endif
539 { 518 {
540 FILE *fptr = gnulib::fopen (fname.c_str (), mode.c_str ()); 519 FILE *fptr = gnulib::fopen (fname.c_str (), mode.c_str ());
541 520
542 retval = octave_stdiostream::create (fname, fptr, md, 521 retval = octave_stdiostream::create (fname, fptr, md,
543 flt_fmt); 522 flt_fmt);
544 523
545 if (! fptr) 524 if (! fptr)
546 retval.error (gnulib::strerror (errno)); 525 retval.error (gnulib::strerror (errno));
547 } 526 }
548 527
549 }
550 }
551 } 528 }
552 529
553 return retval; 530 return retval;
554 } 531 }
555 532
708 } 685 }
709 else 686 else
710 { 687 {
711 string_vector tmp = octave_stream_list::get_info (args(0)); 688 string_vector tmp = octave_stream_list::get_info (args(0));
712 689
713 if (! error_state) 690 retval(2) = tmp(2);
714 { 691 retval(1) = tmp(1);
715 retval(2) = tmp(2); 692 retval(0) = tmp(0);
716 retval(1) = tmp(1);
717 retval(0) = tmp(0);
718 }
719 693
720 return retval; 694 return retval;
721 } 695 }
722 } 696 }
723 697
731 705
732 int fid = -1; 706 int fid = -1;
733 707
734 octave_stream os = do_stream_open (args(0), mode, arch, "fopen", fid); 708 octave_stream os = do_stream_open (args(0), mode, arch, "fopen", fid);
735 709
736 if (os && ! error_state) 710 if (os)
737 { 711 {
738 retval(1) = ""; 712 retval(1) = "";
739 retval(0) = octave_stream_list::insert (os); 713 retval(0) = octave_stream_list::insert (os);
740 } 714 }
741 else 715 else
807 781
808 if (nargin == 1) 782 if (nargin == 1)
809 { 783 {
810 octave_stream os = octave_stream_list::lookup (args(0), "frewind"); 784 octave_stream os = octave_stream_list::lookup (args(0), "frewind");
811 785
812 if (! error_state) 786 result = os.rewind ();
813 result = os.rewind ();
814 } 787 }
815 else 788 else
816 print_usage (); 789 print_usage ();
817 790
818 if (nargout > 0) 791 if (nargout > 0)
846 819
847 if (nargin == 2 || nargin == 3) 820 if (nargin == 2 || nargin == 3)
848 { 821 {
849 octave_stream os = octave_stream_list::lookup (args(0), "fseek"); 822 octave_stream os = octave_stream_list::lookup (args(0), "fseek");
850 823
851 if (! error_state) 824 octave_value origin_arg = (nargin == 3)
852 { 825 ? args(2) : octave_value (-1.0);
853 octave_value origin_arg = (nargin == 3) 826
854 ? args(2) : octave_value (-1.0); 827 retval = os.seek (args(1), origin_arg);
855
856 retval = os.seek (args(1), origin_arg);
857 }
858 } 828 }
859 else 829 else
860 print_usage (); 830 print_usage ();
861 831
862 return retval; 832 return retval;
876 846
877 if (nargin == 1) 847 if (nargin == 1)
878 { 848 {
879 octave_stream os = octave_stream_list::lookup (args(0), "ftell"); 849 octave_stream os = octave_stream_list::lookup (args(0), "ftell");
880 850
881 if (! error_state) 851 retval = os.tell ();
882 retval = os.tell ();
883 } 852 }
884 else 853 else
885 print_usage (); 854 print_usage ();
886 855
887 return retval; 856 return retval;
927 { 896 {
928 fmt_n = 1; 897 fmt_n = 1;
929 os = octave_stream_list::lookup (args(0), who); 898 os = octave_stream_list::lookup (args(0), who);
930 } 899 }
931 900
932 if (! error_state) 901 if (args(fmt_n).is_string ())
933 { 902 {
934 if (args(fmt_n).is_string ()) 903 octave_value_list tmp_args;
904
905 if (nargin > 1 + fmt_n)
935 { 906 {
936 octave_value_list tmp_args; 907 tmp_args.resize (nargin-fmt_n-1, octave_value ());
937 908
938 if (nargin > 1 + fmt_n) 909 for (int i = fmt_n + 1; i < nargin; i++)
939 { 910 tmp_args(i-fmt_n-1) = args(i);
940 tmp_args.resize (nargin-fmt_n-1, octave_value ());
941
942 for (int i = fmt_n + 1; i < nargin; i++)
943 tmp_args(i-fmt_n-1) = args(i);
944 }
945
946 result = os.printf (args(fmt_n), tmp_args, who);
947 } 911 }
948 else 912
949 error ("%s: format TEMPLATE must be a string", who.c_str ()); 913 result = os.printf (args(fmt_n), tmp_args, who);
950 } 914 }
915 else
916 error ("%s: format TEMPLATE must be a string", who.c_str ());
951 } 917 }
952 else 918 else
953 print_usage (); 919 print_usage ();
954 920
955 if (nargout > 0) 921 if (nargout > 0)
1034 1000
1035 if (nargin == 2) 1001 if (nargin == 2)
1036 { 1002 {
1037 octave_stream os = octave_stream_list::lookup (args(0), who); 1003 octave_stream os = octave_stream_list::lookup (args(0), who);
1038 1004
1039 if (! error_state) 1005 retval = os.puts (args(1), who);
1040 retval = os.puts (args(1), who);
1041 } 1006 }
1042 else 1007 else
1043 print_usage (); 1008 print_usage ();
1044 1009
1045 return retval; 1010 return retval;
1198 1163
1199 if (nargin == 3 && args(2).is_string ()) 1164 if (nargin == 3 && args(2).is_string ())
1200 { 1165 {
1201 octave_stream os = octave_stream_list::lookup (args(0), who); 1166 octave_stream os = octave_stream_list::lookup (args(0), who);
1202 1167
1203 if (! error_state) 1168 if (args(1).is_string ())
1204 { 1169 retval = os.oscanf (args(1), who);
1205 if (args(1).is_string ()) 1170 else
1206 retval = os.oscanf (args(1), who); 1171 error ("%s: format TEMPLATE must be a string", who.c_str ());
1207 else
1208 error ("%s: format TEMPLATE must be a string", who.c_str ());
1209 }
1210 } 1172 }
1211 else 1173 else
1212 { 1174 {
1213 retval(2) = "unknown error"; 1175 retval(2) = "unknown error";
1214 retval(1) = 0.0; 1176 retval(1) = 0.0;
1216 1178
1217 if (nargin == 2 || nargin == 3) 1179 if (nargin == 2 || nargin == 3)
1218 { 1180 {
1219 octave_stream os = octave_stream_list::lookup (args(0), who); 1181 octave_stream os = octave_stream_list::lookup (args(0), who);
1220 1182
1221 if (! error_state) 1183 if (args(1).is_string ())
1222 { 1184 {
1223 if (args(1).is_string ()) 1185 octave_idx_type count = 0;
1224 { 1186
1225 octave_idx_type count = 0; 1187 Array<double> size = (nargin == 3)
1226 1188 ? args(2).vector_value ()
1227 Array<double> size = (nargin == 3) 1189 : Array<double> (dim_vector (1, 1),
1228 ? args(2).vector_value () 1190 lo_ieee_inf_value ());
1229 : Array<double> (dim_vector (1, 1), 1191
1230 lo_ieee_inf_value ()); 1192 octave_value tmp = os.scanf (args(1), size, count, who);
1231 1193
1232 if (! error_state) 1194 retval(2) = os.error ();
1233 { 1195 retval(1) = count;
1234 octave_value tmp = os.scanf (args(1), size, count, who); 1196 retval(0) = tmp;
1235
1236 if (! error_state)
1237 {
1238 retval(2) = os.error ();
1239 retval(1) = count;
1240 retval(0) = tmp;
1241 }
1242 }
1243 }
1244 else
1245 error ("%s: format must be a string", who.c_str ());
1246 } 1197 }
1198 else
1199 error ("%s: format must be a string", who.c_str ());
1247 } 1200 }
1248 else 1201 else
1249 print_usage (); 1202 print_usage ();
1250 } 1203 }
1251 1204
1318 retval(1) = 0.0; 1271 retval(1) = 0.0;
1319 retval(0) = Matrix (); 1272 retval(0) = Matrix ();
1320 1273
1321 std::string data = get_sscanf_data (args(0)); 1274 std::string data = get_sscanf_data (args(0));
1322 1275
1323 if (! error_state) 1276 octave_stream os = octave_istrstream::create (data);
1277
1278 if (os.is_valid ())
1324 { 1279 {
1325 octave_stream os = octave_istrstream::create (data); 1280 if (args(1).is_string ())
1326
1327 if (os.is_valid ())
1328 { 1281 {
1329 if (args(1).is_string ()) 1282 octave_idx_type count = 0;
1330 { 1283
1331 octave_idx_type count = 0; 1284 Array<double> size = (nargin == 3)
1332 1285 ? args(2).vector_value ()
1333 Array<double> size = (nargin == 3) 1286 : Array<double> (dim_vector (1, 1),
1334 ? args(2).vector_value () 1287 lo_ieee_inf_value ());
1335 : Array<double> (dim_vector (1, 1), 1288
1336 lo_ieee_inf_value ()); 1289 octave_value tmp = os.scanf (args(1), size, count, who);
1337 1290
1338 octave_value tmp = os.scanf (args(1), size, count, who); 1291 // FIXME: is this the right thing to do?
1339 1292 // Extract error message first, because getting
1340 if (! error_state) 1293 // position will clear it.
1341 { 1294 std::string errmsg = os.error ();
1342 // FIXME: is this the right thing to do? 1295
1343 // Extract error message first, because getting 1296 retval(3) = (os.eof () ? data.length () : os.tell ()) + 1;
1344 // position will clear it. 1297 retval(2) = errmsg;
1345 std::string errmsg = os.error (); 1298 retval(1) = count;
1346 1299 retval(0) = tmp;
1347 retval(3)
1348 = (os.eof () ? data.length () : os.tell ()) + 1;
1349 retval(2) = errmsg;
1350 retval(1) = count;
1351 retval(0) = tmp;
1352 }
1353 }
1354 else
1355 error ("%s: format TEMPLATE must be a string",
1356 who.c_str ());
1357 } 1300 }
1358 else 1301 else
1359 error ("%s: unable to create temporary input buffer", 1302 error ("%s: format TEMPLATE must be a string",
1360 who.c_str ()); 1303 who.c_str ());
1361 } 1304 }
1305 else
1306 error ("%s: unable to create temporary input buffer",
1307 who.c_str ());
1362 } 1308 }
1363 else 1309 else
1364 print_usage (); 1310 print_usage ();
1365 } 1311 }
1366 1312
1423 std::string arch = arch_arg.string_value (); 1369 std::string arch = arch_arg.string_value ();
1424 1370
1425 oct_mach_info::float_format flt_fmt 1371 oct_mach_info::float_format flt_fmt
1426 = oct_mach_info::string_to_float_format (arch); 1372 = oct_mach_info::string_to_float_format (arch);
1427 1373
1428 if (! error_state) 1374 retval = os.read (size, block_size, input_type,
1429 retval = os.read (size, block_size, input_type, 1375 output_type, skip, flt_fmt, count);
1430 output_type, skip, flt_fmt, count);
1431 } 1376 }
1432 else 1377 else
1433 error ("fread: ARCH architecture type must be a string"); 1378 error ("fread: ARCH architecture type must be a string");
1434 } 1379 }
1435 else 1380 else
1627 retval(1) = -1.0; 1572 retval(1) = -1.0;
1628 retval(0) = Matrix (); 1573 retval(0) = Matrix ();
1629 1574
1630 octave_stream os = octave_stream_list::lookup (args(0), "fread"); 1575 octave_stream os = octave_stream_list::lookup (args(0), "fread");
1631 1576
1632 if (! error_state) 1577 octave_value size = lo_ieee_inf_value ();
1633 { 1578 octave_value prec = "uchar";
1634 octave_value size = lo_ieee_inf_value (); 1579 octave_value skip = 0;
1635 octave_value prec = "uchar"; 1580 octave_value arch = "unknown";
1636 octave_value skip = 0; 1581
1637 octave_value arch = "unknown"; 1582 int idx = 1;
1638 1583
1639 int idx = 1; 1584 if (nargin > idx && ! args(idx).is_string ())
1640 1585 size = args(idx++);
1641 if (nargin > idx && ! args(idx).is_string ()) 1586
1642 size = args(idx++); 1587 if (nargin > idx)
1643 1588 prec = args(idx++);
1644 if (nargin > idx) 1589
1645 prec = args(idx++); 1590 if (nargin > idx)
1646 1591 skip = args(idx++);
1647 if (nargin > idx) 1592
1648 skip = args(idx++); 1593 if (nargin > idx)
1649 1594 arch = args(idx++);
1650 if (nargin > idx) 1595 else if (skip.is_string ())
1651 arch = args(idx++); 1596 {
1652 else if (skip.is_string ()) 1597 arch = skip;
1653 { 1598 skip = 0;
1654 arch = skip; 1599 }
1655 skip = 0; 1600
1656 } 1601 octave_idx_type count = -1;
1657 1602
1658 octave_idx_type count = -1; 1603 octave_value tmp = do_fread (os, size, prec, skip, arch, count);
1659 1604
1660 octave_value tmp = do_fread (os, size, prec, skip, arch, count); 1605 retval(1) = count;
1661 1606 retval(0) = tmp;
1662 retval(1) = count;
1663 retval(0) = tmp;
1664 }
1665 } 1607 }
1666 else 1608 else
1667 print_usage (); 1609 print_usage ();
1668 1610
1669 return retval; 1611 return retval;
1696 std::string arch = arch_arg.string_value (); 1638 std::string arch = arch_arg.string_value ();
1697 1639
1698 oct_mach_info::float_format flt_fmt 1640 oct_mach_info::float_format flt_fmt
1699 = oct_mach_info::string_to_float_format (arch); 1641 = oct_mach_info::string_to_float_format (arch);
1700 1642
1701 if (! error_state) 1643 retval = os.write (data, block_size, output_type,
1702 retval = os.write (data, block_size, output_type, 1644 skip, flt_fmt);
1703 skip, flt_fmt);
1704 } 1645 }
1705 else 1646 else
1706 error ("fwrite: ARCH architecture type must be a string"); 1647 error ("fwrite: ARCH architecture type must be a string");
1707 } 1648 }
1708 else 1649 else
1745 1686
1746 if (nargin > 1 && nargin < 6) 1687 if (nargin > 1 && nargin < 6)
1747 { 1688 {
1748 octave_stream os = octave_stream_list::lookup (args(0), "fwrite"); 1689 octave_stream os = octave_stream_list::lookup (args(0), "fwrite");
1749 1690
1750 if (! error_state) 1691 octave_value prec = "uchar";
1751 { 1692 octave_value skip = 0;
1752 octave_value prec = "uchar"; 1693 octave_value arch = "unknown";
1753 octave_value skip = 0; 1694
1754 octave_value arch = "unknown"; 1695 int idx = 1;
1755 1696
1756 int idx = 1; 1697 octave_value data = args(idx++);
1757 1698
1758 octave_value data = args(idx++); 1699 if (nargin > idx)
1759 1700 prec = args(idx++);
1760 if (nargin > idx) 1701
1761 prec = args(idx++); 1702 if (nargin > idx)
1762 1703 skip = args(idx++);
1763 if (nargin > idx) 1704
1764 skip = args(idx++); 1705 if (nargin > idx)
1765 1706 arch = args(idx++);
1766 if (nargin > idx) 1707 else if (skip.is_string ())
1767 arch = args(idx++); 1708 {
1768 else if (skip.is_string ()) 1709 arch = skip;
1769 { 1710 skip = 0;
1770 arch = skip; 1711 }
1771 skip = 0; 1712
1772 } 1713 double status = do_fwrite (os, data, prec, skip, arch);
1773 1714
1774 double status = do_fwrite (os, data, prec, skip, arch); 1715 retval = status;
1775
1776 retval = status;
1777 }
1778 } 1716 }
1779 else 1717 else
1780 print_usage (); 1718 print_usage ();
1781 1719
1782 return retval; 1720 return retval;
1800 1738
1801 if (nargin == 1) 1739 if (nargin == 1)
1802 { 1740 {
1803 octave_stream os = octave_stream_list::lookup (args(0), "feof"); 1741 octave_stream os = octave_stream_list::lookup (args(0), "feof");
1804 1742
1805 if (! error_state) 1743 retval = os.eof () ? 1.0 : 0.0;
1806 retval = os.eof () ? 1.0 : 0.0;
1807 } 1744 }
1808 else 1745 else
1809 print_usage (); 1746 print_usage ();
1810 1747
1811 return retval; 1748 return retval;
1838 1775
1839 if (nargin == 1 || nargin == 2) 1776 if (nargin == 1 || nargin == 2)
1840 { 1777 {
1841 octave_stream os = octave_stream_list::lookup (args(0), "ferror"); 1778 octave_stream os = octave_stream_list::lookup (args(0), "ferror");
1842 1779
1843 if (! error_state) 1780 bool clear = false;
1844 { 1781
1845 bool clear = false; 1782 if (nargin == 2)
1846 1783 {
1847 if (nargin == 2) 1784 std::string opt = args(1).string_value ();
1848 { 1785
1849 std::string opt = args(1).string_value (); 1786 clear = (opt == "clear");
1850 1787 }
1851 if (! error_state) 1788
1852 clear = (opt == "clear"); 1789 int error_number = 0;
1853 else 1790
1854 return retval; 1791 std::string error_message = os.error (clear, error_number);
1855 } 1792
1856 1793 retval(1) = error_number;
1857 int error_number = 0; 1794 retval(0) = error_message;
1858
1859 std::string error_message = os.error (clear, error_number);
1860
1861 retval(1) = error_number;
1862 retval(0) = error_message;
1863 }
1864 } 1795 }
1865 else 1796 else
1866 print_usage (); 1797 print_usage ();
1867 1798
1868 return retval; 1799 return retval;
2274 } 2205 }
2275 else 2206 else
2276 { 2207 {
2277 int oct_mask = convert (mask, 8, 10); 2208 int oct_mask = convert (mask, 8, 10);
2278 2209
2279 if (! error_state) 2210 status = convert (octave_umask (oct_mask), 10, 8);
2280 status = convert (octave_umask (oct_mask), 10, 8);
2281 } 2211 }
2282 } 2212 }
2283 else 2213 else
2284 { 2214 {
2285 status = -1; 2215 status = -1;