changeset 20983:004fa31be0b7

use print_usage instead of usage * oct-hist.cc, make_int.cc: Use print_usage instead of usage. * oct-hist.cc: Eliminate unnecessary instances of retval variables.
author John W. Eaton <jwe@octave.org>
date Fri, 25 Dec 2015 08:09:11 -0500
parents d27f66b4b8e6
children 167c536419a7
files examples/code/make_int.cc libinterp/corefcn/oct-hist.cc
diffstat 2 files changed, 27 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/examples/code/make_int.cc	Fri Dec 25 00:48:01 2015 -0500
+++ b/examples/code/make_int.cc	Fri Dec 25 08:09:11 2015 -0500
@@ -281,7 +281,7 @@
       retval = octave_value (new octave_integer (NINT (d)));
     }
   else
-    usage ("make_int");
+    print_usage ();
 
   return retval;
 }
--- a/libinterp/corefcn/oct-hist.cc	Fri Dec 25 00:48:01 2015 -0500
+++ b/libinterp/corefcn/oct-hist.cc	Fri Dec 25 08:09:11 2015 -0500
@@ -351,8 +351,6 @@
 mk_tmp_hist_file (const octave_value_list& args,
                   bool insert_curr, const char *warn_for)
 {
-  std::string retval;
-
   string_vector hlist = command_history::list ();
 
   int hist_count = hlist.numel () - 1;  // switch to zero-based indexing
@@ -379,42 +377,32 @@
 
   int nargin = args.length ();
 
-  bool usage_error = false;
   if (nargin == 2)
     {
-      if (get_int_arg (args(0), hist_beg)
-          && get_int_arg (args(1), hist_end))
-        {
-          if (hist_beg < 0)
-            hist_beg += (hist_count + 1);
-          else
-            hist_beg--;
-          if (hist_end < 0)
-            hist_end += (hist_count + 1);
-          else
-            hist_end--;
-        }
+      if (! get_int_arg (args(0), hist_beg)
+          || ! get_int_arg (args(1), hist_end))
+        error ("%s: arguments must be integers", warn_for);
+
+      if (hist_beg < 0)
+        hist_beg += (hist_count + 1);
       else
-        usage_error = true;
+        hist_beg--;
+      if (hist_end < 0)
+        hist_end += (hist_count + 1);
+      else
+        hist_end--;
     }
   else if (nargin == 1)
     {
-      if (get_int_arg (args(0), hist_beg))
-        {
-          if (hist_beg < 0)
-            hist_beg += (hist_count + 1);
-          else
-            hist_beg--;
-          hist_end = hist_beg;
-        }
+      if (! get_int_arg (args(0), hist_beg))
+        error ("%s: argument must be an integer", warn_for);
+
+      if (hist_beg < 0)
+        hist_beg += (hist_count + 1);
       else
-        usage_error = true;
-    }
+        hist_beg--;
 
-  if (usage_error)
-    {
-      usage ("%s [first] [last]", warn_for);
-      return retval;
+      hist_end = hist_beg;
     }
 
   if (hist_beg > hist_count || hist_end > hist_count)
@@ -603,11 +591,12 @@
 @seealso{run_history, history}\n\
 @end deftypefn")
 {
-  octave_value_list retval;
+  if (args.length () > 2)
+    print_usage ();
 
   do_edit_history (args);
 
-  return retval;
+  return ovl ();
 }
 
 DEFUN (history, args, nargout,
@@ -652,14 +641,11 @@
 @seealso{edit_history, run_history}\n\
 @end deftypefn")
 {
-  octave_value retval;
+  // Call do_history even if nargout is zero to display history list.
 
   string_vector hlist = do_history (args, nargout);
 
-  if (nargout > 0)
-    retval = Cell (hlist);
-
-  return retval;
+  return nargout > 0 ? ovl (Cell (hlist)) : ovl ();
 }
 
 DEFUN (run_history, args, ,
@@ -714,11 +700,12 @@
 @seealso{edit_history, history}\n\
 @end deftypefn")
 {
-  octave_value_list retval;
+  if (args.length () > 2)
+    print_usage ();
 
   do_run_history (args);
 
-  return retval;
+  return ovl ();
 }
 
 DEFUN (history_control, args, nargout,