comparison libinterp/corefcn/oct-stream.cc @ 20590:1a0a433c8263

eliminate more simple uses of error_state * dirfns.cc, oct-map.cc, oct-stream.cc, regexp.cc, ov-base-mat.cc, ov-cell.cc, pt-idx.cc, pt-mat.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Mon, 05 Oct 2015 21:13:12 -0400
parents 44eb1102f8a8
children
comparison
equal deleted inserted replaced
20589:b10432a40432 20590:1a0a433c8263
143 ::error ("%s: invalid size specification", who.c_str ()); 143 ::error ("%s: invalid size specification", who.c_str ());
144 } 144 }
145 else 145 else
146 ::error ("%s: invalid size specification", who.c_str ()); 146 ::error ("%s: invalid size specification", who.c_str ());
147 147
148 if (! error_state) 148 nr = get_size (dnr, who);
149 { 149
150 nr = get_size (dnr, who); 150 if (dnc >= 0.0)
151 151 nc = get_size (dnc, who);
152 if (! error_state && dnc >= 0.0)
153 nc = get_size (dnc, who);
154 }
155 } 152 }
156 153
157 scanf_format_list::scanf_format_list (const std::string& s) 154 scanf_format_list::scanf_format_list (const std::string& s)
158 : nconv (0), curr_idx (0), list (dim_vector (16, 1)), buf (0) 155 : nconv (0), curr_idx (0), list (dim_vector (16, 1)), buf (0)
159 { 156 {
1917 1914
1918 bool one_elt_size_spec; 1915 bool one_elt_size_spec;
1919 1916
1920 get_size (size, nr, nc, one_elt_size_spec, who); 1917 get_size (size, nr, nc, one_elt_size_spec, who);
1921 1918
1922 if (! error_state) 1919 retval = do_scanf (fmt_list, nr, nc, one_elt_size_spec,
1923 retval = do_scanf (fmt_list, nr, nc, one_elt_size_spec, 1920 conversion_count, who);
1924 conversion_count, who);
1925 } 1921 }
1926 } 1922 }
1927 else 1923 else
1928 invalid_operation (who, "reading"); 1924 invalid_operation (who, "reading");
1929 1925
2359 { 2355 {
2360 int retval = 0; 2356 int retval = 0;
2361 2357
2362 octave_value val = get_next_value (); 2358 octave_value val = get_next_value ();
2363 2359
2360 double dval = val.double_value (true);
2361
2364 if (! error_state) 2362 if (! error_state)
2365 { 2363 {
2366 double dval = val.double_value (true); 2364 if (D_NINT (dval) == dval)
2367 2365 retval = NINT (dval);
2368 if (! error_state) 2366 else
2369 { 2367 curr_state = conversion_error;
2370 if (D_NINT (dval) == dval)
2371 retval = NINT (dval);
2372 else
2373 curr_state = conversion_error;
2374 }
2375 } 2368 }
2376 2369
2377 return retval; 2370 return retval;
2378 } 2371 }
2379 2372
2585 { 2578 {
2586 std::string tfmt = switch_to_g_format (elt); 2579 std::string tfmt = switch_to_g_format (elt);
2587 2580
2588 double dval = val.double_value (true); 2581 double dval = val.double_value (true);
2589 2582
2590 if (! error_state) 2583 retval += do_printf_conv (os, tfmt.c_str (), nsa,
2591 retval += do_printf_conv (os, tfmt.c_str (), nsa, 2584 sa_1, sa_2, dval, who);
2592 sa_1, sa_2, dval, who);
2593 } 2585 }
2594 break; 2586 break;
2595 2587
2596 case 'o': case 'x': case 'X': case 'u': 2588 case 'o': case 'x': case 'X': case 'u':
2597 if (ok_for_unsigned_int_conv (val)) 2589 if (ok_for_unsigned_int_conv (val))
2609 { 2601 {
2610 std::string tfmt = switch_to_g_format (elt); 2602 std::string tfmt = switch_to_g_format (elt);
2611 2603
2612 double dval = val.double_value (true); 2604 double dval = val.double_value (true);
2613 2605
2614 if (! error_state) 2606 retval += do_printf_conv (os, tfmt.c_str (), nsa,
2615 retval += do_printf_conv (os, tfmt.c_str (), nsa, 2607 sa_1, sa_2, dval, who);
2616 sa_1, sa_2, dval, who);
2617 } 2608 }
2618 break; 2609 break;
2619 2610
2620 case 'f': case 'e': case 'E': 2611 case 'f': case 'e': case 'E':
2621 case 'g': case 'G': 2612 case 'g': case 'G':
2622 { 2613 {
2623 double dval = val.double_value (true); 2614 double dval = val.double_value (true);
2624 2615
2625 if (! error_state) 2616 retval += do_printf_conv (os, fmt, nsa, sa_1, sa_2, dval, who);
2626 retval += do_printf_conv (os, fmt, nsa, sa_1, sa_2, dval, who);
2627 } 2617 }
2628 break; 2618 break;
2629 2619
2630 default: 2620 default:
2631 error ("%s: invalid format specifier", 2621 error ("%s: invalid format specifier",
2654 std::ostream& os = *osp; 2644 std::ostream& os = *osp;
2655 2645
2656 const printf_format_elt *elt = fmt_list.first (); 2646 const printf_format_elt *elt = fmt_list.first ();
2657 2647
2658 printf_value_cache val_cache (args, who); 2648 printf_value_cache val_cache (args, who);
2659
2660 if (error_state)
2661 return retval;
2662 2649
2663 for (;;) 2650 for (;;)
2664 { 2651 {
2665 octave_quit (); 2652 octave_quit ();
2666 2653
2915 err = true; 2902 err = true;
2916 ::error ("%s: invalid maximum length specified", who.c_str ()); 2903 ::error ("%s: invalid maximum length specified", who.c_str ());
2917 } 2904 }
2918 } 2905 }
2919 2906
2920 if (! error_state) 2907 retval = getl (max_len, err, who);
2921 retval = getl (max_len, err, who);
2922 2908
2923 return retval; 2909 return retval;
2924 } 2910 }
2925 2911
2926 std::string 2912 std::string
2955 err = true; 2941 err = true;
2956 ::error ("%s: invalid maximum length specified", who.c_str ()); 2942 ::error ("%s: invalid maximum length specified", who.c_str ());
2957 } 2943 }
2958 } 2944 }
2959 2945
2960 if (! error_state) 2946 retval = gets (max_len, err, who);
2961 retval = gets (max_len, err, who);
2962 2947
2963 return retval; 2948 return retval;
2964 } 2949 }
2965 2950
2966 off_t 2951 off_t
3000 ::error ("%s: invalid number of lines specified", who.c_str ()); 2985 ::error ("%s: invalid number of lines specified", who.c_str ());
3001 } 2986 }
3002 } 2987 }
3003 } 2988 }
3004 2989
3005 if (! error_state) 2990 retval = skipl (count, err, who);
3006 retval = skipl (count, err, who);
3007 2991
3008 return retval; 2992 return retval;
3009 } 2993 }
3010 2994
3011 int 2995 int
3396 3380
3397 get_size (size, nr, nc, one_elt_size_spec, "fread"); 3381 get_size (size, nr, nc, one_elt_size_spec, "fread");
3398 3382
3399 if (! error_state) 3383 if (! error_state)
3400 { 3384 {
3401
3402 octave_idx_type elts_to_read; 3385 octave_idx_type elts_to_read;
3403 3386
3404 if (one_elt_size_spec) 3387 if (one_elt_size_spec)
3405 { 3388 {
3406 // If NR == 0, Matlab returns [](0x0). 3389 // If NR == 0, Matlab returns [](0x0).
4311 { 4294 {
4312 octave_stream retval; 4295 octave_stream retval;
4313 4296
4314 int i = get_file_number (fid); 4297 int i = get_file_number (fid);
4315 4298
4316 if (! error_state) 4299 retval = do_lookup (i, who);
4317 retval = do_lookup (i, who);
4318 4300
4319 return retval; 4301 return retval;
4320 } 4302 }
4321 4303
4322 int 4304 int
4368 } 4350 }
4369 else 4351 else
4370 { 4352 {
4371 int i = get_file_number (fid); 4353 int i = get_file_number (fid);
4372 4354
4373 if (! error_state) 4355 retval = do_remove (i, who);
4374 retval = do_remove (i, who);
4375 } 4356 }
4376 4357
4377 return retval; 4358 return retval;
4378 } 4359 }
4379 4360