# HG changeset patch # User jwe # Date 941820918 0 # Node ID d8d3700fb4abff142a0e622823bab146cb480c39 # Parent 14cfc9475fe4945af8366e26fc906587545da5c3 [project @ 1999-11-05 16:55:17 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,14 @@ 1999-11-05 John W. Eaton + * oct-iostrm.h (octave_istream::eof, octave_ostream::eof): Provide + implementation for these. + + * oct-stream.cc (octave_base_stream::do_scanf): + The stdin stream is only special if we are interactive. + (octave_base_stream::scanf): Ditto. + (octave_base_stream::do_oscanf): Ditto. + (octave_base_stream::oscanf): Ditto. + * ov.h (octave_value::is_stream): New predicate. * ov-file.h (octave_file::is_stream): Return true. * file-io.cc (Fis_stream): New function. diff --git a/src/file-io.cc b/src/file-io.cc --- a/src/file-io.cc +++ b/src/file-io.cc @@ -689,7 +689,7 @@ { octave_stream os = octave_stream_list::lookup (args(0), "fscanf"); - if (error_state) + if (! error_state) { if (args(1).is_string ()) { diff --git a/src/oct-iostrm.cc b/src/oct-iostrm.cc --- a/src/oct-iostrm.cc +++ b/src/oct-iostrm.cc @@ -60,12 +60,28 @@ ::error ("%s: invalid operation", stream_type ()); } +// Return non-zero if EOF has been reached on this stream. + +bool +octave_istream::eof (void) const +{ + return is && is->eof (); +} + octave_stream octave_istream::create (istream *arg, const string& nm) { return octave_stream (new octave_istream (arg, nm)); } +// Return non-zero if EOF has been reached on this stream. + +bool +octave_ostream::eof (void) const +{ + return os && os->eof (); +} + octave_stream octave_ostream::create (ostream *arg, const string& nm) { diff --git a/src/oct-iostrm.h b/src/oct-iostrm.h --- a/src/oct-iostrm.h +++ b/src/oct-iostrm.h @@ -88,6 +88,10 @@ static octave_stream create (istream *arg = 0, const string& nm = string ()); + // Return non-zero if EOF has been reached on this stream. + + bool eof (void) const; + istream *input_stream (void) { return is; } ostream *output_stream (void) { return 0; } @@ -121,6 +125,10 @@ static octave_stream create (ostream *arg, const string& nm = string ()); + // Return non-zero if EOF has been reached on this stream. + + bool eof (void) const; + istream *input_stream (void) { return 0; } ostream *output_stream (void) { return os; } diff --git a/src/oct-stream.cc b/src/oct-stream.cc --- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -36,6 +36,7 @@ #include "str-vec.h" #include "error.h" +#include "input.h" #include "oct-stream.h" #include "oct-obj.h" #include "utils.h" @@ -1271,8 +1272,8 @@ is.clear (is.rdstate () & (~ios::failbit)); // XXX FIXME XXX -- is this the right thing to do? - // What about other streams? - if (name () == "stdin") + + if (interactive && name () == "stdin") { is.clear (); @@ -1351,8 +1352,8 @@ error ("fscanf: read error"); // XXX FIXME XXX -- is this the right thing to do? - // What about other streams? - if (name () == "stdin") + + if (interactive && name () == "stdin") { is.clear (); @@ -1534,8 +1535,8 @@ error ("fscanf: read error"); // XXX FIXME XXX -- is this the right thing to do? - // What about other streams? - if (name () == "stdin") + + if (interactive && name () == "stdin") { is.clear (); @@ -1586,12 +1587,8 @@ error ("fscanf: read error"); // XXX FIXME XXX -- is this the right thing to do? - // Maybe. We should probably also arrange to - // flush the pending input prior to printing a - // prompt. Or maybe just blow off scanf for stdin - // like the MathWorks did. What about other streams? - - if (name () == "stdin") + + if (interactive && name () == "stdin") { is.clear ();