Mercurial > hg > octave-lyh
changeset 6345:9e058e5fa8a7
[project @ 2007-02-22 22:22:53 by jwe]
author | jwe |
---|---|
date | Thu, 22 Feb 2007 22:22:54 +0000 |
parents | 860682863572 |
children | f3c5b02c66bf |
files | src/ChangeLog src/file-io.cc src/oct-stream.cc |
diffstat | 3 files changed, 62 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2007-02-22 John W. Eaton <jwe@octave.org> + + * src/oct-stream.cc (octave_stream::do_gets): If no limit or not + at limit, read ahead one character at end of line for compatibility. + (octave_stream::gets, octave_stream::getl): Set max_len to -1 if + tc_max_len is not defined. + * file-io.cc (Ffgets, Ffgetl): If no limit specified, pass + undefined octave_value object as max_len in call to + octave_stream::gets. + 2007-02-21 John W. Eaton <jwe@octave.org> * mex.cc (mexErrMsgIdAndTxt, mexWarnMsgIdAndTxt): Handle second
--- a/src/file-io.cc +++ b/src/file-io.cc @@ -308,8 +308,7 @@ if (! error_state) { - octave_value len_arg = (nargin == 2) - ? args(1) : octave_value (INT_MAX); + octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); bool err = false; @@ -357,8 +356,7 @@ if (! error_state) { - octave_value len_arg = (nargin == 2) - ? args(1) : octave_value (INT_MAX); + octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); bool err = false;
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -976,26 +976,36 @@ int c = 0; int char_count = 0; - int newline_stripped = 0; - - while (is && (c = is.get ()) != EOF) + + if (max_len != 0) { - char_count++; - - if (c == '\n') + while (is && (c = is.get ()) != EOF) { - if (! strip_newline) + char_count++; + + if (c == '\n') + { + if (! strip_newline) + buf << static_cast<char> (c); + + break; + } + else buf << static_cast<char> (c); - else - newline_stripped = 1; - - break; + + if (max_len > 0 && char_count == max_len) + 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); } if (is.good () || (is.eof () && char_count > 0)) @@ -2801,14 +2811,20 @@ int conv_err = 0; - int max_len = convert_to_valid_int (tc_max_len, conv_err); - - if (conv_err || max_len < 0) + int max_len = -1; + + if (tc_max_len.is_defined ()) { - err = true; - ::error ("%s: invalid maximum length specified", who.c_str ()); + 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 ()); + } } - else + + if (! error_state) retval = getl (max_len, err, who); return retval; @@ -2835,14 +2851,20 @@ int conv_err = 0; - int max_len = convert_to_valid_int (tc_max_len, conv_err); - - if (conv_err || max_len < 0) + int max_len = -1; + + if (tc_max_len.is_defined ()) { - err = true; - ::error ("%s: invalid maximum length specified", who.c_str ()); + 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 ()); + } } - else + + if (! error_state) retval = gets (max_len, err, who); return retval;