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	Fri Feb 13 15:36:43 2009 -0500
+++ b/src/ChangeLog	Fri Feb 13 16:38:27 2009 -0500
@@ -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	Fri Feb 13 15:36:43 2009 -0500
+++ b/src/oct-stream.cc	Fri Feb 13 16:38:27 2009 -0500
@@ -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);