changeset 20846:f2cd811f0f9e

maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint) * file-io.cc (Ffopen): Move nargin checking to the top of the function.
author Mike Miller <mtmiller@octave.org>
date Sat, 12 Dec 2015 09:32:37 -0500
parents 0bb9b4e99ea0
children 56d36905893f
files libinterp/corefcn/file-io.cc
diffstat 1 files changed, 20 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/file-io.cc	Sat Dec 12 15:19:13 2015 +0100
+++ b/libinterp/corefcn/file-io.cc	Sat Dec 12 09:32:37 2015 -0500
@@ -631,6 +631,9 @@
 
   int nargin = args.length ();
 
+  if (nargin < 1 || nargin > 4)
+    print_usage ();
+
   if (nargin == 1)
     {
       if (args(0).is_string ())
@@ -655,33 +658,28 @@
         }
     }
 
-  if (nargin > 0 && nargin < 4)
-    {
-      octave_value mode = (nargin == 2 || nargin == 3)
-                          ? args(1) : octave_value ("r");
+  octave_value mode = (nargin == 2 || nargin == 3)
+                      ? args(1) : octave_value ("r");
 
-      octave_value arch = (nargin == 3)
-                          ? args(2) : octave_value ("native");
-
-      int fid = -1;
-
-      octave_stream os = do_stream_open (args(0), mode, arch, "fopen", fid);
+  octave_value arch = (nargin == 3)
+                      ? args(2) : octave_value ("native");
 
-      if (os)
-        {
-          retval(1) = "";
-          retval(0) = octave_stream_list::insert (os);
-        }
-      else
-        {
-          int error_number = 0;
+  int fid = -1;
+
+  octave_stream os = do_stream_open (args(0), mode, arch, "fopen", fid);
 
-          retval(1) = os.error (false, error_number);
-          retval(0) = -1.0;
-        }
+  if (os)
+    {
+      retval(1) = "";
+      retval(0) = octave_stream_list::insert (os);
     }
   else
-    print_usage ();
+    {
+      int error_number = 0;
+
+      retval(1) = os.error (false, error_number);
+      retval(0) = -1.0;
+    }
 
   return retval;
 }