comparison src/oct-stream.cc @ 5775:ace8d8d26933

[project @ 2006-04-24 19:13:06 by jwe]
author jwe
date Mon, 24 Apr 2006 19:13:11 +0000
parents 7ba9ad1fec11
children cbf717bf8150
comparison
equal deleted inserted replaced
5774:e7af222e98b0 5775:ace8d8d26933
1034 1034
1035 #else 1035 #else
1036 1036
1037 #define OCTAVE_SCAN(is, fmt, arg) octave_scan (is, fmt, arg) 1037 #define OCTAVE_SCAN(is, fmt, arg) octave_scan (is, fmt, arg)
1038 1038
1039 // XXX FIXME XXX -- this needs to be fixed to handle formats which 1039 // FIXME -- this needs to be fixed to handle formats which
1040 // specify a maximum width. 1040 // specify a maximum width.
1041 1041
1042 template <class T> 1042 template <class T>
1043 std::istream& 1043 std::istream&
1044 octave_scan (std::istream& is, const scanf_format_elt& fmt, T* valptr) 1044 octave_scan (std::istream& is, const scanf_format_elt& fmt, T* valptr)
1925 // reset the failbit in the stream state. 1925 // reset the failbit in the stream state.
1926 1926
1927 if (is.rdstate () & std::ios::failbit) 1927 if (is.rdstate () & std::ios::failbit)
1928 is.clear (is.rdstate () & (~std::ios::failbit)); 1928 is.clear (is.rdstate () & (~std::ios::failbit));
1929 1929
1930 // XXX FIXME XXX -- is this the right thing to do? 1930 // FIXME -- is this the right thing to do?
1931 1931
1932 if (interactive && name () == "stdin") 1932 if (interactive && name () == "stdin")
1933 { 1933 {
1934 is.clear (); 1934 is.clear ();
1935 1935
2133 2133
2134 if (ok () && is.fail ()) 2134 if (ok () && is.fail ())
2135 { 2135 {
2136 error ("%s: read error", who.c_str ()); 2136 error ("%s: read error", who.c_str ());
2137 2137
2138 // XXX FIXME XXX -- is this the right thing to do? 2138 // FIXME -- is this the right thing to do?
2139 2139
2140 if (interactive && name () == "stdin") 2140 if (interactive && name () == "stdin")
2141 { 2141 {
2142 // Skip to end of line. 2142 // Skip to end of line.
2143 2143
2681 2681
2682 os << s; 2682 os << s;
2683 2683
2684 if (os) 2684 if (os)
2685 { 2685 {
2686 // XXX FIXME XXX -- why does this seem to be necessary? 2686 // FIXME -- why does this seem to be necessary?
2687 // Without it, output from a loop like 2687 // Without it, output from a loop like
2688 // 2688 //
2689 // for i = 1:100, fputs (stdout, "foo\n"); endfor 2689 // for i = 1:100, fputs (stdout, "foo\n"); endfor
2690 // 2690 //
2691 // doesn't seem to go to the pager immediately. 2691 // doesn't seem to go to the pager immediately.
3040 nda.resize (dim_vector (32, 1), elt_zero); 3040 nda.resize (dim_vector (32, 1), elt_zero);
3041 dat = nda.fortran_vec (); 3041 dat = nda.fortran_vec ();
3042 max_size = 32; 3042 max_size = 32;
3043 } 3043 }
3044 3044
3045 // XXX FIXME XXX -- byte order for Cray? 3045 // FIXME -- byte order for Cray?
3046 3046
3047 bool swap = false; 3047 bool swap = false;
3048 3048
3049 if (oct_mach_info::words_big_endian ()) 3049 if (oct_mach_info::words_big_endian ())
3050 swap = (from_flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian 3050 swap = (from_flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian
3067 3067
3068 octave_idx_type elts_read = 0; 3068 octave_idx_type elts_read = 0;
3069 3069
3070 for (;;) 3070 for (;;)
3071 { 3071 {
3072 // XXX FIXME XXX -- maybe there should be a special case for 3072 // FIXME -- maybe there should be a special case for
3073 // skip == 0. 3073 // skip == 0.
3074 3074
3075 if (is) 3075 if (is)
3076 { 3076 {
3077 if (nr > 0 && nc > 0 && count == max_size) 3077 if (nr > 0 && nc > 0 && count == max_size)
3164 #define DO_READ_VAL_TEMPLATE(RET_T, READ_T) \ 3164 #define DO_READ_VAL_TEMPLATE(RET_T, READ_T) \
3165 template octave_value \ 3165 template octave_value \
3166 do_read<RET_T, READ_T> (octave_stream&, octave_idx_type, octave_idx_type, octave_idx_type, octave_idx_type, bool, \ 3166 do_read<RET_T, READ_T> (octave_stream&, octave_idx_type, octave_idx_type, octave_idx_type, octave_idx_type, bool, \
3167 oct_mach_info::float_format, octave_idx_type&) 3167 oct_mach_info::float_format, octave_idx_type&)
3168 3168
3169 // XXX FIXME XXX -- should we only have float if it is a different 3169 // FIXME -- should we only have float if it is a different
3170 // size from double? 3170 // size from double?
3171 3171
3172 #define INSTANTIATE_DO_READ(VAL_T) \ 3172 #define INSTANTIATE_DO_READ(VAL_T) \
3173 DO_READ_VAL_TEMPLATE (VAL_T, octave_int8); \ 3173 DO_READ_VAL_TEMPLATE (VAL_T, octave_int8); \
3174 DO_READ_VAL_TEMPLATE (VAL_T, octave_uint8); \ 3174 DO_READ_VAL_TEMPLATE (VAL_T, octave_uint8); \
3252 3252
3253 octave_value retval; 3253 octave_value retval;
3254 3254
3255 if (stream_ok ()) 3255 if (stream_ok ())
3256 { 3256 {
3257 // XXX FIXME XXX -- we may eventually want to make this extensible. 3257 // FIXME -- we may eventually want to make this extensible.
3258 3258
3259 // XXX FIXME XXX -- we need a better way to ensure that this 3259 // FIXME -- we need a better way to ensure that this
3260 // numbering stays consistent with the order of the elements in the 3260 // numbering stays consistent with the order of the elements in the
3261 // data_type enum in the oct_data_conv class. 3261 // data_type enum in the oct_data_conv class.
3262 3262
3263 char_count = 0; 3263 char_count = 0;
3264 3264
3287 if (fcn) 3287 if (fcn)
3288 { 3288 {
3289 retval = (*fcn) (*this, nr, nc, block_size, skip, 3289 retval = (*fcn) (*this, nr, nc, block_size, skip,
3290 do_float_fmt_conv, ffmt, char_count); 3290 do_float_fmt_conv, ffmt, char_count);
3291 3291
3292 // XXX FIXME XXX -- kluge! 3292 // FIXME -- kluge!
3293 3293
3294 if (! error_state 3294 if (! error_state
3295 && (output_type == oct_data_conv::dt_char 3295 && (output_type == oct_data_conv::dt_char
3296 || output_type == oct_data_conv::dt_schar 3296 || output_type == oct_data_conv::dt_schar
3297 || output_type == oct_data_conv::dt_uchar)) 3297 || output_type == oct_data_conv::dt_uchar))
3466 oct_mach_info::float_format native_flt_fmt 3466 oct_mach_info::float_format native_flt_fmt
3467 = oct_mach_info::float_format (); 3467 = oct_mach_info::float_format ();
3468 3468
3469 bool do_float_conversion = (flt_fmt != native_flt_fmt); 3469 bool do_float_conversion = (flt_fmt != native_flt_fmt);
3470 3470
3471 // XXX FIXME XXX -- byte order for Cray? 3471 // FIXME -- byte order for Cray?
3472 3472
3473 bool swap = false; 3473 bool swap = false;
3474 3474
3475 if (oct_mach_info::words_big_endian ()) 3475 if (oct_mach_info::words_big_endian ())
3476 swap = (flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian 3476 swap = (flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian
3490 // It seems that Matlab writes zeros instead of actually 3490 // It seems that Matlab writes zeros instead of actually
3491 // seeking. Hmm... 3491 // seeking. Hmm...
3492 3492
3493 if (skip != 0 && (i % block_size) == 0) 3493 if (skip != 0 && (i % block_size) == 0)
3494 { 3494 {
3495 // XXX FIXME XXX -- probably should try to write larger 3495 // FIXME -- probably should try to write larger
3496 // blocks... 3496 // blocks...
3497 3497
3498 unsigned char zero = 0; 3498 unsigned char zero = 0;
3499 for (int j = 0; j < skip; j++) 3499 for (int j = 0; j < skip; j++)
3500 os.write (reinterpret_cast<const char *> (&zero), 1); 3500 os.write (reinterpret_cast<const char *> (&zero), 1);
3702 retval = rep->puts (s, who); 3702 retval = rep->puts (s, who);
3703 3703
3704 return retval; 3704 return retval;
3705 } 3705 }
3706 3706
3707 // XXX FIXME XXX -- maybe this should work for string arrays too. 3707 // FIXME -- maybe this should work for string arrays too.
3708 3708
3709 int 3709 int
3710 octave_stream::puts (const octave_value& tc_s, const std::string& who) 3710 octave_stream::puts (const octave_value& tc_s, const std::string& who)
3711 { 3711 {
3712 int retval = -1; 3712 int retval = -1;