# HG changeset patch # User jwe # Date 953802997 0 # Node ID 0b6b55fd0a5cbcf36e85f23d06819ce74571d76d # Parent 8fbe6931e709b43dcb747c7e823a0da3064ff08b [project @ 2000-03-23 09:16:36 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,8 @@ 2000-03-23 John W. Eaton + * oct-procbuf.h, oct-procbuf.cc (octave_procbuf): + Derive from c_file_ptr_buf instead of filebuf. + * oct-stream.cc (octave_base_stream::printf): Use octave_format instead of ostream::form. Return number of characters written. diff --git a/src/oct-procbuf.cc b/src/oct-procbuf.cc --- a/src/oct-procbuf.cc +++ b/src/oct-procbuf.cc @@ -54,11 +54,6 @@ // This class is based on the procbuf class from libg++, written by // Per Bothner, Copyright (C) 1993 Free Software Foundation. -// -// It should work with the filebuf class from libg++, but it might not -// work with others since it depends on being able to get at the -// underlying file descriptor with filebuf::fd(), which is not -// standard. static octave_procbuf *octave_procbuf_list = 0; @@ -104,7 +99,7 @@ while (octave_procbuf_list) { - ::close (octave_procbuf_list->fd ()); + ::fclose (octave_procbuf_list->f); octave_procbuf_list = octave_procbuf_list->next; } @@ -124,7 +119,9 @@ return 0; } - attach (parent_end); + f = ::fdopen (parent_end, (mode & std::ios::in) ? "w" : "r"); + + open_p = true; next = octave_procbuf_list; octave_procbuf_list = this; @@ -138,8 +135,8 @@ #endif } -int -octave_procbuf::sys_close (void) +octave_procbuf * +octave_procbuf::close (void) { #if defined (HAVE_SYS_WAIT_H) @@ -159,27 +156,24 @@ } } - if (status < 0 || ::close (fd ()) < 0) - return -1; - - { - using namespace std; + if (status == 0 && ::fclose (f) == 0) + { + using namespace std; - do - { - wait_pid = ::waitpid (proc_pid, &wstatus, 0); - } - while (wait_pid == -1 && errno == EINTR); - } + do + { + wait_pid = ::waitpid (proc_pid, &wstatus, 0); + } + while (wait_pid == -1 && errno == EINTR); + } - if (wait_pid == -1) - return -1; + open_p = false; - return wstatus; + return this; #else - return -1; + return 0; #endif } diff --git a/src/oct-procbuf.h b/src/oct-procbuf.h --- a/src/oct-procbuf.h +++ b/src/oct-procbuf.h @@ -26,41 +26,43 @@ #if !defined (octave_octave_procbuf_h) #define octave_octave_procbuf_h 1 -#include - #ifdef HAVE_SYS_TYPES_H #include #endif +#include "c-file-ptr-stream.h" + class -octave_procbuf : public std::filebuf +octave_procbuf : public c_file_ptr_buf { public: octave_procbuf (void) - : std::filebuf (), wstatus (-1), proc_pid (-1), next (0) { } + : c_file_ptr_buf (0), wstatus (-1), open_p (false), proc_pid (-1), + next (0) { } octave_procbuf (const char *command, int mode) - : std::filebuf (), wstatus (-1), proc_pid (-1), next (0) - { open (command, mode); } + : c_file_ptr_buf (0), wstatus (-1), open_p (false), proc_pid (-1), + next (0) { open (command, mode); } ~octave_procbuf (void) { close (); } octave_procbuf *open (const char *command, int mode); - octave_procbuf *close (void) - { return static_cast (std::filebuf::close ()); } - - virtual int sys_close (void); + octave_procbuf *close (void); int wait_status (void) const { return wstatus; } + bool is_open (void) const { return open_p; } + pid_t pid (void) { return proc_pid; } protected: int wstatus; + bool open_p; + pid_t proc_pid; octave_procbuf *next;