On Wed, Jun 09, 2004 at 09:29:37PM +0100, Angus Leeming wrote:

> Ok, as promised, here's is a rewrite of the code in ispell.[Ch]. I've
> written it as a stand-alone app, but it could be slotted straight into
> the lyx sources.
> 
> The code attached uses the Pstreams classes to run and communicate with
> the child process. (I needed to augment pstreambuf a little; diff
> attached too.)
> 
> John, are you in touch with Jon? Would he be interested in a patch? The
> pstreams mailing lists have a total of 3 mails on them, none of 'em
> answered.

I have horrible feeling Jon's going to be pretty busy ATM.

Angus's (Eric's ?) patch is below.

john


--- pstream_orig.h      2004-04-30 19:39:12.000000000 +0100
+++ pstream.h   2004-06-09 21:12:55.000000000 +0100
@@ -145,6 +145,19 @@
       bool
       exited();
 
+      /// pid of process
+      pid_t pid() const { return ppid_; }
+
+      enum output_available {
+         no_output_available = 0,
+         stdout_available = 1,
+         stderr_available = 2
+      };
+
+      /// Report which, if any, of the output streams have characters available to be 
read.
+      output_available
+      out_avail(pmode mode, int sec, int usec = 0) const;
+    
 #if REDI_EVISCERATE_PSTREAMS
       /// Obtain FILE pointers for each of the process' standard streams.
       size_t
@@ -1355,7 +1368,47 @@
       return ret;
     }
 
-  /**
+   /**
+   *  @return  Report which, if any, of the output streams have
+   *           characters available to be read.
+   */
+  template <typename C, typename T>
+     typename basic_pstreambuf<C,T>::output_available
+     basic_pstreambuf<C,T>::out_avail(pmode mode, int sec, int usec) const
+     {
+        // setup select structures
+       fd_set rfds;
+       FD_ZERO(&rfds); // clear
+       int max_fd = -1;
+       if (mode & pstdout) {
+          max_fd = rpipe_[rsrc_out];
+          FD_SET(rpipe_[rsrc_out],&rfds);
+       }
+       if (mode & pstderr) {
+          max_fd = std::max(max_fd, rpipe_[rsrc_err]);
+          FD_SET(rpipe_[rsrc_err],&rfds);
+       }
+
+       if (max_fd == -1)
+          return no_output_available;
+
+       struct timeval tv;
+       tv.tv_sec = sec;
+       tv.tv_usec = usec;
+      
+       ::select(max_fd+1, &rfds, NULL, NULL, &tv);
+
+       output_available oa = no_output_available;
+
+       if (mode & pstdout && FD_ISSET(rpipe_[rsrc_out],&rfds))
+         oa = stdout_available;
+
+       if (mode & pstderr && FD_ISSET(rpipe_[rsrc_err],&rfds))
+         oa = output_available(oa|stderr_available);
+
+       return oa;
+     }
+   /**
    *  @return  True if the associated process has exited, false otherwise.
    *  @see     basic_pstreambuf<C,T>::close()
    */

Reply via email to