diff src/toplev.cc @ 6316:a3a2580435c2

[project @ 2007-02-16 07:23:49 by jwe]
author jwe
date Fri, 16 Feb 2007 07:23:49 +0000
parents e2a1aca62551
children 8810bbf321ce
line wrap: on
line diff
--- a/src/toplev.cc	Fri Feb 16 04:52:42 2007 +0000
+++ b/src/toplev.cc	Fri Feb 16 07:23:49 2007 +0000
@@ -397,6 +397,28 @@
   delete cmd;
 }
 
+static int
+wait_for_input (int fid)
+{
+  int retval = -1;
+
+#if defined (HAVE_SELECT)
+  if (fid >= 0)
+    {
+      fd_set set;
+
+      FD_ZERO (&set);
+      FD_SET (fid, &set);
+
+      retval = select (FD_SETSIZE, &set, 0, 0, 0);
+    }
+#else
+  retval = 1;
+#endif
+
+  return retval;
+}
+
 static octave_value_list
 run_command_and_return_output (const std::string& cmd_str)
 {
@@ -410,15 +432,9 @@
 
       if (*cmd)
 	{
-	  std::ostringstream output_buf;
+	  int fid = cmd->file_number ();
 
-	  // FIXME -- Perhaps we should read more than one
-	  // character at a time and find a way to avoid the call to
-	  // octave_usleep as well?
-
-	  // This is a bit of a kluge...
-
-	  octave_usleep (100);
+	  std::ostringstream output_buf;
 
 	  char ch;
 
@@ -432,7 +448,8 @@
 		    {
 		      cmd->clear ();
 
-		      octave_usleep (100);
+		      if (wait_for_input (fid) != 1)
+			break;			
 		    }
 		  else
 		    break;