diff libinterp/corefcn/input.cc @ 20801:a542a9bf177e

eliminate return statements after calls to print_usage * graphics.cc, hess.cc, input.cc, kron.cc, load-save.cc, lsode.cc, luinc.cc, matrix_type.cc, md5sum.cc, nproc.cc, pager.cc, pr-output.cc, psi.cc, quadcc.cc, rand.cc, regexp.cc, sighandlers.cc, sqrtm.cc, strfind.cc, sub2ind.cc, sylvester.cc: Eliminate return statements after calls to print_usage.
author John W. Eaton <jwe@octave.org>
date Thu, 03 Dec 2015 19:22:54 -0500
parents 200ae1d650b7
children 3d551b2ae928
line wrap: on
line diff
--- a/libinterp/corefcn/input.cc	Thu Dec 03 18:33:00 2015 -0500
+++ b/libinterp/corefcn/input.cc	Thu Dec 03 19:22:54 2015 -0500
@@ -804,16 +804,12 @@
 @seealso{yes_or_no, kbhit, pause, menu, listdlg}\n\
 @end deftypefn")
 {
-  octave_value_list retval;
-
   int nargin = args.length ();
 
-  if (nargin == 1 || nargin == 2)
-    retval = get_user_input (args, std::max (nargout, 1));
-  else
+  if (nargin < 1 || nargin > 2)
     print_usage ();
 
-  return retval;
+  return get_user_input (args, std::max (nargout, 1));
 }
 
 bool
@@ -850,23 +846,17 @@
 @seealso{input}\n\
 @end deftypefn")
 {
-  octave_value retval;
-
   int nargin = args.length ();
 
-  if (nargin == 0 || nargin == 1)
-    {
-      std::string prompt;
-
-      if (nargin == 1)
-        prompt = args(0).xstring_value ("yes_or_no: PROMPT must be a string");
-
-      retval = octave_yes_or_no (prompt);
-    }
-  else
+  if (nargin > 1)
     print_usage ();
 
-  return retval;
+  std::string prompt;
+
+  if (nargin == 1)
+    prompt = args(0).xstring_value ("yes_or_no: PROMPT must be a string");
+
+  return octave_value (octave_yes_or_no (prompt));
 }
 
 octave_value
@@ -929,25 +919,23 @@
 
   int nargin = args.length ();
 
-  if (nargin == 0 || nargin == 1)
-    {
-      unwind_protect frame;
+  if (nargin > 1)
+    print_usage ();
 
-      frame.add_fcn (octave_call_stack::restore_frame,
-                     octave_call_stack::current_frame ());
+  unwind_protect frame;
 
-      // Skip the frame assigned to the keyboard function.
-      octave_call_stack::goto_frame_relative (0);
+  frame.add_fcn (octave_call_stack::restore_frame,
+                 octave_call_stack::current_frame ());
 
-      tree_evaluator::debug_mode = true;
-      tree_evaluator::quiet_breakpoint_flag = false;
-
-      tree_evaluator::current_frame = octave_call_stack::current_frame ();
+  // Skip the frame assigned to the keyboard function.
+  octave_call_stack::goto_frame_relative (0);
 
-      do_keyboard (args);
-    }
-  else
-    print_usage ();
+  tree_evaluator::debug_mode = true;
+  tree_evaluator::quiet_breakpoint_flag = false;
+
+  tree_evaluator::current_frame = octave_call_stack::current_frame ();
+
+  do_keyboard (args);
 
   return retval;
 }
@@ -1109,60 +1097,58 @@
 
   int nargin = args.length ();
 
-  if (nargin == 1)
-    {
-      std::string hint = args(0).string_value ();
+  if (nargin != 1)
+    print_usage ();
 
-      int n = 32;
+  std::string hint = args(0).string_value ();
 
-      string_vector list (n);
+  int n = 32;
+
+  string_vector list (n);
 
-      int k = 0;
+  int k = 0;
 
-      for (;;)
+  for (;;)
+    {
+      std::string cmd = generate_completion (hint, k);
+
+      if (! cmd.empty ())
         {
-          std::string cmd = generate_completion (hint, k);
-
-          if (! cmd.empty ())
+          if (k == n)
             {
-              if (k == n)
-                {
-                  n *= 2;
-                  list.resize (n);
-                }
-
-              list[k++] = cmd;
+              n *= 2;
+              list.resize (n);
             }
-          else
-            {
-              list.resize (k);
-              break;
-            }
-        }
 
-      if (nargout > 0)
-        {
-          if (! list.empty ())
-            retval = list;
-          else
-            retval = "";
+          list[k++] = cmd;
         }
       else
         {
-          // We don't use string_vector::list_in_columns here
-          // because it will be easier for Emacs if the names
-          // appear in a single column.
-
-          int len = list.numel ();
+          list.resize (k);
+          break;
+        }
+    }
 
-          for (int i = 0; i < len; i++)
-            octave_stdout << list[i] << "\n";
-        }
-
-      octave_completion_matches_called = true;
+  if (nargout > 0)
+    {
+      if (! list.empty ())
+        retval = list;
+      else
+        retval = "";
     }
   else
-    print_usage ();
+    {
+      // We don't use string_vector::list_in_columns here
+      // because it will be easier for Emacs if the names
+      // appear in a single column.
+
+      int len = list.numel ();
+
+      for (int i = 0; i < len; i++)
+        octave_stdout << list[i] << "\n";
+    }
+
+  octave_completion_matches_called = true;
 
   return retval;
 }
@@ -1199,16 +1185,17 @@
 
   int nargin = args.length ();
 
+  if (nargin > 1)
+    print_usage ();
+
   if (nargin == 0)
     command_editor::read_init_file ();
-  else if (nargin == 1)
+  else
     {
       std::string file = args(0).string_value ();
 
       command_editor::read_init_file (file);
     }
-  else
-    print_usage ();
 
   return retval;
 }
@@ -1225,11 +1212,11 @@
 {
   octave_value_list retval;
 
-  if (args.length () == 0)
-    command_editor::re_read_init_file ();
-  else
+  if (args.length () != 0)
     print_usage ();
 
+  command_editor::re_read_init_file ();
+
   return retval;
 }
 
@@ -1264,30 +1251,24 @@
 @seealso{remove_input_event_hook}\n\
 @end deftypefn")
 {
-  octave_value retval;
-
   int nargin = args.length ();
 
-  if (nargin == 1 || nargin == 2)
-    {
-      octave_value user_data;
-
-      if (nargin == 2)
-        user_data = args(1);
-
-      hook_function hook_fcn (args(0), user_data);
-
-      if (input_event_hook_functions.empty ())
-        command_editor::add_event_hook (internal_input_event_hook_fcn);
-
-      input_event_hook_functions.insert (hook_fcn.id (), hook_fcn);
-
-      retval = hook_fcn.id ();
-    }
-  else
+  if (nargin < 1 || nargin > 2)
     print_usage ();
 
-  return retval;
+  octave_value user_data;
+
+  if (nargin == 2)
+    user_data = args(1);
+
+  hook_function hook_fcn (args(0), user_data);
+
+  if (input_event_hook_functions.empty ())
+    command_editor::add_event_hook (internal_input_event_hook_fcn);
+
+  input_event_hook_functions.insert (hook_fcn.id (), hook_fcn);
+
+  return octave_value (hook_fcn.id ());
 }
 
 DEFUN (remove_input_event_hook, args, ,
@@ -1304,26 +1285,24 @@
 
   int nargin = args.length ();
 
-  if (nargin == 1 || nargin == 2)
-    {
-      std::string hook_fcn_id = args(0).string_value ("remove_input_event_hook: argument not valid as a hook function name or id");
+  if (nargin < 1 || nargin > 2)
+    print_usage ();
 
-      bool warn = (nargin < 2);
+  std::string hook_fcn_id = args(0).string_value ("remove_input_event_hook: argument not valid as a hook function name or id");
 
-      hook_function_list::iterator p
-        = input_event_hook_functions.find (hook_fcn_id);
+  bool warn = (nargin < 2);
 
-      if (p != input_event_hook_functions.end ())
-        input_event_hook_functions.erase (p);
-      else if (warn)
-        warning ("remove_input_event_hook: %s not found in list",
-                 hook_fcn_id.c_str ());
+  hook_function_list::iterator p
+    = input_event_hook_functions.find (hook_fcn_id);
 
-      if (input_event_hook_functions.empty ())
-        command_editor::remove_event_hook (internal_input_event_hook_fcn);
-    }
-  else
-    print_usage ();
+  if (p != input_event_hook_functions.end ())
+    input_event_hook_functions.erase (p);
+  else if (warn)
+    warning ("remove_input_event_hook: %s not found in list",
+             hook_fcn_id.c_str ());
+
+  if (input_event_hook_functions.empty ())
+    command_editor::remove_event_hook (internal_input_event_hook_fcn);
 
   return retval;
 }
@@ -1475,12 +1454,13 @@
 
   int nargin = args.length ();
 
+  if (nargin > 1)
+    print_usage ();
+
   if (nargin == 0)
     Vdrawnow_requested = true;
-  else if (nargin == 1)
+  else
     Vdrawnow_requested = args(0).bool_value ();
-  else
-    print_usage ();
 
   return retval;
 }
@@ -1495,12 +1475,13 @@
 
   int nargin = args.length ();
 
+  if (nargin > 1)
+    print_usage ();
+
   if (nargin == 0)
     retval = Vgud_mode;
-  else if (nargin == 1)
+  else
     Vgud_mode = args(0).bool_value ();
-  else
-    print_usage ();
 
   return retval;
 }