Mercurial > hg > octave-avbm
changeset 8739:d477e57e811c
handle CRLF and CR in fgetl/fgets
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 13 Feb 2009 16:38:27 -0500 |
parents | c32e710407ee |
children | cb0ea772a4af |
files | src/ChangeLog src/oct-stream.cc |
diffstat | 2 files changed, 27 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2009-02-13 John W. Eaton <jwe@octave.org> + * oct-stream.cc (octave_base_stream::do_gets): Handle CRLF and CR. + * toplev.cc (do_octave_atexit): Only save history if Vsaving_history is true.
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -983,7 +983,31 @@ { char_count++; - if (c == '\n') + // 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);