changeset 6187:2a8922007c12

[project @ 2006-11-29 01:59:59 by jwe]
author jwe
date Wed, 29 Nov 2006 02:00:00 +0000
parents 237a7f535bbc
children 160958073cde
files ChangeLog liboctave/ChangeLog mkoctfile.in src/ChangeLog src/dirfns.cc src/lex.l src/mex.cc
diffstat 7 files changed, 116 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Nov 28 20:13:40 2006 +0000
+++ b/ChangeLog	Wed Nov 29 02:00:00 2006 +0000
@@ -1,4 +1,9 @@
-2006-10-03  David Bateman  <dbateman@free.fr>
+2006-11-28  John W. Eaton  <jwe@octave.org>
+
+	* mkoctfile.in: Construct default output file from basename of
+	input file name.
+
+2006-11-28  David Bateman  <dbateman@free.fr>
 
 	* configure.in: Check for sparse header files in the sparsesuite
 	sub-directory. In the cholmod tests, include the camd libraries, as
--- a/liboctave/ChangeLog	Tue Nov 28 20:13:40 2006 +0000
+++ b/liboctave/ChangeLog	Wed Nov 29 02:00:00 2006 +0000
@@ -1,10 +1,8 @@
-2006-11-22  David Bateman  <dbateman@free.fr>
+2006-11-28  David Bateman  <dbateman@free.fr>
 
 	* oct-sparse.h: Allow sparse headers to also be in a sparsesuite
 	sub-directory.
 
-2006-11-22  David Bateman  <dbateman@free.fr>
-
         * dSparse.cc (SparseMatrix SparseMatrix::inverse(...)): Transpose
 	the matrix type as well when calling tinverse for lower
 	triangular
--- a/mkoctfile.in	Tue Nov 28 20:13:40 2006 +0000
+++ b/mkoctfile.in	Wed Nov 29 02:00:00 2006 +0000
@@ -291,6 +291,7 @@
   if [ -n "$outputfile" ]; then
     octfile="$outputfile"
   else
+    octfile=`basename $octfile`
     octfile=`echo $octfile | $SED 's,\.[^.]*$,,'`$output_ext
   fi
 fi
--- a/src/ChangeLog	Tue Nov 28 20:13:40 2006 +0000
+++ b/src/ChangeLog	Wed Nov 29 02:00:00 2006 +0000
@@ -1,3 +1,23 @@
+2006-11-28  John W. Eaton  <jwe@octave.org>
+
+	* mex.cc (mxArray_struct::get_field_by_number):
+	Return 0 if key_num is out of range.
+	(mxArray_struct::set_field_by_number):
+	Do nothing if key_num is out of range.
+	(mxArray_cell::get_cell, mxArray_cell::set_cell):
+	Avoid out-of-bounds indexing
+
+2006-11-28  Luis F. Ortiz  <lortiz@interactivesupercomputing.com>
+
+	* mex.cc (mxArray_matlab::get_n, mxArray_octave_value::get_n):
+	Return product of last N-1 dims.
+
+2006-11-28  John W. Eaton  <jwe@octave.org>
+
+	* lex.l (eat_whitespace): Also handle CRLF as EOL.
+
+	* dirfns.cc (Fmkdir): Handle "mkdir (parent, dir)".
+
 2006-11-21  John W. Eaton  <jwe@octave.org>
 
 	* load-path.cc (load_path::do_find_file,
--- a/src/dirfns.cc	Tue Nov 28 20:13:40 2006 +0000
+++ b/src/dirfns.cc	Wed Nov 29 02:00:00 2006 +0000
@@ -204,6 +204,7 @@
 DEFCMD (mkdir, args, ,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} mkdir (@var{dir})\n\
+@deftypefn {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} mkdir (@var{parent}, @var{dir})\n\
 Create a directory named @var{dir}.\n\
 \n\
 If successful, @var{status} is 1, with @var{msg} and @var{msgid} empty\n\
@@ -219,27 +220,48 @@
   retval(1) = std::string ();
   retval(0) = false;
 
-  if (args.length () == 1)
+  int nargin = args.length ();
+
+  std::string dirname;
+
+  if (nargin == 2)
     {
-      std::string dirname = args(0).string_value ();
+      std::string parent = args(0).string_value ();
+      std::string dir = args(1).string_value ();
 
       if (error_state)
-	gripe_wrong_type_arg ("mkdir", args(0));
-      else
 	{
-	  std::string msg;
+	  gripe_wrong_type_arg ("mkdir", args(0));
+	  return retval;
+	}
+      else
+	dirname = parent + file_ops::dir_sep_char + dir;
+    }
+  else
+    {
+      dirname = args(0).string_value ();
 
-	  int status = file_ops::mkdir (file_ops::tilde_expand (dirname),
+      if (error_state)
+	{
+	  gripe_wrong_type_arg ("mkdir", args(0));
+	  return retval;
+	}
+    }
+
+  if (nargin == 1 || nargin == 2)
+    {
+      std::string msg;
+
+      int status = file_ops::mkdir (file_ops::tilde_expand (dirname),
 					0777, msg);
 
-	  if (status < 0)
-	    {
-	      retval(2) = "mkdir";
-	      retval(1) = msg;
-	    }
-	  else
-	    retval(0) = true;
+      if (status < 0)
+	{
+	  retval(2) = "mkdir";
+	  retval(1) = msg;
 	}
+      else
+	retval(0) = true;
     }
   else
     print_usage ();
--- a/src/lex.l	Tue Nov 28 20:13:40 2006 +0000
+++ b/src/lex.l	Wed Nov 29 02:00:00 2006 +0000
@@ -1676,6 +1676,28 @@
 		goto done;
 	    }
 
+	case '\r':
+	  if (in_comment)
+	    comment_buf += static_cast<char> (c);
+	  c = yyinput ();
+	  if (c == EOF)
+	    break;
+	  else if (c == '\n')
+	    {
+	      retval |= ATE_NEWLINE;
+	      if (in_comment)
+		{
+		  comment_buf += static_cast<char> (c);
+		  octave_comment_buffer::append (comment_buf);
+		  in_comment = false;
+		  beginning_of_comment = false;
+		}
+	      current_input_column = 0;
+	      break;
+	    }
+
+	  // Fall through...
+
 	default:
 	  if (in_comment)
 	    {
--- a/src/mex.cc	Tue Nov 28 20:13:40 2006 +0000
+++ b/src/mex.cc	Wed Nov 29 02:00:00 2006 +0000
@@ -320,7 +320,18 @@
 
   int get_m (void) const { return val.rows (); }
 
-  int get_n (void) const { return val.columns (); }
+  int get_n (void) const 
+  {
+    int n = 1;
+
+    // Force dims and ndims to be cached.
+    get_dimensions();
+
+    for (int i = ndims - 1; i > 0; i--)
+      n *= dims[i];
+
+    return n;
+  }
 
   int *get_dimensions (void) const
   {
@@ -781,7 +792,15 @@
 
   int get_m (void) const { return dims[0]; }
 
-  int get_n (void) const { return dims[1]; }
+  int get_n (void) const
+  {
+    int n = 1;
+
+    for (int i = ndims - 1 ; i > 0 ; i--)
+      n *= dims[i];
+
+    return n;
+  }
 
   int *get_dimensions (void) const { return dims; }
 
@@ -1641,9 +1660,8 @@
 
   mxArray *get_field_by_number (int index, int key_num) const
   {
-    int idx = nfields * index + key_num;
-
-    return data[idx];
+    return key_num >= 0 && key_num < nfields
+      ? : data[nfields * index + key_num] : 0;
   }
 
   void set_field_by_number (int index, int key_num, mxArray *val);
@@ -1756,7 +1774,10 @@
     mxFree (data);
   }
 
-  mxArray *get_cell (int idx) const { return data[idx]; }
+  mxArray *get_cell (int idx) const
+  {
+    return idx >= 0 && idx < get_number_of_elements () ? data[idx] : 0;
+  }
 
   void set_cell (int idx, mxArray *val);
 
@@ -2210,15 +2231,15 @@
 void
 mxArray_struct::set_field_by_number (int index, int key_num, mxArray *val)
 {
-  int idx = nfields * index + key_num;
-
-  data[idx] = maybe_unmark_array (val);
+  if (key_num >= 0 && key_num < nfields)
+    data[nfields * index + key_num] = maybe_unmark_array (val);
 }
 
 void
 mxArray_cell::set_cell (int idx, mxArray *val)
 {
-  data[idx] = maybe_unmark_array (val);
+  if (idx >= 0 && idx < get_number_of_elements ())
+    data[idx] = maybe_unmark_array (val);
 }
 
 // ------------------------------------------------------------------