From bug-octave-request at bevo dot che dot wisc dot edu Tue Dec 17 18:11:23 2002 Subject: Unidentified subject! From: "John W. Eaton" To: Johannes Martin Cc: bug-octave at bevo dot che dot wisc dot edu Date: Tue, 17 Dec 2002 18:11:08 -0600 On 17-Dec-2002, Johannes Martin wrote: | To: bug-octave at bevo dot che dot wisc dot edu | Cc: jmartin | Subject: fgets fails on files not having final new line | | Bug report for Octave 2.1.36 configured for i686-pc-linux-gnu | | Description: | ----------- | | fgets failes to return the last line of a file that does not end | in a new line. This worked fin in Octave 2.0.16.92. | | Repeat-By: | --------- | | fgets(stdin)4fgets(stdin) | | Expected output (2.0.16.92): | octave:1> fgets(stdin) | 4ans = 4 | octave:2> fgets(stdin) | ans = -1 | Actual output (2.1.36) | octave:1> fgets(stdin) | 4ans = -1 | octave:2> fgets(stdin) | ans = -1 Please try the following patch. jwe 2002-12-17 John W. Eaton * oct-stream.cc (octave_base_stream::do_gets): Correctly read last line of file even if it does not end with new line character. Index: oct-stream.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/oct-stream.cc,v retrieving revision 1.78 diff -c -r1.78 oct-stream.cc *** oct-stream.cc 17 Dec 2002 23:54:34 -0000 1.78 --- oct-stream.cc 18 Dec 2002 00:10:34 -0000 *************** *** 974,998 **** break; } ! if (is.fail ()) { ! err = true; ! std::string msg = fcn; ! msg.append (": read error"); ! error (msg); } ! else if (char_count == 0 && is.eof ()) { err = true; std::string msg = fcn; ! msg.append (": at end of file"); error (msg); - } - else - { - buf << OSSTREAM_ENDS; - retval = OSSTREAM_STR (buf); - OSSTREAM_FREEZE (buf); } } else --- 974,994 ---- break; } ! if (is.good () || (is.eof () && char_count > 0)) { ! buf << OSSTREAM_ENDS; ! retval = OSSTREAM_STR (buf); ! OSSTREAM_FREEZE (buf); } ! else { err = true; std::string msg = fcn; ! if (is.eof () && char_count == 0) ! msg.append (": at end of file"); ! else ! msg.append (": read error"); error (msg); } } else ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------