# HG changeset patch # User jwe # Date 1073758563 0 # Node ID bdc51b369a78bddb7785819645228a455ff4ec4d # Parent b6dc2aad574a922d2ff982609170886ab0b2eae2 [project @ 2004-01-10 18:16:02 by jwe] diff -r b6dc2aad574a -r bdc51b369a78 scripts/ChangeLog --- a/scripts/ChangeLog Fri Jan 09 15:19:43 2004 +0000 +++ b/scripts/ChangeLog Sat Jan 10 18:16:03 2004 +0000 @@ -1,3 +1,25 @@ +2004-01-10 John W. Eaton + + * 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 + + * 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 * statistics/tests/kolmogorov_smirnov_test_2.m: Fix test for ties. diff -r b6dc2aad574a -r bdc51b369a78 scripts/general/num2str.m --- a/scripts/general/num2str.m Fri Jan 09 15:19:43 2004 +0000 +++ b/scripts/general/num2str.m Sat Jan 10 18:16:03 2004 +0000 @@ -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"); diff -r b6dc2aad574a -r bdc51b369a78 scripts/miscellaneous/computer.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/miscellaneous/computer.m Sat Jan 10 18:16:03 2004 +0000 @@ -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 diff -r b6dc2aad574a -r bdc51b369a78 scripts/miscellaneous/delete.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/miscellaneous/delete.m Sat Jan 10 18:16:03 2004 +0000 @@ -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 diff -r b6dc2aad574a -r bdc51b369a78 scripts/miscellaneous/ispc.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/miscellaneous/ispc.m Sat Jan 10 18:16:03 2004 +0000 @@ -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 diff -r b6dc2aad574a -r bdc51b369a78 scripts/miscellaneous/isunix.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/miscellaneous/isunix.m Sat Jan 10 18:16:03 2004 +0000 @@ -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 diff -r b6dc2aad574a -r bdc51b369a78 scripts/miscellaneous/not.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/miscellaneous/not.m Sat Jan 10 18:16:03 2004 +0000 @@ -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 diff -r b6dc2aad574a -r bdc51b369a78 scripts/miscellaneous/unix.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/miscellaneous/unix.m Sat Jan 10 18:16:03 2004 +0000 @@ -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 diff -r b6dc2aad574a -r bdc51b369a78 src/ChangeLog --- a/src/ChangeLog Fri Jan 09 15:19:43 2004 +0000 +++ b/src/ChangeLog Sat Jan 10 18:16:03 2004 +0000 @@ -1,3 +1,20 @@ +2004-01-10 John W. Eaton + + * 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 + + * 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 * ls-hdf5.cc: Fix handle of old versus new format files. diff -r b6dc2aad574a -r bdc51b369a78 src/dirfns.cc --- a/src/dirfns.cc Fri Jan 09 15:19:43 2004 +0000 +++ b/src/dirfns.cc Sat Jan 10 18:16:03 2004 +0000 @@ -140,10 +140,9 @@ delete static_cast (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 diff -r b6dc2aad574a -r bdc51b369a78 src/load-save.cc --- a/src/load-save.cc Fri Jan 09 15:19:43 2004 +0000 +++ b/src/load-save.cc Sat Jan 10 18:16:03 2004 +0000 @@ -613,7 +613,7 @@ load_save_format format = LS_UNKNOWN; - bool force = false; + bool force = true; bool list_only = false; bool verbose = false; diff -r b6dc2aad574a -r bdc51b369a78 src/oct-stream.cc --- a/src/oct-stream.cc Fri Jan 09 15:19:43 2004 +0000 +++ b/src/oct-stream.cc Sat Jan 10 18:16:03 2004 +0000 @@ -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 diff -r b6dc2aad574a -r bdc51b369a78 src/toplev.cc --- a/src/toplev.cc Fri Jan 09 15:19:43 2004 +0000 +++ b/src/toplev.cc Sat Jan 10 18:16:03 2004 +0000 @@ -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; }