# HG changeset patch # User jwe # Date 953796895 0 # Node ID 168c4d71dc63c6662d6d70d87bfb6b0cf9e542be # Parent 58e52fbee1dde8125bff5190e9b999a3d18166df [project @ 2000-03-23 07:34:54 by jwe] diff -r 58e52fbee1dd -r 168c4d71dc63 src/c-file-ptr-stream.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/c-file-ptr-stream.cc Thu Mar 23 07:34:55 2000 +0000 @@ -0,0 +1,126 @@ +/* + +Copyright (C) 2000 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if defined (__GNUG__) +#pragma implementation +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "c_file_ptr_stream.h" + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +c_file_ptr_buf::~c_file_ptr_buf (void) { fflush (f); } + +// XXX FIXME XXX -- I'm sure there is room for improvement here... + +int +c_file_ptr_buf::overflow (int c) +{ + return (c != EOF) ? fputc (c, f) : fflush (f); +} + +int +c_file_ptr_buf::underflow (void) +{ + return fgetc (f); +} + +int +c_file_ptr_buf::uflow (void) +{ + return underflow (); +} + +int +c_file_ptr_buf::pbackfail (int c) +{ + return (c != EOF) ? ungetc (c, f) : EOF; +} + +std::streamsize +c_file_ptr_buf::xsputn (const char* s, std::streamsize n) +{ + return fwrite (s, 1, n, f); +} + +std::streamsize +c_file_ptr_buf::xsgetn (char *s, std::streamsize n) +{ + return fread (s, 1, n, f); +} + +static inline int +seekdir_to_whence (std::ios::seekdir dir) +{ + return ((dir == std::ios::beg) ? SEEK_SET : + (dir == std::ios::cur) ? SEEK_CUR : + (dir == std::ios::end) ? SEEK_END : + dir); +} + +std::streampos +c_file_ptr_buf::seekoff (std::streamoff offset, std::ios::seekdir dir, + std::ios::openmode) +{ + // XXX FIXME XXX -- is this the right thing to do? + + fseek (f, offset, seekdir_to_whence (dir)); + + return ftell (f); +} + +std::streampos +c_file_ptr_buf::seekpos (std::streampos offset, std::ios::openmode) +{ + // XXX FIXME XXX -- is this the right thing to do? + + fseek (f, offset, SEEK_SET); + + return ftell (f); +} + +int +c_file_ptr_buf::sync (void) +{ + return 0; +} + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ + diff -r 58e52fbee1dd -r 168c4d71dc63 src/c-file-ptr-stream.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/c-file-ptr-stream.h Thu Mar 23 07:34:55 2000 +0000 @@ -0,0 +1,106 @@ +/* + +Copyright (C) 2000 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (octave_c_file_ptr_stream_h) +#define octave_c_file_ptr_stream_h 1 + +#ifdef __GNUG__ +#pragma interface +#endif + +#include +#include + +class +c_file_ptr_buf : public std::streambuf +{ +protected: + + FILE *f; + +public: + + FILE* stdiofile (void) const { return f; } + + c_file_ptr_buf (FILE *f_arg) : std::streambuf (), f (f_arg) { } + + ~c_file_ptr_buf (void); + + int overflow (int); + + int underflow (void); + + int uflow (void); + + int pbackfail (int); + + std::streamsize xsputn (const char*, std::streamsize); + + std::streamsize xsgetn (char *, std::streamsize); + + std::streampos seekoff (std::streamoff, std::ios::seekdir, + std::ios::openmode = std::ios::in | std::ios::out); + + std::streampos seekpos (std::streampos, + std::ios::openmode = std::ios::in | std::ios::out); + + int sync (void); +}; + +class +i_c_file_ptr_stream : public std::istream +{ +private: + + c_file_ptr_buf f; + +public: + + i_c_file_ptr_stream (FILE* f_arg) + : std::istream (), f (f_arg) { init (&f); } + + c_file_ptr_buf *rdbuf (void) { return &f; } +}; + +class +o_c_file_ptr_stream : public std::ostream +{ +private: + + c_file_ptr_buf f; + +public: + + o_c_file_ptr_stream (FILE* f_arg) + : std::ostream (), f (f_arg) { init (&f); } + + c_file_ptr_buf *rdbuf (void) { return &f; } +}; + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ + diff -r 58e52fbee1dd -r 168c4d71dc63 src/c_file_ptr_stream.cc --- a/src/c_file_ptr_stream.cc Thu Mar 23 07:25:30 2000 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +0,0 @@ -/* - -Copyright (C) 2000 John W. Eaton - -This file is part of Octave. - -Octave is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any -later version. - -Octave is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#if defined (__GNUG__) -#pragma implementation -#endif - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "c_file_ptr_stream.h" - -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif - -#ifndef SEEK_CUR -#define SEEK_CUR 1 -#endif - -#ifndef SEEK_END -#define SEEK_END 2 -#endif - -c_file_ptr_buf::~c_file_ptr_buf (void) { fflush (f); } - -// XXX FIXME XXX -- I'm sure there is room for improvement here... - -int -c_file_ptr_buf::overflow (int c) -{ - return (c != EOF) ? fputc (c, f) : fflush (f); -} - -int -c_file_ptr_buf::underflow (void) -{ - return fgetc (f); -} - -int -c_file_ptr_buf::uflow (void) -{ - return underflow (); -} - -int -c_file_ptr_buf::pbackfail (int c) -{ - return (c != EOF) ? ungetc (c, f) : EOF; -} - -std::streamsize -c_file_ptr_buf::xsputn (const char* s, std::streamsize n) -{ - return fwrite (s, 1, n, f); -} - -std::streamsize -c_file_ptr_buf::xsgetn (char *s, std::streamsize n) -{ - return fread (s, 1, n, f); -} - -static inline int -seekdir_to_whence (std::ios::seekdir dir) -{ - return ((dir == std::ios::beg) ? SEEK_SET : - (dir == std::ios::cur) ? SEEK_CUR : - (dir == std::ios::end) ? SEEK_END : - dir); -} - -std::streampos -c_file_ptr_buf::seekoff (std::streamoff offset, std::ios::seekdir dir, - std::ios::openmode) -{ - // XXX FIXME XXX -- is this the right thing to do? - - fseek (f, offset, seekdir_to_whence (dir)); - - return ftell (f); -} - -std::streampos -c_file_ptr_buf::seekpos (std::streampos offset, std::ios::openmode) -{ - // XXX FIXME XXX -- is this the right thing to do? - - fseek (f, offset, SEEK_SET); - - return ftell (f); -} - -int -c_file_ptr_buf::sync (void) -{ - return 0; -} - -/* -;;; Local Variables: *** -;;; mode: C++ *** -;;; End: *** -*/ - diff -r 58e52fbee1dd -r 168c4d71dc63 src/c_file_ptr_stream.h --- a/src/c_file_ptr_stream.h Thu Mar 23 07:25:30 2000 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -/* - -Copyright (C) 2000 John W. Eaton - -This file is part of Octave. - -Octave is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any -later version. - -Octave is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#if !defined (octave_c_file_ptr_stream_h) -#define octave_c_file_ptr_stream_h 1 - -#ifdef __GNUG__ -#pragma interface -#endif - -#include -#include - -class -c_file_ptr_buf : public std::streambuf -{ -protected: - - FILE *f; - -public: - - FILE* stdiofile (void) const { return f; } - - c_file_ptr_buf (FILE *f_arg) : std::streambuf (), f (f_arg) { } - - ~c_file_ptr_buf (void); - - int overflow (int); - - int underflow (void); - - int uflow (void); - - int pbackfail (int); - - std::streamsize xsputn (const char*, std::streamsize); - - std::streamsize xsgetn (char *, std::streamsize); - - std::streampos seekoff (std::streamoff, std::ios::seekdir, - std::ios::openmode = std::ios::in | std::ios::out); - - std::streampos seekpos (std::streampos, - std::ios::openmode = std::ios::in | std::ios::out); - - int sync (void); -}; - -class -i_c_file_ptr_stream : public std::istream -{ -private: - - c_file_ptr_buf f; - -public: - - i_c_file_ptr_stream (FILE* f_arg) - : std::istream (), f (f_arg) { init (&f); } - - c_file_ptr_buf *rdbuf (void) { return &f; } -}; - -class -o_c_file_ptr_stream : public std::ostream -{ -private: - - c_file_ptr_buf f; - -public: - - o_c_file_ptr_stream (FILE* f_arg) - : std::ostream (), f (f_arg) { init (&f); } - - c_file_ptr_buf *rdbuf (void) { return &f; } -}; - -#endif - -/* -;;; Local Variables: *** -;;; mode: C++ *** -;;; End: *** -*/ -