Mercurial > hg > octave-lojdl
changeset 4797:19b8225bdaa2
[project @ 2004-02-23 22:10:31 by jwe]
author | jwe |
---|---|
date | Mon, 23 Feb 2004 22:10:32 +0000 |
parents | 962457f25a6d |
children | da0d1c453971 |
files | src/ChangeLog src/c-file-ptr-stream.h src/file-io.cc src/oct-fstrm.cc src/oct-fstrm.h src/oct-iostrm.cc src/oct-iostrm.h src/oct-stdstrm.cc src/oct-stdstrm.h src/oct-stream.cc src/oct-stream.h src/oct-strstrm.cc src/oct-strstrm.h |
diffstat | 13 files changed, 108 insertions(+), 127 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,28 @@ +2004-02-23 John W. Eaton <jwe@bevo.che.wisc.edu> + + * file-io.cc (Fftell): Return long integer instead of streamoff_array. + (do_stream_open): Create octave_stdiostream instead of octave_fstream. + + * oct-fstrm.cc (octave_fstream::seek, octave_fstream::tell): + Always fail. Signatures now match C library functionsb. + * oct-iostrm.cc (octave_base_iostream::seek, + octave_base_iostream::tell): Likewise. + * oct-strstrm.cc (octave_base_strstream::seek, + octave_base_strstream::tell): Likewise. + + * oct-stream.cc (octave_stream::seek, octave_stream::tell): + Signatures now match C-library functions. + + * oct-stdstrm.cc (octave_stdiostream::seek, octave_stdiostream::tell): + Call io_c_file_ptr_stream::seek and tell. Signatures now match + C-library functions. + + * c-file-ptr-stream.h (c_file_ptr_buf::seek, c_file_ptr_buf::tell): + New functions. + (i_c_file_ptr_stream::seek, i_c_file_ptr_stream::tell): Likewise. + (o_c_file_ptr_stream::seek, o_c_file_ptr_stream::tell): Likewise. + (io_c_file_ptr_stream::seek, io_c_file_ptr_stream::tell): Likewise. + 2004-02-20 John W. Eaton <jwe@bevo.che.wisc.edu> * version.h (OCTAVE_VERSION): Now 2.1.55.
--- a/src/c-file-ptr-stream.h +++ b/src/c-file-ptr-stream.h @@ -43,7 +43,7 @@ typedef int (*close_fcn) (FILE *); - FILE* stdiofile (void) const { return f; } + FILE* stdiofile (void) { return f; } c_file_ptr_buf (FILE *f_arg, close_fcn cf_arg = fclose) : std::streambuf (), f (f_arg), cf (cf_arg) @@ -77,6 +77,11 @@ int file_number () const { return f ? fileno (f) : -1; } + int seek (long offset, int origin) + { return f ? fseek (f, offset, origin) : -1; } + + long tell (void) { return f ? ftell (f) : -1; } + static int fclose (FILE *f) { return ::fclose (f); } protected: @@ -105,6 +110,11 @@ void close (void) { if (buf) buf->close (); } + int seek (long offset, int origin) + { return buf ? buf->seek (offset, origin) : -1; } + + long tell (void) { return buf ? buf->tell () : -1; } + private: c_file_ptr_buf *buf; @@ -125,6 +135,11 @@ void close (void) { if (buf) buf->close (); } + int seek (long offset, int origin) + { return buf ? buf->seek (offset, origin) : -1; } + + long tell (void) { return buf ? buf->tell () : -1; } + private: c_file_ptr_buf *buf; @@ -145,6 +160,11 @@ void close (void) { if (buf) buf->close (); } + int seek (long offset, int origin) + { return buf ? buf->seek (offset, origin) : -1; } + + long tell (void) { return buf ? buf->tell () : -1; } + private: c_file_ptr_buf *buf;
--- a/src/file-io.cc +++ b/src/file-io.cc @@ -38,8 +38,9 @@ #include <config.h> #endif +#include <cerrno> #include <climits> -#include <cerrno> +#include <cstdio> #include <iostream> #include <vector> @@ -337,8 +338,15 @@ oct_mach_info::float_format flt_fmt = oct_mach_info::string_to_float_format (arch); - if (! error_state) - retval = octave_fstream::create (name, md, flt_fmt); + FILE *fptr = ::fopen (name.c_str (), mode.c_str ()); + + if (fptr) + { + if (! error_state) + retval = octave_stdiostream::create (name, fptr, md, flt_fmt); + } + else + error ("fopen: failed to open file %s", name.c_str ()); } return retval; @@ -638,7 +646,7 @@ from the beginning of the file @var{fid}.\n\ @end deftypefn") { - octave_value retval = streamoff_array (dim_vector (1, 1), -1); + octave_value retval = -1; int nargin = args.length (); @@ -647,7 +655,7 @@ octave_stream os = octave_stream_list::lookup (args(0), "ftell"); if (! error_state) - retval = streamoff_array (dim_vector (1, 1), os.tell ()); + retval = os.tell (); } else print_usage ("ftell");
--- a/src/oct-fstrm.cc +++ b/src/oct-fstrm.cc @@ -66,41 +66,19 @@ // Position a stream at OFFSET relative to ORIGIN. int -octave_fstream::seek (std::streamoff offset, std::ios::seekdir origin) +octave_fstream::seek (long, int) { - int retval = -1; - - if (! fs.bad ()) - { - fs.clear (); - - std::filebuf *fb = fs.rdbuf (); - - if (fb) - { - fb->pubseekoff (offset, origin); - retval = fs.bad () ? -1 : 0; - } - } - - return retval; + error ("fseek: invalid_operation"); + return -1; } // Return current stream position. -std::streamoff -octave_fstream::tell (void) const +long +octave_fstream::tell (void) { - std::streamoff retval = -1; - - if (fs) - { - std::filebuf *fb = fs.rdbuf (); - - retval = std::streamoff (fb->pubseekoff (0, std::ios::cur)); - } - - return retval; + error ("ftell: invalid_operation"); + return -1; } // Return non-zero if EOF has been reached on this stream.
--- a/src/oct-fstrm.h +++ b/src/oct-fstrm.h @@ -45,11 +45,11 @@ // Position a stream at OFFSET relative to ORIGIN. - int seek (std::streamoff offset, std::ios::seekdir origin); + int seek (long offset, int origin); // Return current stream position. - std::streamoff tell (void) const; + long tell (void); // Return non-zero if EOF has been reached on this stream.
--- a/src/oct-iostrm.cc +++ b/src/oct-iostrm.cc @@ -30,7 +30,7 @@ // Position a stream at OFFSET relative to ORIGIN. int -octave_base_iostream::seek (std::streamoff, std::ios::seekdir) +octave_base_iostream::seek (long, int) { invalid_operation (); return -1; @@ -38,8 +38,8 @@ // Return current stream position. -std::streamoff -octave_base_iostream::tell (void) const +long +octave_base_iostream::tell (void) { invalid_operation (); return -1;
--- a/src/oct-iostrm.h +++ b/src/oct-iostrm.h @@ -40,11 +40,11 @@ // Position a stream at OFFSET relative to ORIGIN. - int seek (std::streamoff offset, std::ios::seekdir origin); + int seek (long offset, int origin); // Return current stream position. - std::streamoff tell (void) const; + long tell (void); // Return non-zero if EOF has been reached on this stream.
--- a/src/oct-stdstrm.cc +++ b/src/oct-stdstrm.cc @@ -31,45 +31,25 @@ // Position a stream at OFFSET relative to ORIGIN. int -octave_stdiostream::seek (std::streamoff offset, std::ios::seekdir origin) +octave_stdiostream::seek (long offset, int origin) { int retval = -1; - if (! bad ()) - { - c_file_ptr_buf *sb = rdbuf (); - - if (sb) - { - clear (); - - sb->pubseekoff (offset, origin); - retval = bad () ? -1 : 0; - } - } + if (s) + retval = s->seek (offset, origin); return retval; } // Return current stream position. -std::streamoff -octave_stdiostream::tell (void) const +long +octave_stdiostream::tell (void) { - std::streamoff retval = -1; - - if (! bad ()) - { - c_file_ptr_buf *sb = rdbuf (); + long retval = -1; - if (sb) - { - retval = std::streamoff (sb->pubseekoff (0, std::ios::cur)); - - if (bad ()) - retval = -1; - } - } + if (s) + retval = s->tell (); return retval; }
--- a/src/oct-stdstrm.h +++ b/src/oct-stdstrm.h @@ -53,11 +53,11 @@ // Position a stream at OFFSET relative to ORIGIN. - int seek (std::streamoff offset, std::ios::seekdir origin); + int seek (long offset, int origin); // Return current stream position. - std::streamoff tell (void) const; + long tell (void); // Return non-zero if EOF has been reached on this stream.
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -2692,7 +2692,7 @@ } int -octave_stream::seek (std::streamoff offset, std::ios::seekdir origin) +octave_stream::seek (long offset, int origin) { int retval = -1; @@ -2708,24 +2708,24 @@ { int retval = -1; - std::streamoff xoffset = tc_offset.streamoff_value (); + long xoffset = tc_offset.long_value (true); if (! error_state) { int conv_err = 0; - std::ios::seekdir origin = std::ios::beg; + int origin = SEEK_SET; if (tc_origin.is_string ()) { std::string xorigin = tc_origin.string_value (); if (xorigin == "bof") - origin = std::ios::beg; + origin = SEEK_SET; else if (xorigin == "cof") - origin = std::ios::cur; + origin = SEEK_CUR; else if (xorigin == "eof") - origin = std::ios::end; + origin = SEEK_END; else conv_err = -1; } @@ -2736,11 +2736,11 @@ if (! conv_err) { if (xorigin == -1) - origin = std::ios::beg; + origin = SEEK_SET; else if (xorigin == 0) - origin = std::ios::cur; + origin = SEEK_CUR; else if (xorigin == 1) - origin = std::ios::end; + origin = SEEK_END; else conv_err = -1; } @@ -2757,10 +2757,10 @@ return retval; } -std::streamoff -octave_stream::tell (void) const +long +octave_stream::tell (void) { - std::streamoff retval = -1; + long retval = -1; if (stream_ok ("tell")) retval = rep->tell ();
--- a/src/oct-stream.h +++ b/src/oct-stream.h @@ -334,11 +334,11 @@ // Position a stream at OFFSET relative to ORIGIN. - virtual int seek (std::streamoff offset, std::ios::seekdir origin) = 0; + virtual int seek (long offset, int origin) = 0; // Return current stream position. - virtual std::streamoff tell (void) const = 0; + virtual long tell (void) = 0; // Return TRUE if EOF has been reached on this stream. @@ -502,10 +502,10 @@ std::string gets (const octave_value& max_len, bool& err, const std::string& who /* = "gets" */); - int seek (std::streamoff offset, std::ios::seekdir origin); + int seek (long offset, int origin); int seek (const octave_value& offset, const octave_value& origin); - std::streamoff tell (void) const; + long tell (void); int rewind (void);
--- a/src/oct-strstrm.cc +++ b/src/oct-strstrm.cc @@ -29,49 +29,19 @@ // Position a stream at OFFSET relative to ORIGIN. int -octave_base_strstream::seek (std::streamoff offset, std::ios::seekdir origin) +octave_base_strstream::seek (long offset, int origin) { - int retval = -1; - - if (! bad ()) - { - std::streambuf *sb = rdbuf (); - - if (sb) - { - clear (); - - sb->pubseekoff (offset, origin); - retval = bad () ? -1 : 0; - } - } - - return retval; + error ("fseek: invalid operation"); + return -1; } // Return current stream position. -std::streamoff -octave_base_strstream::tell (void) const +long +octave_base_strstream::tell (void) { - std::streamoff retval = -1; - - if (! bad ()) - { - // XXX FIXME XXX -- shouldn't have to do this! - - std::streambuf *sb = (const_cast<octave_base_strstream *>(this))->rdbuf (); - - if (sb) - { - retval = std::streamoff (sb->pubseekoff (0, std::ios::cur)); - - if (bad ()) - retval = -1; - } - } - - return retval; + error ("ftell: invalid operation"); + return -1; } octave_stream
--- a/src/oct-strstrm.h +++ b/src/oct-strstrm.h @@ -41,11 +41,11 @@ // Position a stream at OFFSET relative to ORIGIN. - int seek (std::streamoff offset, std::ios::seekdir origin); + int seek (long offset, int origin); // Return current stream position. - std::streamoff tell (void) const; + long tell (void); // The name of the file.