Mercurial > hg > octave-nkf
diff src/oct-stream.cc @ 10315:57a59eae83cc
untabify src C++ source files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 11 Feb 2010 12:41:46 -0500 |
parents | ba373aea03d9 |
children | 12884915a8e4 |
line wrap: on
line diff
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -70,16 +70,16 @@ if (! error_state) { if (! lo_ieee_isnan (dval)) - { - int ival = NINT (dval); - - if (ival == dval) - retval = ival; - else - conv_err = 3; - } + { + int ival = NINT (dval); + + if (ival == dval) + retval = ival; + else + conv_err = 3; + } else - conv_err = 2; + conv_err = 2; } else conv_err = 1; @@ -95,15 +95,15 @@ if (! lo_ieee_isnan (d)) { if (! xisinf (d)) - { - if (d >= 0.0) - retval = NINT (d); - else - ::error ("%s: negative value invalid as size specification", - who.c_str ()); - } + { + if (d >= 0.0) + retval = NINT (d); + else + ::error ("%s: negative value invalid as size specification", + who.c_str ()); + } else - retval = -1; + retval = -1; } else ::error ("%s: NaN is invalid as size specification", who.c_str ()); @@ -113,7 +113,7 @@ static void get_size (const Array<double>& size, octave_idx_type& nr, octave_idx_type& nc, bool& one_elt_size_spec, - const std::string& who) + const std::string& who) { nr = -1; nc = -1; @@ -138,9 +138,9 @@ dnr = size (0); if (! xisinf (dnr)) - dnc = size (1); + dnc = size (1); else - ::error ("%s: invalid size specification", who.c_str ()); + ::error ("%s: invalid size specification", who.c_str ()); } else ::error ("%s: invalid size specification", who.c_str ()); @@ -150,7 +150,7 @@ nr = get_size (dnr, who); if (! error_state && dnc >= 0.0) - nc = get_size (dnc, who); + nc = get_size (dnc, who); } } @@ -175,54 +175,54 @@ have_more = true; if (! buf) - buf = new std::ostringstream (); + buf = new std::ostringstream (); if (s[i] == '%') - { - // Process percent-escape conversion type. - - process_conversion (s, i, n, width, discard, type, modifier, - num_elts); - - have_more = (buf != 0); - } + { + // Process percent-escape conversion type. + + process_conversion (s, i, n, width, discard, type, modifier, + num_elts); + + have_more = (buf != 0); + } else if (isspace (s[i])) - { - type = scanf_format_elt::whitespace_conversion; - - width = 0; - discard = false; - modifier = '\0'; - *buf << " "; - - while (++i < n && isspace (s[i])) - /* skip whitespace */; - - add_elt_to_list (width, discard, type, modifier, num_elts); - - have_more = false; - } + { + type = scanf_format_elt::whitespace_conversion; + + width = 0; + discard = false; + modifier = '\0'; + *buf << " "; + + while (++i < n && isspace (s[i])) + /* skip whitespace */; + + add_elt_to_list (width, discard, type, modifier, num_elts); + + have_more = false; + } else - { - type = scanf_format_elt::literal_conversion; - - width = 0; - discard = false; - modifier = '\0'; - - while (i < n && ! isspace (s[i]) && s[i] != '%') - *buf << s[i++]; - - add_elt_to_list (width, discard, type, modifier, num_elts); - - have_more = false; - } + { + type = scanf_format_elt::literal_conversion; + + width = 0; + discard = false; + modifier = '\0'; + + while (i < n && ! isspace (s[i]) && s[i] != '%') + *buf << s[i++]; + + add_elt_to_list (width, discard, type, modifier, num_elts); + + have_more = false; + } if (nconv < 0) - { - have_more = false; - break; - } + { + have_more = false; + break; + } } if (have_more) @@ -241,29 +241,29 @@ { scanf_format_elt *elt = list(i); delete elt; - } + } } void scanf_format_list::add_elt_to_list (int width, bool discard, char type, - char modifier, octave_idx_type& num_elts, - const std::string& char_class) + char modifier, octave_idx_type& num_elts, + const std::string& char_class) { if (buf) { std::string text = buf->str (); if (! text.empty ()) - { - scanf_format_elt *elt - = new scanf_format_elt (text.c_str (), width, discard, type, - modifier, char_class); - - if (num_elts == list.length ()) - list.resize (2 * num_elts); - - list(num_elts++) = elt; - } + { + scanf_format_elt *elt + = new scanf_format_elt (text.c_str (), width, discard, type, + modifier, char_class); + + if (num_elts == list.length ()) + list.resize (2 * num_elts); + + list(num_elts++) = elt; + } delete buf; buf = 0; @@ -284,22 +284,22 @@ unsigned char c = s[i++]; if (c == '-' && i > 1 && i < len - && static_cast<unsigned char> (s[i-2]) <= static_cast<unsigned char> (s[i])) - { - // Add all characters from the range except the first (we - // already added it below). - - for (c = s[i-2]+1; c < s[i]; c++) - retval += c; - } + && static_cast<unsigned char> (s[i-2]) <= static_cast<unsigned char> (s[i])) + { + // Add all characters from the range except the first (we + // already added it below). + + for (c = s[i-2]+1; c < s[i]; c++) + retval += c; + } else - { - // Add the character to the class. Only add '-' if it is - // the last character in the class. - - if (c != '-' || i == len) - retval += c; - } + { + // Add the character to the class. Only add '-' if it is + // the last character in the class. + + if (c != '-' || i == len) + retval += c; + } } return retval; @@ -323,86 +323,86 @@ while (i < n) { switch (s[i]) - { - case '*': - if (discard) - nconv = -1; - else - { - discard = true; - *buf << s[i++]; - } - break; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - if (have_width) - nconv = -1; - else - { - char c = s[i++]; - width = width * 10 + c - '0'; - have_width = true; - *buf << c; - while (i < n && isdigit (s[i])) - { - c = s[i++]; - width = width * 10 + c - '0'; - *buf << c; - } - } - break; - - case 'h': case 'l': case 'L': - if (modifier != '\0') - nconv = -1; - else - modifier = s[i++]; - break; - - case 'd': case 'i': case 'o': case 'u': case 'x': - if (modifier == 'L') - { - nconv = -1; - break; - } - goto fini; - - case 'e': case 'f': case 'g': - if (modifier == 'h') - { - nconv = -1; - break; - } - - // No float or long double conversions, thanks. - *buf << 'l'; - - goto fini; - - case 'c': case 's': case 'p': case '%': case '[': - if (modifier != '\0') - { - nconv = -1; - break; - } - goto fini; - - fini: - { - if (finish_conversion (s, i, n, width, discard, type, - modifier, num_elts) == 0) - return; - } - break; - - default: - nconv = -1; - break; - } + { + case '*': + if (discard) + nconv = -1; + else + { + discard = true; + *buf << s[i++]; + } + break; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + if (have_width) + nconv = -1; + else + { + char c = s[i++]; + width = width * 10 + c - '0'; + have_width = true; + *buf << c; + while (i < n && isdigit (s[i])) + { + c = s[i++]; + width = width * 10 + c - '0'; + *buf << c; + } + } + break; + + case 'h': case 'l': case 'L': + if (modifier != '\0') + nconv = -1; + else + modifier = s[i++]; + break; + + case 'd': case 'i': case 'o': case 'u': case 'x': + if (modifier == 'L') + { + nconv = -1; + break; + } + goto fini; + + case 'e': case 'f': case 'g': + if (modifier == 'h') + { + nconv = -1; + break; + } + + // No float or long double conversions, thanks. + *buf << 'l'; + + goto fini; + + case 'c': case 's': case 'p': case '%': case '[': + if (modifier != '\0') + { + nconv = -1; + break; + } + goto fini; + + fini: + { + if (finish_conversion (s, i, n, width, discard, type, + modifier, num_elts) == 0) + return; + } + break; + + default: + nconv = -1; + break; + } if (nconv < 0) - break; + break; } nconv = -1; @@ -431,44 +431,44 @@ type = s[i]; if (s[i] == '[') - { - *buf << s[i++]; - - if (i < n) - { - beg_idx = i; - - if (s[i] == '^') - { - type = '^'; - *buf << s[i++]; - - if (i < n) - { - beg_idx = i; - - if (s[i] == ']') - *buf << s[i++]; - } - } - else if (s[i] == ']') - *buf << s[i++]; - } - - while (i < n && s[i] != ']') - *buf << s[i++]; - - if (i < n && s[i] == ']') - { - end_idx = i-1; - *buf << s[i++]; - } - - if (s[i-1] != ']') - retval = nconv = -1; - } + { + *buf << s[i++]; + + if (i < n) + { + beg_idx = i; + + if (s[i] == '^') + { + type = '^'; + *buf << s[i++]; + + if (i < n) + { + beg_idx = i; + + if (s[i] == ']') + *buf << s[i++]; + } + } + else if (s[i] == ']') + *buf << s[i++]; + } + + while (i < n && s[i] != ']') + *buf << s[i++]; + + if (i < n && s[i] == ']') + { + end_idx = i-1; + *buf << s[i++]; + } + + if (s[i-1] != ']') + retval = nconv = -1; + } else - *buf << s[i++]; + *buf << s[i++]; nconv++; } @@ -476,8 +476,8 @@ if (nconv >= 0) { if (beg_idx != std::string::npos && end_idx != std::string::npos) - char_class = expand_char_class (s.substr (beg_idx, - end_idx - beg_idx + 1)); + char_class = expand_char_class (s.substr (beg_idx, + end_idx - beg_idx + 1)); add_elt_to_list (width, discard, type, modifier, num_elts, char_class); } @@ -495,21 +495,21 @@ scanf_format_elt *elt = list(i); std::cerr - << "width: " << elt->width << "\n" - << "discard: " << elt->discard << "\n" - << "type: "; + << "width: " << elt->width << "\n" + << "discard: " << elt->discard << "\n" + << "type: "; if (elt->type == scanf_format_elt::literal_conversion) - std::cerr << "literal text\n"; + std::cerr << "literal text\n"; else if (elt->type == scanf_format_elt::whitespace_conversion) - std::cerr << "whitespace\n"; + std::cerr << "whitespace\n"; else - std::cerr << elt->type << "\n"; + std::cerr << elt->type << "\n"; std::cerr - << "modifier: " << elt->modifier << "\n" - << "char_class: `" << undo_string_escapes (elt->char_class) << "'\n" - << "text: `" << undo_string_escapes (elt->text) << "'\n\n"; + << "modifier: " << elt->modifier << "\n" + << "char_class: `" << undo_string_escapes (elt->char_class) << "'\n" + << "text: `" << undo_string_escapes (elt->text) << "'\n\n"; } } @@ -521,21 +521,21 @@ if (n > 0) { for (octave_idx_type i = 0; i < n; i++) - { - scanf_format_elt *elt = list(i); - - switch (elt->type) - { - case 'c': case 's': case '%': case '[': case '^': - case scanf_format_elt::literal_conversion: - case scanf_format_elt::whitespace_conversion: - break; - - default: - return false; - break; - } - } + { + scanf_format_elt *elt = list(i); + + switch (elt->type) + { + case 'c': case 's': case '%': case '[': case '^': + case scanf_format_elt::literal_conversion: + case scanf_format_elt::whitespace_conversion: + break; + + default: + return false; + break; + } + } return true; } @@ -551,20 +551,20 @@ if (n > 0) { for (octave_idx_type i = 0; i < n; i++) - { - scanf_format_elt *elt = list(i); - - switch (elt->type) - { - case 'd': case 'i': case 'o': case 'u': case 'x': - case 'e': case 'f': case 'g': - break; - - default: - return false; - break; - } - } + { + scanf_format_elt *elt = list(i); + + switch (elt->type) + { + case 'd': case 'i': case 'o': case 'u': case 'x': + case 'e': case 'f': case 'g': + break; + + default: + return false; + break; + } + } return true; } @@ -596,7 +596,7 @@ if (n == 0) { printf_format_elt *elt - = new printf_format_elt ("", args, fw, prec, flags, type, modifier); + = new printf_format_elt ("", args, fw, prec, flags, type, modifier); list(num_elts++) = elt; @@ -605,55 +605,55 @@ else { while (i < n) - { - have_more = true; - - if (! buf) - { - buf = new std::ostringstream (); - empty_buf = true; - } - - switch (s[i]) - { - case '%': - { - if (empty_buf) - { - process_conversion (s, i, n, args, flags, fw, prec, - type, modifier, num_elts); - - have_more = (buf != 0); - } - else - add_elt_to_list (args, flags, fw, prec, type, modifier, - num_elts); - } - break; - - default: - { - args = 0; - flags = ""; - fw = 0; - prec = 0; - modifier = '\0'; - type = '\0'; - *buf << s[i++]; - empty_buf = false; - } - break; - } - - if (nconv < 0) - { - have_more = false; - break; - } - } + { + have_more = true; + + if (! buf) + { + buf = new std::ostringstream (); + empty_buf = true; + } + + switch (s[i]) + { + case '%': + { + if (empty_buf) + { + process_conversion (s, i, n, args, flags, fw, prec, + type, modifier, num_elts); + + have_more = (buf != 0); + } + else + add_elt_to_list (args, flags, fw, prec, type, modifier, + num_elts); + } + break; + + default: + { + args = 0; + flags = ""; + fw = 0; + prec = 0; + modifier = '\0'; + type = '\0'; + *buf << s[i++]; + empty_buf = false; + } + break; + } + + if (nconv < 0) + { + have_more = false; + break; + } + } if (have_more) - add_elt_to_list (args, flags, fw, prec, type, modifier, num_elts); + add_elt_to_list (args, flags, fw, prec, type, modifier, num_elts); list.resize (num_elts); @@ -669,29 +669,29 @@ { printf_format_elt *elt = list(i); delete elt; - } + } } void printf_format_list::add_elt_to_list (int args, const std::string& flags, - int fw, int prec, char type, - char modifier, octave_idx_type& num_elts) + int fw, int prec, char type, + char modifier, octave_idx_type& num_elts) { if (buf) { std::string text = buf->str (); if (! text.empty ()) - { - printf_format_elt *elt - = new printf_format_elt (text.c_str (), args, fw, prec, flags, - type, modifier); - - if (num_elts == list.length ()) - list.resize (2 * num_elts); - - list(num_elts++) = elt; - } + { + printf_format_elt *elt + = new printf_format_elt (text.c_str (), args, fw, prec, flags, + type, modifier); + + if (num_elts == list.length ()) + list.resize (2 * num_elts); + + list(num_elts++) = elt; + } delete buf; buf = 0; @@ -717,41 +717,41 @@ while (i < n) { switch (s[i]) - { - case '-': case '+': case ' ': case '0': case '#': - flags += s[i]; - *buf << s[i++]; - break; - - default: - nxt = true; - break; - } + { + case '-': case '+': case ' ': case '0': case '#': + flags += s[i]; + *buf << s[i++]; + break; + + default: + nxt = true; + break; + } if (nxt) - break; + break; } if (i < n) { if (s[i] == '*') - { - fw = -1; - args++; - *buf << s[i++]; - } + { + fw = -1; + args++; + *buf << s[i++]; + } else - { - if (isdigit (s[i])) - { - int nn = 0; - std::string tmp = s.substr (i); - sscanf (tmp.c_str (), "%d%n", &fw, &nn); - } - - while (i < n && isdigit (s[i])) - *buf << s[i++]; - } + { + if (isdigit (s[i])) + { + int nn = 0; + std::string tmp = s.substr (i); + sscanf (tmp.c_str (), "%d%n", &fw, &nn); + } + + while (i < n && isdigit (s[i])) + *buf << s[i++]; + } } if (i < n && s[i] == '.') @@ -759,40 +759,40 @@ *buf << s[i++]; if (i < n) - { - if (s[i] == '*') - { - prec = -1; - args++; - *buf << s[i++]; - } - else - { - if (isdigit (s[i])) - { - int nn = 0; - std::string tmp = s.substr (i); - sscanf (tmp.c_str (), "%d%n", &prec, &nn); - } - - while (i < n && isdigit (s[i])) - *buf << s[i++]; - } - } + { + if (s[i] == '*') + { + prec = -1; + args++; + *buf << s[i++]; + } + else + { + if (isdigit (s[i])) + { + int nn = 0; + std::string tmp = s.substr (i); + sscanf (tmp.c_str (), "%d%n", &prec, &nn); + } + + while (i < n && isdigit (s[i])) + *buf << s[i++]; + } + } } if (i < n) { switch (s[i]) - { - case 'h': case 'l': case 'L': - modifier = s[i]; - *buf << s[i++]; - break; - - default: - break; - } + { + case 'h': case 'l': case 'L': + modifier = s[i]; + *buf << s[i++]; + break; + + default: + break; + } } if (i < n) @@ -812,26 +812,26 @@ case 'd': case 'i': case 'o': case 'x': case 'X': case 'u': case 'c': if (modifier == 'L') - { - nconv = -1; - break; - } + { + nconv = -1; + break; + } goto fini; case 'f': case 'e': case 'E': case 'g': case 'G': if (modifier == 'h' || modifier == 'l') - { - nconv = -1; - break; - } + { + nconv = -1; + break; + } goto fini; case 's': case 'p': case '%': if (modifier != '\0') - { - nconv = -1; - break; - } + { + nconv = -1; + break; + } goto fini; fini: @@ -841,10 +841,10 @@ *buf << s[i++]; if (type != '%' || args != 0) - nconv++; + nconv++; if (type != '%') - args++; + args++; add_elt_to_list (args, flags, fw, prec, type, modifier, num_elts); @@ -866,13 +866,13 @@ printf_format_elt *elt = list(i); std::cerr - << "args: " << elt->args << "\n" - << "flags: `" << elt->flags << "'\n" - << "width: " << elt->fw << "\n" - << "prec: " << elt->prec << "\n" - << "type: `" << elt->type << "'\n" - << "modifier: `" << elt->modifier << "'\n" - << "text: `" << undo_string_escapes (elt->text) << "'\n\n"; + << "args: " << elt->args << "\n" + << "flags: `" << elt->flags << "'\n" + << "width: " << elt->fw << "\n" + << "prec: " << elt->prec << "\n" + << "type: `" << elt->type << "'\n" + << "modifier: `" << elt->modifier << "'\n" + << "text: `" << undo_string_escapes (elt->text) << "'\n\n"; } } @@ -911,9 +911,9 @@ if (i_fid >= 0) { if (o_fid >= 0) - retval = (i_fid == o_fid) ? i_fid : -1; + retval = (i_fid == o_fid) ? i_fid : -1; else - retval = i_fid; + retval = i_fid; } else if (o_fid >= 0) retval = o_fid; @@ -960,15 +960,15 @@ std::string octave_base_stream::do_gets (octave_idx_type max_len, bool& err, - bool strip_newline, const std::string& who) + bool strip_newline, const std::string& who) { std::string retval; if ((interactive || forced_interactive) && file_number () == 0) { ::error ("%s: unable to read from stdin while running interactively", - who.c_str ()); - + who.c_str ()); + return retval; } @@ -986,71 +986,71 @@ int char_count = 0; if (max_len != 0) - { - while (is && (c = is.get ()) != EOF) - { - char_count++; - - // Handle CRLF, CR, or LF as line ending. - - if (c == '\r') - { - if (! strip_newline) - buf << static_cast<char> (c); - - c = is.get (); - - if (c != EOF) - { - if (c == '\n') - { - char_count++; - - if (! strip_newline) - buf << static_cast<char> (c); - } - else - is.putback (c); - } - - break; - } - else if (c == '\n') - { - if (! strip_newline) - buf << static_cast<char> (c); - - break; - } - else - buf << static_cast<char> (c); - - if (max_len > 0 && char_count == max_len) - break; - } - } + { + while (is && (c = is.get ()) != EOF) + { + char_count++; + + // Handle CRLF, CR, or LF as line ending. + + if (c == '\r') + { + if (! strip_newline) + buf << static_cast<char> (c); + + c = is.get (); + + if (c != EOF) + { + if (c == '\n') + { + char_count++; + + if (! strip_newline) + buf << static_cast<char> (c); + } + else + is.putback (c); + } + + break; + } + else if (c == '\n') + { + if (! strip_newline) + buf << static_cast<char> (c); + + break; + } + else + buf << static_cast<char> (c); + + if (max_len > 0 && char_count == max_len) + break; + } + } if (! is.eof () && char_count > 0) - { - // GAGME. Matlab seems to check for EOF even if the last - // character in a file is a newline character. This is NOT - // what the corresponding C-library functions do. - int disgusting_compatibility_hack = is.get (); - if (! is.eof ()) - is.putback (disgusting_compatibility_hack); - } + { + // GAGME. Matlab seems to check for EOF even if the last + // character in a file is a newline character. This is NOT + // what the corresponding C-library functions do. + int disgusting_compatibility_hack = is.get (); + if (! is.eof ()) + is.putback (disgusting_compatibility_hack); + } if (is.good () || (is.eof () && char_count > 0)) - retval = buf.str (); + retval = buf.str (); else - { - err = true; - - if (is.eof () && char_count == 0) - error (who, "at end of file"); - else - error (who, "read error"); - } + { + err = true; + + if (is.eof () && char_count == 0) + error (who, "at end of file"); + else + error (who, "read error"); + } } else { @@ -1081,8 +1081,8 @@ if ((interactive || forced_interactive) && file_number () == 0) { ::error ("%s: unable to read from stdin while running interactively", - who.c_str ()); - + who.c_str ()); + return count; } @@ -1152,15 +1152,15 @@ case 'i': { - int c1 = is.get (); - - if (! is.eof ()) - { - if (c1 == '0') - { - int c2 = is.peek (); - - if (c2 == 'x' || c2 == 'X') + int c1 = is.get (); + + if (! is.eof ()) + { + if (c1 == '0') + { + int c2 = is.peek (); + + if (c2 == 'x' || c2 == 'X') { is.ignore (); if (std::isxdigit (is.peek ())) @@ -1168,23 +1168,23 @@ else ref = 0; } - else - { - if (c2 == '0' || c2 == '1' || c2 == '2' - || c2 == '3' || c2 == '4' || c2 == '5' - || c2 == '6' || c2 == '7') - is >> std::oct >> ref >> std::dec; - else - ref = 0; - } - } - else - { - is.putback (c1); - - is >> ref; - } - } + else + { + if (c2 == '0' || c2 == '1' || c2 == '2' + || c2 == '3' || c2 == '4' || c2 == '5' + || c2 == '6' || c2 == '7') + is >> std::oct >> ref >> std::dec; + else + ref = 0; + } + } + else + { + is.putback (c1); + + is >> ref; + } + } } break; @@ -1226,7 +1226,7 @@ template<> std::istream& octave_scan<> (std::istream& is, const scanf_format_elt& /* fmt */, - char* valptr) + char* valptr) { return is >> valptr; } @@ -1266,159 +1266,159 @@ case 'f': case 'g': { - int c1 = EOF; - - while (is && (c1 = is.get ()) != EOF && isspace (c1)) - /* skip whitespace */; - - if (c1 != EOF) - { - if (c1 == 'N') - { - int c2 = is.get (); - - if (c2 != EOF) - { - if (c2 == 'A') - { - int c3 = is.get (); - - if (c3 != EOF) - { - is.putback (c3); - - if (isspace (c3) || ispunct (c3)) - ref = octave_NA; - else - { - is.putback (c2); - is.putback (c1); - - is >> ref; - } - } - else - { - is.clear (); - - ref = octave_NA; - } - } - else if (c2 == 'a') - { - int c3 = is.get (); - - if (c3 != EOF) - { - if (c3 == 'N') - { - int c4 = is.get (); - - if (c4 != EOF) - { - is.putback (c4); - - if (isspace (c4) || ispunct (c4)) - ref = octave_NaN; - else - { - is.putback (c3); - is.putback (c2); - is.putback (c1); - - is >> ref; - } - } - else - { - is.clear (); - - ref = octave_NaN; - } - } - else - { - is.putback (c3); - is.putback (c2); - is.putback (c1); - - is >> ref; - } - } - } - else - { - is.putback (c2); - is.putback (c1); - - is >> ref; - } - } - } - else if (c1 == 'I') - { - int c2 = is.get (); - - if (c2 != EOF) - { - if (c2 == 'n') - { - int c3 = is.get (); - - if (c3 != EOF) - { - if (c3 == 'f') - { - int c4 = is.get (); - - if (c4 != EOF) - { - is.putback (c4); - - if (isspace (c4) || ispunct (c4)) - ref = octave_Inf; - else - { - is.putback (c3); - is.putback (c2); - is.putback (c1); - - is >> ref; - } - } - else - { - is.clear (); - - ref = octave_Inf; - } - } - else - { - is.putback (c3); - is.putback (c2); - is.putback (c1); - - is >> ref; - } - } - else - { - is.putback (c2); - is.putback (c1); - - is >> ref; - } - } - } - } - else - { - is.putback (c1); - - is >> ref; - } - } + int c1 = EOF; + + while (is && (c1 = is.get ()) != EOF && isspace (c1)) + /* skip whitespace */; + + if (c1 != EOF) + { + if (c1 == 'N') + { + int c2 = is.get (); + + if (c2 != EOF) + { + if (c2 == 'A') + { + int c3 = is.get (); + + if (c3 != EOF) + { + is.putback (c3); + + if (isspace (c3) || ispunct (c3)) + ref = octave_NA; + else + { + is.putback (c2); + is.putback (c1); + + is >> ref; + } + } + else + { + is.clear (); + + ref = octave_NA; + } + } + else if (c2 == 'a') + { + int c3 = is.get (); + + if (c3 != EOF) + { + if (c3 == 'N') + { + int c4 = is.get (); + + if (c4 != EOF) + { + is.putback (c4); + + if (isspace (c4) || ispunct (c4)) + ref = octave_NaN; + else + { + is.putback (c3); + is.putback (c2); + is.putback (c1); + + is >> ref; + } + } + else + { + is.clear (); + + ref = octave_NaN; + } + } + else + { + is.putback (c3); + is.putback (c2); + is.putback (c1); + + is >> ref; + } + } + } + else + { + is.putback (c2); + is.putback (c1); + + is >> ref; + } + } + } + else if (c1 == 'I') + { + int c2 = is.get (); + + if (c2 != EOF) + { + if (c2 == 'n') + { + int c3 = is.get (); + + if (c3 != EOF) + { + if (c3 == 'f') + { + int c4 = is.get (); + + if (c4 != EOF) + { + is.putback (c4); + + if (isspace (c4) || ispunct (c4)) + ref = octave_Inf; + else + { + is.putback (c3); + is.putback (c2); + is.putback (c1); + + is >> ref; + } + } + else + { + is.clear (); + + ref = octave_Inf; + } + } + else + { + is.putback (c3); + is.putback (c2); + is.putback (c1); + + is >> ref; + } + } + else + { + is.putback (c2); + is.putback (c1); + + is >> ref; + } + } + } + } + else + { + is.putback (c1); + + is >> ref; + } + } } break; @@ -1433,67 +1433,67 @@ template <class T> void do_scanf_conv (std::istream& is, const scanf_format_elt& fmt, - T valptr, Matrix& mval, double *data, octave_idx_type& idx, - octave_idx_type& conversion_count, octave_idx_type nr, octave_idx_type max_size, - bool discard) + T valptr, Matrix& mval, double *data, octave_idx_type& idx, + octave_idx_type& conversion_count, octave_idx_type nr, octave_idx_type max_size, + bool discard) { OCTAVE_SCAN (is, fmt, valptr); if (is) { if (idx == max_size && ! discard) - { - max_size *= 2; - - if (nr > 0) - mval.resize (nr, max_size / nr, 0.0); - else - mval.resize (max_size, 1, 0.0); - - data = mval.fortran_vec (); - } + { + max_size *= 2; + + if (nr > 0) + mval.resize (nr, max_size / nr, 0.0); + else + mval.resize (max_size, 1, 0.0); + + data = mval.fortran_vec (); + } if (! discard) - { - conversion_count++; - data[idx++] = *(valptr); - } + { + conversion_count++; + data[idx++] = *(valptr); + } } } template void do_scanf_conv (std::istream&, const scanf_format_elt&, int*, - Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); + Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); template void do_scanf_conv (std::istream&, const scanf_format_elt&, long int*, - Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); + Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); template void do_scanf_conv (std::istream&, const scanf_format_elt&, short int*, - Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); + Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); template void do_scanf_conv (std::istream&, const scanf_format_elt&, unsigned int*, - Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); + Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); template void do_scanf_conv (std::istream&, const scanf_format_elt&, unsigned long int*, - Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); + Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); template void do_scanf_conv (std::istream&, const scanf_format_elt&, unsigned short int*, - Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); + Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); #if 0 template void do_scanf_conv (std::istream&, const scanf_format_elt&, float*, - Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); + Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); #endif template void do_scanf_conv (std::istream&, const scanf_format_elt&, double*, - Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); + Matrix&, double*, octave_idx_type&, octave_idx_type&, octave_idx_type, octave_idx_type, bool); #define DO_WHITESPACE_CONVERSION() \ do \ @@ -1501,10 +1501,10 @@ int c = EOF; \ \ while (is && (c = is.get ()) != EOF && isspace (c)) \ - /* skip whitespace */; \ + /* skip whitespace */; \ \ if (c != EOF) \ - is.putback (c); \ + is.putback (c); \ } \ while (0) @@ -1517,21 +1517,21 @@ int i = 0; \ \ while (i < n && is && (c = is.get ()) != EOF) \ - { \ - if (c == static_cast<unsigned char> (fmt[i])) \ - { \ - i++; \ - continue; \ - } \ - else \ - { \ - is.putback (c); \ - break; \ - } \ - } \ + { \ + if (c == static_cast<unsigned char> (fmt[i])) \ + { \ + i++; \ + continue; \ + } \ + else \ + { \ + is.putback (c); \ + break; \ + } \ + } \ \ if (i != n) \ - is.setstate (std::ios::failbit); \ + is.setstate (std::ios::failbit); \ } \ while (0) @@ -1541,15 +1541,15 @@ int c = is.get (); \ \ if (c != EOF) \ - { \ - if (c != '%') \ - { \ - is.putback (c); \ - is.setstate (std::ios::failbit); \ - } \ - } \ + { \ + if (c != '%') \ + { \ + is.putback (c); \ + is.setstate (std::ios::failbit); \ + } \ + } \ else \ - is.setstate (std::ios::failbit); \ + is.setstate (std::ios::failbit); \ } \ while (0) @@ -1627,7 +1627,7 @@ do \ { \ if (! width) \ - width = INT_MAX; \ + width = INT_MAX; \ \ std::ostringstream buf; \ \ @@ -1637,21 +1637,21 @@ \ if (elt->type == '[') \ { \ - int chars_read = 0; \ - while (is && chars_read++ < width && (c = is.get ()) != EOF \ - && char_class.find (c) != std::string::npos) \ - buf << static_cast<char> (c); \ - } \ + int chars_read = 0; \ + while (is && chars_read++ < width && (c = is.get ()) != EOF \ + && char_class.find (c) != std::string::npos) \ + buf << static_cast<char> (c); \ + } \ else \ - { \ - int chars_read = 0; \ - while (is && chars_read++ < width && (c = is.get ()) != EOF \ - && char_class.find (c) == std::string::npos) \ - buf << static_cast<char> (c); \ - } \ + { \ + int chars_read = 0; \ + while (is && chars_read++ < width && (c = is.get ()) != EOF \ + && char_class.find (c) == std::string::npos) \ + buf << static_cast<char> (c); \ + } \ \ if (width == INT_MAX && c != EOF) \ - is.putback (c); \ + is.putback (c); \ \ tmp = buf.str (); \ \ @@ -1666,55 +1666,55 @@ width = tmp.length (); \ \ if (is) \ - { \ - int i = 0; \ + { \ + int i = 0; \ \ - if (! discard) \ - { \ - conversion_count++; \ + if (! discard) \ + { \ + conversion_count++; \ \ - while (i < width) \ - { \ - if (data_index == max_size) \ - { \ - max_size *= 2; \ + while (i < width) \ + { \ + if (data_index == max_size) \ + { \ + max_size *= 2; \ \ - if (all_char_conv) \ - { \ - if (one_elt_size_spec) \ - mval.resize (1, max_size, 0.0); \ - else if (nr > 0) \ - mval.resize (nr, max_size / nr, 0.0); \ - else \ - panic_impossible (); \ - } \ - else if (nr > 0) \ - mval.resize (nr, max_size / nr, 0.0); \ - else \ - mval.resize (max_size, 1, 0.0); \ + if (all_char_conv) \ + { \ + if (one_elt_size_spec) \ + mval.resize (1, max_size, 0.0); \ + else if (nr > 0) \ + mval.resize (nr, max_size / nr, 0.0); \ + else \ + panic_impossible (); \ + } \ + else if (nr > 0) \ + mval.resize (nr, max_size / nr, 0.0); \ + else \ + mval.resize (max_size, 1, 0.0); \ \ - data = mval.fortran_vec (); \ - } \ + data = mval.fortran_vec (); \ + } \ \ - data[data_index++] = tmp[i++]; \ - } \ - } \ - } \ + data[data_index++] = tmp[i++]; \ + } \ + } \ + } \ } \ while (0) octave_value octave_base_stream::do_scanf (scanf_format_list& fmt_list, - octave_idx_type nr, octave_idx_type nc, bool one_elt_size_spec, - octave_idx_type& conversion_count, const std::string& who) + octave_idx_type nr, octave_idx_type nc, bool one_elt_size_spec, + octave_idx_type& conversion_count, const std::string& who) { octave_value retval = Matrix (); if ((interactive || forced_interactive) && file_number () == 0) { ::error ("%s: unable to read from stdin while running interactively", - who.c_str ()); - + who.c_str ()); + return retval; } @@ -1727,7 +1727,7 @@ if (nr == 0 || nc == 0) { if (one_elt_size_spec) - nc = 0; + nc = 0; return Matrix (nr, nc, 0.0); } @@ -1751,44 +1751,44 @@ // conversion). if (one_elt_size_spec) - { - max_size = 512; - mval.resize (1, max_size, 0.0); - - if (nr > 0) - max_conv = nr; - } + { + max_size = 512; + mval.resize (1, max_size, 0.0); + + if (nr > 0) + max_conv = nr; + } else if (nr > 0) - { - if (nc > 0) - { - mval.resize (nr, nc, 0.0); - max_size = max_conv = nr * nc; - } - else - { - mval.resize (nr, 32, 0.0); - max_size = nr * 32; - } - } + { + if (nc > 0) + { + mval.resize (nr, nc, 0.0); + max_size = max_conv = nr * nc; + } + else + { + mval.resize (nr, 32, 0.0); + max_size = nr * 32; + } + } else - panic_impossible (); + panic_impossible (); } else if (nr > 0) { if (nc > 0) - { - // Will not resize later. - mval.resize (nr, nc, 0.0); - max_size = nr * nc; - max_conv = max_size; - } + { + // Will not resize later. + mval.resize (nr, nc, 0.0); + max_size = nr * nc; + max_conv = max_size; + } else - { - // Maybe resize later. - mval.resize (nr, 32, 0.0); - max_size = nr * 32; - } + { + // Maybe resize later. + mval.resize (nr, 32, 0.0); + max_size = nr * 32; + } } else { @@ -1812,250 +1812,250 @@ octave_idx_type num_fmt_elts = fmt_list.length (); for (;;) - { - octave_quit (); - - if (elt) - { - if (! (elt->type == scanf_format_elt::whitespace_conversion + { + octave_quit (); + + if (elt) + { + if (! (elt->type == scanf_format_elt::whitespace_conversion || elt->type == scanf_format_elt::literal_conversion || elt->type == '%') && max_conv > 0 && conversion_count == max_conv) - { - if (all_char_conv && one_elt_size_spec) - { - final_nr = 1; - final_nc = data_index; - } - else - { - final_nr = nr; - final_nc = (data_index - 1) / nr + 1; - } - - break; - } - else if (data_index == max_size) - { - max_size *= 2; - - if (all_char_conv) - { - if (one_elt_size_spec) - mval.resize (1, max_size, 0.0); - else if (nr > 0) - mval.resize (nr, max_size / nr, 0.0); - else - panic_impossible (); - } - else if (nr > 0) - mval.resize (nr, max_size / nr, 0.0); - else - mval.resize (max_size, 1, 0.0); - - data = mval.fortran_vec (); - } - - const char *fmt = elt->text; - - bool discard = elt->discard; - - switch (elt->type) - { - case scanf_format_elt::whitespace_conversion: - DO_WHITESPACE_CONVERSION (); - break; - - case scanf_format_elt::literal_conversion: - DO_LITERAL_CONVERSION (); - break; - - case '%': - DO_PCT_CONVERSION (); - break; - - case 'd': case 'i': - { - switch (elt->modifier) - { - case 'h': - { - short int tmp; - do_scanf_conv (is, *elt, &tmp, mval, data, - data_index, conversion_count, - nr, max_size, discard); - } - break; - - case 'l': - { - long int tmp; - do_scanf_conv (is, *elt, &tmp, mval, data, - data_index, conversion_count, - nr, max_size, discard); - } - break; - - default: - { - int tmp; - do_scanf_conv (is, *elt, &tmp, mval, data, - data_index, conversion_count, - nr, max_size, discard); - } - break; - } - } - break; - - case 'o': case 'u': case 'x': - { - switch (elt->modifier) - { - case 'h': - { - unsigned short int tmp; - do_scanf_conv (is, *elt, &tmp, mval, data, - data_index, conversion_count, - nr, max_size, discard); - } - break; - - case 'l': - { - unsigned long int tmp; - do_scanf_conv (is, *elt, &tmp, mval, data, - data_index, conversion_count, - nr, max_size, discard); - } - break; - - default: - { - unsigned int tmp; - do_scanf_conv (is, *elt, &tmp, mval, data, - data_index, conversion_count, - nr, max_size, discard); - } - break; - } - } - break; - - case 'e': case 'f': case 'g': - { - double tmp; - - do_scanf_conv (is, *elt, &tmp, mval, data, - data_index, conversion_count, - nr, max_size, discard); - } - break; - - case 'c': - { - BEGIN_C_CONVERSION (); - - FINISH_CHARACTER_CONVERSION (); - - is.setf (flags); - } - break; - - case 's': - { - BEGIN_S_CONVERSION (); - - FINISH_CHARACTER_CONVERSION (); - } - break; - - case '[': case '^': - { - BEGIN_CHAR_CLASS_CONVERSION (); - - FINISH_CHARACTER_CONVERSION (); - } - break; - - case 'p': - error ("%s: unsupported format specifier", who.c_str ()); - break; - - default: - error ("%s: internal format error", who.c_str ()); - break; - } - - if (! ok ()) - { - break; - } - else if (! is) - { - if (all_char_conv) - { - if (one_elt_size_spec) - { - final_nr = 1; - final_nc = data_index; - } - else if (data_index > nr) - { - final_nr = nr; - final_nc = (data_index - 1) / nr + 1; - } - else - { - final_nr = data_index; - final_nc = 1; - } - } - else if (nr > 0) - { - if (data_index > nr) - { - final_nr = nr; - final_nc = (data_index - 1) / nr + 1; - } - else - { - final_nr = data_index; - final_nc = 1; - } - } - else - { - final_nr = data_index; - final_nc = 1; - } - - // If it looks like we have a matching failure, then - // reset the failbit in the stream state. - - if (is.rdstate () & std::ios::failbit) - is.clear (is.rdstate () & (~std::ios::failbit)); - - // FIXME -- is this the right thing to do? - - if (interactive && name () == "stdin") - { - is.clear (); - - // Skip to end of line. - - bool err; - do_gets (-1, err, false, who); - } - - break; - } - } - else - { - error ("%s: internal format error", who.c_str ()); - break; - } + { + if (all_char_conv && one_elt_size_spec) + { + final_nr = 1; + final_nc = data_index; + } + else + { + final_nr = nr; + final_nc = (data_index - 1) / nr + 1; + } + + break; + } + else if (data_index == max_size) + { + max_size *= 2; + + if (all_char_conv) + { + if (one_elt_size_spec) + mval.resize (1, max_size, 0.0); + else if (nr > 0) + mval.resize (nr, max_size / nr, 0.0); + else + panic_impossible (); + } + else if (nr > 0) + mval.resize (nr, max_size / nr, 0.0); + else + mval.resize (max_size, 1, 0.0); + + data = mval.fortran_vec (); + } + + const char *fmt = elt->text; + + bool discard = elt->discard; + + switch (elt->type) + { + case scanf_format_elt::whitespace_conversion: + DO_WHITESPACE_CONVERSION (); + break; + + case scanf_format_elt::literal_conversion: + DO_LITERAL_CONVERSION (); + break; + + case '%': + DO_PCT_CONVERSION (); + break; + + case 'd': case 'i': + { + switch (elt->modifier) + { + case 'h': + { + short int tmp; + do_scanf_conv (is, *elt, &tmp, mval, data, + data_index, conversion_count, + nr, max_size, discard); + } + break; + + case 'l': + { + long int tmp; + do_scanf_conv (is, *elt, &tmp, mval, data, + data_index, conversion_count, + nr, max_size, discard); + } + break; + + default: + { + int tmp; + do_scanf_conv (is, *elt, &tmp, mval, data, + data_index, conversion_count, + nr, max_size, discard); + } + break; + } + } + break; + + case 'o': case 'u': case 'x': + { + switch (elt->modifier) + { + case 'h': + { + unsigned short int tmp; + do_scanf_conv (is, *elt, &tmp, mval, data, + data_index, conversion_count, + nr, max_size, discard); + } + break; + + case 'l': + { + unsigned long int tmp; + do_scanf_conv (is, *elt, &tmp, mval, data, + data_index, conversion_count, + nr, max_size, discard); + } + break; + + default: + { + unsigned int tmp; + do_scanf_conv (is, *elt, &tmp, mval, data, + data_index, conversion_count, + nr, max_size, discard); + } + break; + } + } + break; + + case 'e': case 'f': case 'g': + { + double tmp; + + do_scanf_conv (is, *elt, &tmp, mval, data, + data_index, conversion_count, + nr, max_size, discard); + } + break; + + case 'c': + { + BEGIN_C_CONVERSION (); + + FINISH_CHARACTER_CONVERSION (); + + is.setf (flags); + } + break; + + case 's': + { + BEGIN_S_CONVERSION (); + + FINISH_CHARACTER_CONVERSION (); + } + break; + + case '[': case '^': + { + BEGIN_CHAR_CLASS_CONVERSION (); + + FINISH_CHARACTER_CONVERSION (); + } + break; + + case 'p': + error ("%s: unsupported format specifier", who.c_str ()); + break; + + default: + error ("%s: internal format error", who.c_str ()); + break; + } + + if (! ok ()) + { + break; + } + else if (! is) + { + if (all_char_conv) + { + if (one_elt_size_spec) + { + final_nr = 1; + final_nc = data_index; + } + else if (data_index > nr) + { + final_nr = nr; + final_nc = (data_index - 1) / nr + 1; + } + else + { + final_nr = data_index; + final_nc = 1; + } + } + else if (nr > 0) + { + if (data_index > nr) + { + final_nr = nr; + final_nc = (data_index - 1) / nr + 1; + } + else + { + final_nr = data_index; + final_nc = 1; + } + } + else + { + final_nr = data_index; + final_nc = 1; + } + + // If it looks like we have a matching failure, then + // reset the failbit in the stream state. + + if (is.rdstate () & std::ios::failbit) + is.clear (is.rdstate () & (~std::ios::failbit)); + + // FIXME -- is this the right thing to do? + + if (interactive && name () == "stdin") + { + is.clear (); + + // Skip to end of line. + + bool err; + do_gets (-1, err, false, who); + } + + break; + } + } + else + { + error ("%s: internal format error", who.c_str ()); + break; + } if (nconv == 0 && ++trips == num_fmt_elts) { @@ -2074,7 +2074,7 @@ } else elt = fmt_list.next (nconv > 0); - } + } } if (ok ()) @@ -2084,7 +2084,7 @@ retval = mval; if (all_char_conv) - retval = retval.convert_to_str (false, true); + retval = retval.convert_to_str (false, true); } return retval; @@ -2092,7 +2092,7 @@ octave_value octave_base_stream::scanf (const std::string& fmt, const Array<double>& size, - octave_idx_type& conversion_count, const std::string& who) + octave_idx_type& conversion_count, const std::string& who) { octave_value retval = Matrix (); @@ -2105,20 +2105,20 @@ scanf_format_list fmt_list (fmt); if (fmt_list.num_conversions () == -1) - ::error ("%s: invalid format specified", who.c_str ()); + ::error ("%s: invalid format specified", who.c_str ()); else - { - octave_idx_type nr = -1; - octave_idx_type nc = -1; - - bool one_elt_size_spec; - - get_size (size, nr, nc, one_elt_size_spec, who); - - if (! error_state) - retval = do_scanf (fmt_list, nr, nc, one_elt_size_spec, - conversion_count, who); - } + { + octave_idx_type nr = -1; + octave_idx_type nc = -1; + + bool one_elt_size_spec; + + get_size (size, nr, nc, one_elt_size_spec, who); + + if (! error_state) + retval = do_scanf (fmt_list, nr, nc, one_elt_size_spec, + conversion_count, who); + } } else invalid_operation (who, "reading"); @@ -2128,7 +2128,7 @@ bool octave_base_stream::do_oscanf (const scanf_format_elt *elt, - octave_value& retval, const std::string& who) + octave_value& retval, const std::string& who) { bool quit = false; @@ -2141,135 +2141,135 @@ std::ios::fmtflags flags = is.flags (); if (elt) - { - const char *fmt = elt->text; - - bool discard = elt->discard; - - switch (elt->type) - { - case scanf_format_elt::whitespace_conversion: - DO_WHITESPACE_CONVERSION (); - break; - - case scanf_format_elt::literal_conversion: - DO_LITERAL_CONVERSION (); - break; - - case '%': - { - DO_PCT_CONVERSION (); - - if (! is) - quit = true; - - } - break; - - case 'd': case 'i': - { - int tmp; - - if (OCTAVE_SCAN (is, *elt, &tmp)) - { - if (! discard) - retval = tmp; - } - else - quit = true; - } - break; - - case 'o': case 'u': case 'x': - { - long int tmp; - - if (OCTAVE_SCAN (is, *elt, &tmp)) - { - if (! discard) - retval = tmp; - } - else - quit = true; - } - break; - - case 'e': case 'f': case 'g': - { - double tmp; - - if (OCTAVE_SCAN (is, *elt, &tmp)) - { - if (! discard) - retval = tmp; - } - else - quit = true; - } - break; - - case 'c': - { - BEGIN_C_CONVERSION (); - - if (! discard) - retval = tmp; - - if (! is) - quit = true; - - is.setf (flags); - } - break; - - case 's': - { - BEGIN_S_CONVERSION (); - - if (! discard) - retval = tmp; - - if (! is) - quit = true; - } - break; - - case '[': case '^': - { - BEGIN_CHAR_CLASS_CONVERSION (); - - if (! discard) - retval = tmp; - - if (! is) - quit = true; - } - break; - - case 'p': - error ("%s: unsupported format specifier", who.c_str ()); - break; - - default: - error ("%s: internal format error", who.c_str ()); - break; - } - } + { + const char *fmt = elt->text; + + bool discard = elt->discard; + + switch (elt->type) + { + case scanf_format_elt::whitespace_conversion: + DO_WHITESPACE_CONVERSION (); + break; + + case scanf_format_elt::literal_conversion: + DO_LITERAL_CONVERSION (); + break; + + case '%': + { + DO_PCT_CONVERSION (); + + if (! is) + quit = true; + + } + break; + + case 'd': case 'i': + { + int tmp; + + if (OCTAVE_SCAN (is, *elt, &tmp)) + { + if (! discard) + retval = tmp; + } + else + quit = true; + } + break; + + case 'o': case 'u': case 'x': + { + long int tmp; + + if (OCTAVE_SCAN (is, *elt, &tmp)) + { + if (! discard) + retval = tmp; + } + else + quit = true; + } + break; + + case 'e': case 'f': case 'g': + { + double tmp; + + if (OCTAVE_SCAN (is, *elt, &tmp)) + { + if (! discard) + retval = tmp; + } + else + quit = true; + } + break; + + case 'c': + { + BEGIN_C_CONVERSION (); + + if (! discard) + retval = tmp; + + if (! is) + quit = true; + + is.setf (flags); + } + break; + + case 's': + { + BEGIN_S_CONVERSION (); + + if (! discard) + retval = tmp; + + if (! is) + quit = true; + } + break; + + case '[': case '^': + { + BEGIN_CHAR_CLASS_CONVERSION (); + + if (! discard) + retval = tmp; + + if (! is) + quit = true; + } + break; + + case 'p': + error ("%s: unsupported format specifier", who.c_str ()); + break; + + default: + error ("%s: internal format error", who.c_str ()); + break; + } + } if (ok () && is.fail ()) - { - error ("%s: read error", who.c_str ()); - - // FIXME -- is this the right thing to do? - - if (interactive && name () == "stdin") - { - // Skip to end of line. - - bool err; - do_gets (-1, err, false, who); - } - } + { + error ("%s: read error", who.c_str ()); + + // FIXME -- is this the right thing to do? + + if (interactive && name () == "stdin") + { + // Skip to end of line. + + bool err; + do_gets (-1, err, false, who); + } + } } return quit; @@ -2291,56 +2291,56 @@ octave_idx_type nconv = fmt_list.num_conversions (); if (nconv == -1) - ::error ("%s: invalid format specified", who.c_str ()); + ::error ("%s: invalid format specified", who.c_str ()); else - { - is.clear (); - - octave_idx_type len = fmt_list.length (); - - retval.resize (nconv+1, Matrix ()); - - const scanf_format_elt *elt = fmt_list.first (); - - int num_values = 0; - - bool quit = false; - - for (octave_idx_type i = 0; i < len; i++) - { - octave_value tmp; - - quit = do_oscanf (elt, tmp, who); - - if (quit) - break; - else - { - if (tmp.is_defined ()) - retval (num_values++) = tmp; - - if (! ok ()) - break; - - elt = fmt_list.next (nconv > 0); - } - } - - retval(nconv) = num_values; - - if (! quit) - { - // Pick up any trailing stuff. - if (ok () && len > nconv) - { - octave_value tmp; - - elt = fmt_list.next (); - - do_oscanf (elt, tmp, who); - } - } - } + { + is.clear (); + + octave_idx_type len = fmt_list.length (); + + retval.resize (nconv+1, Matrix ()); + + const scanf_format_elt *elt = fmt_list.first (); + + int num_values = 0; + + bool quit = false; + + for (octave_idx_type i = 0; i < len; i++) + { + octave_value tmp; + + quit = do_oscanf (elt, tmp, who); + + if (quit) + break; + else + { + if (tmp.is_defined ()) + retval (num_values++) = tmp; + + if (! ok ()) + break; + + elt = fmt_list.next (nconv > 0); + } + } + + retval(nconv) = num_values; + + if (! quit) + { + // Pick up any trailing stuff. + if (ok () && len > nconv) + { + octave_value tmp; + + elt = fmt_list.next (); + + do_oscanf (elt, tmp, who); + } + } + } } else invalid_operation (who, "reading"); @@ -2363,7 +2363,7 @@ os->flush (); if (os->good ()) - retval = 0; + retval = 0; } else invalid_operation ("fflush", "writing"); @@ -2385,13 +2385,13 @@ { for (octave_idx_type i = 0; i < values.length (); i++) { - octave_value val = values(i); - - if (val.is_map () || val.is_cell () || val.is_object ()) - { - gripe_wrong_type_arg (who, val); - break; - } + octave_value val = values(i); + + if (val.is_map () || val.is_cell () || val.is_object ()) + { + gripe_wrong_type_arg (who, val); + break; + } } } @@ -2443,49 +2443,49 @@ while (! exhausted ()) { if (! data) - { - octave_value tmp_val = values (val_idx); - - // Force string conversion here for compatibility. - - curr_val = tmp_val.array_value (true); - - if (! error_state) - { - elt_idx = 0; - n_elts = curr_val.length (); - data = curr_val.data (); - } - else - { - curr_state = conversion_error; - break; - } - } + { + octave_value tmp_val = values (val_idx); + + // Force string conversion here for compatibility. + + curr_val = tmp_val.array_value (true); + + if (! error_state) + { + elt_idx = 0; + n_elts = curr_val.length (); + data = curr_val.data (); + } + else + { + curr_state = conversion_error; + break; + } + } if (elt_idx < n_elts) - { - retval = data[elt_idx++]; - - if (elt_idx >= n_elts) - { - elt_idx = 0; - val_idx++; - data = 0; - } - - break; - } + { + retval = data[elt_idx++]; + + if (elt_idx >= n_elts) + { + elt_idx = 0; + val_idx++; + data = 0; + } + + break; + } else - { - val_idx++; - data = 0; - - if (n_elts == 0 && exhausted ()) - curr_state = conversion_error; - - continue; - } + { + val_idx++; + data = 0; + + if (n_elts == 0 && exhausted ()) + curr_state = conversion_error; + + continue; + } } return retval; @@ -2501,9 +2501,9 @@ if (! error_state) { if (D_NINT (dval) == dval) - retval = NINT (dval); + retval = NINT (dval); else - curr_state = conversion_error; + curr_state = conversion_error; } return retval; @@ -2521,27 +2521,27 @@ octave_value tval = values (val_idx++); if (tval.rows () == 1) - retval = tval.string_value (); + retval = tval.string_value (); else - { - // In the name of Matlab compatibility. - - charMatrix chm = tval.char_matrix_value (); - - octave_idx_type nr = chm.rows (); - octave_idx_type nc = chm.columns (); - - int k = 0; - - retval.resize (nr * nc, '\0'); - - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - retval[k++] = chm(i,j); - } + { + // In the name of Matlab compatibility. + + charMatrix chm = tval.char_matrix_value (); + + octave_idx_type nr = chm.rows (); + octave_idx_type nc = chm.columns (); + + int k = 0; + + retval.resize (nr * nc, '\0'); + + for (octave_idx_type j = 0; j < nc; j++) + for (octave_idx_type i = 0; i < nr; i++) + retval[k++] = chm(i,j); + } if (error_state) - curr_state = conversion_error; + curr_state = conversion_error; } return retval; @@ -2552,7 +2552,7 @@ template <class T> int do_printf_conv (std::ostream& os, const char *fmt, int nsa, int sa_1, - int sa_2, T arg, const std::string& who) + int sa_2, T arg, const std::string& who) { int retval = 0; @@ -2580,54 +2580,54 @@ template int do_printf_conv (std::ostream&, const char*, int, int, int, int, - const std::string&); + const std::string&); template int do_printf_conv (std::ostream&, const char*, int, int, int, long, - const std::string&); + const std::string&); template int do_printf_conv (std::ostream&, const char*, int, int, int, unsigned int, - const std::string&); + const std::string&); template int do_printf_conv (std::ostream&, const char*, int, int, int, unsigned long, - const std::string&); + const std::string&); template int do_printf_conv (std::ostream&, const char*, int, int, int, double, - const std::string&); + const std::string&); template int do_printf_conv (std::ostream&, const char*, int, int, int, const char*, - const std::string&); + const std::string&); #define DO_DOUBLE_CONV(TQUAL) \ do \ { \ if (val > std::numeric_limits<TQUAL long>::max () \ - || val < std::numeric_limits<TQUAL long>::min ()) \ - { \ - std::string tfmt = fmt; \ + || val < std::numeric_limits<TQUAL long>::min ()) \ + { \ + std::string tfmt = fmt; \ \ - tfmt.replace (tfmt.rfind (elt->type), 1, ".f"); \ + tfmt.replace (tfmt.rfind (elt->type), 1, ".f"); \ \ - if (elt->modifier == 'l') \ - tfmt.replace (tfmt.rfind (elt->modifier), 1, ""); \ + if (elt->modifier == 'l') \ + tfmt.replace (tfmt.rfind (elt->modifier), 1, ""); \ \ - retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2, \ - val, who); \ - } \ + retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2, \ + val, who); \ + } \ else \ - retval += do_printf_conv (os, fmt, nsa, sa_1, sa_2, \ - static_cast<TQUAL long> (val), who); \ + retval += do_printf_conv (os, fmt, nsa, sa_1, sa_2, \ + static_cast<TQUAL long> (val), who); \ } \ while (0) int octave_base_stream::do_printf (printf_format_list& fmt_list, - const octave_value_list& args, - const std::string& who) + const octave_value_list& args, + const std::string& who) { int retval = 0; @@ -2644,141 +2644,141 @@ printf_value_cache val_cache (args, who); if (error_state) - return retval; + return retval; for (;;) - { - octave_quit (); - - if (elt) - { - // NSA is the number of `star' args to convert. - - int nsa = (elt->fw < 0) + (elt->prec < 0); - - int sa_1 = 0; - int sa_2 = 0; - - if (nsa > 0) - { - sa_1 = val_cache.int_value (); - - if (! val_cache) - break; - else - { - if (nsa > 1) - { - sa_2 = val_cache.int_value (); - - if (! val_cache) - break; - } - } - } - - const char *fmt = elt->text; - - if (elt->type == '%') - { - os << "%"; - retval++; - } - else if (elt->args == 0 && elt->text) - { - os << elt->text; - retval += strlen (elt->text); - } - else if (elt->type == 's') - { - std::string val = val_cache.string_value (); - - if (val_cache) - retval += do_printf_conv (os, fmt, nsa, sa_1, - sa_2, val.c_str (), who); - else - break; - } - else - { - double val = val_cache.double_value (); - - if (val_cache) - { - if (lo_ieee_isnan (val) || xisinf (val)) - { - std::string tfmt = fmt; - std::string::size_type i1, i2; - - tfmt.replace ((i1 = tfmt.rfind (elt->type)), - 1, 1, 's'); - - if ((i2 = tfmt.rfind ('.')) != std::string::npos && i2 < i1) - { - tfmt.erase (i2, i1-i2); - if (elt->prec < 0) - nsa--; - } - - const char *tval = xisinf (val) - ? (val < 0 ? "-Inf" : "Inf") - : (lo_ieee_is_NA (val) ? "NA" : "NaN"); - - retval += do_printf_conv (os, tfmt.c_str (), - nsa, sa_1, sa_2, - tval, who); - } - else - { - char type = elt->type; - - switch (type) - { - case 'd': case 'i': case 'c': - DO_DOUBLE_CONV (OCTAVE_EMPTY_CPP_ARG); - break; - - case 'o': case 'x': case 'X': case 'u': - DO_DOUBLE_CONV (unsigned); - break; - - case 'f': case 'e': case 'E': - case 'g': case 'G': - retval - += do_printf_conv (os, fmt, nsa, sa_1, sa_2, - val, who); - break; - - default: - error ("%s: invalid format specifier", - who.c_str ()); - return -1; - break; - } - } - } - else - break; - } - - if (! os) - { - error ("%s: write error", who.c_str ()); - break; - } - } - else - { - ::error ("%s: internal error handling format", who.c_str ()); - retval = -1; - break; - } - - elt = fmt_list.next (nconv > 0 && ! val_cache.exhausted ()); - - if (! elt || (val_cache.exhausted () && elt->args > 0)) - break; - } + { + octave_quit (); + + if (elt) + { + // NSA is the number of `star' args to convert. + + int nsa = (elt->fw < 0) + (elt->prec < 0); + + int sa_1 = 0; + int sa_2 = 0; + + if (nsa > 0) + { + sa_1 = val_cache.int_value (); + + if (! val_cache) + break; + else + { + if (nsa > 1) + { + sa_2 = val_cache.int_value (); + + if (! val_cache) + break; + } + } + } + + const char *fmt = elt->text; + + if (elt->type == '%') + { + os << "%"; + retval++; + } + else if (elt->args == 0 && elt->text) + { + os << elt->text; + retval += strlen (elt->text); + } + else if (elt->type == 's') + { + std::string val = val_cache.string_value (); + + if (val_cache) + retval += do_printf_conv (os, fmt, nsa, sa_1, + sa_2, val.c_str (), who); + else + break; + } + else + { + double val = val_cache.double_value (); + + if (val_cache) + { + if (lo_ieee_isnan (val) || xisinf (val)) + { + std::string tfmt = fmt; + std::string::size_type i1, i2; + + tfmt.replace ((i1 = tfmt.rfind (elt->type)), + 1, 1, 's'); + + if ((i2 = tfmt.rfind ('.')) != std::string::npos && i2 < i1) + { + tfmt.erase (i2, i1-i2); + if (elt->prec < 0) + nsa--; + } + + const char *tval = xisinf (val) + ? (val < 0 ? "-Inf" : "Inf") + : (lo_ieee_is_NA (val) ? "NA" : "NaN"); + + retval += do_printf_conv (os, tfmt.c_str (), + nsa, sa_1, sa_2, + tval, who); + } + else + { + char type = elt->type; + + switch (type) + { + case 'd': case 'i': case 'c': + DO_DOUBLE_CONV (OCTAVE_EMPTY_CPP_ARG); + break; + + case 'o': case 'x': case 'X': case 'u': + DO_DOUBLE_CONV (unsigned); + break; + + case 'f': case 'e': case 'E': + case 'g': case 'G': + retval + += do_printf_conv (os, fmt, nsa, sa_1, sa_2, + val, who); + break; + + default: + error ("%s: invalid format specifier", + who.c_str ()); + return -1; + break; + } + } + } + else + break; + } + + if (! os) + { + error ("%s: write error", who.c_str ()); + break; + } + } + else + { + ::error ("%s: internal error handling format", who.c_str ()); + retval = -1; + break; + } + + elt = fmt_list.next (nconv > 0 && ! val_cache.exhausted ()); + + if (! elt || (val_cache.exhausted () && elt->args > 0)) + break; + } } else invalid_operation (who, "writing"); @@ -2788,8 +2788,8 @@ int octave_base_stream::printf (const std::string& fmt, - const octave_value_list& args, - const std::string& who) + const octave_value_list& args, + const std::string& who) { int retval = 0; @@ -2817,23 +2817,23 @@ os << s; if (os) - { - // FIXME -- why does this seem to be necessary? - // Without it, output from a loop like - // - // for i = 1:100, fputs (stdout, "foo\n"); endfor - // - // doesn't seem to go to the pager immediately. - - os.flush (); - - if (os) - retval = 0; - else - error ("%s: write error", who.c_str ()); - } + { + // FIXME -- why does this seem to be necessary? + // Without it, output from a loop like + // + // for i = 1:100, fputs (stdout, "foo\n"); endfor + // + // doesn't seem to go to the pager immediately. + + os.flush (); + + if (os) + retval = 0; + else + error ("%s: write error", who.c_str ()); + } else - error ("%s: write error", who.c_str ()); + error ("%s: write error", who.c_str ()); } else invalid_operation (who, "writing"); @@ -2890,12 +2890,12 @@ if (rep != s.rep) { if (rep && --rep->count == 0) - delete rep; + delete rep; rep = s.rep; if (rep) - rep->count++; + rep->count++; } return *this; @@ -2925,7 +2925,7 @@ std::string octave_stream::getl (const octave_value& tc_max_len, bool& err, - const std::string& who) + const std::string& who) { std::string retval; @@ -2940,10 +2940,10 @@ max_len = convert_to_valid_int (tc_max_len, conv_err); if (conv_err || max_len < 0) - { - err = true; - ::error ("%s: invalid maximum length specified", who.c_str ()); - } + { + err = true; + ::error ("%s: invalid maximum length specified", who.c_str ()); + } } if (! error_state) @@ -2965,7 +2965,7 @@ std::string octave_stream::gets (const octave_value& tc_max_len, bool& err, - const std::string& who) + const std::string& who) { std::string retval; @@ -2980,10 +2980,10 @@ max_len = convert_to_valid_int (tc_max_len, conv_err); if (conv_err || max_len < 0) - { - err = true; - ::error ("%s: invalid maximum length specified", who.c_str ()); - } + { + err = true; + ::error ("%s: invalid maximum length specified", who.c_str ()); + } } if (! error_state) @@ -3050,34 +3050,34 @@ status = rep->seek (offset, origin); if (status == 0) - { - long save_pos = rep->tell (); - - rep->seek (0, SEEK_END); - - long pos_eof = rep->tell (); - - // I don't think save_pos can be less than zero, but we'll - // check anyway... - - if (save_pos > pos_eof || save_pos < 0) - { - // Seek outside bounds of file. Failure should leave - // position unchanged. - - rep->seek (orig_pos, SEEK_SET); - - status = -1; - } - else - { - // Is it possible for this to fail? We are just - // returning to a position after the first successful - // seek. - - rep->seek (save_pos, SEEK_SET); - } - } + { + long save_pos = rep->tell (); + + rep->seek (0, SEEK_END); + + long pos_eof = rep->tell (); + + // I don't think save_pos can be less than zero, but we'll + // check anyway... + + if (save_pos > pos_eof || save_pos < 0) + { + // Seek outside bounds of file. Failure should leave + // position unchanged. + + rep->seek (orig_pos, SEEK_SET); + + status = -1; + } + else + { + // Is it possible for this to fail? We are just + // returning to a position after the first successful + // seek. + + rep->seek (save_pos, SEEK_SET); + } + } } return status; @@ -3085,7 +3085,7 @@ int octave_stream::seek (const octave_value& tc_offset, - const octave_value& tc_origin) + const octave_value& tc_origin) { int retval = -1; @@ -3098,44 +3098,44 @@ int origin = SEEK_SET; if (tc_origin.is_string ()) - { - std::string xorigin = tc_origin.string_value (); - - if (xorigin == "bof") - origin = SEEK_SET; - else if (xorigin == "cof") - origin = SEEK_CUR; - else if (xorigin == "eof") - origin = SEEK_END; - else - conv_err = -1; - } + { + std::string xorigin = tc_origin.string_value (); + + if (xorigin == "bof") + origin = SEEK_SET; + else if (xorigin == "cof") + origin = SEEK_CUR; + else if (xorigin == "eof") + origin = SEEK_END; + else + conv_err = -1; + } else - { - int xorigin = convert_to_valid_int (tc_origin, conv_err); - - if (! conv_err) - { - if (xorigin == -1) - origin = SEEK_SET; - else if (xorigin == 0) - origin = SEEK_CUR; - else if (xorigin == 1) - origin = SEEK_END; - else - conv_err = -1; - } - } + { + int xorigin = convert_to_valid_int (tc_origin, conv_err); + + if (! conv_err) + { + if (xorigin == -1) + origin = SEEK_SET; + else if (xorigin == 0) + origin = SEEK_CUR; + else if (xorigin == 1) + origin = SEEK_END; + else + conv_err = -1; + } + } if (! conv_err) - { - retval = seek (xoffset, origin); - - if (retval != 0) - error ("fseek: failed to seek to requested position"); - } + { + retval = seek (xoffset, origin); + + if (retval != 0) + error ("fseek: failed to seek to requested position"); + } else - error ("fseek: invalid value for origin"); + error ("fseek: invalid value for origin"); } else error ("fseek: invalid value for offset"); @@ -3181,8 +3181,8 @@ template <class RET_T, class READ_T> octave_value do_read (octave_stream& strm, octave_idx_type nr, octave_idx_type nc, octave_idx_type block_size, - octave_idx_type skip, bool do_float_fmt_conv, bool do_NA_conv, - oct_mach_info::float_format from_flt_fmt, octave_idx_type& count) + octave_idx_type skip, bool do_float_fmt_conv, bool do_NA_conv, + oct_mach_info::float_format from_flt_fmt, octave_idx_type& count) { octave_value retval; @@ -3203,17 +3203,17 @@ if (nr > 0) { if (nc > 0) - { - nda.resize (dim_vector (nr, nc), elt_zero); - dat = nda.fortran_vec (); - max_size = nr * nc; - } + { + nda.resize (dim_vector (nr, nc), elt_zero); + dat = nda.fortran_vec (); + max_size = nr * nc; + } else - { - nda.resize (dim_vector (nr, 32), elt_zero); - dat = nda.fortran_vec (); - max_size = nr * 32; - } + { + nda.resize (dim_vector (nr, 32), elt_zero); + dat = nda.fortran_vec (); + max_size = nr * 32; + } } else { @@ -3228,8 +3228,8 @@ if (oct_mach_info::words_big_endian ()) swap = (from_flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian - || from_flt_fmt == oct_mach_info::flt_fmt_vax_g - || from_flt_fmt == oct_mach_info::flt_fmt_vax_g); + || from_flt_fmt == oct_mach_info::flt_fmt_vax_g + || from_flt_fmt == oct_mach_info::flt_fmt_vax_g); else swap = (from_flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian); @@ -3248,95 +3248,95 @@ octave_idx_type elts_read = 0; for (;;) - { - // FIXME -- maybe there should be a special case for - // skip == 0. - - if (is) - { - if (nr > 0 && nc > 0 && count == max_size) - { - final_nr = nr; - final_nc = nc; - - break; - } - - is.read (u.buf, sizeof (typename strip_template_param<octave_int, READ_T>::type)); - - // We only swap bytes for integer types. For float - // types, the format conversion will also handle byte - // swapping. - - if (swap) - swap_bytes<sizeof (typename strip_template_param<octave_int, READ_T>::type)> (u.buf); - else if (do_float_fmt_conv) - do_float_format_conversion - (u.buf, - sizeof (typename strip_template_param<octave_int, READ_T>::type), - 1, from_flt_fmt, oct_mach_info::float_format ()); - - typename RET_T::element_type tmp - = static_cast <typename RET_T::element_type> (u.val); - - if (is) - { - if (count == max_size) - { - max_size *= 2; - - if (nr > 0) - nda.resize (dim_vector (nr, max_size / nr), - elt_zero); - else - nda.resize (dim_vector (max_size, 1), elt_zero); - - dat = nda.fortran_vec (); - } - - if (do_NA_conv && __lo_ieee_is_old_NA (tmp)) - tmp = __lo_ieee_replace_old_NA (tmp); - - dat[count++] = tmp; - - elts_read++; - } - - int seek_status = 0; - - if (skip != 0 && elts_read == block_size) - { - seek_status = strm.seek (skip, SEEK_CUR); - elts_read = 0; - } - - if (is.eof () || seek_status < 0) - { - if (nr > 0) - { - if (count > nr) - { - final_nr = nr; - final_nc = (count - 1) / nr + 1; - } - else - { - final_nr = count; - final_nc = 1; - } - } - else - { - final_nr = count; - final_nc = 1; - } - - break; - } - } - else if (is.eof ()) - break; - } + { + // FIXME -- maybe there should be a special case for + // skip == 0. + + if (is) + { + if (nr > 0 && nc > 0 && count == max_size) + { + final_nr = nr; + final_nc = nc; + + break; + } + + is.read (u.buf, sizeof (typename strip_template_param<octave_int, READ_T>::type)); + + // We only swap bytes for integer types. For float + // types, the format conversion will also handle byte + // swapping. + + if (swap) + swap_bytes<sizeof (typename strip_template_param<octave_int, READ_T>::type)> (u.buf); + else if (do_float_fmt_conv) + do_float_format_conversion + (u.buf, + sizeof (typename strip_template_param<octave_int, READ_T>::type), + 1, from_flt_fmt, oct_mach_info::float_format ()); + + typename RET_T::element_type tmp + = static_cast <typename RET_T::element_type> (u.val); + + if (is) + { + if (count == max_size) + { + max_size *= 2; + + if (nr > 0) + nda.resize (dim_vector (nr, max_size / nr), + elt_zero); + else + nda.resize (dim_vector (max_size, 1), elt_zero); + + dat = nda.fortran_vec (); + } + + if (do_NA_conv && __lo_ieee_is_old_NA (tmp)) + tmp = __lo_ieee_replace_old_NA (tmp); + + dat[count++] = tmp; + + elts_read++; + } + + int seek_status = 0; + + if (skip != 0 && elts_read == block_size) + { + seek_status = strm.seek (skip, SEEK_CUR); + elts_read = 0; + } + + if (is.eof () || seek_status < 0) + { + if (nr > 0) + { + if (count > nr) + { + final_nr = nr; + final_nc = (count - 1) / nr + 1; + } + else + { + final_nr = count; + final_nc = 1; + } + } + else + { + final_nr = count; + final_nc = 1; + } + + break; + } + } + else if (is.eof ()) + break; + } } nda.resize (dim_vector (final_nr, final_nc), elt_zero); @@ -3349,7 +3349,7 @@ #define DO_READ_VAL_TEMPLATE(RET_T, READ_T) \ template octave_value \ do_read<RET_T, READ_T> (octave_stream&, octave_idx_type, octave_idx_type, octave_idx_type, octave_idx_type, bool, bool, \ - oct_mach_info::float_format, octave_idx_type&) + oct_mach_info::float_format, octave_idx_type&) // FIXME -- should we only have float if it is a different // size from double? @@ -3383,7 +3383,7 @@ INSTANTIATE_DO_READ (boolNDArray); typedef octave_value (*read_fptr) (octave_stream&, octave_idx_type, octave_idx_type, octave_idx_type, octave_idx_type, bool, bool, - oct_mach_info::float_format ffmt, octave_idx_type&); + oct_mach_info::float_format ffmt, octave_idx_type&); #define FILL_TABLE_ROW(R, VAL_T) \ read_fptr_table[R][oct_data_conv::dt_int8] = do_read<VAL_T, octave_int8>; \ @@ -3403,10 +3403,10 @@ octave_value octave_stream::read (const Array<double>& size, octave_idx_type block_size, - oct_data_conv::data_type input_type, - oct_data_conv::data_type output_type, - octave_idx_type skip, oct_mach_info::float_format ffmt, - octave_idx_type& char_count) + oct_data_conv::data_type input_type, + oct_data_conv::data_type output_type, + octave_idx_type skip, oct_mach_info::float_format ffmt, + octave_idx_type& char_count) { static bool initialized = false; @@ -3458,42 +3458,42 @@ get_size (size, nr, nc, ignore, "fread"); if (! error_state) - { - if (nr == 0 || nc == 0) - retval = Matrix (nr, nc); - else - { - if (ffmt == oct_mach_info::flt_fmt_unknown) - ffmt = float_format (); - - read_fptr fcn = read_fptr_table[output_type][input_type]; - - bool do_float_fmt_conv = ((input_type == oct_data_conv::dt_double - || input_type == oct_data_conv::dt_single) - && ffmt != float_format ()); - - bool do_NA_conv = (output_type == oct_data_conv::dt_double); - - if (fcn) - { - retval = (*fcn) (*this, nr, nc, block_size, skip, - do_float_fmt_conv, do_NA_conv, - ffmt, char_count); - - // FIXME -- kluge! - - if (! error_state - && (output_type == oct_data_conv::dt_char - || output_type == oct_data_conv::dt_schar - || output_type == oct_data_conv::dt_uchar)) - retval = retval.char_matrix_value (); - } - else - error ("fread: unable to read and convert requested types"); - } - } + { + if (nr == 0 || nc == 0) + retval = Matrix (nr, nc); + else + { + if (ffmt == oct_mach_info::flt_fmt_unknown) + ffmt = float_format (); + + read_fptr fcn = read_fptr_table[output_type][input_type]; + + bool do_float_fmt_conv = ((input_type == oct_data_conv::dt_double + || input_type == oct_data_conv::dt_single) + && ffmt != float_format ()); + + bool do_NA_conv = (output_type == oct_data_conv::dt_double); + + if (fcn) + { + retval = (*fcn) (*this, nr, nc, block_size, skip, + do_float_fmt_conv, do_NA_conv, + ffmt, char_count); + + // FIXME -- kluge! + + if (! error_state + && (output_type == oct_data_conv::dt_char + || output_type == oct_data_conv::dt_schar + || output_type == oct_data_conv::dt_uchar)) + retval = retval.char_matrix_value (); + } + else + error ("fread: unable to read and convert requested types"); + } + } else - invalid_operation ("fread", "reading"); + invalid_operation ("fread", "reading"); } return retval; @@ -3501,28 +3501,28 @@ octave_idx_type octave_stream::write (const octave_value& data, octave_idx_type block_size, - oct_data_conv::data_type output_type, octave_idx_type skip, - oct_mach_info::float_format flt_fmt) + oct_data_conv::data_type output_type, octave_idx_type skip, + oct_mach_info::float_format flt_fmt) { octave_idx_type retval = -1; if (stream_ok ()) { if (! error_state) - { - if (flt_fmt == oct_mach_info::flt_fmt_unknown) - flt_fmt = float_format (); - - octave_idx_type status = data.write (*this, block_size, output_type, - skip, flt_fmt); - - if (status < 0) - error ("fwrite: write error"); - else - retval = status; - } + { + if (flt_fmt == oct_mach_info::flt_fmt_unknown) + flt_fmt = float_format (); + + octave_idx_type status = data.write (*this, block_size, output_type, + skip, flt_fmt); + + if (status < 0) + error ("fwrite: write error"); + else + retval = status; + } else - invalid_operation ("fwrite", "writing"); + invalid_operation ("fwrite", "writing"); } return retval; @@ -3538,7 +3538,7 @@ swap_bytes<sizeof (typename T::val_type)> (&tmp); os.write (reinterpret_cast<const char *> (&tmp), - sizeof (typename T::val_type)); + sizeof (typename T::val_type)); } template void write_int (std::ostream&, bool, const octave_int8&); @@ -3553,8 +3553,8 @@ template <class T> static inline bool do_write (std::ostream& os, const T& val, oct_data_conv::data_type output_type, - oct_mach_info::float_format flt_fmt, bool swap, - bool do_float_conversion) + oct_mach_info::float_format flt_fmt, bool swap, + bool do_float_conversion) { bool retval = true; @@ -3609,29 +3609,29 @@ case oct_data_conv::dt_single: { - float f = static_cast<float> (val); - - if (do_float_conversion) - do_float_format_conversion (&f, 1, flt_fmt); - - os.write (reinterpret_cast<const char *> (&f), sizeof (float)); + float f = static_cast<float> (val); + + if (do_float_conversion) + do_float_format_conversion (&f, 1, flt_fmt); + + os.write (reinterpret_cast<const char *> (&f), sizeof (float)); } break; case oct_data_conv::dt_double: { - double d = static_cast<double> (val); - if (do_float_conversion) - do_double_format_conversion (&d, 1, flt_fmt); - - os.write (reinterpret_cast<const char *> (&d), sizeof (double)); + double d = static_cast<double> (val); + if (do_float_conversion) + do_double_format_conversion (&d, 1, flt_fmt); + + os.write (reinterpret_cast<const char *> (&d), sizeof (double)); } break; default: retval = false; (*current_liboctave_error_handler) - ("write: invalid type specification"); + ("write: invalid type specification"); break; } @@ -3640,41 +3640,41 @@ template bool do_write (std::ostream&, const octave_int8&, oct_data_conv::data_type, - oct_mach_info::float_format, bool, bool); + oct_mach_info::float_format, bool, bool); template bool do_write (std::ostream&, const octave_uint8&, oct_data_conv::data_type, - oct_mach_info::float_format, bool, bool); + oct_mach_info::float_format, bool, bool); template bool do_write (std::ostream&, const octave_int16&, oct_data_conv::data_type, - oct_mach_info::float_format, bool, bool); + oct_mach_info::float_format, bool, bool); template bool do_write (std::ostream&, const octave_uint16&, oct_data_conv::data_type, - oct_mach_info::float_format, bool, bool); + oct_mach_info::float_format, bool, bool); template bool do_write (std::ostream&, const octave_int32&, oct_data_conv::data_type, - oct_mach_info::float_format, bool, bool); + oct_mach_info::float_format, bool, bool); template bool do_write (std::ostream&, const octave_uint32&, oct_data_conv::data_type, - oct_mach_info::float_format, bool, bool); + oct_mach_info::float_format, bool, bool); template bool do_write (std::ostream&, const octave_int64&, oct_data_conv::data_type, - oct_mach_info::float_format, bool, bool); + oct_mach_info::float_format, bool, bool); template bool do_write (std::ostream&, const octave_uint64&, oct_data_conv::data_type, - oct_mach_info::float_format, bool, bool); + oct_mach_info::float_format, bool, bool); template <class T> octave_idx_type octave_stream::write (const Array<T>& data, octave_idx_type block_size, - oct_data_conv::data_type output_type, - octave_idx_type skip, oct_mach_info::float_format flt_fmt) + oct_data_conv::data_type output_type, + octave_idx_type skip, oct_mach_info::float_format flt_fmt) { octave_idx_type retval = -1; @@ -3697,8 +3697,8 @@ if (oct_mach_info::words_big_endian ()) swap = (flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian - || flt_fmt == oct_mach_info::flt_fmt_vax_g - || flt_fmt == oct_mach_info::flt_fmt_vax_g); + || flt_fmt == oct_mach_info::flt_fmt_vax_g + || flt_fmt == oct_mach_info::flt_fmt_vax_g); else swap = (flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian); @@ -3707,62 +3707,62 @@ std::ostream *osp = output_stream (); if (osp) - { - std::ostream& os = *osp; - - if (skip != 0 && (i % block_size) == 0) - { - // Seek to skip when inside bounds of existing file. - // Otherwise, write NUL to skip. - - long orig_pos = tell (); - - seek (0, SEEK_END); - - long eof_pos = tell (); - - // Is it possible for this to fail to return us to the - // original position? - seek (orig_pos, SEEK_SET); - - long remaining = eof_pos - orig_pos; - - if (remaining < skip) - { - seek (0, SEEK_END); - - // FIXME -- probably should try to write larger - // blocks... - - unsigned char zero = 0; - for (octave_idx_type j = 0; j < skip - remaining; j++) - os.write (reinterpret_cast<const char *> (&zero), 1); - } - else - seek (skip, SEEK_CUR); - } - - if (os) - { - status = do_write (os, d[i], output_type, flt_fmt, swap, - do_float_conversion); - - if (os && status) - count++; - else - break; - } - else - { - status = false; - break; - } - } + { + std::ostream& os = *osp; + + if (skip != 0 && (i % block_size) == 0) + { + // Seek to skip when inside bounds of existing file. + // Otherwise, write NUL to skip. + + long orig_pos = tell (); + + seek (0, SEEK_END); + + long eof_pos = tell (); + + // Is it possible for this to fail to return us to the + // original position? + seek (orig_pos, SEEK_SET); + + long remaining = eof_pos - orig_pos; + + if (remaining < skip) + { + seek (0, SEEK_END); + + // FIXME -- probably should try to write larger + // blocks... + + unsigned char zero = 0; + for (octave_idx_type j = 0; j < skip - remaining; j++) + os.write (reinterpret_cast<const char *> (&zero), 1); + } + else + seek (skip, SEEK_CUR); + } + + if (os) + { + status = do_write (os, d[i], output_type, flt_fmt, swap, + do_float_conversion); + + if (os && status) + count++; + else + break; + } + else + { + status = false; + break; + } + } else - { - status = false; - break; - } + { + status = false; + break; + } } if (status) @@ -3773,67 +3773,67 @@ template octave_idx_type octave_stream::write (const Array<char>&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array<bool>&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array<double>&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array<float>&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array<octave_int8>&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array<octave_uint8>&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array<octave_int16>&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array<octave_uint16>&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array<octave_int32>&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array<octave_uint32>&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array<octave_int64>&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); template octave_idx_type octave_stream::write (const Array<octave_uint64>&, octave_idx_type, - oct_data_conv::data_type, - octave_idx_type, oct_mach_info::float_format); + oct_data_conv::data_type, + octave_idx_type, oct_mach_info::float_format); octave_value octave_stream::scanf (const std::string& fmt, const Array<double>& size, - octave_idx_type& count, const std::string& who) + octave_idx_type& count, const std::string& who) { octave_value retval; @@ -3845,7 +3845,7 @@ octave_value octave_stream::scanf (const octave_value& fmt, const Array<double>& size, - octave_idx_type& count, const std::string& who) + octave_idx_type& count, const std::string& who) { octave_value retval = Matrix (); @@ -3854,7 +3854,7 @@ std::string sfmt = fmt.string_value (); if (fmt.is_sq_string ()) - sfmt = do_string_escapes (sfmt); + sfmt = do_string_escapes (sfmt); retval = scanf (sfmt, size, count, who); } @@ -3889,7 +3889,7 @@ std::string sfmt = fmt.string_value (); if (fmt.is_sq_string ()) - sfmt = do_string_escapes (sfmt); + sfmt = do_string_escapes (sfmt); retval = oscanf (sfmt, who); } @@ -3905,7 +3905,7 @@ int octave_stream::printf (const std::string& fmt, const octave_value_list& args, - const std::string& who) + const std::string& who) { int retval = -1; @@ -3917,7 +3917,7 @@ int octave_stream::printf (const octave_value& fmt, const octave_value_list& args, - const std::string& who) + const std::string& who) { int retval = 0; @@ -3926,7 +3926,7 @@ std::string sfmt = fmt.string_value (); if (fmt.is_sq_string ()) - sfmt = do_string_escapes (sfmt); + sfmt = do_string_escapes (sfmt); retval = printf (sfmt, args, who); } @@ -4050,17 +4050,17 @@ else if (in_mode == (std::ios::in | std::ios::binary)) retval = "rb"; else if (in_mode == (std::ios::out | std::ios::binary) - || in_mode == (std::ios::out | std::ios::trunc | std::ios::binary)) + || in_mode == (std::ios::out | std::ios::trunc | std::ios::binary)) retval = "wb"; else if (in_mode == (std::ios::out | std::ios::app | std::ios::binary)) retval = "ab"; else if (in_mode == (std::ios::in | std::ios::out | std::ios::binary)) retval = "r+b"; else if (in_mode == (std::ios::in | std::ios::out | std::ios::trunc - | std::ios::binary)) + | std::ios::binary)) retval = "w+b"; else if (in_mode == (std::ios::in | std::ios::out | std::ios::ate - | std::ios::binary)) + | std::ios::binary)) retval = "a+b"; return retval; @@ -4225,7 +4225,7 @@ octave_stream octave_stream_list::do_lookup (const octave_value& fid, - const std::string& who) const + const std::string& who) const { octave_stream retval; @@ -4250,22 +4250,22 @@ ostrl_map::iterator iter = list.find (fid); if (iter != list.end ()) - { - octave_stream os = iter->second; + { + octave_stream os = iter->second; list.erase (iter); lookup_cache = list.end (); // FIXME: is this check redundant? - if (os.is_valid ()) - { - os.close (); - retval = 0; - } - else - gripe_invalid_file_id (fid, who); - } + if (os.is_valid ()) + { + os.close (); + retval = 0; + } + else + gripe_invalid_file_id (fid, who); + } else - gripe_invalid_file_id (fid, who); + gripe_invalid_file_id (fid, who); } else gripe_invalid_file_id (fid, who); @@ -4289,7 +4289,7 @@ int i = get_file_number (fid); if (! error_state) - retval = do_remove (i, who); + retval = do_remove (i, who); } return retval; @@ -4376,16 +4376,16 @@ octave_stream os = p->second; buf << " " - << std::setiosflags (std::ios::right) - << std::setw (4) << p->first << " " - << std::setiosflags (std::ios::left) - << std::setw (3) - << octave_stream::mode_as_string (os.mode ()) - << " " - << std::setw (9) - << oct_mach_info::float_format_as_string (os.float_format ()) - << " " - << os.name () << "\n"; + << std::setiosflags (std::ios::right) + << std::setw (4) << p->first << " " + << std::setiosflags (std::ios::left) + << std::setw (3) + << octave_stream::mode_as_string (os.mode ()) + << " " + << std::setw (9) + << oct_mach_info::float_format_as_string (os.float_format ()) + << " " + << os.name () << "\n"; } buf << "\n"; @@ -4407,7 +4407,7 @@ // Skip stdin, stdout, and stderr. if (p->first > 2 && p->second) - retval(0,num_open++) = p->first; + retval(0,num_open++) = p->first; } retval.resize ((num_open > 0), num_open); @@ -4425,21 +4425,21 @@ std::string nm = fid.string_value (); for (ostrl_map::const_iterator p = list.begin (); p != list.end (); p++) - { - // stdin (std::cin), stdout (std::cout), and stderr (std::cerr) - // are unnamed. - - if (p->first > 2) - { - octave_stream os = p->second; - - if (os && os.name () == nm) - { - retval = p->first; - break; - } - } - } + { + // stdin (std::cin), stdout (std::cout), and stderr (std::cerr) + // are unnamed. + + if (p->first > 2) + { + octave_stream os = p->second; + + if (os && os.name () == nm) + { + retval = p->first; + break; + } + } + } } else { @@ -4448,9 +4448,9 @@ int int_fid = convert_to_valid_int (fid, conv_err); if (conv_err) - ::error ("file id must be a file object, std::string, or integer value"); + ::error ("file id must be a file object, std::string, or integer value"); else - retval = int_fid; + retval = int_fid; } return retval;