# HG changeset patch # User John W. Eaton # Date 1234561107 18000 # Node ID d477e57e811c34988a58f7be563680cdbfb58660 # Parent c32e710407ee5bd9efe3f0c3f18119f23c9c9097 handle CRLF and CR in fgetl/fgets diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2009-02-13 John W. Eaton + * 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. diff --git a/src/oct-stream.cc b/src/oct-stream.cc --- 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 (c); + + c = is.get (); + + if (c != EOF) + { + if (c == '\n') + { + char_count++; + + if (! strip_newline) + buf << static_cast (c); + } + else + is.putback (c); + } + + break; + } + else if (c == '\n') { if (! strip_newline) buf << static_cast (c);