changeset 483:41a70d08c1f7

[project @ 1994-06-30 18:30:21 by jwe]
author jwe
date Thu, 30 Jun 1994 18:31:46 +0000
parents 680426c10c5e
children e19ec79471e3
files src/g-builtins.cc src/procstream.cc src/procstream.h
diffstat 3 files changed, 24 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/g-builtins.cc
+++ b/src/g-builtins.cc
@@ -1592,29 +1592,29 @@
 {
   tree_constant *retval = NULL_TREE_CONST;
 
-  if (nargin == 2 || nargin == 3)
+  if (nargin == 2 && args[1].is_string_type ())
     {
-      if (args[1].is_string_type ())
+      iprocstream cmd (args[1].string_value ());
+      char ch;
+      ostrstream output_buf;
+      while (cmd.get (ch))
+	output_buf.put (ch);
+      output_buf << ends;
+      int status = cmd.close ();
+      switch (nargout)
 	{
-	  iprocstream cmd (args[1].string_value ());
-	  char ch;
-	  ostrstream output_buf;
-	  while (cmd.get (ch))
-	    output_buf.put (ch);
-
-	  output_buf << ends;
-	  if (nargin == 2)
-	    {
-	      maybe_page_output (output_buf);
-	    }
-	  else
-	    {
-	      retval = new tree_constant [2];
-	      retval[0] = tree_constant (output_buf.str ());
-	    }
+	case 1:
+	  maybe_page_output (output_buf);
+	  retval = new tree_constant[1];
+	  retval[0] = tree_constant ((double) status);
+	  break;
+	case 2:
+	  retval = new tree_constant[3];
+	  retval[0] = tree_constant ((double) status);
+	  retval[1] = tree_constant (output_buf.str ());
+	  break;
+	  break;
 	}
-      else
-	error ("shell_cmd: first argument must be a string");
     }
   else
     print_usage ("shell_cmd");
--- a/src/procstream.cc
+++ b/src/procstream.cc
@@ -51,11 +51,13 @@
     set (ios::badbit);
 }
 
-void
+int
 procstreambase::close (void)
 {
+  int status = rdbuf()->sys_close ();
   if (! rdbuf()->close ())
     set (ios::failbit);
+  return status;
 }
 
 /*
--- a/src/procstream.h
+++ b/src/procstream.h
@@ -42,7 +42,7 @@
 
   void open (const char *command, int mode = ios::out);
   int is_open (void) { return rdbuf()->is_open (); }
-  void close (void);
+  int close (void);
 };
 
 class