changeset 4691:bdc51b369a78

[project @ 2004-01-10 18:16:02 by jwe]
author jwe
date Sat, 10 Jan 2004 18:16:03 +0000
parents b6dc2aad574a
children ae49c6ba722c
files scripts/ChangeLog scripts/general/num2str.m scripts/miscellaneous/computer.m scripts/miscellaneous/delete.m scripts/miscellaneous/ispc.m scripts/miscellaneous/isunix.m scripts/miscellaneous/not.m scripts/miscellaneous/unix.m src/ChangeLog src/dirfns.cc src/load-save.cc src/oct-stream.cc src/toplev.cc
diffstat 13 files changed, 331 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,25 @@
+2004-01-10  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* miscellaneous/dir.m: New file.
+
+	* general/num2str.m: Use "%d" as format if values are ints with
+	magnitude less than 1e10.
+
+2004-01-09  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* general/num2str.m: If single arg is string, return it.
+
+	* miscellaneous/not.m: New file.
+
+	* miscellaneous/unix.m: New file.
+
+	* miscellaneous/isunix.m: New file.
+	* miscellaneous/ispc.m: New file.
+
+	* miscellaneous/computer.m: New file.
+
+	* miscellaneous/delete.m: New file.
+
 2004-01-08  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* statistics/tests/kolmogorov_smirnov_test_2.m: Fix test for ties.
--- a/scripts/general/num2str.m
+++ b/scripts/general/num2str.m
@@ -39,13 +39,17 @@
 	fmt = sprintf ("%%.%dg", arg);
       endif
     else
-      if (isscalar (x))
+      if (isnumeric (x) && round (x) == x && abs (x) < 1e10)
+	fmt = "%d";
+      elseif (isscalar (x))
 	fmt = "%.4g";
       else
 	fmt = "%11.4g";
       endif
     endif
-    if (iscomplex (x))
+    if (isstr (x))
+      retval = x;
+    elseif (iscomplex (x))
       error ("num2str: sorry, can't handle complex numbers yet");
     else
       fmt = strcat (repmat (fmt, 1, columns (x)), "\n");
new file mode 100644
--- /dev/null
+++ b/scripts/miscellaneous/computer.m
@@ -0,0 +1,56 @@
+## Copyright (C) 2004 John W. Eaton
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} computer ()
+## Print or return a string of the form @var{cpu}-@var{vendor}-@var{os}
+## that identifies the kind of computer Octave is running on.  If invoked
+## with an output argument, the value is returned instead of printed.  For
+## example,
+##
+## @example
+## @group
+## computer ()
+##      @print{} i586-pc-linux-gnu
+##
+## x = computer ()
+##      @result{} x = "i586-pc-linux-gnu"
+## @end group
+## @end example
+## @end deftypefn
+
+function retval = computer ()
+
+  if (nargin != 0)
+    warning ("computer: ignoring extra arguments");
+  endif
+
+  msg = octave_config_info ("canonical_host_type");
+
+  if (strcmp (msg, "unknown"))
+    msg = "Hi Dave, I'm a HAL-9000";
+  endif
+
+  if (nargout == 0)
+    printf ("%s\n", msg);
+  else
+    retval = msg;
+  endif
+
+endfunction
new file mode 100644
--- /dev/null
+++ b/scripts/miscellaneous/delete.m
@@ -0,0 +1,37 @@
+## Copyright (C) 2004 John W. Eaton
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} delete (file)
+## Delete the named file.  Delete is a wrapper for @code{unlink}.
+## @end deftypefn
+
+## PKG_ADD: mark_as_command delete
+
+## Author: jwe
+
+function delete (file)
+
+  if (nargin == 1)
+    unlink (file);
+  else
+    usage ("delete (file)");
+  endif
+
+endfunction
new file mode 100644
--- /dev/null
+++ b/scripts/miscellaneous/ispc.m
@@ -0,0 +1,33 @@
+## Copyright (C) 2004 John W. Eaton
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} ispc ()
+## Return 1 if Octave is running on a Windows system and 0 otherwise.
+## @end deftypefn
+
+function retval = ispc ()
+
+  if (nargin == 0)
+    retval = octave_config_info ("windows");
+  else
+    usage ("ispc ()");
+  endif
+
+endfunction
new file mode 100644
--- /dev/null
+++ b/scripts/miscellaneous/isunix.m
@@ -0,0 +1,33 @@
+## Copyright (C) 2004 John W. Eaton
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} isunix ()
+## Return 1 if Octave is running on a Unix-like system and 0 otherwise.
+## @end deftypefn
+
+function retval = isunix ()
+
+  if (nargin == 0)
+    retval = octave_config_info ("unix");
+  else
+    usage ("isunix ()");
+  endif
+
+endfunction
new file mode 100644
--- /dev/null
+++ b/scripts/miscellaneous/not.m
@@ -0,0 +1,34 @@
+## Copyright (C) 2004 John W. Eaton
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} not (@var{val})
+## Return the logical negation of val.  This function is equivalent to
+## @code{! val}.
+## @end deftypefn
+
+function retval = not (val)
+
+  if (nargin == 1)
+    retval = ! val;
+  else
+    usage ("not (val)");
+  endif
+
+endfunction
new file mode 100644
--- /dev/null
+++ b/scripts/miscellaneous/unix.m
@@ -0,0 +1,43 @@
+## Copyright (C) 2004 John W. Eaton
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {[@var{status}, @var{text}]} isunix (@var{command})
+## @deftypefnx {Function File} {[@var{status}, @var{text}]} isunix (@var{command}, "-echo")
+## Execute a system command if running under a Unix-like operating
+## system, otherwise do nothing.  Return the exit status of the program
+## in @var{status} and any output sent to the standard output in
+## @var{text}.  If the optional second argument @code{"-echo"} is given,
+## then also send the output from the command to the standard output.
+
+## Author: octave-forge ???
+## Adapted by: jwe
+
+function [status, text] = unix (cmd, echo_arg)
+
+  if (nargin < 1 || nargin > 2)
+    usage ( "[status, text] = unix (cmd, '-echo')");
+  elseif (isunix ())
+    [text, status] = system (cmd);
+    if (nargin > 1 || nargout == 0)
+      printf ("%s\n", text);
+    endif
+  endif
+
+endfunction
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,20 @@
+2004-01-10  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* dirfns.cc (Fglob): Always return list of files as a cell array.
+	(Freaddir): Likewise.
+
+	* dirfns.cc (Fls): If nargout > 0, return ls output.
+
+2004-01-09  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* load-save.cc (Fload): Assume -force by default.
+
+	* oct-stream.cc (octave_base_stream::write):
+	Allow fwrite (fid, "some string") to work.
+
+	* toplev.cc (Fcomputer): Delete.
+	(octave_config_info): Add unix and windows fields to the struct.
+
 2004-01-06  David Bateman  <dbateman@free.fr>
 
 	* ls-hdf5.cc: Fix handle of old versus new format files.
--- a/src/dirfns.cc
+++ b/src/dirfns.cc
@@ -140,10 +140,9 @@
   delete static_cast <iprocstream *> (p);
 }
 
-DEFCMD (ls, args, ,
+DEFCMD (ls, args, nargout,
   "-*- texinfo -*-\n\
 @deffn {Command} ls options\n\
-@deffnx {Command} dir options\n\
 List directory contents.  For example,\n\
 \n\
 @example\n\
@@ -158,7 +157,7 @@
 from system to system.\n\
 @end deffn")
 {
-  octave_value_list retval;
+  octave_value retval;
 
   int argc = args.length () + 1;
 
@@ -193,10 +192,15 @@
 
       char ch;
 
+      OSSTREAM output_buf;
+
       for (;;)
 	{
 	  if (cmd->get (ch))
-	    octave_stdout << ch;
+	    {
+	      octave_stdout << ch;
+	      output_buf << ch;
+	    }
 	  else
 	    {
 	      if (! cmd->eof () && errno == EAGAIN)
@@ -209,6 +213,13 @@
 		break;
 	    }
 	}
+
+      output_buf << OSSTREAM_ENDS;
+
+      if (nargout > 0)
+	retval = OSSTREAM_STR (output_buf);
+
+      OSSTREAM_FREEZE (output_buf);
     }
   else
     error ("couldn't start process for ls!");
@@ -218,8 +229,6 @@
   return retval;
 }
 
-DEFALIAS (dir, ls);
-
 DEFUN (pwd, , nargout,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} pwd ()\n\
@@ -246,8 +255,8 @@
 DEFUN (readdir, args, ,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {[@var{files}, @var{err}, @var{msg}] =} readdir (@var{dir})\n\
-Return names of the files in the directory @var{dir} as an array of\n\
-strings.  If an error occurs, return an empty matrix in @var{files}.\n\
+Return names of the files in the directory @var{dir} as a cell array of\n\
+strings.  If an error occurs, return an empty cell array in @var{files}.\n\
 \n\
 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
@@ -258,7 +267,7 @@
 
   retval(2) = std::string ();
   retval(1) = -1.0;
-  retval(0) = Matrix ();
+  retval(0) = Cell ();
 
   if (args.length () == 1)
     {
@@ -273,7 +282,7 @@
 	  if (dir)
 	    {
 	      string_vector dirlist = dir.read ();
-	      retval(0) = dirlist.qsort ();
+	      retval(0) = Cell (dirlist.qsort ());
 	      retval(1) = 0.0;
 	    }
 	  else
@@ -555,8 +564,8 @@
 DEFUN (glob, args, ,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} glob (@var{pattern})\n\
-Given an array of strings in @var{pattern}, return the list of file\n\
-names that match any of them, or an empty string if no patterns match.\n\
+Given an array of strings in @var{pattern}, return a cell array of file\n\
+names that match any of them, or an empty cell array if no patterns match.\n\
 Tilde expansion is performed on each of the patterns before looking for\n\
 matching file names.  For example,\n\
 \n\
@@ -566,9 +575,6 @@
      @result{} \"/vmlinuz\"\n\
 @end group\n\
 @end example\n\
-\n\
-Note that multiple values are returned in a string matrix with the fill\n\
-character set to ASCII NUL.\n\
 @end deftypefn")
 {
   octave_value retval;
@@ -583,12 +589,7 @@
 	{
 	  glob_match pattern (file_ops::tilde_expand (pat));
 
-	  string_vector list = pattern.glob ();
-
-	  if (list.empty ())
-	    retval = "";
-	  else
-	    retval = list;
+	  retval = Cell (pattern.glob ());
 	}
     }
   else
--- a/src/load-save.cc
+++ b/src/load-save.cc
@@ -613,7 +613,7 @@
 
   load_save_format format = LS_UNKNOWN;
 
-  bool force = false;
+  bool force = true;
   bool list_only = false;
   bool verbose = false;
 
--- a/src/oct-stream.cc
+++ b/src/oct-stream.cc
@@ -2058,19 +2058,28 @@
     {
       std::ostream& os = *osp;
 
-      Matrix mval = data.matrix_value ();
+      int status = 0;
+
+      // XXX FIXME XXX -- the octave_value class should probably have
+      // a write method that would handle the dispatch for us?
+      //
+      // If DATA is a character matrix, then it is a bit of a kluge to
+      // force it to be a double matrix and then write it out as uchar
+      // data, but this is the quick fix...
+
+      Matrix mval = data.matrix_value (true);
 
       if (! error_state)
 	{
 	  if (ffmt == oct_mach_info::flt_fmt_unknown)
 	    ffmt = float_format ();
 
-	  int tmp = mval.write (os, dt, skip, ffmt);
-
-	  if (tmp < 0)
+	  status = mval.write (os, dt, skip, ffmt);
+
+	  if (status < 0)
 	    error ("fwrite: write error");
 	  else
-	    retval = tmp;
+	    retval = status;
 	}
     }
   else
--- a/src/toplev.cc
+++ b/src/toplev.cc
@@ -251,47 +251,6 @@
   return retval;
 }
 
-DEFUN (computer, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn {Built-in Function} {} computer ()\n\
-Print or return a string of the form @var{cpu}-@var{vendor}-@var{os}\n\
-that identifies the kind of computer Octave is running on.  If invoked\n\
-with an output argument, the value is returned instead of printed.  For\n\
-example,\n\
-\n\
-@example\n\
-@group\n\
-computer ()\n\
-     @print{} i586-pc-linux-gnu\n\
-\n\
-x = computer ()\n\
-     @result{} x = \"i586-pc-linux-gnu\"\n\
-@end group\n\
-@end example\n\
-@end deftypefn")
-{
-  octave_value retval;
-
-  int nargin = args.length ();
-
-  if (nargin != 0)
-    warning ("computer: ignoring extra arguments");
-
-  std::string msg;
-
-  if (strcmp (OCTAVE_CANONICAL_HOST_TYPE, "unknown") == 0)
-    msg = "Hi Dave, I'm a HAL-9000";
-  else
-    msg = OCTAVE_CANONICAL_HOST_TYPE;
-
-  if (nargout == 0)
-    octave_stdout << msg << "\n";
-  else
-    retval = msg;
-
-  return retval;
-}
-
 DEFUN (quit, args, nargout,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} exit (@var{status})\n\
@@ -796,6 +755,19 @@
 	    break;
 	}
 
+      bool unix_system = true;
+      bool windows_system = false;
+
+#if defined (WIN32)
+      windows_system = true;
+#if !defined (__CYGWIN__)
+      unix_system = false;
+#endif
+#endif
+
+      m.assign ("unix", octave_value (unix_system));
+      m.assign ("windows", octave_value (windows_system));
+
       initialized = true;
     }