74 int ival =
NINT (dval);
102 ::error (
"%s: negative value invalid as size specification",
109 ::error (
"%s: NaN is invalid as size specification", who.c_str ());
116 bool& one_elt_size_spec,
const std::string& who)
121 one_elt_size_spec =
false;
130 one_elt_size_spec =
true;
134 dnc = (dnr == 0.0) ? 0.0 : 1.0;
136 else if (sz_len == 2)
143 ::error (
"%s: invalid size specification", who.c_str ());
146 ::error (
"%s: invalid size specification", who.c_str ());
158 : nconv (0), curr_idx (0), list (
dim_vector (16, 1)), buf (0)
162 size_t n = s.length ();
167 bool discard =
false;
168 char modifier =
'\0';
171 bool have_more =
true;
178 buf =
new std::ostringstream ();
187 have_more = (
buf != 0);
189 else if (isspace (s[i]))
198 while (++i < n && isspace (s[i]))
213 while (i < n && ! isspace (s[i]) && s[i] !=
'%')
250 const std::string& char_class)
254 std::string
text =
buf->str ();
260 modifier, char_class);
265 list(num_elts++) = elt;
278 size_t len = s.length ();
284 unsigned char c = s[i++];
286 if (c ==
'-' && i > 1 && i < len
287 && ( static_cast<unsigned char> (s[i-2])
288 <= static_cast<unsigned char> (s[i])))
293 for (c = s[i-2]+1; c < s[i]; c++)
301 if (c !=
'-' || i == len)
311 size_t n,
int& width,
bool& discard,
312 char&
type,
char& modifier,
322 bool have_width =
false;
338 case '0':
case '1':
case '2':
case '3':
case '4':
339 case '5':
case '6':
case '7':
case '8':
case '9':
345 width = width * 10 + c -
'0';
348 while (i < n && isdigit (s[i]))
351 width = width * 10 + c -
'0';
357 case 'h':
case 'l':
case 'L':
358 if (modifier !=
'\0')
364 case 'd':
case 'i':
case 'o':
case 'u':
case 'x':
372 case 'e':
case 'f':
case 'g':
384 case 'c':
case 's':
case 'p':
case '%':
case '[':
385 if (modifier !=
'\0')
395 modifier, num_elts) == 0)
414 size_t n,
int& width,
bool discard,
415 char&
type,
char modifier,
420 std::string char_class;
422 size_t beg_idx = std::string::npos;
423 size_t end_idx = std::string::npos;
455 else if (s[i] ==
']')
459 while (i < n && s[i] !=
']')
462 if (i < n && s[i] ==
']')
479 if (beg_idx != std::string::npos && end_idx != std::string::npos)
481 end_idx - beg_idx + 1));
483 add_elt_to_list (width, discard, type, modifier, num_elts, char_class);
499 <<
"width: " << elt->
width <<
"\n"
500 <<
"discard: " << elt->
discard <<
"\n"
504 std::cerr <<
"literal text\n";
506 std::cerr <<
"whitespace\n";
508 std::cerr << elt->
type <<
"\n";
511 <<
"modifier: " << elt->
modifier <<
"\n"
530 case 'c':
case 's':
case '%':
case '[':
case '^':
560 case 'd':
case 'i':
case 'o':
case 'u':
case 'x':
561 case 'e':
case 'f':
case 'g':
579 : nconv (0), curr_idx (0), list (
dim_vector (16, 1)), buf (0)
583 size_t n = s.length ();
591 char modifier =
'\0';
594 bool have_more =
true;
595 bool empty_buf =
true;
602 list(num_elts++) = elt;
614 buf =
new std::ostringstream ();
625 type, modifier, num_elts);
627 have_more = (
buf != 0);
678 int fw,
int prec,
char type,
683 std::string
text =
buf->str ();
694 list(num_elts++) = elt;
704 size_t n,
int& args, std::string& flags,
705 int& fw,
int& prec,
char& modifier,
723 case '-':
case '+':
case ' ':
case '0':
case '#':
750 std::string tmp = s.substr (i);
751 sscanf (tmp.c_str (),
"%d%n", &fw, &
nn);
754 while (i < n && isdigit (s[i]))
759 if (i < n && s[i] ==
'.')
776 std::string tmp = s.substr (i);
777 sscanf (tmp.c_str (),
"%d%n", &prec, &
nn);
780 while (i < n && isdigit (s[i]))
790 case 'h':
case 'l':
case 'L':
808 int args,
const std::string& flags,
809 int fw,
int prec,
char modifier,
814 case 'd':
case 'i':
case 'o':
case 'x':
case 'X':
823 case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
824 if (modifier ==
'h' || modifier ==
'l')
831 case 's':
case 'p':
case '%':
832 if (modifier !=
'\0')
845 if (type !=
'%' || args != 0)
866 for (
int i = 0; i < n; i++)
871 <<
"args: " << elt->
args <<
"\n"
872 <<
"flags: '" << elt->
flags <<
"'\n"
873 <<
"width: " << elt->
fw <<
"\n"
874 <<
"prec: " << elt->
prec <<
"\n"
875 <<
"type: '" << elt->
type <<
"'\n"
876 <<
"modifier: '" << elt->
modifier <<
"'\n"
892 errmsg = who +
": " + msg;
920 bool strip_newline,
const std::string& who)
926 ::error (
"%s: unable to read from stdin while running interactively",
938 std::istream& is = *isp;
940 std::ostringstream buf;
947 while (is && (c = is.get ()) != EOF)
956 buf << static_cast<char> (c);
967 buf << static_cast<char> (c);
978 buf << static_cast<char> (c);
983 buf << static_cast<char> (c);
985 if (max_len > 0 && char_count == max_len)
990 if (! is.eof () && char_count > 0)
995 int disgusting_compatibility_hack = is.get ();
997 is.putback (disgusting_compatibility_hack);
1000 if (is.good () || (is.eof () && char_count > 0))
1001 retval = buf.str ();
1006 if (is.eof () && char_count == 0)
1007 error (who,
"at end of file");
1009 error (who,
"read error");
1023 const std::string& who)
1025 return do_gets (max_len, err,
true, who);
1030 const std::string& who)
1032 return do_gets (max_len, err,
false, who);
1042 ::error (
"%s: unable to read from stdin while running interactively",
1054 std::istream& is = *isp;
1056 int c = 0, lastc = -1;
1059 while (is && (c = is.get ()) != EOF)
1063 if (c ==
'\r' || (c ==
'\n' && lastc !=
'\r'))
1073 if (c ==
'\r' && is.peek () ==
'\n')
1079 error (who,
"read error");
1094 #define OCTAVE_SCAN(is, fmt, arg) octave_scan (is, fmt, arg)
1105 is >> std::oct >> ref >> std::dec;
1109 is >> std::hex >> ref >> std::dec;
1116 while (is && (c1 = is.get ()) != EOF && isspace (c1))
1123 int c2 = is.peek ();
1125 if (c2 ==
'x' || c2 ==
'X')
1128 if (std::isxdigit (is.peek ()))
1129 is >> std::hex >> ref >> std::dec;
1135 if (c2 ==
'0' || c2 ==
'1' || c2 ==
'2'
1136 || c2 ==
'3' || c2 ==
'4' || c2 ==
'5'
1137 || c2 ==
'6' || c2 ==
'7')
1138 is >> std::oct >> ref >> std::dec;
1172 is.width (fmt.
width);
1175 std::istringstream ss (tmp);
1193 return is >> valptr;
1200 double& ref = *valptr;
1210 while (is && (c1 = is.get ()) != EOF && isspace (c1))
1217 ref = octave_read_value<double> (is);
1241 if (idx == max_size && ! discard)
1246 mval.
resize (nr, max_size / nr, 0.0);
1248 mval.
resize (max_size, 1, 0.0);
1256 data[idx++] = *(valptr);
1266 #define DO_WHITESPACE_CONVERSION() \
1271 while (is && (c = is.get ()) != EOF && isspace (c)) \
1279 #define DO_LITERAL_CONVERSION() \
1284 int n = strlen (fmt); \
1287 while (i < n && is && (c = is.get ()) != EOF) \
1289 if (c == static_cast<unsigned char> (fmt[i])) \
1302 is.setstate (std::ios::failbit); \
1306 #define DO_PCT_CONVERSION() \
1309 int c = is.get (); \
1316 is.setstate (std::ios::failbit); \
1320 is.setstate (std::ios::failbit); \
1324 #define BEGIN_C_CONVERSION() \
1325 is.unsetf (std::ios::skipws); \
1327 int width = elt->width ? elt->width : 1; \
1329 std::string tmp (width, '\0'); \
1334 while (is && n < width && (c = is.get ()) != EOF) \
1335 tmp[n++] = static_cast<char> (c); \
1337 if (n > 0 && c == EOF) \
1344 #define BEGIN_S_CONVERSION() \
1345 int width = elt->width; \
1353 tmp = std::string (width, '\0'); \
1359 while (is && (c = is.get ()) != EOF) \
1361 if (! isspace (c)) \
1363 tmp[n++] = static_cast<char> (c); \
1368 while (is && n < width && (c = is.get ()) != EOF) \
1376 tmp[n++] = static_cast<char> (c); \
1379 if (n > 0 && c == EOF) \
1386 is >> std::ws >> tmp; \
1392 #define BEGIN_CHAR_CLASS_CONVERSION() \
1393 int width = elt->width; \
1400 width = std::numeric_limits<int>::max (); \
1402 std::ostringstream buf; \
1404 std::string char_class = elt->char_class; \
1408 if (elt->type == '[') \
1410 int chars_read = 0; \
1411 while (is && chars_read++ < width && (c = is.get ()) != EOF \
1412 && char_class.find (c) != std::string::npos) \
1413 buf << static_cast<char> (c); \
1417 int chars_read = 0; \
1418 while (is && chars_read++ < width && (c = is.get ()) != EOF \
1419 && char_class.find (c) == std::string::npos) \
1420 buf << static_cast<char> (c); \
1423 if (width == std::numeric_limits<int>::max () && c != EOF) \
1429 is.setstate (std::ios::failbit); \
1430 else if (c == EOF) \
1436 #define FINISH_CHARACTER_CONVERSION() \
1439 width = tmp.length (); \
1447 conversion_count++; \
1451 if (data_index == max_size) \
1455 if (all_char_conv) \
1457 if (one_elt_size_spec) \
1458 mval.resize (1, max_size, 0.0); \
1460 mval.resize (nr, max_size / nr, 0.0); \
1462 panic_impossible (); \
1465 mval.resize (nr, max_size / nr, 0.0); \
1467 mval.resize (max_size, 1, 0.0); \
1469 data = mval.fortran_vec (); \
1472 data[data_index++] = tmp[i++]; \
1482 bool one_elt_size_spec,
1484 const std::string& who)
1490 ::error (
"%s: unable to read from stdin while running interactively",
1496 conversion_count = 0;
1502 if (nr == 0 || nc == 0)
1504 if (one_elt_size_spec)
1507 return Matrix (nr, nc, 0.0);
1528 if (one_elt_size_spec)
1531 mval.
resize (1, max_size, 0.0);
1540 mval.
resize (nr, nc, 0.0);
1541 max_size = max_conv = nr * nc;
1545 mval.
resize (nr, 32, 0.0);
1557 mval.
resize (nr, nc, 0.0);
1559 max_conv = max_size;
1564 mval.
resize (nr, 32, 0.0);
1571 mval.
resize (32, 1, 0.0);
1579 std::istream& is = *isp;
1583 std::ios::fmtflags flags = is.flags ();
1597 || elt->
type ==
'%')
1598 && max_conv > 0 && conversion_count == max_conv)
1600 if (all_char_conv && one_elt_size_spec)
1603 final_nc = data_index;
1608 final_nc = (data_index - 1) / nr + 1;
1613 else if (data_index == max_size)
1619 if (one_elt_size_spec)
1620 mval.
resize (1, max_size, 0.0);
1622 mval.
resize (nr, max_size / nr, 0.0);
1627 mval.
resize (nr, max_size / nr, 0.0);
1629 mval.
resize (max_size, 1, 0.0);
1634 const char *fmt = elt->
text;
1660 data_index, conversion_count,
1661 nr, max_size, discard);
1669 data_index, conversion_count,
1670 nr, max_size, discard);
1678 data_index, conversion_count,
1679 nr, max_size, discard);
1686 case 'o':
case 'u':
case 'x':
1692 unsigned short int tmp;
1694 data_index, conversion_count,
1695 nr, max_size, discard);
1701 unsigned long int tmp;
1703 data_index, conversion_count,
1704 nr, max_size, discard);
1712 data_index, conversion_count,
1713 nr, max_size, discard);
1720 case 'e':
case 'f':
case 'g':
1725 data_index, conversion_count,
1726 nr, max_size, discard);
1757 error (
"%s: unsupported format specifier", who.c_str ());
1761 error (
"%s: internal format error", who.c_str ());
1773 if (one_elt_size_spec)
1776 final_nc = data_index;
1778 else if (data_index > nr)
1781 final_nc = (data_index - 1) / nr + 1;
1785 final_nr = data_index;
1791 if (data_index > nr)
1794 final_nc = (data_index - 1) / nr + 1;
1798 final_nr = data_index;
1804 final_nr = data_index;
1811 if (is.rdstate () & std::ios::failbit)
1812 is.clear (is.rdstate () & (~std::ios::failbit));
1823 do_gets (-1, err,
false, who);
1831 error (
"%s: internal format error", who.c_str ());
1835 if (nconv == 0 && ++trips == num_fmt_elts)
1837 if (all_char_conv && one_elt_size_spec)
1840 final_nc = data_index;
1845 final_nc = (data_index - 1) / nr + 1;
1851 elt = fmt_list.
next (nconv > 0);
1857 mval.
resize (final_nr, final_nc, 0.0);
1871 const std::string& who)
1875 conversion_count = 0;
1884 ::
error (
"%s: invalid format specified", who.c_str ());
1890 bool one_elt_size_spec;
1892 get_size (size, nr, nc, one_elt_size_spec, who);
1895 retval =
do_scanf (fmt_list, nr, nc, one_elt_size_spec,
1896 conversion_count, who);
1915 std::istream& is = *isp;
1917 std::ios::fmtflags flags = is.flags ();
1921 const char *fmt = elt->
text;
1959 case 'o':
case 'u':
case 'x':
1973 case 'e':
case 'f':
case 'g':
2026 error (
"%s: unsupported format specifier", who.c_str ());
2030 error (
"%s: internal format error", who.c_str ());
2035 if (
ok () && is.fail ())
2037 error (
"%s: read error", who.c_str ());
2046 do_gets (-1, err,
false, who);
2063 std::istream& is = *isp;
2070 ::error (
"%s: invalid format specified", who.c_str ());
2096 retval(num_values++) = tmp;
2101 elt = fmt_list.
next (nconv > 0);
2105 retval(nconv) = num_values;
2108 retval(nconv+1) =
error (
false, err_num);
2113 if (
ok () && len > nconv)
2117 elt = fmt_list.
next ();
2161 : values (args), val_idx (0), elt_idx (0),
2162 n_vals (values.
length ()), n_elts (0), data (0),
2180 double double_value (
void);
2183 int int_value (
void);
2186 std::string string_value (
void);
2188 operator bool ()
const {
return (curr_state == ok); }
2217 double retval = 0.0;
2282 if (
D_NINT (dval) == dval)
2283 retval =
NINT (dval);
2302 if (tval.
rows () == 1)
2315 retval.resize (nr * nc,
'\0');
2319 retval[k++] = chm(i,j);
2334 int sa_2, T
arg,
const std::string& who)
2353 ::error (
"%s: internal error handling format", who.c_str ());
2360 #define DO_DOUBLE_CONV(TQUAL) \
2363 if (val > std::numeric_limits<TQUAL long>::max () \
2364 || val < std::numeric_limits<TQUAL long>::min ()) \
2366 std::string tfmt = fmt; \
2368 tfmt.replace (tfmt.rfind (elt->type), 1, ".f"); \
2370 if (elt->modifier == 'l') \
2371 tfmt.replace (tfmt.rfind (elt->modifier), 1, ""); \
2373 retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2, \
2377 retval += do_printf_conv (os, fmt, nsa, sa_1, sa_2, \
2378 static_cast<TQUAL long> (val), who); \
2385 const std::string& who)
2395 std::ostream& os = *osp;
2412 int nsa = (elt->
fw < 0) + (elt->
prec < 0);
2435 const char *fmt = elt->
text;
2437 if (elt->
type ==
'%')
2442 else if (elt->
args == 0 && elt->
text)
2445 retval += strlen (elt->
text);
2447 else if (elt->
type ==
's')
2453 sa_2, val.c_str (), who);
2465 std::string tfmt = fmt;
2466 std::string::size_type i1, i2;
2468 tfmt.replace ((i1 = tfmt.rfind (elt->
type)),
2471 if ((i2 = tfmt.rfind (
'.')) != std::string::npos
2474 tfmt.erase (i2, i1-i2);
2481 if (elt->
flags.find (
'+') != std::string::npos)
2482 tval = (val < 0 ?
"-Inf" :
"+Inf");
2484 tval = (val < 0 ?
"-Inf" :
"Inf");
2486 if (elt->
flags.find (
'+') != std::string::npos)
2501 case 'd':
case 'i':
case 'c':
2505 case 'o':
case 'x':
case 'X':
case 'u':
2509 case 'f':
case 'e':
case 'E':
2512 sa_1, sa_2, val, who);
2516 error (
"%s: invalid format specifier",
2529 error (
"%s: write error", who.c_str ());
2535 ::error (
"%s: internal error handling format", who.c_str ());
2540 elt = fmt_list.
next (nconv > 0 && ! val_cache.
exhausted ());
2555 const std::string& who)
2562 ::
error (
"%s: invalid format specified", who.c_str ());
2564 retval =
do_printf (fmt_list, args, who);
2578 std::ostream& os = *osp;
2596 error (
"%s: write error", who.c_str ());
2599 error (
"%s: write error", who.c_str ());
2612 err_num =
fail ? -1 : 0;
2614 std::string tmp =
errmsg;
2627 error (who, std::string (
"stream not open for ") + rw);
2684 retval =
rep->
getl (max_len, err, who);
2691 const std::string& who)
2705 if (conv_err || max_len < 0)
2708 ::error (
"%s: invalid maximum length specified", who.c_str ());
2713 retval =
getl (max_len, err, who);
2724 retval =
rep->
gets (max_len, err, who);
2731 const std::string& who)
2745 if (conv_err || max_len < 0)
2748 ::error (
"%s: invalid maximum length specified", who.c_str ());
2753 retval =
gets (max_len, err, who);
2764 retval =
rep->
skipl (count, err, who);
2771 const std::string& who)
2789 if (conv_err || count < 0)
2792 ::error (
"%s: invalid number of lines specified", who.c_str ());
2798 retval =
skipl (count, err, who);
2814 off_t orig_pos =
rep->
tell ();
2836 status =
rep->
seek (offset, origin);
2842 off_t desired_pos =
rep->
tell ();
2847 if (desired_pos > eof_pos || desired_pos < 0)
2880 off_t xoffset = val.
value ();
2892 if (xorigin ==
"bof")
2894 else if (xorigin ==
"cof")
2896 else if (xorigin ==
"eof")
2909 else if (xorigin == 0)
2911 else if (xorigin == 1)
2920 retval =
seek (xoffset, origin);
2923 error (
"fseek: failed to seek to requested position");
2926 error (
"fseek: invalid value for origin");
2929 error (
"fseek: invalid value for offset");
2954 bool retval =
false;
2969 template <
class SRC_T,
class DST_T>
2975 bool do_float_fmt_conv,
bool do_NA_conv,
2978 typedef typename DST_T::element_type dst_elt_type;
2982 dst_elt_type *conv_data = conv.fortran_vec ();
2986 for (std::list<void *>::const_iterator it = input_buf_list.begin ();
2987 it != input_buf_list.end (); it++)
2989 SRC_T *data =
static_cast<SRC_T *
> (*it);
2991 if (swap || do_float_fmt_conv)
2997 swap_bytes<sizeof (SRC_T)> (&data[i]);
2998 else if (do_float_fmt_conv)
3003 dst_elt_type tmp (data[i]);
3018 dst_elt_type tmp (data[i]);
3030 conv_data[j] = data[i];
3037 input_buf_list.clear ();
3040 conv_data[i] = dst_elt_type (0);
3048 bool swap,
bool do_float_fmt_conv,
bool do_NA_conv,
3051 #define TABLE_ELT(T, U, V, W) \
3052 conv_fptr_table[oct_data_conv::T][oct_data_conv::U] = convert_and_copy<V, W>
3054 #define FILL_TABLE_ROW(T, V) \
3055 TABLE_ELT (T, dt_int8, V, int8NDArray); \
3056 TABLE_ELT (T, dt_uint8, V, uint8NDArray); \
3057 TABLE_ELT (T, dt_int16, V, int16NDArray); \
3058 TABLE_ELT (T, dt_uint16, V, uint16NDArray); \
3059 TABLE_ELT (T, dt_int32, V, int32NDArray); \
3060 TABLE_ELT (T, dt_uint32, V, uint32NDArray); \
3061 TABLE_ELT (T, dt_int64, V, int64NDArray); \
3062 TABLE_ELT (T, dt_uint64, V, uint64NDArray); \
3063 TABLE_ELT (T, dt_single, V, FloatNDArray); \
3064 TABLE_ELT (T, dt_double, V, NDArray); \
3065 TABLE_ELT (T, dt_char, V, charNDArray); \
3066 TABLE_ELT (T, dt_schar, V, charNDArray); \
3067 TABLE_ELT (T, dt_uchar, V, charNDArray); \
3068 TABLE_ELT (T, dt_logical, V, boolNDArray);
3090 for (
int j = 0; j < 14; j++)
3091 conv_fptr_table[i][j] = 0;
3127 switch (output_type)
3146 retval =
fptr (input_buf_list, input_buf_elts, elts_read,
3147 nr, nc, swap, do_float_fmt_conv, do_NA_conv, ffmt);
3153 (*current_liboctave_error_handler)
3154 (
"read: invalid type specification");
3174 bool one_elt_size_spec =
false;
3186 get_size (size, nr, nc, one_elt_size_spec,
"fread");
3194 if (one_elt_size_spec)
3217 if (nr == 0 || nc == 0)
3223 elts_to_read = nr * nc;
3225 bool read_to_eof = elts_to_read < 0;
3232 input_buf_elts = 1024 * 1024;
3234 input_buf_elts = elts_to_read;
3237 input_buf_elts = block_size;
3244 assert (input_buf_size >= 0);
3253 std::istream& is = *isp;
3255 std::list <void *> input_buf_list;
3259 while (is && ! is.eof ()
3260 && (read_to_eof || elts_read < elts_to_read))
3262 char *input_buf =
new char [input_buf_size];
3264 is.read (input_buf, input_buf_size);
3266 size_t count = is.gcount ();
3268 char_count += count;
3270 elts_read += count / input_elt_size;
3272 input_buf_list.push_back (input_buf);
3274 if (is && skip != 0 && elts_read == block_size)
3278 if (seek_status < 0)
3286 nc = elts_read / nr + 1;
3291 retval =
finalize_read (input_buf_list, input_buf_elts, elts_read,
3292 nr, nc, input_type, output_type, ffmt);
3295 error (
"fread: invalid input stream");
3322 error (
"fwrite: write error");
3333 template <
class T,
class V>
3338 typedef typename V::val_type val_type;
3340 val_type *vt_data = static_cast <val_type *> (conv_data);
3346 vt_data[i] = val.value ();
3349 swap_bytes<sizeof (val_type)> (&vt_data[i]);
3371 switch (output_type)
3376 convert_ints<T, octave_int8> (data, conv_data, n_elts, swap);
3381 convert_ints<T, octave_uint8> (data, conv_data, n_elts, swap);
3385 convert_ints<T, octave_int16> (data, conv_data, n_elts, swap);
3389 convert_ints<T, octave_uint16> (data, conv_data, n_elts, swap);
3393 convert_ints<T, octave_int32> (data, conv_data, n_elts, swap);
3397 convert_ints<T, octave_uint32> (data, conv_data, n_elts, swap);
3401 convert_ints<T, octave_int64> (data, conv_data, n_elts, swap);
3405 convert_ints<T, octave_uint64> (data, conv_data, n_elts, swap);
3410 float *vt_data = static_cast <
float *> (conv_data);
3414 vt_data[i] = data[i];
3416 if (do_float_conversion)
3424 double *vt_data = static_cast <
double *> (conv_data);
3428 vt_data[i] = data[i];
3430 if (do_float_conversion)
3438 (*current_liboctave_error_handler)
3439 (
"write: invalid type specification");
3449 bool status =
false;
3455 std::ostream& os = *osp;
3459 os.write (static_cast<const char *> (data), nbytes);
3472 bool status =
false;
3478 std::ostream& os = *osp;
3483 off_t orig_pos =
tell ();
3487 off_t eof_pos =
tell ();
3493 size_t remaining = eof_pos - orig_pos;
3495 if (remaining < skip)
3501 unsigned char zero = 0;
3502 for (
size_t j = 0; j < skip - remaining; j++)
3503 os.write (reinterpret_cast<const char *> (&zero), 1);
3526 bool do_data_conversion = (swap || ! is_equivalent_type<T> (output_type)
3534 chunk_size = block_size;
3535 else if (do_data_conversion)
3536 chunk_size = 1024 * 1024;
3542 const T *pdata = data.
data ();
3554 if (chunk_size > remaining_nel)
3555 chunk_size = remaining_nel;
3557 bool status =
false;
3559 if (do_data_conversion)
3566 status =
convert_data (&pdata[i], conv_data, chunk_size,
3567 output_type, flt_fmt);
3573 status =
write_bytes (pdata,
sizeof (T) * chunk_size);
3584 #define INSTANTIATE_WRITE(T) \
3587 octave_stream::write (const Array<T>& data, octave_idx_type block_size, \
3588 oct_data_conv::data_type output_type, \
3589 octave_idx_type skip, \
3590 oct_mach_info::float_format flt_fmt)
3620 retval =
rep->
scanf (fmt, size, count, who);
3638 retval =
scanf (sfmt, size, count, who);
3644 error (who +
": format must be a string");
3673 retval =
oscanf (sfmt, who);
3679 error (who +
": format must be a string");
3687 const std::string& who)
3699 const std::string& who)
3710 retval =
printf (sfmt, args, who);
3716 error (who +
": format must be a string");
3743 retval =
puts (s, who);
3749 error (who +
": argument must be a string");
3769 std::string retval =
"invalid stream object";
3772 retval =
rep->
error (clear, err_num);
3813 std::string retval =
"???";
3814 std::ios::openmode in_mode =
static_cast<std::ios::openmode
> (
mode);
3816 if (in_mode == std::ios::in)
3818 else if (in_mode == std::ios::out
3819 || in_mode == (std::ios::out | std::ios::trunc))
3821 else if (in_mode == (std::ios::out | std::ios::app))
3823 else if (in_mode == (std::ios::in | std::ios::out))
3825 else if (in_mode == (std::ios::in | std::ios::out | std::ios::trunc))
3827 else if (in_mode == (std::ios::in | std::ios::out | std::ios::ate))
3829 else if (in_mode == (std::ios::in | std::ios::binary))
3831 else if (in_mode == (std::ios::out | std::ios::binary)
3832 || in_mode == (std::ios::out | std::ios::trunc | std::ios::binary))
3834 else if (in_mode == (std::ios::out | std::ios::app | std::ios::binary))
3836 else if (in_mode == (std::ios::in | std::ios::out | std::ios::binary))
3838 else if (in_mode == (std::ios::in | std::ios::out | std::ios::trunc
3839 | std::ios::binary))
3841 else if (in_mode == (std::ios::in | std::ios::out | std::ios::ate
3842 | std::ios::binary))
3865 ::error (
"unable to create stream list object!");
3949 return stream_number;
3961 if (
list.size () <
list.max_size ())
3962 list[stream_number] = os;
3966 error (
"could not create file id");
3969 return stream_number;
3977 ::
error (
"invalid stream number = %d", fid);
3979 ::error (
"%s: invalid stream number = %d", who.c_str (), fid);
3993 ostrl_map::const_iterator iter =
list.find (fid);
3995 if (iter !=
list.end ())
3997 retval = iter->second;
4012 const std::string& who)
const
4034 ostrl_map::iterator iter =
list.find (fid);
4036 if (iter !=
list.end ())
4095 for (ostrl_map::iterator iter =
list.begin (); iter !=
list.end (); iter++)
4097 int fid = iter->first;
4105 for (
int fid = 0; fid < 3; fid++)
list[fid] = saved_os[fid];
4122 retval(0) = os.
name ();
4125 ::error (
"invalid file id = %d", fid);
4142 ::error (
"file id must be a file object or integer value");
4152 std::ostringstream buf;
4155 <<
" number mode arch name\n"
4156 <<
" ------ ---- ---- ----\n";
4158 for (ostrl_map::const_iterator p =
list.begin (); p !=
list.end (); p++)
4163 << std::setiosflags (std::ios::right)
4164 << std::setw (4) << p->first <<
" "
4172 << os.
name () <<
"\n";
4177 retval = buf.str ();
4189 for (ostrl_map::const_iterator p =
list.begin (); p !=
list.end (); p++)
4193 if (p->first > 2 && p->second)
4194 retval(0,num_open++) = p->first;
4197 retval.
resize ((num_open > 0), num_open);
4211 for (ostrl_map::const_iterator p =
list.begin (); p !=
list.end (); p++)
4220 if (os && os.
name () == nm)
4235 ::error (
"file id must be a file object, std::string, or integer value");