# HG changeset patch
# User Yu Liu <yul.liuiyu@gmail.com>
# Date 1449933836 28800
#      Sat Dec 12 07:23:56 2015 -0800
# Node ID a1e57afb3c9096bc2b86ecc1f9304f02fed9cc3b
# Parent  3e0edd5dfb5d78a9c9b3da879a2788a7b42d2e31
Code sprint 2015: Refactor print_usage() in syscalls.cc to resemble m-files

diff -r 3e0edd5dfb5d -r a1e57afb3c90 libinterp/corefcn/syscalls.cc
--- a/libinterp/corefcn/syscalls.cc	Thu Dec 10 22:27:03 2015 -0800
+++ b/libinterp/corefcn/syscalls.cc	Sat Dec 12 07:23:56 2015 -0800
@@ -637,11 +637,10 @@
 
   int nargin = args.length ();
 
-  if (nargin == 0)
-    retval = octave_syscalls::geteuid ();
-  else
+  if (nargin != 0)
     print_usage ();
 
+  retval = octave_syscalls::geteuid ();
   return retval;
 }
 
@@ -656,11 +655,10 @@
 
   int nargin = args.length ();
 
-  if (nargin == 0)
-    retval = octave_syscalls::getuid ();
-  else
+  if (nargin != 0)
     print_usage ();
 
+  retval = octave_syscalls::getuid ();
   return retval;
 }
 
@@ -691,22 +689,20 @@
   retval(1) = std::string ();
   retval(0) = -1;
 
-  if (args.length () == 2)
-    {
-      pid_t pid = args(0).int_value (true);
-
-      int sig = args(1).int_value (true);
-
-      std::string msg;
-
-      int status = octave_syscalls::kill (pid, sig, msg);
-
-      retval(1) = msg;
-      retval(0) = status;
-    }
-  else
+  if (args.length () != 2)
     print_usage ();
 
+  pid_t pid = args(0).int_value (true);
+
+  int sig = args(1).int_value (true);
+
+  std::string msg;
+
+  int status = octave_syscalls::kill (pid, sig, msg);
+
+  retval(1) = msg;
+  retval(0) = status;
+ 
   return retval;
 }
 
@@ -723,17 +719,15 @@
 {
   octave_value_list retval;
 
-  if (args.length () == 1)
-    {
-      std::string fname = args(0).xstring_value ("lstat: NAME must be a string");
-
-      file_stat fs (fname, false);
-
-      retval = mk_stat_result (fs);
-    }
-  else
+  if (args.length () != 1)
     print_usage ();
 
+    std::string fname = args(0).xstring_value ("lstat: NAME must be a string");
+
+    file_stat fs (fname, false);
+
+    retval = mk_stat_result (fs);
+ 
   return retval;
 }
 
@@ -790,30 +784,29 @@
 
   int nargin = args.length ();
 
-  if (nargin == 2)
+  if (nargin != 2)
+    print_usage ();
+    
+  std::string name = args(0).xstring_value ("mkfifo: FILE must be a string");
+
+  int octal_mode = args(1).xint_value ("mkfifo: MODE must be an integer");
+
+  if (octal_mode < 0)
+    error ("mkfifo: MODE must be a positive integer value");
+  else
     {
-      std::string name = args(0).xstring_value ("mkfifo: FILE must be a string");
+      int mode = convert (octal_mode, 8, 10);
 
-      int octal_mode = args(1).xint_value ("mkfifo: MODE must be an integer");
+      std::string msg;
 
-      if (octal_mode < 0)
-        error ("mkfifo: MODE must be a positive integer value");
-      else
-        {
-          int mode = convert (octal_mode, 8, 10);
+      int status = octave_mkfifo (name, mode, msg);
 
-          std::string msg;
+      retval(0) = status;
 
-          int status = octave_mkfifo (name, mode, msg);
+      if (status < 0)
+          retval(1) = msg;
+    }
 
-          retval(0) = status;
-
-          if (status < 0)
-            retval(1) = msg;
-        }
-    }
-  else
-    print_usage ();
 
   return retval;
 }
@@ -852,34 +845,32 @@
 
   int nargin = args.length ();
 
-  if (nargin == 0)
+  if (nargin != 0)
+    print_usage ();
+
+  int fid[2];
+
+  std::string msg;
+
+  int status = octave_syscalls::pipe (fid, msg);
+
+  if (status < 0)
+    retval(3) = msg;
+  else
     {
-      int fid[2];
+      FILE *ifile = fdopen (fid[0], "r");
+      FILE *ofile = fdopen (fid[1], "w");
 
-      std::string msg;
+      octave_stream is = octave_stdiostream::create ("pipe-in", ifile,
+                                                       std::ios::in);
 
-      int status = octave_syscalls::pipe (fid, msg);
+      octave_stream os = octave_stdiostream::create ("pipe-out", ofile,
+                                                       std::ios::out);
 
-      if (status < 0)
-        retval(3) = msg;
-      else
-        {
-          FILE *ifile = fdopen (fid[0], "r");
-          FILE *ofile = fdopen (fid[1], "w");
-
-          octave_stream is = octave_stdiostream::create ("pipe-in", ifile,
-                                                         std::ios::in);
-
-          octave_stream os = octave_stdiostream::create ("pipe-out", ofile,
-                                                         std::ios::out);
-
-          retval(2) = status;
-          retval(1) = octave_stream_list::insert (os);
-          retval(0) = octave_stream_list::insert (is);
-        }
+      retval(2) = status;
+      retval(1) = octave_stream_list::insert (os);
+      retval(0) = octave_stream_list::insert (is);
     }
-  else
-    print_usage ();
 
   return retval;
 }
@@ -982,27 +973,25 @@
 {
   octave_value_list retval;
 
-  if (args.length () == 1)
-    {
-      if (args(0).is_scalar_type ())
-        {
-          int fid = octave_stream_list::get_file_number (args(0));
+  if (args.length () != 1)
+    print_usage ();
 
-          file_fstat fs (fid);
+    if (args(0).is_scalar_type ())
+      {
+        int fid = octave_stream_list::get_file_number (args(0));
 
-          retval = mk_stat_result (fs);
-        }
-      else
-        {
-          std::string fname = args(0).xstring_value ("stat: NAME must be a string");
+        file_fstat fs (fid);
 
-          file_stat fs (fname);
+        retval = mk_stat_result (fs);
+      }
+    else
+      {
+        std::string fname = args(0).xstring_value ("stat: NAME must be a string");
 
-          retval = mk_stat_result (fs);
-        }
-    }
-  else
-    print_usage ();
+	file_stat fs (fname);
+
+	retval = mk_stat_result (fs);
+      }
 
   return retval;
 }
@@ -1018,14 +1007,12 @@
 {
   octave_value retval = false;
 
-  if (args.length () == 1)
-    {
-      double mode = args(0).xdouble_value ("S_ISREG: invalid MODE value");
+  if (args.length () != 1)
+    print_usage ();
 
-      retval = file_stat::is_reg (static_cast<mode_t> (mode));
-    }
-  else
-    print_usage ();
+  double mode = args(0).xdouble_value ("S_ISREG: invalid MODE value");
+
+  retval = file_stat::is_reg (static_cast<mode_t> (mode));
 
   return retval;
 }
@@ -1041,14 +1028,12 @@
 {
   octave_value retval = false;
 
-  if (args.length () == 1)
-    {
-      double mode = args(0).xdouble_value ("S_ISDIR: invalid MODE value");
+  if (args.length () != 1)
+    print_usage ();
 
-      retval = file_stat::is_dir (static_cast<mode_t> (mode));
-    }
-  else
-    print_usage ();
+  double mode = args(0).xdouble_value ("S_ISDIR: invalid MODE value");
+
+  retval = file_stat::is_dir (static_cast<mode_t> (mode));
 
   return retval;
 }
@@ -1064,14 +1049,13 @@
 {
   octave_value retval = false;
 
-  if (args.length () == 1)
-    {
-      double mode = args(0).xdouble_value ("S_ISCHR: invalid MODE value");
+  if (args.length () != 1)
+    print_usage ();
 
-      retval = file_stat::is_chr (static_cast<mode_t> (mode));
-    }
-  else
-    print_usage ();
+  double mode = args(0).xdouble_value ("S_ISCHR: invalid MODE value");
+
+  retval = file_stat::is_chr (static_cast<mode_t> (mode));
+
 
   return retval;
 }
@@ -1087,14 +1071,12 @@
 {
   octave_value retval = false;
 
-  if (args.length () == 1)
-    {
-      double mode = args(0).xdouble_value ("S_ISBLK: invalid MODE value");
+  if (args.length () != 1)
+    print_usage ();
 
-      retval = file_stat::is_blk (static_cast<mode_t> (mode));
-    }
-  else
-    print_usage ();
+  double mode = args(0).xdouble_value ("S_ISBLK: invalid MODE value");
+
+  retval = file_stat::is_blk (static_cast<mode_t> (mode));
 
   return retval;
 }
@@ -1110,14 +1092,12 @@
 {
   octave_value retval = false;
 
-  if (args.length () == 1)
-    {
-      double mode = args(0).xdouble_value ("S_ISFIFO: invalid MODE value");
+  if (args.length () != 1)
+    print_usage ();
 
-      retval = file_stat::is_fifo (static_cast<mode_t> (mode));
-    }
-  else
-    print_usage ();
+  double mode = args(0).xdouble_value ("S_ISFIFO: invalid MODE value");
+
+  retval = file_stat::is_fifo (static_cast<mode_t> (mode));
 
   return retval;
 }
@@ -1133,14 +1113,12 @@
 {
   octave_value retval = false;
 
-  if (args.length () == 1)
-    {
-      double mode = args(0).xdouble_value ("S_ISLNK: invalid MODE value");
+  if (args.length () != 1)
+    print_usage ();
 
-      retval = file_stat::is_lnk (static_cast<mode_t> (mode));
-    }
-  else
-    print_usage ();
+  double mode = args(0).xdouble_value ("S_ISLNK: invalid MODE value");
+
+  retval = file_stat::is_lnk (static_cast<mode_t> (mode));
 
   return retval;
 }
@@ -1156,14 +1134,13 @@
 {
   octave_value retval = false;
 
-  if (args.length () == 1)
-    {
-      double mode = args(0).xdouble_value ("S_ISSOCK: invalid MODE value");
+  if (args.length () != 1)
+    print_usage ();
 
-      retval = file_stat::is_sock (static_cast<mode_t> (mode));
-    }
-  else
-    print_usage ();
+  double mode = args(0).xdouble_value ("S_ISSOCK: invalid MODE value");
+
+  retval = file_stat::is_sock (static_cast<mode_t> (mode));
+
 
   return retval;
 }
@@ -1176,11 +1153,11 @@
 {
   octave_value retval;
 
-  if (args.length () == 0)
-    retval = octave_env::get_host_name ();
-  else
+  if (args.length () != 0)
     print_usage ();
 
+  retval = octave_env::get_host_name ();
+
   return retval;
 }
 
@@ -1211,24 +1188,23 @@
 {
   octave_value_list retval;
 
-  if (args.length () == 0)
-    {
-      octave_uname sysinfo;
+  if (args.length () != 0)
+    print_usage ();
 
-      octave_scalar_map m;
+  octave_uname sysinfo;
 
-      m.assign ("sysname", sysinfo.sysname ());
-      m.assign ("nodename", sysinfo.nodename ());
-      m.assign ("release", sysinfo.release ());
-      m.assign ("version", sysinfo.version ());
-      m.assign ("machine", sysinfo.machine ());
+  octave_scalar_map m;
 
-      retval(2) = sysinfo.message ();
-      retval(1) = sysinfo.error ();
-      retval(0) = m;
-    }
-  else
-    print_usage ();
+  m.assign ("sysname", sysinfo.sysname ());
+  m.assign ("nodename", sysinfo.nodename ());
+  m.assign ("release", sysinfo.release ());
+  m.assign ("version", sysinfo.version ());
+  m.assign ("machine", sysinfo.machine ());
+
+  retval(2) = sysinfo.message ();
+  retval(1) = sysinfo.error ();
+  retval(0) = m;
+
 
   return retval;
 }
@@ -1251,19 +1227,18 @@
 
   int nargin = args.length ();
 
-  if (nargin == 1)
-    {
-      std::string name = args(0).xstring_value ("unlink: FILE must be a string");
+  if (nargin != 1)
+    print_usage ();
 
-      std::string msg;
+  std::string name = args(0).xstring_value ("unlink: FILE must be a string");
 
-      int status = octave_unlink (name, msg);
+  std::string msg;
 
-      retval(1) = msg;
-      retval(0) = status;
-    }
-  else
-    print_usage ();
+  int status = octave_unlink (name, msg);
+
+  retval(1) = msg;
+  retval(0) = status;
+
 
   return retval;
 }
@@ -1323,28 +1298,26 @@
 
   int nargin = args.length ();
 
-  if (nargin == 1 || nargin == 2)
-    {
-      pid_t pid = args(0).xint_value ("waitpid: OPTIONS must be an integer");
+  if (nargin != 1 && nargin != 2)
+    print_usage ();
 
-      int options = 0;
+  pid_t pid = args(0).xint_value ("waitpid: OPTIONS must be an integer");
 
-      if (args.length () == 2)
-        options = args(1).xint_value ("waitpid: PID must be an integer value");
+  int options = 0;
 
-      std::string msg;
+  if (args.length () == 2)
+    options = args(1).xint_value ("waitpid: PID must be an integer value");
 
-      int status = 0;
+  std::string msg;
 
-      pid_t result = octave_syscalls::waitpid (pid, &status,
-                                               options, msg);
+  int status = 0;
 
-      retval(2) = msg;
-      retval(1) = status;
-      retval(0) = result;
-    }
-  else
-    print_usage ();
+  pid_t result = octave_syscalls::waitpid (pid, &status,
+                                           options, msg);
+
+  retval(2) = msg;
+  retval(1) = status;
+  retval(0) = result;
 
   return retval;
 }
@@ -1359,14 +1332,12 @@
 {
   octave_value retval = false;
 
-  if (args.length () == 1)
-    {
-      int status = args(0).xint_value ("WIFEXITED: STATUS must be an integer");
+  if (args.length () != 1)
+    print_usage ();
 
-      retval = octave_wait::ifexited (status);
-    }
-  else
-    print_usage ();
+  int status = args(0).xint_value ("WIFEXITED: STATUS must be an integer");
+
+  retval = octave_wait::ifexited (status);
 
   return retval;
 }
@@ -1403,14 +1374,13 @@
 {
   octave_value retval = false;
 
-  if (args.length () == 1)
-    {
-      int status = args(0).xint_value ("WIFSIGNALED: STATUS must be an integer");
+  if (args.length () != 1)
+    print_usage ();
 
-      retval = octave_wait::ifsignaled (status);
-    }
-  else
-    print_usage ();
+  int status = args(0).xint_value ("WIFSIGNALED: STATUS must be an integer");
+
+  retval = octave_wait::ifsignaled (status);
+
 
   return retval;
 }
@@ -1427,14 +1397,13 @@
 {
   octave_value retval = 0;
 
-  if (args.length () == 1)
-    {
-      int status = args(0).xint_value ("WTERMSIG: STATUS must be an integer");
+  if (args.length () != 1)
+    print_usage ();
 
-      retval = octave_wait::termsig (status);
-    }
-  else
-    print_usage ();
+  int status = args(0).xint_value ("WTERMSIG: STATUS must be an integer");
+
+  retval = octave_wait::termsig (status);
+
 
   return retval;
 }
@@ -1453,14 +1422,13 @@
 {
   octave_value retval = false;
 
-  if (args.length () == 1)
-    {
-      int status = args(0).xint_value ("WCOREDUMP: STATUS must be an integer");
+  if (args.length () != 1)
+    print_usage ();
 
-      retval = octave_wait::coredump (status);
-    }
-  else
-    print_usage ();
+  int status = args(0).xint_value ("WCOREDUMP: STATUS must be an integer");
+
+  retval = octave_wait::coredump (status);
+
 
   return retval;
 }
@@ -1478,14 +1446,13 @@
 {
   octave_value retval = false;
 
-  if (args.length () == 1)
-    {
-      int status = args(0).xint_value ("WIFSTOPPED: STATUS must be an integer");
+  if (args.length () != 1)
+    print_usage ();
 
-      retval = octave_wait::ifstopped (status);
-    }
-  else
-    print_usage ();
+  int status = args(0).xint_value ("WIFSTOPPED: STATUS must be an integer");
+
+  retval = octave_wait::ifstopped (status);
+
 
   return retval;
 }
@@ -1502,14 +1469,13 @@
 {
   octave_value retval = 0;
 
-  if (args.length () == 1)
-    {
-      int status = args(0).xint_value ("WSTOPSIG: STATUS must be an integer");
+  if (args.length () != 1)
+    print_usage ();
 
-        retval = octave_wait::stopsig (status);
-    }
-  else
-    print_usage ();
+  int status = args(0).xint_value ("WSTOPSIG: STATUS must be an integer");
+
+  retval = octave_wait::stopsig (status);
+
 
   return retval;
 }
@@ -1524,14 +1490,13 @@
 {
   octave_value retval = false;
 
-  if (args.length () == 1)
-    {
-      int status = args(0).xint_value ("WIFCONTINUED: STATUS must be an integer");
+  if (args.length () != 1)
+    print_usage ();
 
-      retval = octave_wait::ifcontinued (status);
-    }
-  else
-    print_usage ();
+  int status = args(0).xint_value ("WIFCONTINUED: STATUS must be an integer");
+
+  retval = octave_wait::ifcontinued (status);
+
 
   return retval;
 }
@@ -1547,19 +1512,18 @@
 {
   octave_value_list retval;
 
-  if (args.length () == 1)
-    {
-      std::string name = args(0).xstring_value ("canonicalize_file_name: NAME must be a string");
-      std::string msg;
+  if (args.length () != 1)
+    print_usage ();
 
-      std::string result = octave_canonicalize_file_name (name, msg);
+  std::string name = args(0).xstring_value ("canonicalize_file_name: NAME must be a string");
+  std::string msg;
 
-      retval(2) = msg;
-      retval(1) = msg.empty () ? 0 : -1;
-      retval(0) = result;
-    }
-  else
-    print_usage ();
+  std::string result = octave_canonicalize_file_name (name, msg);
+
+  retval(2) = msg;
+  retval(1) = msg.empty () ? 0 : -1;
+  retval(0) = result;
+
 
   return retval;
 }
@@ -1571,11 +1535,11 @@
 
   int nargin = args.length ();
 
-  if (nargin == 0)
-    retval = val;
-  else
+  if (nargin != 0)
     print_usage ();
 
+  retval = val;
+
   return retval;
 }
 
