Mercurial > hg > octave-nkf
changeset 1380:79f80c6229be
[project @ 1995-09-12 07:03:33 by jwe]
author | jwe |
---|---|
date | Tue, 12 Sep 1995 07:06:14 +0000 |
parents | e29697484908 |
children | 4b01352e52d8 |
files | src/dirfns.cc src/load-save.cc src/load-save.h src/procstream.cc src/procstream.h |
diffstat | 5 files changed, 154 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dirfns.cc +++ b/src/dirfns.cc @@ -437,7 +437,7 @@ output_buf << ends; maybe_page_output (output_buf); - + delete [] ls_command; DELETE_ARGV;
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -2894,6 +2894,32 @@ } } +void +save_user_variables (void) +{ + // XXX FIXME XXX -- should choose better file name? + + const char *fname = "octave-core"; + + message (0, "attempting to save variables to `%s'...", fname); + + load_save_format format = get_default_save_format (); + + unsigned mode = ios::out|ios::trunc; + if (format == LS_BINARY || format == LS_MAT_BINARY) + mode |= ios::bin; + + ofstream file (fname, mode); + + if (file) + { + save_vars (0, 0, file, 0, format, 0); + message (0, "save to `%s' complete", fname); + } + else + warning ("unable to open `%s' for writing...", fname); +} + DEFUN_TEXT ("save", Fsave, Ssave, -1, 1, "save [-ascii] [-binary] [-float-binary] [-mat-binary] \n\ [-save-builtins] file [pattern ...]\n\
--- a/src/load-save.h +++ b/src/load-save.h @@ -34,6 +34,8 @@ extern int save_three_d (ostream& os, const tree_constant& t, int parametric = 0); +extern void save_user_variables (void); + #endif /*
--- a/src/procstream.cc +++ b/src/procstream.cc @@ -29,34 +29,121 @@ #include <config.h> #endif +#include <fstream.h> +#include <procbuf.h> + #include "procstream.h" -procstreambase::procstreambase (void) +iprocstream::iprocstream (void) { - init (new procbuf ()); + pbuf = new procbuf (); + + init (pbuf); } -procstreambase::procstreambase (const char *command, int mode) +iprocstream::iprocstream (const char *command, int mode) { - init (new procbuf ()); - if (! rdbuf()->open (command, mode)) + pbuf = new procbuf (); + + init (pbuf); + + if (! pbuf->open (command, mode)) set (ios::badbit); } +iprocstream::~iprocstream (void) +{ + close (); +} + void -procstreambase::open (const char *command, int mode) +iprocstream::open (const char *command, int mode) { clear (); - if (! rdbuf()->open (command, mode)) + + if (! pbuf) + pbuf = new procbuf (); + + if (! pbuf->open (command, mode)) set (ios::badbit); } int -procstreambase::close (void) +iprocstream::is_open (void) +{ + return pbuf && pbuf->is_open (); +} + +int +iprocstream::close (void) +{ + int status = 0; + + if (is_open ()) + { + + status = pbuf->sys_close (); + + if (! pbuf->close ()) + set (ios::failbit); + } + + return status; +} + +oprocstream::oprocstream (void) +{ + pbuf = new procbuf (); + + init (pbuf); +} + +oprocstream::oprocstream (const char *command, int mode) { - int status = rdbuf()->sys_close (); - if (! rdbuf()->close ()) - set (ios::failbit); + pbuf = new procbuf (); + + init (pbuf); + + if (! pbuf->open (command, mode)) + set (ios::badbit); +} + +oprocstream::~oprocstream (void) +{ + close (); +} + +void +oprocstream::open (const char *command, int mode) +{ + clear (); + + if (! pbuf) + pbuf = new procbuf (); + + if (! pbuf->open (command, mode)) + set (ios::badbit); +} + +int +oprocstream::is_open (void) +{ + return pbuf && pbuf->is_open (); +} + +int +oprocstream::close (void) +{ + int status = 0; + + if (is_open ()) + { + status = pbuf->sys_close (); + + if (! pbuf->close ()) + set (ios::failbit); + } + return status; }
--- a/src/procstream.h +++ b/src/procstream.h @@ -28,41 +28,46 @@ #pragma interface #endif -#include <iostream.h> -#include <procbuf.h> +#include <fstream.h> + +class procbuf; class -procstreambase : virtual public ios +iprocstream : public ifstream { - public: - procstreambase (void); - procstreambase (const char *command, int mode = ios::out); +public: + iprocstream (void); + iprocstream (const char *command, int mode=ios::in); + + ~iprocstream (void); - procbuf *rdbuf (void) const { return (procbuf *) _strbuf; } + void open (const char *command, int mode=ios::in); + + int is_open (void); - void open (const char *command, int mode = ios::out); - int is_open (void) { return rdbuf()->is_open (); } int close (void); + +private: + procbuf *pbuf; }; class -iprocstream : public procstreambase, public istream +oprocstream : public ofstream { - public: - iprocstream (void) : procstreambase () {} - iprocstream (const char *command) : procstreambase (command, ios::in) {} +public: + oprocstream (void); + oprocstream (const char *command, int mode=ios::out); - void open (const char *command) { procstreambase::open (command, ios::in); } -}; + ~oprocstream (void); -class -oprocstream : public procstreambase, public ostream -{ - public: - oprocstream (void) : procstreambase () {} - oprocstream (const char *command) : procstreambase (command, ios::out) {} + void open (const char *command, int mode=ios::out); + + int is_open (void); - void open (const char *command) { procstreambase::open (command, ios::out); } + int close (void); + +private: + procbuf *pbuf; }; #endif @@ -73,6 +78,3 @@ ;;; page-delimiter: "^/\\*" *** ;;; End: *** */ - - -