comparison src/oct-stream.cc @ 3523:b80bbb43a1a9

[project @ 2000-02-02 10:25:52 by jwe]
author jwe
date Wed, 02 Feb 2000 10:26:25 +0000
parents d14c483b3c12
children 97cf542676e1
comparison
equal deleted inserted replaced
3522:bd422cf62f0c 3523:b80bbb43a1a9
150 if (! error_state && dnc >= 0.0) 150 if (! error_state && dnc >= 0.0)
151 nc = get_size (dnc, warn_for); 151 nc = get_size (dnc, warn_for);
152 } 152 }
153 } 153 }
154 154
155 scanf_format_list::scanf_format_list (const string& s) 155 scanf_format_list::scanf_format_list (const std::string& s)
156 : nconv (0), curr_idx (0), list (16), buf (0) 156 : nconv (0), curr_idx (0), list (16), buf (0)
157 { 157 {
158 int num_elts = 0; 158 int num_elts = 0;
159 159
160 int n = s.length (); 160 int n = s.length ();
171 while (i < n) 171 while (i < n)
172 { 172 {
173 have_more = true; 173 have_more = true;
174 174
175 if (! buf) 175 if (! buf)
176 buf = new ostrstream (); 176 buf = new std::ostrstream ();
177 177
178 if (s[i] == '%') 178 if (s[i] == '%')
179 { 179 {
180 // Process percent-escape conversion type. 180 // Process percent-escape conversion type.
181 181
242 } 242 }
243 243
244 void 244 void
245 scanf_format_list::add_elt_to_list (int width, bool discard, char type, 245 scanf_format_list::add_elt_to_list (int width, bool discard, char type,
246 char modifier, int& num_elts, 246 char modifier, int& num_elts,
247 const string& char_class) 247 const std::string& char_class)
248 { 248 {
249 if (buf) 249 if (buf)
250 { 250 {
251 *buf << ends; 251 *buf << ends;
252 252
273 buf = 0; 273 buf = 0;
274 } 274 }
275 } 275 }
276 276
277 static string 277 static string
278 expand_char_class (const string& s) 278 expand_char_class (const std::string& s)
279 { 279 {
280 string retval; 280 std::string retval;
281 281
282 size_t len = s.length (); 282 size_t len = s.length ();
283 283
284 size_t i = 0; 284 size_t i = 0;
285 285
308 308
309 return retval; 309 return retval;
310 } 310 }
311 311
312 void 312 void
313 scanf_format_list::process_conversion (const string& s, int& i, int n, 313 scanf_format_list::process_conversion (const std::string& s, int& i, int n,
314 int& width, bool& discard, char& type, 314 int& width, bool& discard, char& type,
315 char& modifier, int& num_elts) 315 char& modifier, int& num_elts)
316 { 316 {
317 width = 0; 317 width = 0;
318 discard = false; 318 discard = false;
410 410
411 nconv = -1; 411 nconv = -1;
412 } 412 }
413 413
414 int 414 int
415 scanf_format_list::finish_conversion (const string& s, int& i, int n, 415 scanf_format_list::finish_conversion (const std::string& s, int& i, int n,
416 int& width, bool discard, char& type, 416 int& width, bool discard, char& type,
417 char modifier, int& num_elts) 417 char modifier, int& num_elts)
418 { 418 {
419 int retval = 0; 419 int retval = 0;
420 420
421 string char_class; 421 std::string char_class;
422 422
423 if (s[i] == '%') 423 if (s[i] == '%')
424 *buf << s[i++]; 424 *buf << s[i++];
425 else 425 else
426 { 426 {
570 return false; 570 return false;
571 } 571 }
572 572
573 // Ugh again. 573 // Ugh again.
574 574
575 printf_format_list::printf_format_list (const string& s) 575 printf_format_list::printf_format_list (const std::string& s)
576 : nconv (0), curr_idx (0), list (16), buf (0) 576 : nconv (0), curr_idx (0), list (16), buf (0)
577 { 577 {
578 int num_elts = 0; 578 int num_elts = 0;
579 579
580 int n = s.length (); 580 int n = s.length ();
590 while (i < n) 590 while (i < n)
591 { 591 {
592 have_more = true; 592 have_more = true;
593 593
594 if (! buf) 594 if (! buf)
595 buf = new ostrstream (); 595 buf = new std::ostrstream ();
596 596
597 switch (s[i]) 597 switch (s[i])
598 { 598 {
599 case '%': 599 case '%':
600 process_conversion (s, i, n, args, type, modifier, num_elts); 600 process_conversion (s, i, n, args, type, modifier, num_elts);
665 buf = 0; 665 buf = 0;
666 } 666 }
667 } 667 }
668 668
669 void 669 void
670 printf_format_list::process_conversion (const string& s, int& i, int n, 670 printf_format_list::process_conversion (const std::string& s, int& i, int n,
671 int& args, char& modifier, 671 int& args, char& modifier,
672 char& type, int& num_elts) 672 char& type, int& num_elts)
673 { 673 {
674 args = 0; 674 args = 0;
675 modifier = '\0'; 675 modifier = '\0';
748 else 748 else
749 nconv = -1; 749 nconv = -1;
750 } 750 }
751 751
752 void 752 void
753 printf_format_list::finish_conversion (const string& s, int& i, 753 printf_format_list::finish_conversion (const std::string& s, int& i,
754 int args, char modifier, 754 int args, char modifier,
755 char& type, int& num_elts) 755 char& type, int& num_elts)
756 756
757 { 757 {
758 switch (s[i]) 758 switch (s[i])
837 if (name () == "stderr") 837 if (name () == "stderr")
838 return 2; 838 return 2;
839 839
840 int retval = -1; 840 int retval = -1;
841 841
842 istream *is = input_stream (); 842 std::istream *is = input_stream ();
843 ostream *os = output_stream (); 843 std::ostream *os = output_stream ();
844 844
845 int i_fid = is ? ((filebuf *) (is->rdbuf ()))->fd () : -1; 845 int i_fid = is ? ((filebuf *) (is->rdbuf ()))->fd () : -1;
846 int o_fid = os ? ((filebuf *) (os->rdbuf ()))->fd () : -1; 846 int o_fid = os ? ((filebuf *) (os->rdbuf ()))->fd () : -1;
847 847
848 if (i_fid >= 0) 848 if (i_fid >= 0)
857 857
858 return retval; 858 return retval;
859 } 859 }
860 860
861 void 861 void
862 octave_base_stream::error (const string& msg) 862 octave_base_stream::error (const std::string& msg)
863 { 863 {
864 fail = true; 864 fail = true;
865 errmsg = msg; 865 errmsg = msg;
866 } 866 }
867 867
877 877
878 string 878 string
879 octave_base_stream::do_gets (int max_len, bool& err, 879 octave_base_stream::do_gets (int max_len, bool& err,
880 bool strip_newline, const char *fcn) 880 bool strip_newline, const char *fcn)
881 { 881 {
882 string retval; 882 std::string retval;
883 883
884 err = false; 884 err = false;
885 885
886 istream *isp = input_stream (); 886 std::istream *isp = input_stream ();
887 887
888 if (isp) 888 if (isp)
889 { 889 {
890 istream& is = *isp; 890 std::istream& is = *isp;
891 891
892 // XXX FIXME XXX -- this should probably be converted to use 892 // XXX FIXME XXX -- this should probably be converted to use
893 // sstream when that is available. 893 // sstream when that is available.
894 ostrstream buf; 894 std::ostrstream buf;
895 895
896 int c = 0; 896 int c = 0;
897 int count = 0; 897 int count = 0;
898 int newline_stripped = 0; 898 int newline_stripped = 0;
899 899
918 } 918 }
919 919
920 if (is.fail ()) 920 if (is.fail ())
921 { 921 {
922 err = true; 922 err = true;
923 string msg = fcn; 923 std::string msg = fcn;
924 msg.append (": read error"); 924 msg.append (": read error");
925 error (msg); 925 error (msg);
926 } 926 }
927 else if (count == 0 && is.eof ()) 927 else if (count == 0 && is.eof ())
928 { 928 {
929 err = true; 929 err = true;
930 string msg = fcn; 930 std::string msg = fcn;
931 msg.append (": at end of file"); 931 msg.append (": at end of file");
932 error (msg); 932 error (msg);
933 } 933 }
934 else 934 else
935 { 935 {
967 { 967 {
968 Matrix retval; 968 Matrix retval;
969 969
970 count = 0; 970 count = 0;
971 971
972 istream *isp = input_stream (); 972 std::istream *isp = input_stream ();
973 973
974 if (isp) 974 if (isp)
975 { 975 {
976 istream& is = *isp; 976 std::istream& is = *isp;
977 977
978 int nr = -1; 978 int nr = -1;
979 int nc = -1; 979 int nc = -1;
980 980
981 bool ignore; 981 bool ignore;
1001 return retval; 1001 return retval;
1002 } 1002 }
1003 1003
1004 template <class T> 1004 template <class T>
1005 void 1005 void
1006 do_scanf_conv (istream& is, const char *fmt, T valptr, Matrix& mval, 1006 do_scanf_conv (std::istream& is, const char *fmt, T valptr, Matrix& mval,
1007 double *data, int& idx, int& conv_count, int nr, 1007 double *data, int& idx, int& conv_count, int nr,
1008 int max_size, bool discard) 1008 int max_size, bool discard)
1009 { 1009 {
1010 is.scan (fmt, valptr); 1010 is.scan (fmt, valptr);
1011 1011
1030 } 1030 }
1031 } 1031 }
1032 } 1032 }
1033 1033
1034 template void 1034 template void
1035 do_scanf_conv (istream&, const char*, int*, Matrix&, double*, int&, 1035 do_scanf_conv (std::istream&, const char*, int*, Matrix&, double*, int&,
1036 int&, int, int, bool); 1036 int&, int, int, bool);
1037 1037
1038 template void 1038 template void
1039 do_scanf_conv (istream&, const char*, long int*, Matrix&, double*, int&, 1039 do_scanf_conv (std::istream&, const char*, long int*, Matrix&, double*, int&,
1040 int&, int, int, bool); 1040 int&, int, int, bool);
1041 1041
1042 template void 1042 template void
1043 do_scanf_conv (istream&, const char*, short int*, Matrix&, double*, int&, 1043 do_scanf_conv (std::istream&, const char*, short int*, Matrix&, double*, int&,
1044 int&, int, int, bool); 1044 int&, int, int, bool);
1045 1045
1046 #if 0 1046 #if 0
1047 template void 1047 template void
1048 do_scanf_conv (istream&, const char*, float*, Matrix&, double*, int&, 1048 do_scanf_conv (std::istream&, const char*, float*, Matrix&, double*, int&,
1049 int&, int, int, bool); 1049 int&, int, int, bool);
1050 #endif 1050 #endif
1051 1051
1052 template void 1052 template void
1053 do_scanf_conv (istream&, const char*, double*, Matrix&, double*, int&, 1053 do_scanf_conv (std::istream&, const char*, double*, Matrix&, double*, int&,
1054 int&, int, int, bool); 1054 int&, int, int, bool);
1055 1055
1056 #define DO_WHITESPACE_CONVERSION() \ 1056 #define DO_WHITESPACE_CONVERSION() \
1057 do \ 1057 do \
1058 { \ 1058 { \
1168 } \ 1168 } \
1169 else \ 1169 else \
1170 { \ 1170 { \
1171 ostrstream buf; \ 1171 ostrstream buf; \
1172 \ 1172 \
1173 string char_class = elt->char_class; \ 1173 std::string char_class = elt->char_class; \
1174 \ 1174 \
1175 int c = EOF; \ 1175 int c = EOF; \
1176 \ 1176 \
1177 if (elt->type == '[') \ 1177 if (elt->type == '[') \
1178 { \ 1178 { \
1258 nc = 0; 1258 nc = 0;
1259 1259
1260 return Matrix (nr, nc, 0.0); 1260 return Matrix (nr, nc, 0.0);
1261 } 1261 }
1262 1262
1263 istream *isp = input_stream (); 1263 std::istream *isp = input_stream ();
1264 1264
1265 bool all_char_conv = fmt_list.all_character_conversions (); 1265 bool all_char_conv = fmt_list.all_character_conversions ();
1266 1266
1267 Matrix mval; 1267 Matrix mval;
1268 double *data = 0; 1268 double *data = 0;
1314 max_size = 32; 1314 max_size = 32;
1315 } 1315 }
1316 1316
1317 if (isp) 1317 if (isp)
1318 { 1318 {
1319 istream& is = *isp; 1319 std::istream& is = *isp;
1320 1320
1321 const scanf_format_elt *elt = fmt_list.first (); 1321 const scanf_format_elt *elt = fmt_list.first ();
1322 1322
1323 ios::fmtflags flags = is.flags (); 1323 ios::fmtflags flags = is.flags ();
1324 1324
1552 { 1552 {
1553 octave_value retval = Matrix (); 1553 octave_value retval = Matrix ();
1554 1554
1555 count = 0; 1555 count = 0;
1556 1556
1557 istream *isp = input_stream (); 1557 std::istream *isp = input_stream ();
1558 1558
1559 if (isp) 1559 if (isp)
1560 { 1560 {
1561 istream& is = *isp; 1561 std::istream& is = *isp;
1562 1562
1563 scanf_format_list fmt_list (fmt); 1563 scanf_format_list fmt_list (fmt);
1564 1564
1565 switch (fmt_list.num_conversions ()) 1565 switch (fmt_list.num_conversions ())
1566 { 1566 {
1629 octave_base_stream::do_oscanf (const scanf_format_elt *elt, 1629 octave_base_stream::do_oscanf (const scanf_format_elt *elt,
1630 octave_value& retval) 1630 octave_value& retval)
1631 { 1631 {
1632 bool quit = false; 1632 bool quit = false;
1633 1633
1634 istream *isp = input_stream (); 1634 std::istream *isp = input_stream ();
1635 1635
1636 if (isp) 1636 if (isp)
1637 { 1637 {
1638 istream& is = *isp; 1638 std::istream& is = *isp;
1639 1639
1640 ios::fmtflags flags = is.flags (); 1640 ios::fmtflags flags = is.flags ();
1641 1641
1642 if (elt) 1642 if (elt)
1643 { 1643 {
1764 1764
1765 return quit; 1765 return quit;
1766 } 1766 }
1767 1767
1768 octave_value_list 1768 octave_value_list
1769 octave_base_stream::oscanf (const string& fmt) 1769 octave_base_stream::oscanf (const std::string& fmt)
1770 { 1770 {
1771 octave_value_list retval; 1771 octave_value_list retval;
1772 1772
1773 istream *isp = input_stream (); 1773 std::istream *isp = input_stream ();
1774 1774
1775 if (isp) 1775 if (isp)
1776 { 1776 {
1777 istream& is = *isp; 1777 std::istream& is = *isp;
1778 1778
1779 scanf_format_list fmt_list (fmt); 1779 scanf_format_list fmt_list (fmt);
1780 1780
1781 int nconv = fmt_list.num_conversions (); 1781 int nconv = fmt_list.num_conversions ();
1782 1782
1876 int 1876 int
1877 octave_base_stream::flush (void) 1877 octave_base_stream::flush (void)
1878 { 1878 {
1879 int retval = -1; 1879 int retval = -1;
1880 1880
1881 ostream *os = output_stream (); 1881 std::ostream *os = output_stream ();
1882 1882
1883 if (os) 1883 if (os)
1884 { 1884 {
1885 os->flush (); 1885 os->flush ();
1886 1886
1898 oct_data_conv::data_type dt, int skip, 1898 oct_data_conv::data_type dt, int skip,
1899 oct_mach_info::float_format flt_fmt) 1899 oct_mach_info::float_format flt_fmt)
1900 { 1900 {
1901 int retval = -1; 1901 int retval = -1;
1902 1902
1903 ostream *osp = output_stream (); 1903 std::ostream *osp = output_stream ();
1904 1904
1905 if (osp) 1905 if (osp)
1906 { 1906 {
1907 ostream& os = *osp; 1907 std::ostream& os = *osp;
1908 1908
1909 Matrix mval = data.matrix_value (); 1909 Matrix mval = data.matrix_value ();
1910 1910
1911 if (! error_state) 1911 if (! error_state)
1912 { 1912 {
1946 1946
1947 // Get the current value as an int and advance the internal pointer. 1947 // Get the current value as an int and advance the internal pointer.
1948 int int_value (void); 1948 int int_value (void);
1949 1949
1950 // Get the current value as a string and advance the internal pointer. 1950 // Get the current value as a string and advance the internal pointer.
1951 string string_value (void); 1951 std::string string_value (void);
1952 1952
1953 operator bool () const { return (curr_state == ok); } 1953 operator bool () const { return (curr_state == ok); }
1954 1954
1955 bool no_more_values (void) { return curr_state == list_exhausted; } 1955 bool no_more_values (void) { return curr_state == list_exhausted; }
1956 1956
2070 } 2070 }
2071 2071
2072 string 2072 string
2073 printf_value_cache::string_value (void) 2073 printf_value_cache::string_value (void)
2074 { 2074 {
2075 string retval; 2075 std::string retval;
2076 2076
2077 if (looking_at_string ()) 2077 if (looking_at_string ())
2078 { 2078 {
2079 if (elt_idx != 0) 2079 if (elt_idx != 0)
2080 { 2080 {
2093 2093
2094 // Ugh again and again. 2094 // Ugh again and again.
2095 2095
2096 template <class T> 2096 template <class T>
2097 void 2097 void
2098 do_printf_conv (ostream& os, const char *fmt, int nsa, int sa_1, 2098 do_printf_conv (std::ostream& os, const char *fmt, int nsa, int sa_1,
2099 int sa_2, bool have_arg, T arg) 2099 int sa_2, bool have_arg, T arg)
2100 { 2100 {
2101 switch (nsa) 2101 switch (nsa)
2102 { 2102 {
2103 case 2: 2103 case 2:
2126 break; 2126 break;
2127 } 2127 }
2128 } 2128 }
2129 2129
2130 template void 2130 template void
2131 do_printf_conv (ostream&, const char*, int, int, int, bool, int); 2131 do_printf_conv (std::ostream&, const char*, int, int, int, bool, int);
2132 2132
2133 template void 2133 template void
2134 do_printf_conv (ostream&, const char*, int, int, int, bool, long); 2134 do_printf_conv (std::ostream&, const char*, int, int, int, bool, long);
2135 2135
2136 template void 2136 template void
2137 do_printf_conv (ostream&, const char*, int, int, int, bool, double); 2137 do_printf_conv (std::ostream&, const char*, int, int, int, bool, double);
2138 2138
2139 template void 2139 template void
2140 do_printf_conv (ostream&, const char*, int, int, int, bool, const char*); 2140 do_printf_conv (std::ostream&, const char*, int, int, int, bool, const char*);
2141 2141
2142 int 2142 int
2143 octave_base_stream::do_printf (printf_format_list& fmt_list, 2143 octave_base_stream::do_printf (printf_format_list& fmt_list,
2144 const octave_value_list& args) 2144 const octave_value_list& args)
2145 { 2145 {
2146 int retval = -1; 2146 int retval = -1;
2147 2147
2148 ostream *osp = output_stream (); 2148 std::ostream *osp = output_stream ();
2149 2149
2150 if (osp) 2150 if (osp)
2151 { 2151 {
2152 ostream& os = *osp; 2152 std::ostream& os = *osp;
2153 2153
2154 const printf_format_elt *elt = fmt_list.first (); 2154 const printf_format_elt *elt = fmt_list.first ();
2155 2155
2156 printf_value_cache val_cache (args); 2156 printf_value_cache val_cache (args);
2157 2157
2194 do_printf_conv (os, fmt, nsa, sa_1, sa_2, false, 0.0); 2194 do_printf_conv (os, fmt, nsa, sa_1, sa_2, false, 0.0);
2195 else 2195 else
2196 { 2196 {
2197 if (elt->type == 's' && val_cache.looking_at_string ()) 2197 if (elt->type == 's' && val_cache.looking_at_string ())
2198 { 2198 {
2199 string val = val_cache.string_value (); 2199 std::string val = val_cache.string_value ();
2200 2200
2201 if (val_cache) 2201 if (val_cache)
2202 do_printf_conv (os, fmt, nsa, sa_1, sa_2, true, 2202 do_printf_conv (os, fmt, nsa, sa_1, sa_2, true,
2203 val.c_str ()); 2203 val.c_str ());
2204 else 2204 else
2271 2271
2272 return retval; 2272 return retval;
2273 } 2273 }
2274 2274
2275 int 2275 int
2276 octave_base_stream::printf (const string& fmt, const octave_value_list& args) 2276 octave_base_stream::printf (const std::string& fmt, const octave_value_list& args)
2277 { 2277 {
2278 int retval = -1; 2278 int retval = -1;
2279 2279
2280 ostream *osp = output_stream (); 2280 std::ostream *osp = output_stream ();
2281 2281
2282 if (osp) 2282 if (osp)
2283 { 2283 {
2284 ostream& os = *osp; 2284 std::ostream& os = *osp;
2285 2285
2286 printf_format_list fmt_list (fmt); 2286 printf_format_list fmt_list (fmt);
2287 2287
2288 switch (fmt_list.num_conversions ()) 2288 switch (fmt_list.num_conversions ())
2289 { 2289 {
2322 2322
2323 return retval; 2323 return retval;
2324 } 2324 }
2325 2325
2326 int 2326 int
2327 octave_base_stream::puts (const string& s) 2327 octave_base_stream::puts (const std::string& s)
2328 { 2328 {
2329 int retval = -1; 2329 int retval = -1;
2330 2330
2331 ostream *osp = output_stream (); 2331 std::ostream *osp = output_stream ();
2332 2332
2333 if (osp) 2333 if (osp)
2334 { 2334 {
2335 ostream& os = *osp; 2335 std::ostream& os = *osp;
2336 2336
2337 os << s; 2337 os << s;
2338 2338
2339 if (os) 2339 if (os)
2340 { 2340 {
2372 string 2372 string
2373 octave_base_stream::error (bool clear_err, int& err_num) 2373 octave_base_stream::error (bool clear_err, int& err_num)
2374 { 2374 {
2375 err_num = fail ? -1 : 0; 2375 err_num = fail ? -1 : 0;
2376 2376
2377 string tmp = errmsg; 2377 std::string tmp = errmsg;
2378 2378
2379 if (clear_err) 2379 if (clear_err)
2380 clear (); 2380 clear ();
2381 2381
2382 return tmp; 2382 return tmp;
2383 } 2383 }
2384 2384
2385 void 2385 void
2386 octave_base_stream::invalid_operation (const char *op, const char *rw) 2386 octave_base_stream::invalid_operation (const char *op, const char *rw)
2387 { 2387 {
2388 string msg = op; 2388 std::string msg = op;
2389 msg.append (": stream not open for "); 2389 msg.append (": stream not open for ");
2390 msg.append (rw); 2390 msg.append (rw);
2391 error (msg); 2391 error (msg);
2392 } 2392 }
2393 2393
2440 } 2440 }
2441 2441
2442 string 2442 string
2443 octave_stream::getl (int max_len, bool& err) 2443 octave_stream::getl (int max_len, bool& err)
2444 { 2444 {
2445 string retval; 2445 std::string retval;
2446 2446
2447 if (stream_ok ("getl")) 2447 if (stream_ok ("getl"))
2448 retval = rep->getl (max_len, err); 2448 retval = rep->getl (max_len, err);
2449 2449
2450 return retval; 2450 return retval;
2451 } 2451 }
2452 2452
2453 string 2453 string
2454 octave_stream::getl (const octave_value& tc_max_len, bool& err) 2454 octave_stream::getl (const octave_value& tc_max_len, bool& err)
2455 { 2455 {
2456 string retval; 2456 std::string retval;
2457 2457
2458 err = false; 2458 err = false;
2459 2459
2460 int conv_err = 0; 2460 int conv_err = 0;
2461 2461
2473 } 2473 }
2474 2474
2475 string 2475 string
2476 octave_stream::gets (int max_len, bool& err) 2476 octave_stream::gets (int max_len, bool& err)
2477 { 2477 {
2478 string retval; 2478 std::string retval;
2479 2479
2480 if (stream_ok ("fgets")) 2480 if (stream_ok ("fgets"))
2481 retval = rep->gets (max_len, err); 2481 retval = rep->gets (max_len, err);
2482 2482
2483 return retval; 2483 return retval;
2484 } 2484 }
2485 2485
2486 string 2486 string
2487 octave_stream::gets (const octave_value& tc_max_len, bool& err) 2487 octave_stream::gets (const octave_value& tc_max_len, bool& err)
2488 { 2488 {
2489 string retval; 2489 std::string retval;
2490 2490
2491 err = false; 2491 err = false;
2492 2492
2493 int conv_err = 0; 2493 int conv_err = 0;
2494 2494
2530 { 2530 {
2531 ios::seek_dir origin = ios::beg; 2531 ios::seek_dir origin = ios::beg;
2532 2532
2533 if (tc_origin.is_string ()) 2533 if (tc_origin.is_string ())
2534 { 2534 {
2535 string xorigin = tc_origin.string_value (); 2535 std::string xorigin = tc_origin.string_value ();
2536 2536
2537 if (xorigin == "bof") 2537 if (xorigin == "bof")
2538 origin = ios::beg; 2538 origin = ios::beg;
2539 else if (xorigin == "cof") 2539 else if (xorigin == "cof")
2540 origin = ios::cur; 2540 origin = ios::cur;
2636 2636
2637 return retval; 2637 return retval;
2638 } 2638 }
2639 2639
2640 octave_value 2640 octave_value
2641 octave_stream::scanf (const string& fmt, const Matrix& size, int& count) 2641 octave_stream::scanf (const std::string& fmt, const Matrix& size, int& count)
2642 { 2642 {
2643 octave_value retval; 2643 octave_value retval;
2644 2644
2645 if (stream_ok ("fscanf")) 2645 if (stream_ok ("fscanf"))
2646 retval = rep->scanf (fmt, size, count); 2646 retval = rep->scanf (fmt, size, count);
2647 2647
2648 return retval; 2648 return retval;
2649 } 2649 }
2650 2650
2651 octave_value_list 2651 octave_value_list
2652 octave_stream::oscanf (const string& fmt) 2652 octave_stream::oscanf (const std::string& fmt)
2653 { 2653 {
2654 octave_value_list retval; 2654 octave_value_list retval;
2655 2655
2656 if (stream_ok ("fscanf")) 2656 if (stream_ok ("fscanf"))
2657 retval = rep->oscanf (fmt); 2657 retval = rep->oscanf (fmt);
2658 2658
2659 return retval; 2659 return retval;
2660 } 2660 }
2661 2661
2662 int 2662 int
2663 octave_stream::printf (const string& fmt, const octave_value_list& args) 2663 octave_stream::printf (const std::string& fmt, const octave_value_list& args)
2664 { 2664 {
2665 int retval = -1; 2665 int retval = -1;
2666 2666
2667 if (stream_ok ("fprintf")) 2667 if (stream_ok ("fprintf"))
2668 retval = rep->printf (fmt, args); 2668 retval = rep->printf (fmt, args);
2669 2669
2670 return retval; 2670 return retval;
2671 } 2671 }
2672 2672
2673 int 2673 int
2674 octave_stream::puts (const string& s) 2674 octave_stream::puts (const std::string& s)
2675 { 2675 {
2676 int retval = -1; 2676 int retval = -1;
2677 2677
2678 if (stream_ok ("fputs")) 2678 if (stream_ok ("fputs"))
2679 retval = rep->puts (s); 2679 retval = rep->puts (s);
2688 { 2688 {
2689 int retval = -1; 2689 int retval = -1;
2690 2690
2691 if (tc_s.is_string ()) 2691 if (tc_s.is_string ())
2692 { 2692 {
2693 string s = tc_s.string_value (); 2693 std::string s = tc_s.string_value ();
2694 retval = rep->puts (s); 2694 retval = rep->puts (s);
2695 } 2695 }
2696 else 2696 else
2697 error ("fputs: argument must be a string"); 2697 error ("fputs: argument must be a string");
2698 2698
2711 } 2711 }
2712 2712
2713 string 2713 string
2714 octave_stream::error (bool clear, int& err_num) 2714 octave_stream::error (bool clear, int& err_num)
2715 { 2715 {
2716 string retval; 2716 std::string retval;
2717 2717
2718 if (stream_ok ("ferror", false)) 2718 if (stream_ok ("ferror", false))
2719 retval = rep->error (clear, err_num); 2719 retval = rep->error (clear, err_num);
2720 2720
2721 return retval; 2721 return retval;
2722 } 2722 }
2723 2723
2724 string 2724 string
2725 octave_stream::name (void) const 2725 octave_stream::name (void) const
2726 { 2726 {
2727 string retval; 2727 std::string retval;
2728 2728
2729 if (stream_ok ("name")) 2729 if (stream_ok ("name"))
2730 retval = rep->name (); 2730 retval = rep->name ();
2731 2731
2732 return retval; 2732 return retval;
2755 } 2755 }
2756 2756
2757 string 2757 string
2758 octave_stream::mode_as_string (int mode) 2758 octave_stream::mode_as_string (int mode)
2759 { 2759 {
2760 string retval = "???"; 2760 std::string retval = "???";
2761 2761
2762 switch (mode) 2762 switch (mode)
2763 { 2763 {
2764 case ios::in: 2764 case ios::in:
2765 retval = "r"; 2765 retval = "r";
2849 { 2849 {
2850 return (instance_ok ()) ? instance->do_insert (os) : octave_value (-1.0); 2850 return (instance_ok ()) ? instance->do_insert (os) : octave_value (-1.0);
2851 } 2851 }
2852 2852
2853 octave_stream 2853 octave_stream
2854 octave_stream_list::lookup (int fid, const string& who) 2854 octave_stream_list::lookup (int fid, const std::string& who)
2855 { 2855 {
2856 return (instance_ok ()) ? instance->do_lookup (fid, who) : octave_stream (); 2856 return (instance_ok ()) ? instance->do_lookup (fid, who) : octave_stream ();
2857 } 2857 }
2858 2858
2859 octave_stream 2859 octave_stream
2860 octave_stream_list::lookup (const octave_value& fid, const string& who) 2860 octave_stream_list::lookup (const octave_value& fid, const std::string& who)
2861 { 2861 {
2862 return (instance_ok ()) ? instance->do_lookup (fid, who) : octave_stream (); 2862 return (instance_ok ()) ? instance->do_lookup (fid, who) : octave_stream ();
2863 } 2863 }
2864 2864
2865 int 2865 int
2866 octave_stream_list::remove (int fid, const string& who) 2866 octave_stream_list::remove (int fid, const std::string& who)
2867 { 2867 {
2868 return (instance_ok ()) ? instance->do_remove (fid, who) : -1; 2868 return (instance_ok ()) ? instance->do_remove (fid, who) : -1;
2869 } 2869 }
2870 2870
2871 int 2871 int
2872 octave_stream_list::remove (const octave_value& fid, const string& who) 2872 octave_stream_list::remove (const octave_value& fid, const std::string& who)
2873 { 2873 {
2874 return (instance_ok ()) ? instance->do_remove (fid, who) : -1; 2874 return (instance_ok ()) ? instance->do_remove (fid, who) : -1;
2875 } 2875 }
2876 2876
2877 void 2877 void
2894 } 2894 }
2895 2895
2896 string 2896 string
2897 octave_stream_list::list_open_files (void) 2897 octave_stream_list::list_open_files (void)
2898 { 2898 {
2899 return (instance_ok ()) ? instance->do_list_open_files () : string (); 2899 return (instance_ok ()) ? instance->do_list_open_files () : std::string ();
2900 } 2900 }
2901 2901
2902 octave_value 2902 octave_value
2903 octave_stream_list::open_file_numbers (void) 2903 octave_stream_list::open_file_numbers (void)
2904 { 2904 {
2948 2948
2949 return octave_value (os, stream_number); 2949 return octave_value (os, stream_number);
2950 } 2950 }
2951 2951
2952 static void 2952 static void
2953 gripe_invalid_file_id (int fid, const string& who) 2953 gripe_invalid_file_id (int fid, const std::string& who)
2954 { 2954 {
2955 if (who.empty ()) 2955 if (who.empty ())
2956 ::error ("invalid stream number = %d", fid); 2956 ::error ("invalid stream number = %d", fid);
2957 else 2957 else
2958 ::error ("%s: invalid stream number = %d", who.c_str (), fid); 2958 ::error ("%s: invalid stream number = %d", who.c_str (), fid);
2959 } 2959 }
2960 2960
2961 octave_stream 2961 octave_stream
2962 octave_stream_list::do_lookup (int fid, const string& who) const 2962 octave_stream_list::do_lookup (int fid, const std::string& who) const
2963 { 2963 {
2964 octave_stream retval; 2964 octave_stream retval;
2965 2965
2966 if (fid >= 0 && fid < curr_len) 2966 if (fid >= 0 && fid < curr_len)
2967 retval = list(fid); 2967 retval = list(fid);
2971 return retval; 2971 return retval;
2972 } 2972 }
2973 2973
2974 octave_stream 2974 octave_stream
2975 octave_stream_list::do_lookup (const octave_value& fid, 2975 octave_stream_list::do_lookup (const octave_value& fid,
2976 const string& who) const 2976 const std::string& who) const
2977 { 2977 {
2978 octave_stream retval; 2978 octave_stream retval;
2979 2979
2980 int i = get_file_number (fid); 2980 int i = get_file_number (fid);
2981 2981
2984 2984
2985 return retval; 2985 return retval;
2986 } 2986 }
2987 2987
2988 int 2988 int
2989 octave_stream_list::do_remove (int fid, const string& who) 2989 octave_stream_list::do_remove (int fid, const std::string& who)
2990 { 2990 {
2991 int retval = -1; 2991 int retval = -1;
2992 2992
2993 // Can't remove stdin (cin), stdout (cout), or stderr (cerr). 2993 // Can't remove stdin (cin), stdout (cout), or stderr (cerr).
2994 2994
3010 3010
3011 return retval; 3011 return retval;
3012 } 3012 }
3013 3013
3014 int 3014 int
3015 octave_stream_list::do_remove (const octave_value& fid, const string& who) 3015 octave_stream_list::do_remove (const octave_value& fid, const std::string& who)
3016 { 3016 {
3017 int retval = -1; 3017 int retval = -1;
3018 3018
3019 int i = get_file_number (fid); 3019 int i = get_file_number (fid);
3020 3020
3077 } 3077 }
3078 3078
3079 string 3079 string
3080 octave_stream_list::do_list_open_files (void) const 3080 octave_stream_list::do_list_open_files (void) const
3081 { 3081 {
3082 string retval; 3082 std::string retval;
3083 3083
3084 // XXX FIXME XXX -- this should probably be converted to use sstream 3084 // XXX FIXME XXX -- this should probably be converted to use sstream
3085 // when that is available. 3085 // when that is available.
3086 ostrstream buf; 3086 std::ostrstream buf;
3087 3087
3088 buf << "\n" 3088 buf << "\n"
3089 << " number mode arch name\n" 3089 << " number mode arch name\n"
3090 << " ------ ---- ---- ----\n"; 3090 << " ------ ---- ---- ----\n";
3091 3091
3093 { 3093 {
3094 octave_stream os = list(i); 3094 octave_stream os = list(i);
3095 3095
3096 if (os) 3096 if (os)
3097 { 3097 {
3098 string mode = octave_stream::mode_as_string (os.mode ()); 3098 std::string mode = octave_stream::mode_as_string (os.mode ());
3099 3099
3100 string arch = 3100 std::string arch =
3101 oct_mach_info::float_format_as_string (os.float_format ()); 3101 oct_mach_info::float_format_as_string (os.float_format ());
3102 3102
3103 string name = os.name (); 3103 std::string name = os.name ();
3104 3104
3105 buf << " " 3105 buf << " "
3106 << setiosflags (ios::right) 3106 << setiosflags (ios::right)
3107 << setw (4) << i << " " 3107 << setw (4) << i << " "
3108 << setiosflags (ios::left) 3108 << setiosflags (ios::left)
3148 { 3148 {
3149 int retval = -1; 3149 int retval = -1;
3150 3150
3151 if (fid.is_string ()) 3151 if (fid.is_string ())
3152 { 3152 {
3153 string nm = fid.string_value (); 3153 std::string nm = fid.string_value ();
3154 3154
3155 // stdin (cin), stdout (cout), and stderr (cerr) are unnamed. 3155 // stdin (cin), stdout (cout), and stderr (cerr) are unnamed.
3156 3156
3157 for (int i = 3; i < curr_len; i++) 3157 for (int i = 3; i < curr_len; i++)
3158 { 3158 {
3170 int conv_err = 0; 3170 int conv_err = 0;
3171 3171
3172 int int_fid = convert_to_valid_int (fid, conv_err); 3172 int int_fid = convert_to_valid_int (fid, conv_err);
3173 3173
3174 if (conv_err) 3174 if (conv_err)
3175 ::error ("file id must be a file object, string, or integer value"); 3175 ::error ("file id must be a file object, std::string, or integer value");
3176 else 3176 else
3177 retval = int_fid; 3177 retval = int_fid;
3178 } 3178 }
3179 3179
3180 return retval; 3180 return retval;