changeset 4715:7bed0ef1a6ad

[project @ 2004-01-22 22:10:28 by jwe]
author jwe
date Thu, 22 Jan 2004 22:10:28 +0000
parents 4302ab3fefd7
children fe25e290fafb
files src/ChangeLog src/file-io.cc test/octave.test/io/io.exp test/octave.test/io/printf-1.m
diffstat 4 files changed, 37 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Thu Jan 22 20:50:18 2004 +0000
+++ b/src/ChangeLog	Thu Jan 22 22:10:28 2004 +0000
@@ -1,5 +1,12 @@
 2004-01-22  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* file-io.cc (Ffrewind): Only return value if nargout > 0.
+	(Ffprintf): Likewise.
+	(Fprintf): Likewise.
+
+	* file-io.cc (Ffrewind): Return 0 for success, -1 for failure.
+	Make docs match.
+
 	* Makefile.in (distclean): Remove DOCSTRINGS.
 	(maintainer-clean): Remove $(OPT_HANDLERS).
 
--- a/src/file-io.cc	Thu Jan 22 20:50:18 2004 +0000
+++ b/src/file-io.cc	Thu Jan 22 22:10:28 2004 +0000
@@ -567,15 +567,17 @@
   return retval;
 }
 
-DEFUN (frewind, args, ,
+DEFUN (frewind, args, nargout,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} frewind (@var{fid})\n\
 Move the file pointer to the beginning of the file @var{fid}, returning\n\
-1 for success, and 0 if an error was encountered.  It is equivalent to\n\
+0 for success, and -1 if an error was encountered.  It is equivalent to\n\
 @code{fseek (@var{fid}, 0, SEEK_SET)}.\n\
 @end deftypefn")
 {
-  octave_value retval = -1;
+  octave_value retval;
+
+  int result = -1;
 
   int nargin = args.length ();
 
@@ -584,11 +586,14 @@
       octave_stream os = octave_stream_list::lookup (args(0), "frewind");
 
       if (! error_state)
-	retval = os.rewind ();
+	result = os.rewind ();
     }
   else
     print_usage ("frewind");
 
+  if (nargout > 0)
+    retval = result;
+
   return retval;
 }
 
@@ -659,7 +664,9 @@
 {
   static std::string who = "fprintf";
 
-  octave_value retval = -1;
+  octave_value retval;
+
+  int result = -1;
 
   bool return_char_count = true;
 
@@ -673,12 +680,6 @@
       if (args(0).is_string ()) 
 	{
 	  os = octave_stream_list::lookup (1, who);
-
-	  // For compatibility with Matlab, which does not return the
-	  // character count when behaving like printf (no file id
-	  // parameter).
-
-	  return_char_count = (nargout != 0);
 	}
       else
 	{
@@ -702,7 +703,7 @@
 		    tmp_args(i-fmt_n-1) = args(i);
 		}
 
-	      retval = os.printf (fmt, tmp_args, who);
+	      result = os.printf (fmt, tmp_args, who);
 	    }
 	  else
 	    ::error ("%s: format must be a string", who.c_str ());
@@ -711,13 +712,13 @@
   else
     print_usage (who);
 
-  if (return_char_count)
-    return retval;
-  else
-    return octave_value();
+  if (nargout > 0)
+    retval = result;
+
+  return retval;
 }
 
-DEFUN (printf, args, ,
+DEFUN (printf, args, nargout,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} printf (@var{fid}, @var{template}, @dots{})\n\
 Print optional arguments under the control of the template string\n\
@@ -727,7 +728,9 @@
 {
   static std::string who = "printf";
 
-  octave_value retval = -1;
+  octave_value retval;
+
+  int result = -1;
 
   int nargin = args.length ();
 
@@ -747,7 +750,7 @@
 		tmp_args(i-1) = args(i);
 	    }
 
-	  retval = stdout_stream.printf (fmt, tmp_args, who);
+	  result = stdout_stream.printf (fmt, tmp_args, who);
 	}
       else
 	::error ("%s: format must be a string", who.c_str ());
@@ -755,6 +758,9 @@
   else
     print_usage (who);
 
+  if (nargout > 0)
+    retval = result;
+
   return retval;
 }
 
@@ -1796,9 +1802,9 @@
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} umask (@var{mask})\n\
 Set the permission mask for file creation.  The parameter @var{mask}\n\
- is an integer, interpreted as an octal number.  If successful,\n\
- returns the previous value of the mask (as an integer to be\n\
- interpreted as an octal number); otherwise an error message is printed.\n\
+is an integer, interpreted as an octal number.  If successful,\n\
+returns the previous value of the mask (as an integer to be\n\
+interpreted as an octal number); otherwise an error message is printed.\n\
 @end deftypefn")
 {
   octave_value_list retval;
--- a/test/octave.test/io/io.exp	Thu Jan 22 20:50:18 2004 +0000
+++ b/test/octave.test/io/io.exp	Thu Jan 22 22:10:28 2004 +0000
@@ -47,7 +47,7 @@
 do_test sscanf-5.m
 
 set test printf-1
-set prog_output "test: 1\nans = 8"
+set prog_output "test: 1\nx = 8"
 do_test printf-1.m
 
 set test printf-2
--- a/test/octave.test/io/printf-1.m	Thu Jan 22 20:50:18 2004 +0000
+++ b/test/octave.test/io/printf-1.m	Thu Jan 22 22:10:28 2004 +0000
@@ -1,1 +1,1 @@
-printf ("%s: %d\n", "test", 1)
+x = printf ("%s: %d\n", "test", 1)