Mercurial > hg > octave-jordi
comparison src/oct-stream.cc @ 3553:c5600b44bef9
[project @ 2000-02-03 03:22:37 by jwe]
author | jwe |
---|---|
date | Thu, 03 Feb 2000 03:22:38 +0000 |
parents | 41daa489833a |
children | 12d7ec415f35 |
comparison
equal
deleted
inserted
replaced
3552:41daa489833a | 3553:c5600b44bef9 |
---|---|
843 int retval = -1; | 843 int retval = -1; |
844 | 844 |
845 std::istream *is = input_stream (); | 845 std::istream *is = input_stream (); |
846 std::ostream *os = output_stream (); | 846 std::ostream *os = output_stream (); |
847 | 847 |
848 int i_fid = is ? ((filebuf *) (is->rdbuf ()))->fd () : -1; | 848 int i_fid = is ? ((std::filebuf *) (is->rdbuf ()))->fd () : -1; |
849 int o_fid = os ? ((filebuf *) (os->rdbuf ()))->fd () : -1; | 849 int o_fid = os ? ((std::filebuf *) (os->rdbuf ()))->fd () : -1; |
850 | 850 |
851 if (i_fid >= 0) | 851 if (i_fid >= 0) |
852 { | 852 { |
853 if (o_fid >= 0) | 853 if (o_fid >= 0) |
854 retval = (i_fid == o_fid) ? i_fid : -1; | 854 retval = (i_fid == o_fid) ? i_fid : -1; |
895 // XXX FIXME XXX -- this should probably be converted to use | 895 // XXX FIXME XXX -- this should probably be converted to use |
896 // sstream when that is available. | 896 // sstream when that is available. |
897 std::ostrstream buf; | 897 std::ostrstream buf; |
898 | 898 |
899 int c = 0; | 899 int c = 0; |
900 int count = 0; | 900 int char_count = 0; |
901 int newline_stripped = 0; | 901 int newline_stripped = 0; |
902 | 902 |
903 while (is && (c = is.get ()) != EOF) | 903 while (is && (c = is.get ()) != EOF) |
904 { | 904 { |
905 count++; | 905 char_count++; |
906 | 906 |
907 if (c == '\n') | 907 if (c == '\n') |
908 { | 908 { |
909 if (! strip_newline) | 909 if (! strip_newline) |
910 buf << (char) c; | 910 buf << (char) c; |
914 break; | 914 break; |
915 } | 915 } |
916 else | 916 else |
917 buf << (char) c; | 917 buf << (char) c; |
918 | 918 |
919 if (max_len > 0 && count == max_len) | 919 if (max_len > 0 && char_count == max_len) |
920 break; | 920 break; |
921 } | 921 } |
922 | 922 |
923 if (is.fail ()) | 923 if (is.fail ()) |
924 { | 924 { |
925 err = true; | 925 err = true; |
926 std::string msg = fcn; | 926 std::string msg = fcn; |
927 msg.append (": read error"); | 927 msg.append (": read error"); |
928 error (msg); | 928 error (msg); |
929 } | 929 } |
930 else if (count == 0 && is.eof ()) | 930 else if (char_count == 0 && is.eof ()) |
931 { | 931 { |
932 err = true; | 932 err = true; |
933 std::string msg = fcn; | 933 std::string msg = fcn; |
934 msg.append (": at end of file"); | 934 msg.append (": at end of file"); |
935 error (msg); | 935 error (msg); |
964 } | 964 } |
965 | 965 |
966 octave_value | 966 octave_value |
967 octave_base_stream::read (const Matrix& size, | 967 octave_base_stream::read (const Matrix& size, |
968 oct_data_conv::data_type dt, int skip, | 968 oct_data_conv::data_type dt, int skip, |
969 oct_mach_info::float_format flt_fmt, int& count) | 969 oct_mach_info::float_format ffmt, |
970 int& char_count) | |
970 { | 971 { |
971 Matrix retval; | 972 Matrix retval; |
972 | 973 |
973 count = 0; | 974 char_count = 0; |
974 | 975 |
975 std::istream *isp = input_stream (); | 976 std::istream *isp = input_stream (); |
976 | 977 |
977 if (isp) | 978 if (isp) |
978 { | 979 { |
985 | 986 |
986 get_size (size, nr, nc, ignore, "fread"); | 987 get_size (size, nr, nc, ignore, "fread"); |
987 | 988 |
988 if (! error_state) | 989 if (! error_state) |
989 { | 990 { |
990 if (flt_fmt == oct_mach_info::unknown) | 991 if (ffmt == oct_mach_info::unknown) |
991 flt_fmt = float_format (); | 992 ffmt = float_format (); |
992 | 993 |
993 int tmp = retval.read (is, nr, nc, dt, skip, flt_fmt); | 994 int tmp = retval.read (is, nr, nc, dt, skip, ffmt); |
994 | 995 |
995 if (tmp < 0) | 996 if (tmp < 0) |
996 error ("fread: read error"); | 997 error ("fread: read error"); |
997 else | 998 else |
998 count = tmp; | 999 char_count = tmp; |
999 } | 1000 } |
1000 } | 1001 } |
1001 else | 1002 else |
1002 invalid_operation ("fread", "reading"); | 1003 invalid_operation ("fread", "reading"); |
1003 | 1004 |
1548 | 1549 |
1549 return retval; | 1550 return retval; |
1550 } | 1551 } |
1551 | 1552 |
1552 octave_value | 1553 octave_value |
1553 octave_base_stream::scanf (const string& fmt, const Matrix& size, | 1554 octave_base_stream::scanf (const std::string& fmt, const Matrix& size, |
1554 int& count) | 1555 int& count) |
1555 { | 1556 { |
1556 octave_value retval = Matrix (); | 1557 octave_value retval = Matrix (); |
1557 | 1558 |
1558 count = 0; | 1559 count = 0; |
1897 } | 1898 } |
1898 | 1899 |
1899 int | 1900 int |
1900 octave_base_stream::write (const octave_value& data, | 1901 octave_base_stream::write (const octave_value& data, |
1901 oct_data_conv::data_type dt, int skip, | 1902 oct_data_conv::data_type dt, int skip, |
1902 oct_mach_info::float_format flt_fmt) | 1903 oct_mach_info::float_format ffmt) |
1903 { | 1904 { |
1904 int retval = -1; | 1905 int retval = -1; |
1905 | 1906 |
1906 std::ostream *osp = output_stream (); | 1907 std::ostream *osp = output_stream (); |
1907 | 1908 |
1911 | 1912 |
1912 Matrix mval = data.matrix_value (); | 1913 Matrix mval = data.matrix_value (); |
1913 | 1914 |
1914 if (! error_state) | 1915 if (! error_state) |
1915 { | 1916 { |
1916 if (flt_fmt == oct_mach_info::unknown) | 1917 if (ffmt == oct_mach_info::unknown) |
1917 flt_fmt = float_format (); | 1918 ffmt = float_format (); |
1918 | 1919 |
1919 int tmp = mval.write (os, dt, skip, flt_fmt); | 1920 int tmp = mval.write (os, dt, skip, ffmt); |
1920 | 1921 |
1921 if (tmp < 0) | 1922 if (tmp < 0) |
1922 error ("fwrite: write error"); | 1923 error ("fwrite: write error"); |
1923 else | 1924 else |
1924 retval = tmp; | 1925 retval = tmp; |