changeset 6726:6b7ba4a31876

[project @ 2007-06-14 20:16:44 by jwe]
author jwe
date Thu, 14 Jun 2007 20:16:45 +0000
parents dd930ff7f754
children 3d1e0a056e6e
files src/ChangeLog src/oct-prcstrm.cc src/oct-procbuf.cc src/sysdep.cc src/sysdep.h
diffstat 5 files changed, 50 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Thu Jun 14 18:23:02 2007 +0000
+++ b/src/ChangeLog	Thu Jun 14 20:16:45 2007 +0000
@@ -1,7 +1,12 @@
 2007-06-14  John W. Eaton  <jwe@octave.org>
 
-	* oct-procbuf.cc (procbuf::open): Open pipe in binary mode for
-	Windows.
+	* sysdep.cc (octave_popen, octave_pclose): New functions.
+	* sysdep.h: Provide decls.
+
+	* oct-procbuf.cc (procbuf::open): Use octave_popen.
+	(procbuf::close): Use octave_pclose.
+	* oct-prcstrm.cc (octave_oprocstream::octave_oprocstream, 
+	octave_iprocstream::ictave_oprocstream): Likewise.
 
 	* graphics.h (text::text_properties::rotation): New data member.
 	* graphics.cc (text::text_properties::text_properties, 
--- a/src/oct-prcstrm.cc	Thu Jun 14 18:23:02 2007 +0000
+++ b/src/oct-prcstrm.cc	Thu Jun 14 20:16:45 2007 +0000
@@ -28,20 +28,7 @@
 #include <cstdio>
 
 #include "oct-prcstrm.h"
-
-// FIXME -- perhaps this should be handled more globally.  See also
-// oct-procbuf.cc.
-
-#if defined (_MSC_VER)
-#define popen _popen
-#define pclose _pclose
-#endif
-
-static int
-cxx_pclose (FILE *f)
-{
-  return ::pclose (f);
-}
+#include "sysdep.h"
 
 octave_stream
 octave_iprocstream::create (const std::string& n, std::ios::openmode arg_md,
@@ -53,8 +40,8 @@
 octave_iprocstream::octave_iprocstream (const std::string& n,
 					std::ios::openmode arg_md,
 					oct_mach_info::float_format ff)
-  : octave_stdiostream (n, ::popen (n.c_str (), "r"),
-			arg_md, ff, cxx_pclose)
+  : octave_stdiostream (n, octave_popen (n.c_str (), "r"),
+			arg_md, ff, octave_pclose)
 {
 }
 
@@ -73,8 +60,8 @@
 octave_oprocstream::octave_oprocstream (const std::string& n,
 					std::ios::openmode arg_md,
 					oct_mach_info::float_format ff)
-  : octave_stdiostream (n, ::popen (n.c_str (), "w"),
-			arg_md, ff, cxx_pclose)
+  : octave_stdiostream (n, octave_popen (n.c_str (), "w"),
+			arg_md, ff, octave_pclose)
 {
 }
 
--- a/src/oct-procbuf.cc	Thu Jun 14 18:23:02 2007 +0000
+++ b/src/oct-procbuf.cc	Thu Jun 14 20:16:45 2007 +0000
@@ -40,6 +40,7 @@
 #include "lo-utils.h"
 #include "oct-procbuf.h"
 #include "oct-syscalls.h"
+#include "sysdep.h"
 #include "variables.h"
 
 #include "defun.h"
@@ -51,17 +52,6 @@
 
 static octave_procbuf *octave_procbuf_list = 0;
 
-// FIXME -- perhaps this should be handled more globally.  See also
-// oct-prcstrm.cc.
-
-#if defined (__CYGWIN__)
-#define W32POPEN popen
-#define W32PCLOSE pclose
-#elif defined (__MINGW32__) || defined (_MSC_VER)
-#define W32POPEN _popen
-#define W32PCLOSE _pclose
-#endif
-
 #ifndef BUFSIZ
 #define BUFSIZ 1024
 #endif
@@ -74,7 +64,7 @@
   if (is_open ()) 
     return 0;
 
-  f = ::W32POPEN (command, (mode & std::ios::in) ? "rb" : "wb");
+  f = octave_popen (command, (mode & std::ios::in) ? "r" : "w");
 
   if (! f)
     return 0;
@@ -179,7 +169,7 @@
 
   if (f)
     {
-      wstatus = ::W32PCLOSE (f);
+      wstatus = octave_pclose (f);
       f = 0;
     }
 
--- a/src/sysdep.cc	Thu Jun 14 18:23:02 2007 +0000
+++ b/src/sysdep.cc	Thu Jun 14 20:16:45 2007 +0000
@@ -516,6 +516,36 @@
   curr_on = on;
 }
 
+FILE *
+octave_popen (const char *command, const char *mode)
+{
+#if defined (__MINGW32__) || defined (_MSC_VER)
+  if (mode && mode[0] && ! mode[1])
+    {
+      char tmode[3];
+      tmode[0] = mode[0];
+      tmode[1] = 'b';
+      tmode[2] = 0;
+
+      return _popen (command, tmode);
+    }
+  else
+    return _popen (command, mode);
+#else
+  return popen (command, mode);
+#endif
+}
+
+int
+octave_pclose (FILE *f)
+{
+#if defined (__MINGW32__) || defined (_MSC_VER)
+  return _pclose (f);
+#else
+  return pclose (f);
+#endif
+}
+
 // Read one character from the terminal.
 
 int
--- a/src/sysdep.h	Thu Jun 14 18:23:02 2007 +0000
+++ b/src/sysdep.h	Thu Jun 14 20:16:45 2007 +0000
@@ -24,6 +24,8 @@
 #if !defined (octave_sysdep_h)
 #define octave_sysdep_h 1
 
+#include <cstdio>
+
 #include <string>
 
 #include "lo-ieee.h"
@@ -35,6 +37,9 @@
 
 extern void raw_mode (bool, bool wait = true);
 
+extern FILE *octave_popen (const char *command, const char *mode);
+extern int octave_pclose (FILE *f);
+
 extern OCTINTERP_API int octave_kbhit (bool wait = true);
 
 extern void w32_set_quiet_shutdown (void);