changeset 14010:99e33d556d5c

Merge in Carnë's changes
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Wed, 07 Dec 2011 19:06:13 -0500
parents a73e110857e4 (diff) c71a4c53e70a (current diff)
children 431c6b00653d
files scripts/pkg/pkg.m
diffstat 304 files changed, 4346 insertions(+), 2285 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgsub	Wed Dec 07 19:06:13 2011 -0500
@@ -0,0 +1,1 @@
+gnulib = [git]git://git.sv.gnu.org/gnulib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgsubstate	Wed Dec 07 19:06:13 2011 -0500
@@ -0,0 +1,1 @@
+bb052d4a7416accaad0747e84bd2a0accbfcf923 gnulib
--- a/NEWS	Tue Nov 29 05:16:09 2011 +0000
+++ b/NEWS	Wed Dec 07 19:06:13 2011 -0500
@@ -3,6 +3,28 @@
 
  ** The PCRE library is now required to build Octave.
 
+ ** The following binary elementwise operators and functions now perform
+    Numpy-like broadcasting (a.k.a. binary singleton expansion):
+
+    plus      ldivide   rem    eq    gt     xor
+    minus     power     mod    ne    ge
+    times     max       atan2  lt    and
+    rdivide   min       hypot  le    or
+
+    +         .*        &
+    -         ./        |
+    .+        .\
+    .-        .^
+
+    +=        .*=       &=
+    -=        ./=       |=
+    .+=       .\=
+    .-=       .^=
+
+    This makes the bsxfun function mostly redundant except for
+    user-defined functions.  A new section in the manual has been written
+    to explain and clarify this change.
+
  ** Octave now features a profiler, thanks to the work of Daniel Kraft
     under the Google Summer of Code mentorship program.  The manual has
     been updated to reflect this addition.  The new user-visible
@@ -72,21 +94,43 @@
               Now accepts cellstr inputs.
 
  ** Octave warning IDs updated
+    "associativity-change": removed
+    "complex-cmp-ops"     : removed
     "empty-list-elements" : removed
     "fortran-indexing"    : removed
-    "complex-cmp-ops"     : removed
+    "precedence-change"   : removed
     "string-concat"       : renamed to "mixed-string-concat"
 
  ** Matlab-compatible preference functions added:
 
     addpref  getpref  ispref  rmpref  setpref
 
+ ** Matlab-compatible handle graphics functions added:
+
+    guidata         uipanel        uitoolbar
+    guihandles      uipushtool     uiwait
+    uicontextmenu   uiresume       waitfor
+    uicontrol       uitoggletool
+
+    The uiXXX functions above are experimental.
+
+    Except for uiwait and uiresume, the uiXXX functions are not supported on
+    the FLTK backend.
+
+    The gnuplot backend does not support any of the uiXXX functions nor
+    the waitfor function.
+
+ ** New keyword parfor
+
+    parfor (parallel for loop) is now recognized as a valid keyword.
+    Implementation, however, is still mapped to an ordinary for loop.
+
  ** Other new functions added in 3.6.0:
 
-    is_dq_string      python      zscore
-    is_sq_string      usejava 
-    nthargout         waitbar
-                      
+    is_dq_string    nthargout    usejava     
+    is_sq_string    python       waitbar
+    narginchk       recycle      zscore            
+    
  ** Deprecated functions.
 
     The following functions were deprecated in Octave 3.2 and have been
--- a/build-aux/bootstrap	Tue Nov 29 05:16:09 2011 +0000
+++ b/build-aux/bootstrap	Wed Dec 07 19:06:13 2011 -0500
@@ -169,8 +169,10 @@
 # default.
 bootstrap_sync=false
 
-# Use git to update gnulib sources
-use_git=true
+# Don't use git to update gnulib sources. We keep gnulib under a
+# Mercurial subrepository instead
+use_git=false
+GNULIB_SRCDIR=gnulib/
 
 # find_tool ENVVAR NAMES...
 # -------------------------
--- a/build-aux/bootstrap.conf	Tue Nov 29 05:16:09 2011 +0000
+++ b/build-aux/bootstrap.conf	Wed Dec 07 19:06:13 2011 -0500
@@ -40,6 +40,7 @@
   lstat
   mkdir
   mkfifo
+  mkostemp
   mkstemp
   mktime
   nanosleep
@@ -73,7 +74,7 @@
   truncf
   unistd
   unlink
-  vsnprintf
+  vasprintf
 "
 
 # Additional xgettext options to use.  Use "\\\newline" to break lines.
--- a/configure.ac	Tue Nov 29 05:16:09 2011 +0000
+++ b/configure.ac	Wed Dec 07 19:06:13 2011 -0500
@@ -171,11 +171,20 @@
 AC_ARG_ENABLE(octave-allocator,
   [AS_HELP_STRING([--enable-octave-allocator],
      [use the obsolete octave_allocator class for many of Octave's objects (mostly octave_value types).  You probably do NOT want to enable this feature.  (default is no)])],
-  [if test "$enableval" = yes; then USE_ALLOCATOR=true; fi], [])
+  [if test "$enableval" = yes; then USE_OCTAVE_ALLOCATOR=true; fi], [])
 if $USE_OCTAVE_ALLOCATOR; then
   AC_DEFINE(USE_OCTAVE_ALLOCATOR, 1, [Define to use octave_allocator class.])
 fi
 
+USE_ATOMIC_REFCOUNT=false
+AC_ARG_ENABLE(atomic-refcount,
+  [AS_HELP_STRING([--enable-atomic-refcount],
+     [use atomic operations for internal reference counting. This is required for thread-safe behavior.  (default is no)])],
+  [if test "$enableval" = yes; then USE_ATOMIC_REFCOUNT=true; fi], [])
+if $USE_ATOMIC_REFCOUNT; then
+  AC_DEFINE(USE_ATOMIC_REFCOUNT, 1, [Define to use atomic operations for reference counting.])
+fi
+
 ### Make it possible to disable running Make in the doc directory.
 ### Useful for building on systems without TeX, for example.
 DOCDIR=doc
@@ -2089,6 +2098,9 @@
 typedef OCTAVE_IDX_TYPE octave_idx_type;
 
 #include <stdint.h>
+
+/* Tag indicating octave config.h has been included */
+#define OCTAVE_CONFIG_INCLUDED 1
 ])
 
 ### Do the substitutions in all the Makefiles.
@@ -2465,6 +2477,22 @@
   warn_msg_printed=true
 fi
 
+if $USE_ATOMIC_REFCOUNT; then
+  AC_MSG_WARN([])
+  AC_MSG_WARN([Using atomic reference counting.])
+  AC_MSG_WARN([This feature allows to access octave data safely from])
+  AC_MSG_WARN([another thread, for instance from a GUI. However this])
+  AC_MSG_WARN([results in a small performance penalty in the octave])
+  AC_MSG_WARN([interpreter.])
+  AC_MSG_WARN([])
+  if $USE_OCTAVE_ALLOCATOR; then
+    AC_MSG_WARN([Thread-safe behavior is not guaranteed unless you also])
+    AC_MSG_WARN([disable the use of the octave_allocator class.])
+    AC_MSG_WARN([])
+  fi
+  warn_msg_printed=true
+fi
+
 if $warn_msg_printed; then
   AC_MSG_NOTICE([])
   AC_MSG_NOTICE([NOTE: libraries may be skipped if a library is not found OR])
--- a/doc/interpreter/Makefile.am	Tue Nov 29 05:16:09 2011 +0000
+++ b/doc/interpreter/Makefile.am	Wed Dec 07 19:06:13 2011 -0500
@@ -118,6 +118,7 @@
   fn-idx.texi \
   func.texi \
   geometry.texi \
+  gui.texi \
   gpl.texi \
   grammar.texi \
   image.texi \
--- a/doc/interpreter/contributors.in	Tue Nov 29 05:16:09 2011 +0000
+++ b/doc/interpreter/contributors.in	Wed Dec 07 19:06:13 2011 -0500
@@ -210,6 +210,7 @@
 Thomas L. Scofield
 Daniel J. Sebald
 Dmitri A. Sergatskov
+Vanya Sergeev
 Baylis Shanks
 Andriy Shinkarchuck
 Joseph P. Skudlarek
--- a/doc/interpreter/debug.txi	Tue Nov 29 05:16:09 2011 +0000
+++ b/doc/interpreter/debug.txi	Wed Dec 07 19:06:13 2011 -0500
@@ -194,7 +194,7 @@
 profiling is enabled, each call to a function (supporting built-ins,
 operators, functions in oct- and mex-files, user-defined functions in
 Octave code and anonymous functions) is recorded while running Octave
-code. After that, this data can aid in analyzing the code behaviour, and
+code. After that, this data can aid in analyzing the code behavior, and
 is in particular helpful for finding ``hot spots'' in the code which use
 up a lot of computation time and are the best targets to spend
 optimization efforts on.
@@ -221,7 +221,7 @@
 @end group
 @end example
 
-This shows that most of the runtime was spent executing the function
+This shows that most of the run time was spent executing the function
 @samp{myfib}, and some minor proportion evaluating the listed binary
 operators. Furthermore, it is shown how often the function was called
 and the profiler also records that it is recursive.
@@ -334,7 +334,7 @@
 once. The second expensive operation is the matrix-vector product in the
 routine @code{timesteps}. @footnote{We only know it is the binary
 multiplication operator, but fortunately this operator appears only at
-one place in the code and thus we know which occurence takes so much
+one place in the code and thus we know which occurrence takes so much
 time. If there were multiple places, we would have to use the
 hierarchical profile to find out the exact place which uses up the time
 which is not covered in this example.}
@@ -405,7 +405,7 @@
 suboptimal way, and most of the time was spent in @code{bar} itself.
 
 Finally, let's say we want to profile the execution of both @code{foo}
-and @code{bar} together. Since we already have the runtime data
+and @code{bar} together. Since we already have the run-time data
 collected for @code{bar}, we can restart the profiler without clearing
 the existing data and collect the missing statistics about @code{foo}.
 This is done by:
--- a/doc/interpreter/doccheck/aspell-octave.en.pws	Tue Nov 29 05:16:09 2011 +0000
+++ b/doc/interpreter/doccheck/aspell-octave.en.pws	Wed Dec 07 19:06:13 2011 -0500
@@ -1,11 +1,12 @@
 personal_ws-1.1 en 1
 Abramowitz
 accumarray
+Acknowledgements
 acknowledgements
-Acknowledgements
 ACM
 adams
 Affero
+afterwards
 Ahalt
 aifm
 AIX
@@ -15,8 +16,8 @@
 alnum
 alphanum
 amd
+ANOVA
 anova
-ANOVA
 Anymap
 API
 approximant
@@ -32,14 +33,15 @@
 Autoconf
 autocorrelations
 autocovariances
+autoload
 Autoload
-autoload
 autoloaded
 autoloading
 Autoloading
 autoregression
 autoregressions
 autoscaled
+AutoScaling
 AWK
 backend
 Backends
@@ -104,6 +106,7 @@
 ceil
 cellstr
 ChangeLog
+changelogs
 changeset
 changesets
 Chaves
@@ -128,12 +131,14 @@
 cof
 coffset
 colamd
+collectoutput
 colorbar
 colormap
 colperm
 Comint
 Commandline
 commentstyle
+ComplexEqn
 cond
 condest
 conformant
@@ -151,6 +156,7 @@
 cov
 CPLEX
 CreateFcn
+CRLF
 csymamd
 ctranspose
 CTRL
@@ -167,6 +173,8 @@
 dataset
 datasets
 datasource
+datestr
+datestrings
 davis
 ddd
 dddd
@@ -175,8 +183,8 @@
 deallocated
 deconv
 deftypefn
+Delaunay
 delaunay
-Delaunay
 delaunayn
 DeleteFcn
 delim
@@ -225,9 +233,11 @@
 endian
 Endian
 endif
+endofline
 Engle's
 eof
 EOF
+EOLs
 EOS
 eps
 eq
@@ -257,8 +267,9 @@
 facevertexcdata
 fcdf
 femmodel
+FFF
+FFT
 fft
-FFT
 fftn
 fftpack
 FFTs
@@ -269,6 +280,7 @@
 filename
 filenames
 Filesystem
+FinDiffType
 finv
 FIRfilter
 FIXME
@@ -292,6 +304,7 @@
 Frobenius
 Fs
 FSF
+FunValCheck
 gamcdf
 gaminv
 gampdf
@@ -319,17 +332,18 @@
 globbing
 glpk
 GLS
+gnuplot
 Gnuplot
-gnuplot
 gnuplot's
 Golub
 Gonnet
+goto
 Goto
-goto
 gotos
 GPL
 gplot
 grabdemo
+GradObj
 GraphicsMagick
 Graymap
 grayscale
@@ -346,6 +360,7 @@
 Hankel
 Hanning
 hardcode
+hardcoding
 Hauberg
 HDF
 hdf
@@ -377,8 +392,8 @@
 hygepdf
 hygernd
 Hyndman
+Hypergeometric
 hypergeometric
-Hypergeometric
 IEEE
 iff
 ifft
@@ -446,13 +461,14 @@
 ldivide
 ldots
 le
+Leftarrow
 leftarrow
-Leftarrow
 Leftrightarrow
 leftrightarrow
 Lehoucq
 leq
 Levinson
+LF
 lfloor
 li
 libcruft
@@ -463,12 +479,13 @@
 lineanchors
 linefeeds
 linesearch
+linespec
 linespoints
 linkprop
 literalspacing
 Liu
+LM
 lm
-LM
 loadpath
 Lobatto
 logit
@@ -506,8 +523,10 @@
 matchcase
 matlab
 Matsumoto
+MaxFunEvals
 maxima
 MaxIntervalCount
+MaxIter
 mcnemar
 McNemar's
 meansq
@@ -515,8 +534,8 @@
 Mersenne
 meshgrid
 meshgridded
+metafile
 Metafile
-metafile
 metafiles
 Metafont
 mex
@@ -548,6 +567,7 @@
 multi
 multibyte
 multiline
+multipledelimsasone
 MultiSelect
 mxArray
 myclass
@@ -590,6 +610,7 @@
 noscal
 noshare
 notin
+nthargout
 NTSC
 nul
 Nx
@@ -626,8 +647,8 @@
 PCRE
 PCX
 pcx
+pdf
 PDF
-pdf
 periodogram
 perp
 Petzold's
@@ -661,6 +682,8 @@
 presolver
 printf
 priori
+Profiler
+profiler
 propto
 proven
 ps
@@ -677,15 +700,15 @@
 qhull
 QP
 QQ
+qrupdate
 QRUPDATE
-qrupdate
 quadcc
 quadgk
 quadl
 quadpack
 quadv
+quantile
 Quantile
-quantile
 quantiles
 Quickhull
 qz
@@ -703,6 +726,7 @@
 Readline
 readline
 recursing
+reentrant
 regex
 regressor
 reimported
@@ -718,6 +742,7 @@
 resnorm
 resparsify
 RET
+returnonerror
 rfloor
 RGB
 Riccati
@@ -791,9 +816,10 @@
 Stadlober
 stairstep
 Stallman
+startup
 Startup
-startup
 stdnormal
+stdout
 Stegun
 Stepleman
 stepsize
@@ -812,8 +838,8 @@
 subexpressions
 subfunction
 Subfunction
+subfunctions
 Subfunctions
-subfunctions
 subinterval
 Subintervals
 subintervals
@@ -826,8 +852,8 @@
 subprocesses
 Subprocesses
 subsasgn
+Subscripted
 subscripted
-Subscripted
 subscripting
 subseteq
 subsindex
@@ -857,8 +883,9 @@
 Tcv
 terminal's
 tex
+texinfo
 Texinfo
-texinfo
+textscan
 th
 ths
 tif
@@ -878,6 +905,7 @@
 tpdf
 traceback
 trapz
+treatasempty
 treelayout
 treeplot
 tridiagonal
@@ -888,6 +916,7 @@
 Tx
 txi
 typedefs
+TypicalX
 ub
 UB
 uchar
@@ -955,16 +984,16 @@
 wblpdf
 wblrnd
 Weibull
+Welch
 welch
-Welch
 WestOutside
 whitespace
 Whitespace
 whos
 wienrnd
 Wikipedia
+wilcoxon
 Wilcoxon
-wilcoxon
 wildcard
 Wildcards
 wildcards
@@ -1000,10 +1029,10 @@
 ydata
 yerrorbar
 yerrorbars
+yy
 YY
-yy
+yyyy
 YYYY
-yyyy
 yyyymmdd
 yyyymmddTHHMMSS
 Zechner
--- a/doc/interpreter/grammar.txi	Tue Nov 29 05:16:09 2011 +0000
+++ b/doc/interpreter/grammar.txi	Wed Dec 07 19:06:13 2011 -0500
@@ -41,16 +41,17 @@
 @item @code{case} @tab @code{catch} @tab @code{classdef}
 @item @code{continue} @tab @code{do} @tab @code{else}
 @item @code{elseif} @tab @code{end} @tab @code{end_try_catch}
-@item @code{end_unwind_protect} @tab @code{endclassdef} @tab @code{endevents}
-@item @code{endfor} @tab @code{endfunction} @tab @code{endif}
-@item @code{endmethods} @tab @code{endproperties} @tab @code{endswitch}
-@item @code{endwhile} @tab @code{events} @tab @code{for}
+@item @code{end_unwind_protect} @tab @code{endclassdef} @tab @code{endenumeration}
+@item @code{endevents} @tab @code{endfor} @tab @code{endfunction}
+@item @code{endif} @tab @code{endmethods} @tab @code{endparfor}
+@item @code{endproperties} @tab @code{endswitch} @tab @code{endwhile}
+@item @code{enumeration} @tab @code{events} @tab @code{for}
 @item @code{function} @tab @code{get} @tab @code{global}
 @item @code{if} @tab @code{methods} @tab @code{otherwise}
-@item @code{persistent} @tab @code{properties} @tab @code{return}
-@item @code{set} @tab @code{static} @tab @code{switch}
-@item @code{try} @tab @code{until} @tab @code{unwind_protect}
-@item @code{unwind_protect_cleanup}@tab @code{while}
+@item @code{parfor} @tab @code{persistent} @tab @code{properties}
+@item @code{return} @tab @code{set} @tab @code{static}
+@item @code{switch} @tab @code{try} @tab @code{until}
+@item @code{unwind_protect} @tab @code{unwind_protect_cleanup} @tab @code{while}
 @end multitable
 
 The function @code{iskeyword} can be used to quickly check whether an
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/interpreter/gui.txi	Wed Dec 07 19:06:13 2011 -0500
@@ -0,0 +1,93 @@
+@c Copyright (C) 2011 Rik Wehbring
+@c
+@c This file is part of Octave.
+@c
+@c Octave is free software; you can redistribute it and/or modify it
+@c under the terms of the GNU General Public License as published by the
+@c Free Software Foundation; either version 3 of the License, or (at
+@c your option) any later version.
+@c 
+@c Octave is distributed in the hope that it will be useful, but WITHOUT
+@c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+@c FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+@c for more details.
+@c 
+@c You should have received a copy of the GNU General Public License
+@c along with Octave; see the file COPYING.  If not, see
+@c <http://www.gnu.org/licenses/>.
+
+@node GUI Development
+@chapter GUI Development
+
+Octave is principally a batch or command-line language.  However, it does
+offer some limited features for constructing graphical interfaces for
+interacting with users.
+
+The GUI elements available are I/O dialogs and a progress bar.  For example,
+rather than hardcoding a filename for output results a script can open a dialog
+box and allow the user to choose a file.  Similarly, if a calculation is
+expected to take a long time a script can display a progress bar.
+
+Several utility functions make it possible to store private data for use with
+a GUI which will not pollute the user's variable space.
+
+Finally, a program written in Octave might want to have long term storage of
+preferences or state variables.  This can be done with user-defined
+preferences.
+
+@menu
+* I/O Dialogs::       
+* Progress Bar::       
+* GUI Utility Functions::       
+* User-Defined Preferences::       
+@end menu
+
+@node I/O Dialogs
+@section I/O Dialogs
+
+Simple dialog menus are available for choosing directories or files.  They
+return a string variable which can then be used with any command requiring
+a file name.
+
+@DOCSTRING(uigetdir)
+
+@DOCSTRING(uigetfile)
+
+@DOCSTRING(uiputfile)
+
+@node Progress Bar
+@section Progress Bar
+@cindex Progress Bar
+
+@DOCSTRING(waitbar)
+
+@node GUI Utility Functions
+@section GUI Utility Functions
+
+These functions do not implement a GUI element but are useful when developing
+programs that do.  @strong{Warning:} The functions @code{uiwait},
+@code{uiresume}, and @code{waitfor} are only available for the FLTK tooolkit.
+
+@DOCSTRING(guidata)
+
+@DOCSTRING(guihandles)
+
+@DOCSTRING(uiwait)
+
+@DOCSTRING(uiresume)
+
+@DOCSTRING(waitfor)
+
+@node User-Defined Preferences
+@section User-Defined Preferences
+
+@DOCSTRING(addpref)
+
+@DOCSTRING(getpref)
+
+@DOCSTRING(ispref)
+
+@DOCSTRING(rmpref)
+
+@DOCSTRING(setpref)
+
--- a/doc/interpreter/io.txi	Tue Nov 29 05:16:09 2011 +0000
+++ b/doc/interpreter/io.txi	Wed Dec 07 19:06:13 2011 -0500
@@ -28,7 +28,6 @@
 @menu
 * Basic Input and Output::      
 * C-Style I/O Functions::       
-* GUI Dialogs for I/O::       
 @end menu
 
 @node Basic Input and Output
@@ -1065,16 +1064,3 @@
 @end group
 @end example
 
-@node GUI Dialogs for I/O
-@section GUI Dialogs for I/O
-
-Simple dialog menus are available for choosing directories or files.  They
-return a string variable which can then be used when calling any command
-requiring a file name.
-
-@DOCSTRING(uigetdir)
-
-@DOCSTRING(uigetfile)
-
-@DOCSTRING(uiputfile)
-
--- a/doc/interpreter/obsolete.txi	Tue Nov 29 05:16:09 2011 +0000
+++ b/doc/interpreter/obsolete.txi	Wed Dec 07 19:06:13 2011 -0500
@@ -118,4 +118,37 @@
 @item @code{weibull_pdf} @tab @code{wblpdf} @tab 3.4.0
 @item @code{weibull_rnd} @tab @code{wblrnd} @tab 3.4.0
 @item @code{wiener_rnd} @tab @code{wienrnd} @tab 3.4.0
+@item @code{create_set} @tab @code{unique} @tab 3.6.0
+@item @code{dmult} @tab @code{diag (A) * B} @tab 3.6.0
+@item @code{iscommand} @tab None @tab 3.6.0
+@item @code{israwcommand} @tab None @tab 3.6.0
+@item @code{lchol} @tab @code{chol (@dots{}, "lower")} @tab 3.6.0
+@item @code{loadimage} @tab @code{load} or @code{imread} @tab 3.6.0
+@item @code{mark_as_command} @tab None @tab 3.6.0
+@item @code{mark_as_rawcommand} @tab None @tab 3.6.0
+@item @code{spatan2} @tab @code{atan2} @tab 3.6.0
+@item @code{spchol} @tab @code{chol} @tab 3.6.0
+@item @code{spchol2inv} @tab @code{chol2inv} @tab 3.6.0
+@item @code{spcholinv} @tab @code{cholinv} @tab 3.6.0
+@item @code{spcumprod} @tab @code{cumprod} @tab 3.6.0
+@item @code{spcumsum} @tab @code{cumsum} @tab 3.6.0
+@item @code{spdet} @tab @code{det} @tab 3.6.0
+@item @code{spdiag} @tab @code{sparse (diag (@dots{}))} @tab 3.6.0
+@item @code{spfind} @tab @code{find} @tab 3.6.0
+@item @code{sphcat} @tab @code{horzcat} @tab 3.6.0
+@item @code{spinv} @tab @code{inv} @tab 3.6.0
+@item @code{spkron} @tab @code{kron} @tab 3.6.0
+@item @code{splchol} @tab @code{chol (@dots{}, "lower")} @tab 3.6.0
+@item @code{split} @tab @code{char (strsplit (s, t))} @tab 3.6.0
+@item @code{splu} @tab @code{lu} @tab 3.6.0
+@item @code{spmax} @tab @code{max} @tab 3.6.0
+@item @code{spmin} @tab @code{min} @tab 3.6.0
+@item @code{spprod} @tab @code{prod} @tab 3.6.0
+@item @code{spqr} @tab @code{qr} @tab 3.6.0
+@item @code{spsum} @tab @code{sum} @tab 3.6.0
+@item @code{spsumsq} @tab @code{sumsq} @tab 3.6.0
+@item @code{spvcat} @tab @code{vertcat} @tab 3.6.0
+@item @code{str2mat} @tab @code{char} @tab 3.6.0
+@item @code{unmark_command} @tab None @tab 3.6.0
+@item @code{unmark_rawcommand} @tab None @tab 3.6.0
 @end multitable
--- a/doc/interpreter/octave.texi	Tue Nov 29 05:16:09 2011 +0000
+++ b/doc/interpreter/octave.texi	Wed Dec 07 19:06:13 2011 -0500
@@ -213,6 +213,7 @@
 * Image Processing::            
 * Audio Processing::            
 * Object Oriented Programming::            
+* GUI Development::            
 * System Utilities::            
 * Packages:: 
 * Dynamically Linked Functions::
@@ -476,7 +477,6 @@
 
 * Basic Input and Output::      
 * C-Style I/O Functions::       
-* GUI Dialogs for I/O::       
 
 Basic Input and Output
 
@@ -754,6 +754,13 @@
 * Operator Overloading::
 * Precedence of Objects::
 
+GUI Development
+
+* I/O Dialogs::       
+* Progress Bar::       
+* GUI Utility Functions::       
+* User-Defined Preferences::
+
 System Utilities
 
 * Timing Utilities::            
@@ -855,7 +862,7 @@
 Reporting Bugs
 
 * Bug Criteria::                
-* Bug Tracker::ff               Where to submit your bug report.
+* Bug Tracker::                 Where to submit your bug report.
 * Bug Reporting::               How to report a bug effectively.
 * Sending Patches::             How to send a patch for Octave.
 
@@ -914,6 +921,7 @@
 @include image.texi
 @include audio.texi
 @include oop.texi
+@include gui.texi
 @include system.texi
 @include package.texi
 
--- a/doc/interpreter/plot.txi	Tue Nov 29 05:16:09 2011 +0000
+++ b/doc/interpreter/plot.txi	Wed Dec 07 19:06:13 2011 -0500
@@ -1808,6 +1808,7 @@
 @item deletefcn
 
 @item displayname
+The text of the legend entry corresponding to this line.
 
 @item erasemode
 
@@ -1819,11 +1820,6 @@
 
 @item interruptible
 
-@item keylabel
-The text of the legend entry corresponding to this line.  Note that this
-property is not compatible with @sc{matlab} and may be removed in a
-future version of Octave.
-
 @item ldata
 The lower errorbar in the y direction to be plotted.
 
@@ -1925,6 +1921,7 @@
 @item deletefcn
 
 @item displayname
+The text of the legend entry corresponding to this line.
 
 @item edgecolor
 
@@ -2132,6 +2129,9 @@
 
 @item diffusestrength
 
+@item displayname
+The text of the legend entry corresponding to this line.
+
 @item edgealpha
 
 @item edgecolor
@@ -2163,8 +2163,6 @@
 
 @item interruptible
 
-@item keylabel
-
 @item linestyle
 @xref{Line Styles}.
 
@@ -2282,6 +2280,9 @@
 
 @item diffusestrength
 
+@item displayname
+The text of the legend entry corresponding to this surface.
+
 @item edgealpha
 
 @item edgecolor
@@ -2304,11 +2305,6 @@
 
 @item interruptible
 
-@item keylabel
-The text of the legend entry corresponding to this surface.  Note that
-this property is not compatible with @sc{matlab} and may be removed in a
-future version of Octave.
-
 @item linestyle
 
 @item linewidth
@@ -2397,7 +2393,7 @@
 
 Although default values may be set for any object, they are set in
 parent objects and apply to child objects, of the specified object type.
-For example, seeting the default @code{color} property of @code{line}
+For example, setting the default @code{color} property of @code{line}
 objects to "green", for the @code{root} object, will result in all
 @code{line} objects inheriting the @code{color} "green" as the default
 value.
--- a/doc/interpreter/poly.txi	Tue Nov 29 05:16:09 2011 +0000
+++ b/doc/interpreter/poly.txi	Wed Dec 07 19:06:13 2011 -0500
@@ -107,7 +107,7 @@
 @section Derivatives / Integrals / Transforms
 
 Octave comes with functions for computing the derivative and the integral
-of a polynomial.  The functions @code{polyderiv} and @code{polyint}
+of a polynomial.  The functions @code{polyder} and @code{polyint}
 both return new polynomials describing the result.  As an example we'll
 compute the definite integral of @math{p(x) = x^2 + 1} from 0 to 3.
 
@@ -120,8 +120,6 @@
 @end group
 @end example
 
-@DOCSTRING(polyderiv)
-
 @DOCSTRING(polyder)
 
 @DOCSTRING(polyint)
--- a/doc/interpreter/stats.txi	Tue Nov 29 05:16:09 2011 +0000
+++ b/doc/interpreter/stats.txi	Wed Dec 07 19:06:13 2011 -0500
@@ -118,8 +118,6 @@
 
 @DOCSTRING(histc)
 
-@DOCSTRING(cut)
-
 @c FIXME: really want to put a reference to unique here
 @c @DOCSTRING(values)
 
--- a/doc/interpreter/strings.txi	Tue Nov 29 05:16:09 2011 +0000
+++ b/doc/interpreter/strings.txi	Wed Dec 07 19:06:13 2011 -0500
@@ -147,6 +147,12 @@
 @end group
 @end example
 
+In scripts the two different string types can be distinguished if necessary
+by using @code{is_dq_string} and @code{is_sq_string}.
+
+@DOCSTRING(is_dq_string)
+
+@DOCSTRING(is_sq_string)
 
 @node Character Arrays
 @section Character Arrays
--- a/doc/interpreter/system.txi	Tue Nov 29 05:16:09 2011 +0000
+++ b/doc/interpreter/system.txi	Wed Dec 07 19:06:13 2011 -0500
@@ -503,6 +503,8 @@
 
 @DOCSTRING(octave_config_info)
 
+@DOCSTRING(usejava)
+
 @DOCSTRING(getrusage)
 
 @node Hashing Functions
--- a/doc/interpreter/testfun.txi	Tue Nov 29 05:16:09 2011 +0000
+++ b/doc/interpreter/testfun.txi	Wed Dec 07 19:06:13 2011 -0500
@@ -167,9 +167,10 @@
 
 @example
 @group
-   %!function @var{a} = fn(@var{b})
+   %!function @var{a} = fn (@var{b})
    %!  @var{a} = 2*@var{b};
-   %!assert (@var{a}(2),4);
+   %!endfunction
+   %!assert (@var{fn}(2), 4);
 @end group
 @end example
 
@@ -263,13 +264,16 @@
 comment: ignore everything within the block
 
 @item %!shared x,y,z
-declares variables for use in multiple tests
+declare variables for use in multiple tests
 
 @item %!function
-defines a function value for a shared variable
+define a function for use in multiple tests
+
+@item %!endfunction
+close a function definition
 
 @item %!assert (x, y, tol)
-shorthand for %!test assert (x, y, tol)
+shorthand for @code{%!test assert (x, y, tol)}
 @end table
 
 You can also create test scripts for builtins and your own C++
--- a/etc/HACKING	Tue Nov 29 05:16:09 2011 +0000
+++ b/etc/HACKING	Wed Dec 07 19:06:13 2011 -0500
@@ -7,8 +7,7 @@
 
 These notes are intended to help people working on sources checked-out from
 the savannah source code repository.
-These requirements do not apply when building from a distribution
-tarball.
+These requirements do not apply when building from a distribution tarball.
 
 ** Requirements
 
@@ -120,7 +119,7 @@
     fftpack        * subroutines for fast fourier transforms
     lapack-xtra    * wrappers for lapack functions used in Octave
     misc           * miscellaneous utilities
-    odepack        * odinary differential equation solver
+    odepack        * ordinary differential equation solver
     ordered-qz     * code for ordering eigenvalues for QZ factorization
     quadpack       * subroutines for numerical integration
     ranlib         * random number generators
@@ -137,8 +136,8 @@
     @ftp           * ftp object class
     general        * utility functions
     geometry       * geometry algorithms
+    help           * help subsystem functions
     image          * image processing
-    help           * help subsystem functions
     io             * input/output functions
     linear-algebra * linear algebra stuff
     miscellaneous  * stuff that doesn't fit anywhere else
@@ -147,6 +146,7 @@
     pkg            * the package manager
     plot           * plotting functions
     polynomial     * polynomial manipulation
+    prefs          * user-defined preferences
     set            * set manipulation
     signal         * signal processing
     sparse         * sparse matrix support
@@ -159,13 +159,13 @@
     time           * time and date functions
 
   src           -- the interpreter itself plus lots of infrastructure
-                   around it. Octave's extensive octave_value class
+                   around it.  Octave's extensive octave_value class
                    hierarchy for polymorphically handling all Octave
-                   types is defined here. The built-in functions are
+                   types is defined here.  The built-in functions are
                    also defined here, so if "help foo" tells you foo is
                    built-in, its source will be somewhere in this
                    directory.
-    DLD-FUNCTIONS  * Dynamically linked oct files. If you see "help foo"
+    DLD-FUNCTIONS  * Dynamically linked oct files.  If you see "help foo"
                      telling you that foo is defined in foo.oct, then
                      foo.cc will be found here and contain the source
                      code.
@@ -184,7 +184,7 @@
 jwe@octave.org
 
 
-Last updated: Wed Sep 28 22:37:37 CDT 2011
+Last updated: Tue Nov 22 20:51:34 PST 2011
 
 
 ################################################################################
--- a/libcruft/arpack/module.mk	Tue Nov 29 05:16:09 2011 +0000
+++ b/libcruft/arpack/module.mk	Wed Dec 07 19:06:13 2011 -0500
@@ -29,7 +29,6 @@
   arpack/src/dnapps.f \
   arpack/src/dnaup2.f \
   arpack/src/dnaupd.f \
-  arpack/src/dnaupe.f \
   arpack/src/dnconv.f \
   arpack/src/dneigh.f \
   arpack/src/dneupd.f \
@@ -54,7 +53,6 @@
   arpack/src/snapps.f \
   arpack/src/snaup2.f \
   arpack/src/snaupd.f \
-  arpack/src/snaupe.f \
   arpack/src/snconv.f \
   arpack/src/sneigh.f \
   arpack/src/sneupd.f \
--- a/liboctave/Array.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/Array.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -84,7 +84,7 @@
 void
 Array<T>::clear (void)
 {
-  if (--rep->count <= 0)
+  if (--rep->count == 0)
     delete rep;
 
   rep = nil_rep ();
@@ -99,7 +99,7 @@
 void
 Array<T>::clear (const dim_vector& dv)
 {
-  if (--rep->count <= 0)
+  if (--rep->count == 0)
     delete rep;
 
   rep = new ArrayRep (dv.safe_numel ());
--- a/liboctave/Array.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/Array.h	Wed Dec 07 19:06:13 2011 -0500
@@ -110,8 +110,12 @@
     {
       if (rep->count > 1)
         {
-          --rep->count;
-          rep = new ArrayRep (slice_data, slice_len);
+          ArrayRep *r = new ArrayRep (slice_data, slice_len);
+
+          if (--rep->count == 0)
+            delete rep;
+          
+          rep = r;
           slice_data = rep->data;
         }
     }
@@ -152,10 +156,12 @@
 
   typename Array<T>::ArrayRep *nil_rep (void) const
     {
-      static typename Array<T>::ArrayRep *nr
-        = new typename Array<T>::ArrayRep ();
+      // NR was originally allocated with new, but that does not seem
+      // to be necessary since it will never be deleted.  So just use
+      // a static object instead.
 
-      return nr;
+      static typename Array<T>::ArrayRep nr;
+      return &nr;
     }
 
 public:
@@ -225,7 +231,7 @@
 
   ~Array (void)
     {
-      if (--rep->count <= 0)
+      if (--rep->count == 0)
         delete rep;
     }
 
@@ -233,7 +239,7 @@
     {
       if (this != &a)
         {
-          if (--rep->count <= 0)
+          if (--rep->count == 0)
             delete rep;
 
           rep = a.rep;
--- a/liboctave/CSparse.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/CSparse.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -579,7 +579,7 @@
 SparseComplexMatrix::column (octave_idx_type i) const
 {
   octave_idx_type nr = rows ();
-  ComplexColumnVector retval (nr);
+  ComplexColumnVector retval (nr, 0);
 
   for (octave_idx_type k = cidx (i); k < cidx (i+1); k++)
     retval(ridx (k)) = data (k);
--- a/liboctave/Makefile.am	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/Makefile.am	Wed Dec 07 19:06:13 2011 -0500
@@ -244,6 +244,7 @@
   randmtzig.h \
   randpoisson.h \
   regex-match.h \
+  singleton-cleanup.h \
   sparse-sort.h \
   sparse-util.h \
   statdefs.h \
@@ -452,6 +453,7 @@
   oct-uname.cc \
   pathsearch.cc \
   regex-match.cc \
+  singleton-cleanup.cc \
   sparse-sort.cc \
   sparse-util.cc \
   str-vec.cc \
--- a/liboctave/Sparse.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/Sparse.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -667,7 +667,7 @@
 template <class T>
 Sparse<T>::~Sparse (void)
 {
-  if (--rep->count <= 0)
+  if (--rep->count == 0)
     delete rep;
 }
 
@@ -677,7 +677,7 @@
 {
   if (this != &a)
     {
-      if (--rep->count <= 0)
+      if (--rep->count == 0)
         delete rep;
 
       rep = a.rep;
--- a/liboctave/Sparse.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/Sparse.h	Wed Dec 07 19:06:13 2011 -0500
@@ -147,8 +147,12 @@
     {
       if (rep->count > 1)
         {
-          --rep->count;
-          rep = new SparseRep (*rep);
+          SparseRep *r = new SparseRep (*rep);
+
+          if (--rep->count == 0)
+            delete rep;
+
+          rep = r;
         }
     }
 
@@ -165,18 +169,17 @@
 
   typename Sparse<T>::SparseRep *nil_rep (void) const
     {
-      static typename Sparse<T>::SparseRep *nr
-        = new typename Sparse<T>::SparseRep ();
-
-      nr->count++;
-
-      return nr;
+      static typename Sparse<T>::SparseRep nr;
+      return &nr;
     }
 
 public:
 
   Sparse (void)
-    : rep (nil_rep ()), dimensions (dim_vector(0,0)) { }
+    : rep (nil_rep ()), dimensions (dim_vector(0,0))
+    {
+      rep->count++;
+    }
 
   explicit Sparse (octave_idx_type n)
     : rep (new typename Sparse<T>::SparseRep (n)),
--- a/liboctave/SparseCmplxQR.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/SparseCmplxQR.h	Wed Dec 07 19:06:13 2011 -0500
@@ -96,7 +96,7 @@
 
   ~SparseComplexQR (void)
     {
-      if (--rep->count <= 0)
+      if (--rep->count == 0)
         delete rep;
     }
 
@@ -104,7 +104,7 @@
     {
       if (this != &a)
         {
-          if (--rep->count <= 0)
+          if (--rep->count == 0)
             delete rep;
 
           rep = a.rep;
--- a/liboctave/SparseQR.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/SparseQR.h	Wed Dec 07 19:06:13 2011 -0500
@@ -98,7 +98,7 @@
 
   ~SparseQR (void)
     {
-      if (--rep->count <= 0)
+      if (--rep->count == 0)
         delete rep;
     }
 
@@ -106,7 +106,7 @@
     {
       if (this != &a)
         {
-          if (--rep->count <= 0)
+          if (--rep->count == 0)
             delete rep;
 
           rep = a.rep;
--- a/liboctave/cmd-edit.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/cmd-edit.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -42,6 +42,7 @@
 #include "oct-env.h"
 #include "oct-mutex.h"
 #include "oct-time.h"
+#include "singleton-cleanup.h"
 
 command_editor *command_editor::instance = 0;
 
@@ -831,7 +832,12 @@
   bool retval = true;
 
   if (! instance)
-    make_command_editor ();
+    {
+      make_command_editor ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
@@ -1227,6 +1233,12 @@
 }
 
 void
+command_editor::run_event_hooks (void)
+{
+  event_handler ();
+}
+
+void
 command_editor::read_init_file (const std::string& file_arg)
 {
   if (instance_ok ())
--- a/liboctave/cmd-edit.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/cmd-edit.h	Wed Dec 07 19:06:13 2011 -0500
@@ -137,6 +137,8 @@
 
   static void remove_event_hook (event_hook_fcn f);
 
+  static void run_event_hooks (void);
+
   static void read_init_file (const std::string& file = std::string ());
 
   static void re_read_init_file (void);
@@ -182,6 +184,8 @@
   // The real thing.
   static command_editor *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
 protected:
 
   // To use something other than the GNU readline library, derive a new
--- a/liboctave/cmd-hist.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/cmd-hist.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -49,6 +49,7 @@
 #include "oct-rl-hist.h"
 
 #include "file-stat.h"
+#include "singleton-cleanup.h"
 
 class
 gnu_history : public command_history
@@ -467,7 +468,12 @@
   bool retval = true;
 
   if (! instance)
-    make_command_history ();
+    {
+      make_command_history ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
--- a/liboctave/cmd-hist.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/cmd-hist.h	Wed Dec 07 19:06:13 2011 -0500
@@ -126,6 +126,8 @@
   // The real thing.
   static command_history *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
 protected:
 
   // To use something other than the GNU history library, derive a new
--- a/liboctave/dSparse.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/dSparse.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -585,7 +585,7 @@
 SparseMatrix::column (octave_idx_type i) const
 {
   octave_idx_type nr = rows ();
-  ColumnVector retval (nr);
+  ColumnVector retval (nr, 0);
 
   for (octave_idx_type k = cidx (i); k < cidx (i+1); k++)
     retval(ridx (k)) = data (k);
--- a/liboctave/dim-vector.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/dim-vector.h	Wed Dec 07 19:06:13 2011 -0500
@@ -32,6 +32,7 @@
 
 #include "lo-error.h"
 #include "lo-macros.h"
+#include "oct-refcount.h"
 
 // Rationale: This implementation is more tricky than Array, but the
 // big plus is that dim_vector requires only one allocation instead of
@@ -128,8 +129,12 @@
   {
     if (count () > 1)
       {
-        --count();
-        rep = clonerep ();
+	octave_idx_type *new_rep = clonerep ();
+
+	if (OCTREFCOUNT_ATOMIC_DECREMENT(&(count())) == 0)
+	  freerep ();
+
+        rep = new_rep;
       }
   }
 
@@ -222,9 +227,11 @@
 
   static octave_idx_type dim_max (void);
 
-  explicit dim_vector (void) : rep (nil_rep ()) { count()++; }
+  explicit dim_vector (void) : rep (nil_rep ())
+  { OCTREFCOUNT_ATOMIC_INCREMENT (&(count())); }
 
-  dim_vector (const dim_vector& dv) : rep (dv.rep) { count()++; }
+  dim_vector (const dim_vector& dv) : rep (dv.rep)
+  { OCTREFCOUNT_ATOMIC_INCREMENT (&(count())); }
 
   static dim_vector alloc (int n)
   {
@@ -235,11 +242,11 @@
   {
     if (&dv != this)
       {
-        if (--count() <= 0)
+        if (OCTREFCOUNT_ATOMIC_DECREMENT (&(count())) == 0)
           freerep ();
 
         rep = dv.rep;
-        count()++;
+        OCTREFCOUNT_ATOMIC_INCREMENT (&(count()));
       }
 
     return *this;
@@ -247,7 +254,7 @@
 
   ~dim_vector (void)
   {
-    if (--count() <= 0)
+    if (OCTREFCOUNT_ATOMIC_DECREMENT (&(count())) == 0)
       freerep ();
   }
 
@@ -265,7 +272,7 @@
       {
         octave_idx_type *r = resizerep (n, fill_value);
 
-        if (--count() <= 0)
+        if (OCTREFCOUNT_ATOMIC_DECREMENT (&(count())) == 0)
           freerep ();
 
         rep = r;
--- a/liboctave/file-ops.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/file-ops.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -42,11 +42,12 @@
 #include "file-ops.h"
 #include "file-stat.h"
 #include "oct-env.h"
+#include "oct-locbuf.h"
 #include "oct-passwd.h"
 #include "pathlen.h"
 #include "quit.h"
+#include "singleton-cleanup.h"
 #include "str-vec.h"
-#include "oct-locbuf.h"
 
 file_ops *file_ops::instance = 0;
 
@@ -73,13 +74,16 @@
       instance = new file_ops (system_dir_sep_char, system_dir_sep_str,
                                system_dir_sep_chars);
 
-      if (! instance)
-        {
-          (*current_liboctave_error_handler)
-            ("unable to create file_ops object!");
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
-          retval = false;
-        }
+  if (! instance)
+    {
+      (*current_liboctave_error_handler)
+        ("unable to create file_ops object!");
+
+      retval = false;
     }
 
   return retval;
--- a/liboctave/file-ops.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/file-ops.h	Wed Dec 07 19:06:13 2011 -0500
@@ -99,6 +99,8 @@
 
   static file_ops *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   // No copying!
 
   file_ops (const file_ops&);
--- a/liboctave/mach-info.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/mach-info.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -27,6 +27,7 @@
 #include "f77-fcn.h"
 #include "lo-error.h"
 #include "mach-info.h"
+#include "singleton-cleanup.h"
 
 extern "C"
 {
@@ -163,7 +164,12 @@
   bool retval = true;
 
   if (! instance)
-    instance = new oct_mach_info ();
+    {
+      instance = new oct_mach_info ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
--- a/liboctave/mach-info.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/mach-info.h	Wed Dec 07 19:06:13 2011 -0500
@@ -61,6 +61,8 @@
 
   static oct_mach_info *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   // The floating point format for the current machine.
   mutable float_format native_float_fmt;
 
--- a/liboctave/oct-env.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/oct-env.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -58,6 +58,7 @@
 #include "oct-env.h"
 #include "oct-passwd.h"
 #include "oct-syscalls.h"
+#include "singleton-cleanup.h"
 
 octave_env::octave_env (void)
   : follow_symbolic_links (true), verbatim_pwd (true),
@@ -81,7 +82,12 @@
   bool retval = true;
 
   if (! instance)
-    instance = new octave_env ();
+    {
+      instance = new octave_env ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
--- a/liboctave/oct-env.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/oct-env.h	Wed Dec 07 19:06:13 2011 -0500
@@ -115,6 +115,9 @@
   // The real thing.
   static octave_env *instance;
 
+
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   // TRUE means follow symbolic links that point to directories just
   // as if they are real directories.
   bool follow_symbolic_links;
--- a/liboctave/oct-fftw.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/oct-fftw.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -33,6 +33,7 @@
 #include "oct-fftw.h"
 #include "quit.h"
 #include "oct-locbuf.h"
+#include "singleton-cleanup.h"
 
 octave_fftw_planner *octave_fftw_planner::instance = 0;
 
@@ -75,7 +76,12 @@
   bool retval = true;
 
   if (! instance)
-    instance = new octave_fftw_planner ();
+    {
+      instance = new octave_fftw_planner ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
@@ -383,7 +389,12 @@
   bool retval = true;
 
   if (! instance)
-    instance = new octave_float_fftw_planner ();
+    {
+      instance = new octave_float_fftw_planner ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
--- a/liboctave/oct-fftw.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/oct-fftw.h	Wed Dec 07 19:06:13 2011 -0500
@@ -108,6 +108,8 @@
 
   static octave_fftw_planner *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   fftw_plan
   do_create_plan (int dir, const int rank, const dim_vector dims,
                   octave_idx_type howmany, octave_idx_type stride,
@@ -243,6 +245,8 @@
 
   static octave_float_fftw_planner *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   fftwf_plan
   do_create_plan (int dir, const int rank, const dim_vector dims,
                   octave_idx_type howmany, octave_idx_type stride,
--- a/liboctave/oct-locbuf.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/oct-locbuf.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -25,44 +25,55 @@
 #endif
 
 #include <iostream>
+
+#include "lo-error.h"
 #include "oct-locbuf.h"
 
-// Query for configured chunk size, and if not defined, set it to 32 MB.
-// FIXME: 32MB is hard-coded. Maybe we could use something better, like
-// querying for available physical memory.
+// FIXME -- Maybe we should querying for available physical memory?
+
 #ifndef OCTAVE_LOCBUF_CHUNKSIZE_MB
 #define OCTAVE_LOCBUF_CHUNKSIZE_MB 32
 #endif
 
 // Each chunk will be at least this big.
+
 const size_t octave_chunk_buffer::chunk_size =
   static_cast<size_t> (OCTAVE_LOCBUF_CHUNKSIZE_MB) << 20;
 
-char *octave_chunk_buffer::top = 0, *octave_chunk_buffer::chunk = 0;
+char *octave_chunk_buffer::top = 0;
+char *octave_chunk_buffer::chunk = 0;
 size_t octave_chunk_buffer::left = 0;
+size_t octave_chunk_buffer::active = 0;
 
 octave_chunk_buffer::octave_chunk_buffer (size_t size) : cnk (0), dat (0)
 {
-  // Alignment mask. The size of double or long int, whichever is greater.
-  // All data will be aligned to this size. If it's not enough for a type,
-  // that type should not be declared as POD.
+  // Alignment mask. The size of double or long int, whichever is
+  // greater.  All data will be aligned to this size.  If it's not
+  // enough for a type, that type should not be declared as POD.
+
   static const size_t align_mask = (sizeof (long) < sizeof (double)
                                     ? sizeof (double)
                                     : sizeof (long)) - 1;
 
-  if (! size) return;
+  active++;
+
+  if (! size)
+    return;
+
   // Align size. Note that size_t is unsigned, so size-1 must correctly
   // wrap around.
+
   size = ((size - 1) | align_mask) + 1;
 
   if (size > left)
     {
       // Big buffers (> 1/8 chunk) will be allocated as stand-alone and
       // won't disrupt the chain.
+
       if (size > chunk_size >> 3)
         {
-          // Use new [] to get std::bad_alloc if out of memory. Could as
-          // well be std::malloc and handle that ourselves.
+          // Use new [] to get std::bad_alloc if out of memory.
+
           dat = new char [size];
           return;
         }
@@ -73,6 +84,7 @@
     }
 
   // Now allocate memory from the chunk and update state.
+
   cnk = chunk;
   dat = top;
   left -= size;
@@ -81,24 +93,55 @@
 
 octave_chunk_buffer::~octave_chunk_buffer (void)
 {
+  active--;
+
   if (cnk == chunk)
     {
-      // Our chunk is still the active one. Just restore the state.
+      // Our chunk is still the active one.  Just restore the state.
+
       left += top - dat;
       top = dat;
     }
-  else if (! cnk)
+  else
     {
-      // We were a stand-alone buffer.
-      delete [] dat;
+      if (cnk)
+        {
+          // Responsible for deletion.
+
+          delete [] chunk;
+          chunk = cnk;
+          top = dat;
+
+          // FIXME -- the following calcuation of remaining data will
+          // only work if each chunk has the same chunk_size.
+
+          left = chunk_size - (dat - cnk);
+        }
+      else
+        {
+          // We were a stand-alone buffer.
+
+          delete [] dat;
+        }
+    }
+}
+
+// Clear the final chunk of allocated memory.
+
+void
+octave_chunk_buffer::clear (void)
+{
+  if (active == 0)
+    {
+      delete [] chunk;
+      chunk = 0;
+      top = 0;
+      left = 0;
     }
   else
     {
-      // Responsible for deletion.
-      delete [] chunk;
-      chunk = cnk;
-      top = dat;
-      // FIXME: This will only work if chunk_size is constant.
-      left = chunk_size - (dat - cnk);
+      (*current_liboctave_warning_handler)
+        ("octave_chunk_buffer::clear: %d active allocations remain!",
+         active);
     }
 }
--- a/liboctave/oct-locbuf.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/oct-locbuf.h	Wed Dec 07 19:06:13 2011 -0500
@@ -26,8 +26,9 @@
 #include <cstddef>
 #include "oct-cmplx.h"
 
-// The default local buffer simply encapsulates an *array* pointer that gets
-// delete[]d automatically. For common POD types, we provide specializations.
+// The default local buffer simply encapsulates an *array* pointer
+// that gets deleted automatically.  For common POD types, we provide
+// specializations.
 
 template <class T>
 class octave_local_buffer
@@ -50,16 +51,17 @@
   octave_local_buffer& operator = (const octave_local_buffer&);
 };
 
-// For buffers of POD types, we'll be more smart. There is one thing that
-// differentiates a local buffer from a dynamic array - the local buffers, if
-// not manipulated improperly, have a FIFO semantics, meaning that if buffer B
-// is allocated after buffer A, B *must* be deallocated before A. This is
-// *guaranteed* if you use local buffer exclusively through the
-// OCTAVE_LOCAL_BUFFER macro, because the C++ standard *mandates* explicit
-// local objects be destroyed in reverse order of declaration.
-// Therefore, we can avoid memory fragmentation by allocating fairly large
-// chunks of memory and serving local buffers from them in a stack-like manner.
-// The first returning buffer in previous chunk will be responsible for
+// For buffers of POD types, we'll be smarter.  There is one thing
+// that differentiates a local buffer from a dynamic array - the local
+// buffers, if not manipulated improperly, have a FIFO semantics,
+// meaning that if buffer B is allocated after buffer A, B *must* be
+// deallocated before A.  This is *guaranteed* if you use local buffer
+// exclusively through the OCTAVE_LOCAL_BUFFER macro, because the C++
+// standard requires that explicit local objects be destroyed in
+// reverse order of declaration.  Therefore, we can avoid memory
+// fragmentation by allocating fairly large chunks of memory and
+// serving local buffers from them in a stack-like manner.  The first
+// returning buffer in previous chunk will be responsible for
 // deallocating the chunk.
 
 class octave_chunk_buffer
@@ -72,13 +74,30 @@
 
   char *data (void) const { return dat; }
 
+  static OCTAVE_API void clear (void);
+
 private:
+
+  // The number of bytes we allocate for each large chunk of memory we
+  // manage.
   static const size_t chunk_size;
 
-  static char *top, *chunk;
+  // Pointer to the end end of the last allocation.
+  static char *top;
+
+  // Pointer to the current active chunk.
+  static char *chunk;
+
+  // The number of bytes remaining in the active chunk.
   static size_t left;
 
+  // The number of active allocations.
+  static size_t active;
+
+  // Pointer to the current chunk.
   char *cnk;
+
+  // Pointer to the beginning of the most recent allocation.
   char *dat;
 
   // No copying!
@@ -86,8 +105,8 @@
   octave_chunk_buffer& operator = (const octave_chunk_buffer&);
 };
 
-// This specializes octave_local_buffer to use the chunked buffer mechanism
-// for POD types.
+// This specializes octave_local_buffer to use the chunked buffer
+// mechanism for POD types.
 #define SPECIALIZE_POD_BUFFER(TYPE) \
 template <> \
 class octave_local_buffer<TYPE> : private octave_chunk_buffer \
@@ -143,32 +162,37 @@
   }
 };
 
-// If the compiler supports dynamic stack arrays, we can use the attached hack
-// to place small buffer arrays on the stack. It may be even faster than our
-// obstack-like optimization, but is dangerous because stack is a very limited
-// resource, so we disable it.
-#if 0 //defined (HAVE_DYNAMIC_AUTO_ARRAYS)
+// If the compiler supports dynamic stack arrays, we can use the
+// attached hack to place small buffer arrays on the stack. It may be
+// even faster than our obstack-like optimization, but is dangerous
+// because stack is a very limited resource, so we disable it.
+
+#if 0 // defined (HAVE_DYNAMIC_AUTO_ARRAYS)
 
 // Maximum buffer size (in bytes) to be placed on the stack.
 
 #define OCTAVE_LOCAL_BUFFER_MAX_STACK_SIZE 8192
 
-// If we have automatic arrays, we use an automatic array if the size is small
-// enough.  To avoid possibly evaluating `size' multiple times, we first cache
-// it.  Note that we always construct both the stack array and the
-// octave_local_buffer object, but only one of them will be nonempty.
+// If we have automatic arrays, we use an automatic array if the size
+// is small enough.  To avoid possibly evaluating `size' multiple
+// times, we first cache it.  Note that we always construct both the
+// stack array and the octave_local_buffer object, but only one of
+// them will be nonempty.
 
 #define OCTAVE_LOCAL_BUFFER(T, buf, size) \
   const size_t _bufsize_ ## buf = size; \
   const bool _lbufaut_ ## buf = _bufsize_ ## buf * sizeof (T) \
      <= OCTAVE_LOCAL_BUFFER_MAX_STACK_SIZE; \
   T _bufaut_ ## buf [_lbufaut_ ## buf ? _bufsize_ ## buf : 0]; \
-  octave_local_buffer<T> _bufheap_ ## buf (!_lbufaut_ ## buf ? _bufsize_ ## buf : 0); \
-  T *buf = _lbufaut_ ## buf ? _bufaut_ ## buf : static_cast<T *> (_bufheap_ ## buf)
+  octave_local_buffer<T> _bufheap_ ## buf \
+    (!_lbufaut_ ## buf ? _bufsize_ ## buf : 0); \
+  T *buf = _lbufaut_ ## buf \
+    ? _bufaut_ ## buf : static_cast<T *> (_bufheap_ ## buf)
 
 #else
 
-// If we don't have automatic arrays, we simply always use octave_local_buffer.
+// If we don't have automatic arrays, we simply always use
+// octave_local_buffer.
 
 #define OCTAVE_LOCAL_BUFFER(T, buf, size) \
   octave_local_buffer<T> _buffer_ ## buf (size); \
@@ -176,13 +200,14 @@
 
 #endif
 
-// Yeah overloading macros would be nice.
-// Note: we use weird variables in the for loop to avoid warnings about
-// shadowed parameters.
+// Note: we use weird variables in the for loop to avoid warnings
+// about shadowed parameters.
+
 #define OCTAVE_LOCAL_BUFFER_INIT(T, buf, size, value) \
   OCTAVE_LOCAL_BUFFER(T, buf, size); \
   for (size_t _buf_iter = 0, _buf_size = size; \
-       _buf_iter < _buf_size; _buf_iter++) buf[_buf_iter] = value
+        _buf_iter < _buf_size; _buf_iter++) \
+    buf[_buf_iter] = value
 
 #endif
 
--- a/liboctave/oct-mutex.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/oct-mutex.h	Wed Dec 07 19:06:13 2011 -0500
@@ -23,6 +23,8 @@
 #if !defined (octave_octave_mutex_h)
 #define octave_octave_mutex_h 1
 
+#include "oct-refcount.h"
+
 class octave_mutex;
 
 class
@@ -42,7 +44,7 @@
   virtual bool try_lock (void);
 
 private:
-  int count;
+  octave_refcount<int> count;
 };
 
 class
--- a/liboctave/oct-norm.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/oct-norm.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -57,9 +57,10 @@
 #include "floatSVD.h"
 #include "fCmplxSVD.h"
 
-// Theory: norm accumulator is an object that has an accum method able to handle
-// both real and complex element, and a cast operator returning the intermediate
-// norm.
+// Theory: norm accumulator is an object that has an accum method able
+// to handle both real and complex element, and a cast operator
+// returning the intermediate norm. Reference: Higham, N. "Estimating
+// the Matrix p-Norm." Numer. Math. 62, 539-555, 1992.
 
 // norm accumulator for the p-norm
 template <class R>
--- a/liboctave/oct-rand.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/oct-rand.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -29,18 +29,19 @@
 
 #include <stdint.h>
 
+#include "data-conv.h"
 #include "f77-fcn.h"
+#include "lo-error.h"
 #include "lo-ieee.h"
-#include "lo-error.h"
 #include "lo-mappers.h"
+#include "mach-info.h"
+#include "oct-locbuf.h"
 #include "oct-rand.h"
 #include "oct-time.h"
-#include "data-conv.h"
+#include "randgamma.h"
 #include "randmtzig.h"
 #include "randpoisson.h"
-#include "randgamma.h"
-#include "mach-info.h"
-#include "oct-locbuf.h"
+#include "singleton-cleanup.h"
 
 extern "C"
 {
@@ -89,7 +90,12 @@
   bool retval = true;
 
   if (! instance)
-    instance = new octave_rand ();
+    {
+      instance = new octave_rand ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
--- a/liboctave/oct-rand.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/oct-rand.h	Wed Dec 07 19:06:13 2011 -0500
@@ -160,6 +160,8 @@
 
   static octave_rand *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   enum
   {
     unknown_dist,
--- a/liboctave/oct-refcount.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/oct-refcount.h	Wed Dec 07 19:06:13 2011 -0500
@@ -23,6 +23,30 @@
 #if !defined (octave_refcount_h)
 #define octave_refcount_h 1
 
+#ifndef OCTAVE_CONFIG_INCLUDED
+# error "The file <octave/config.h> must be included before oct-refcount.h."
+#endif
+
+#if defined (USE_ATOMIC_REFCOUNT) && (defined (_MSC_VER) || defined (__GNUC__))
+# if defined (_MSC_VER)
+#  include <intrin.h>
+#  define OCTREFCOUNT_ATOMIC_INCREMENT(x) _InterlockedIncrement((long*)x)
+#  define OCTREFCOUNT_ATOMIC_DECREMENT(x) _InterlockedDecrement((long*)x)
+#  define OCTREFCOUNT_ATOMIC_INCREMENT_POST(x) _InterlockedExchangeAdd((long*)x,  1)
+#  define OCTREFCOUNT_ATOMIC_DECREMENT_POST(x) _InterlockedExchangeAdd((long*)x, -1)
+# elif defined (__GNUC__)
+#  define OCTREFCOUNT_ATOMIC_INCREMENT(x) __sync_add_and_fetch(x,  1)
+#  define OCTREFCOUNT_ATOMIC_DECREMENT(x) __sync_add_and_fetch(x, -1)
+#  define OCTREFCOUNT_ATOMIC_INCREMENT_POST(x) __sync_fetch_and_add(x,  1)
+#  define OCTREFCOUNT_ATOMIC_DECREMENT_POST(x) __sync_fetch_and_add(x, -1)
+# endif
+#else // Generic non-locking versions
+# define OCTREFCOUNT_ATOMIC_INCREMENT(x) ++(*(x))
+# define OCTREFCOUNT_ATOMIC_DECREMENT(x) --(*(x))
+# define OCTREFCOUNT_ATOMIC_INCREMENT_POST(x) (*(x))++
+# define OCTREFCOUNT_ATOMIC_DECREMENT_POST(x) (*(x))--
+#endif
+
 // Encapsulates a reference counter.
 template <class T>
 class octave_refcount
@@ -35,28 +59,28 @@
   // Increment/Decrement. int is postfix.
   count_type operator++(void)
     {
-      return ++count;
+      return OCTREFCOUNT_ATOMIC_INCREMENT (&count);
     }
 
   count_type operator++(int)
     {
-      return count++;
+      return OCTREFCOUNT_ATOMIC_INCREMENT_POST (&count);
     }
 
   count_type operator--(void)
     {
-      return --count;
+      return OCTREFCOUNT_ATOMIC_DECREMENT (&count);
     }
 
   count_type operator--(int)
     {
-      return count--;
+      return OCTREFCOUNT_ATOMIC_DECREMENT_POST (&count);
     }
 
-  operator count_type (void) const { return count; }
-
-  // For low-level optimizations only.
-  count_type& direct (void) const { return count; }
+  operator count_type (void) const
+    {
+      return static_cast<count_type const volatile&> (count);
+    }
 
 private:
   count_type count;
--- a/liboctave/oct-spparms.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/oct-spparms.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -29,6 +29,7 @@
 #include "lo-ieee.h"
 
 #include "oct-spparms.h"
+#include "singleton-cleanup.h"
 
 octave_sparse_params *octave_sparse_params::instance = 0;
 
@@ -38,7 +39,12 @@
   bool retval = true;
 
   if (! instance)
-    instance = new octave_sparse_params ();
+    {
+      instance = new octave_sparse_params ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
--- a/liboctave/oct-spparms.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/oct-spparms.h	Wed Dec 07 19:06:13 2011 -0500
@@ -95,6 +95,8 @@
 
   static octave_sparse_params *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   void do_defaults (void);
 
   void do_tight (void);
--- a/liboctave/oct-time.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/oct-time.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -36,6 +36,7 @@
 #include "lo-error.h"
 #include "lo-math.h"
 #include "lo-utils.h"
+#include "oct-locbuf.h"
 #include "oct-time.h"
 
 octave_time::octave_time (const octave_base_tm& tm)
@@ -53,6 +54,10 @@
   t.tm_yday = tm.yday ();
   t.tm_isdst = tm.isdst ();
 
+#if defined (HAVE_STRUCT_TM_GMTOFF)
+  t.tm_gmtoff = tm.gmtoff ();
+#endif
+
 #if defined (HAVE_STRUCT_TM_TM_ZONE)
   std::string s = tm.zone ();
   char *ps = strsave (s.c_str ());
@@ -98,29 +103,17 @@
 //
 // So, we no longer check limits here.
 
-#if 0
-#define DEFINE_SET_INT_FIELD_FCN(f, lo, hi) \
+#define DEFINE_SET_FIELD_FCN(type, f, lo, hi) \
   octave_base_tm& \
-  octave_base_tm::f (int v) \
-  { \
-    if (v < lo || v > hi) \
-      (*current_liboctave_error_handler) \
-        ("invalid value specified for " #f); \
- \
-    tm_ ## f = v; \
- \
-    return *this; \
-  }
-#else
-#define DEFINE_SET_INT_FIELD_FCN(f, lo, hi) \
-  octave_base_tm& \
-  octave_base_tm::f (int v) \
+  octave_base_tm::f (type v) \
   { \
     tm_ ## f = v; \
  \
     return *this; \
   }
-#endif
+
+#define DEFINE_SET_INT_FIELD_FCN(f, lo, hi) \
+  DEFINE_SET_FIELD_FCN (int, f, lo, hi)
 
 DEFINE_SET_INT_FIELD_FCN (usec, 0, 1000000)
 DEFINE_SET_INT_FIELD_FCN (sec, 0, 61)
@@ -132,6 +125,7 @@
 DEFINE_SET_INT_FIELD_FCN (wday, 0, 6)
 DEFINE_SET_INT_FIELD_FCN (yday, 0, 365)
 DEFINE_SET_INT_FIELD_FCN (isdst, 0, 1)
+DEFINE_SET_FIELD_FCN (long, gmtoff, -86400, 0)
 
 octave_base_tm&
 octave_base_tm::zone (const std::string& s)
@@ -163,6 +157,10 @@
       t.tm_yday = tm_yday;
       t.tm_isdst = tm_isdst;
 
+#if defined (HAVE_STRUCT_TM_GMTOFF)
+      t.tm_gmtoff = tm_gmtoff;
+#endif
+
 #if defined (HAVE_STRUCT_TM_TM_ZONE)
       char *ps = strsave (tm_zone.c_str ());
       t.tm_zone = ps;
@@ -215,6 +213,10 @@
   tm_yday = t->tm_yday;
   tm_isdst = t->tm_isdst;
 
+#if defined (HAVE_STRUCT_TM_GMTOFF)
+  tm_gmtoff = t->tm_gmtoff;
+#endif
+
 #if defined (HAVE_STRUCT_TM_TM_ZONE)
   if (t->tm_zone)
     tm_zone = t->tm_zone;
@@ -259,12 +261,16 @@
   t.tm_yday = 0;
   t.tm_isdst = 0;
 
+#if defined (HAVE_STRUCT_TM_GMTOFF)
+  t.tm_gmtoff = 0;
+#endif
+
 #if defined (HAVE_STRUCT_TM_TM_ZONE)
   char *ps = strsave ("");
   t.tm_zone = ps;
 #endif
 
-  char *p = strsave (str.c_str ());
+  const char *p = str.c_str ();
 
   char *q = gnulib::strptime (p, fmt.c_str (), &t);
 
@@ -287,8 +293,6 @@
   else
     nchars = 0;
 
-  delete [] p;
-
   octave_base_tm::init (&t);
 
 #if defined (HAVE_STRUCT_TM_TM_ZONE)
--- a/liboctave/oct-time.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/oct-time.h	Wed Dec 07 19:06:13 2011 -0500
@@ -174,14 +174,14 @@
   octave_base_tm (void)
     : tm_usec (0), tm_sec (0), tm_min (0), tm_hour (0),
       tm_mday (0), tm_mon (0), tm_year (0), tm_wday (0),
-      tm_yday (0), tm_isdst (0), tm_zone ("unknown")
+      tm_yday (0), tm_isdst (0), tm_gmtoff (0), tm_zone ("unknown")
   { }
 
   octave_base_tm (const octave_base_tm& tm)
     : tm_usec (tm.tm_usec), tm_sec (tm.tm_sec), tm_min (tm.tm_min),
       tm_hour (tm.tm_hour), tm_mday (tm.tm_mday), tm_mon (tm.tm_mon),
       tm_year (tm.tm_year), tm_wday (tm.tm_wday), tm_yday (tm.tm_yday),
-      tm_isdst (tm.tm_isdst), tm_zone (tm.tm_zone)
+      tm_isdst (tm.tm_isdst), tm_gmtoff (tm.tm_gmtoff), tm_zone (tm.tm_zone)
   { }
 
   octave_base_tm& operator = (const octave_base_tm& tm)
@@ -198,6 +198,7 @@
         tm_wday = tm.tm_wday;
         tm_yday = tm.tm_yday;
         tm_isdst = tm.tm_isdst;
+        tm_gmtoff = tm.tm_gmtoff;
         tm_zone = tm.tm_zone;
       }
 
@@ -216,6 +217,7 @@
   int wday (void) const { return tm_wday; }
   int yday (void) const { return tm_yday; }
   int isdst (void) const { return tm_isdst; }
+  long gmtoff (void) const { return tm_gmtoff; }
   std::string zone (void) const { return tm_zone; }
 
   octave_base_tm& usec (int v);
@@ -228,6 +230,7 @@
   octave_base_tm& wday (int v);
   octave_base_tm& yday (int v);
   octave_base_tm& isdst (int v);
+  octave_base_tm& gmtoff (long v);
   octave_base_tm& zone (const std::string& s);
 
   std::string strftime (const std::string& fmt) const;
@@ -268,6 +271,9 @@
   int tm_isdst;
 
   // Time zone.
+  long tm_gmtoff;
+
+  // Time zone.
   std::string tm_zone;
 
   void init (void *p);
--- a/liboctave/pathsearch.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/pathsearch.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -31,7 +31,7 @@
 #include "lo-utils.h"
 #include "oct-env.h"
 #include "pathsearch.h"
-#include "str-vec.h"
+#include "singleton-cleanup.h"
 #include "str-vec.h"
 
 #include "kpse.cc"
@@ -47,7 +47,12 @@
   bool retval = true;
 
   if (! instance)
-    instance = new static_members ();
+    {
+      instance = new static_members ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
--- a/liboctave/pathsearch.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/pathsearch.h	Wed Dec 07 19:06:13 2011 -0500
@@ -153,6 +153,8 @@
 
     static static_members *instance;
 
+    static void cleanup_instance (void) { delete instance; instance = 0; }
+
     static bool instance_ok (void);
 
     // No copying!
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/singleton-cleanup.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -0,0 +1,60 @@
+/*
+
+Copyright (C) 2011 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 3 of the License, 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, see
+<http://www.gnu.org/licenses/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <lo-error.h>
+#include <singleton-cleanup.h>
+
+singleton_cleanup_list *singleton_cleanup_list::instance = 0;
+
+singleton_cleanup_list::~singleton_cleanup_list (void)
+{
+  for (std::set<fptr>::iterator p = fcn_list.begin ();
+       p != fcn_list.end (); p++)
+    {
+      fptr fcn = *p;
+
+      fcn ();
+    }
+}
+
+bool
+singleton_cleanup_list::instance_ok (void)
+{
+  bool retval = true;
+
+  if (! instance)
+    instance = new singleton_cleanup_list ();
+
+  if (! instance)
+    {
+      current_liboctave_error_handler
+        ("unable to create singleton_cleanup_list object!");
+
+      retval = false;
+    }
+
+  return retval;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/singleton-cleanup.h	Wed Dec 07 19:06:13 2011 -0500
@@ -0,0 +1,50 @@
+#if !defined (octave_singleton_cleanup_h)
+#define octave_singleton_cleanup_h 1
+
+#include <set>
+
+class
+OCTAVE_API
+singleton_cleanup_list
+{
+protected:
+
+  singleton_cleanup_list (void) : fcn_list () { }
+
+public:
+
+  typedef void (*fptr) (void);
+
+  ~singleton_cleanup_list (void);
+
+  static void add (fptr f)
+  {
+    if (instance_ok ())
+      instance->do_add (f);
+  }
+
+  static void cleanup (void) { delete instance; instance = 0; }
+
+private:
+
+  static singleton_cleanup_list *instance;
+
+  static bool instance_ok (void);
+
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
+  std::set<fptr> fcn_list;
+
+  void do_add (fptr f)
+  {
+    fcn_list.insert (f);
+  }
+
+  // No copying!
+
+  singleton_cleanup_list (const singleton_cleanup_list&);
+
+  singleton_cleanup_list& operator = (const singleton_cleanup_list&);
+};
+
+#endif
--- a/liboctave/sparse-base-chol.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/liboctave/sparse-base-chol.h	Wed Dec 07 19:06:13 2011 -0500
@@ -178,7 +178,7 @@
 
   virtual ~sparse_base_chol (void)
     {
-      if (--rep->count <= 0)
+      if (--rep->count == 0)
         delete rep;
     }
 
@@ -186,7 +186,7 @@
     {
       if (this != &a)
         {
-          if (--rep->count <= 0)
+          if (--rep->count == 0)
             delete rep;
 
           rep = a.rep;
--- a/m4/acinclude.m4	Tue Nov 29 05:16:09 2011 +0000
+++ b/m4/acinclude.m4	Wed Dec 07 19:06:13 2011 -0500
@@ -370,7 +370,8 @@
   assert (in[0] == out[0] && in[1] == out[1]);
 ]])],
   [octave_cv_fortran_integer_size=yes],
-  [octave_cv_fortran_integer_size=no])
+  [octave_cv_fortran_integer_size=no],
+  [octave_cv_fortran_integer_size=yes])
   AC_LANG_POP(C)dnl
   LIBS="$octave_fintsize_save_LIBS"
 rm -f conftest.$ac_objext fintsize.$ac_objext
@@ -818,7 +819,7 @@
 }]])],
   octave_cv_ieee754_data_format=yes,
   octave_cv_ieee754_data_format=no,
-  octave_cv_ieee754_data_format=no)])
+  octave_cv_ieee754_data_format=yes)])
 if test "$cross_compiling" = yes; then
   AC_MSG_RESULT([$octave_cv_ieee754_data_format assumed for cross compilation])
 else
@@ -881,7 +882,7 @@
 ]])],
   octave_cv_umfpack_seperate_split=yes,
   octave_cv_umfpack_seperate_split=no,
-  octave_cv_umfpack_seperate_split=no)])
+  octave_cv_umfpack_seperate_split=yes)])
 if test "$cross_compiling" = yes; then
   AC_MSG_RESULT([$octave_cv_umfpack_seperate_split assumed for cross compilation])
 else
@@ -962,7 +963,10 @@
 coordT points[8] = { -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5 };
 boolT ismalloc = 0;
 return qh_new_qhull (dim, n, points, ismalloc, "qhull ", 0, stderr); 
-]])], [octave_cv_lib_qhull_ok=yes], [octave_cv_lib_qhull_ok=no])])
+]])],
+  [octave_cv_lib_qhull_ok=yes],
+  [octave_cv_lib_qhull_ok=no],
+  [octave_cv_lib_qhull_ok=yes])])
   if test "$octave_cv_lib_qhull_ok" = "yes"; then
     $1
   else
@@ -1337,9 +1341,10 @@
 dnl 4. Bit operations on signed integers work like on unsigned integers,
 dnl    except for the shifts. Shifts are arithmetic.
 dnl
-AC_DEFUN([OCTAVE_FAST_INT_OPS],[
-AC_MSG_CHECKING([whether fast integer arithmetics is usable])
-AC_LANG_PUSH(C++)
+AC_DEFUN([OCTAVE_FAST_INT_OPS],
+[AC_CACHE_CHECK([whether fast integer arithmetics is usable],
+octave_cv_fast_int_ops,
+[AC_LANG_PUSH(C++)
 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
 #include <limits>
 template<class UT, class ST>
@@ -1383,10 +1388,15 @@
   DO_TEST(long long)
 #endif
 ]])],
-[AC_MSG_RESULT([yes])
- AC_DEFINE(HAVE_FAST_INT_OPS,1,[Define if signed integers use two's complement])],
-[AC_MSG_RESULT([no])])
+   [octave_cv_fast_int_ops=yes],
+   [octave_cv_fast_int_ops=no],
+   [octave_cv_fast_int_ops=yes])
 AC_LANG_POP(C++)])
+if test $octave_cv_fast_int_ops = yes; then
+  AC_DEFINE(HAVE_FAST_INT_OPS, 1,
+    [Define if signed integers use two's complement])
+fi
+])
 dnl
 dnl Check to see if the compiler and the linker can handle the flags
 dnl "-framework $1" for the given prologue $2 and the given body $3 of
--- a/scripts/general/accumarray.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/general/accumarray.m	Wed Dec 07 19:06:13 2011 -0500
@@ -24,14 +24,14 @@
 ## Create an array by accumulating the elements of a vector into the
 ## positions defined by their subscripts.  The subscripts are defined by
 ## the rows of the matrix @var{subs} and the values by @var{vals}.  Each
-## row of @var{subs} corresponds to one of the values in @var{vals}. If
+## row of @var{subs} corresponds to one of the values in @var{vals}.  If
 ## @var{vals} is a scalar, it will be used for each of the row of
 ## @var{subs}.
 ##
 ## The size of the matrix will be determined by the subscripts
-## themselves. However, if @var{sz} is defined it determines the matrix
-## size. The length of @var{sz} must correspond to the number of columns
-## in @var{subs}. An exception is if @var{subs} has only one column, in
+## themselves.  However, if @var{sz} is defined it determines the matrix
+## size.  The length of @var{sz} must correspond to the number of columns
+## in @var{subs}.  An exception is if @var{subs} has only one column, in
 ## which case @var{sz} may be the dimensions of a vector and the subscripts
 ## of @var{subs} are taken as the indices into it.
 ##
@@ -42,14 +42,14 @@
 ## function should not depend on the order of the subscripts.
 ##
 ## The elements of the returned array that have no subscripts associated
-## with them are set to zero. Defining @var{fillval} to some other value
-## allows these values to be defined. This behaviour changes, however,
-## for certain values of @var{func}. If @var{func} is @code{min}
+## with them are set to zero.  Defining @var{fillval} to some other value
+## allows these values to be defined.  This behavior changes, however,
+## for certain values of @var{func}.  If @var{func} is @code{min}
 ## (respectively, @code{max}) then the result will be filled with the
 ## minimum (respectively, maximum) integer if @var{vals} is of integral
 ## type, logical false (respectively, logical true) if @var{vals} is of
 ## logical type, zero if @var{fillval} is zero and all values are
-## nonpositive (respectively, nonnegative), and NaN otherwise.
+## non-positive (respectively, non-negative), and NaN otherwise.
 ##
 ## By default @code{accumarray} returns a full matrix.  If
 ## @var{issparse} is logically true, then a sparse matrix is returned
@@ -57,7 +57,7 @@
 ##
 ## The following @code{accumarray} example constructs a frequency table
 ## that in the first column counts how many occurrences each number in
-## the second column has, taken from the vector @var{x}. Note the usage
+## the second column has, taken from the vector @var{x}.  Note the usage
 ## of @code{unique}  for assigning to all repeated elements of @var{x}
 ## the same index (@pxref{doc-unique}).
 ##
@@ -74,7 +74,7 @@
 ## @end group
 ## @end example
 ##
-## Another example, where the result is a multidimensional 3D array and
+## Another example, where the result is a multi-dimensional 3-D array and
 ## the default value (zero) appears in the output:
 ##
 ## @example
@@ -91,9 +91,9 @@
 ##
 ## The complexity in the non-sparse case is generally O(M+N), where N is
 ## the number of subscripts and M is the maximum subscript (linearized
-## in multi-dimensional case). If @var{func} is one of @code{@@sum}
+## in multi-dimensional case).  If @var{func} is one of @code{@@sum}
 ## (default), @code{@@max}, @code{@@min} or @code{@@(x) @{x@}}, an
-## optimized code path is used. Note that for general reduction function
+## optimized code path is used.  Note that for general reduction function
 ## the interpreter overhead can play a major part and it may be more
 ## efficient to do multiple accumarray calls and compute the results in
 ## a vectorized manner.
--- a/scripts/general/blkdiag.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/general/blkdiag.m	Wed Dec 07 19:06:13 2011 -0500
@@ -20,7 +20,7 @@
 ## @deftypefn {Function File} {} blkdiag (@var{A}, @var{B}, @var{C}, @dots{})
 ## Build a block diagonal matrix from @var{A}, @var{B}, @var{C}, @dots{}
 ## All the arguments must be numeric and are two-dimensional matrices or
-## scalars. If any argument is of type sparse, the output will also be
+## scalars.  If any argument is of type sparse, the output will also be
 ## sparse.
 ## @seealso{diag, horzcat, vertcat, sparse}
 ## @end deftypefn
--- a/scripts/general/nargoutchk.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/general/nargoutchk.m	Wed Dec 07 19:06:13 2011 -0500
@@ -25,11 +25,11 @@
 ## Check for correct number of output arguments.
 ##
 ## On the first form, returns an error unless the number of arguments in its
-## caller is between the values of @var{minargs} and @var{maxargs}. It does
-## nothing otherwise. Note that this function evaluates the value of
+## caller is between the values of @var{minargs} and @var{maxargs}.  It does
+## nothing otherwise.  Note that this function evaluates the value of
 ## @code{nargout} on the caller so its value must have not been tampered with.
 ##
-## Both @var{minargs} and @var{maxargs} need to be a numeric scalar. Zero, Inf
+## Both @var{minargs} and @var{maxargs} need to be a numeric scalar.  Zero, Inf
 ## and negative are all valid, and they can have the same value.
 ##
 ## For backward compatibility reasons, the other forms return an appropriate
--- a/scripts/general/nthargout.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/general/nthargout.m	Wed Dec 07 19:06:13 2011 -0500
@@ -20,10 +20,10 @@
 ## @deftypefn  {Function File} {} nthargout (@var{n}, @var{func}, @dots{})
 ## @deftypefnx {Function File} {} nthargout (@var{n}, @var{ntot}, @var{func}, @dots{})
 ## Return the @var{n}th output argument of function given by the
-## function handle or string @var{func}. Any arguments after @var{func}
-## are passed to @var{func}. The total number of arguments to call
+## function handle or string @var{func}.  Any arguments after @var{func}
+## are passed to @var{func}.  The total number of arguments to call
 ## @var{func} with can be passed in @var{ntot}; by default @var{ntot}
-## is @var{n}. The input @var{n} can also be a vector of indices of the
+## is @var{n}.  The input @var{n} can also be a vector of indices of the
 ## output, in which case the output will be a cell array of the
 ## requested output arguments.
 ##
--- a/scripts/general/profexplore.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/general/profexplore.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {} profexplore (@var{data})
+## @deftypefn {Function File} {} profexplore (@var{data})
 ## Interactively explore hierarchical profiler output.
 ##
 ## Assuming @var{data} is the structure with profile data returned by
--- a/scripts/general/profile.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/general/profile.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,10 +17,10 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {} profile on
-## @deftypefnx {Function File} {} profile off
-## @deftypefnx {Function File} {} profile resume
-## @deftypefnx {Function File} {} profile clear
+## @deftypefn  {Command} {} profile on
+## @deftypefnx {Command} {} profile off
+## @deftypefnx {Command} {} profile resume
+## @deftypefnx {Command} {} profile clear
 ## @deftypefnx {Function File} {@var{S} =} profile ('status')
 ## @deftypefnx {Function File} {@var{T} =} profile ('info')
 ## Control the built-in profiler.
--- a/scripts/geometry/voronoi.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/geometry/voronoi.m	Wed Dec 07 19:06:13 2011 -0500
@@ -36,7 +36,7 @@
 ## @url{http://www.qhull.org/html/qh-quick.htm#options}.
 ##
 ## If a single output argument is requested then the Voronoi diagram will be
-## plotted and a graphics handle to the plot is returned.
+## plotted and a graphics handle @var{h} to the plot is returned.
 ## [@var{vx}, @var{vy}] = voronoi(@dots{}) returns the Voronoi vertices
 ## instead of plotting the diagram.
 ##
--- a/scripts/help/unimplemented.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/help/unimplemented.m	Wed Dec 07 19:06:13 2011 -0500
@@ -330,7 +330,6 @@
   "quad2d",
   "questdlg",
   "rbbox",
-  "recycle",
   "reducepatch",
   "reducevolume",
   "resample",
--- a/scripts/image/image.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/image/image.m	Wed Dec 07 19:06:13 2011 -0500
@@ -19,6 +19,7 @@
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {} image (@var{img})
 ## @deftypefnx {Function File} {} image (@var{x}, @var{y}, @var{img})
+## @deftypefnx {Function File} {@var{h} =} image (@dots{})
 ## Display a matrix as a color image.  The elements of @var{img} are indices
 ## into the current colormap, and the colormap will be scaled so that the
 ## extremes of @var{img} are mapped to the extremes of the colormap.
@@ -35,6 +36,8 @@
 ## an image and an ordinary plot need to be overlaid.  The recommended
 ## solution is to display the image and then plot the reversed ydata
 ## using, for example, @code{flipud (ydata,1)}.
+##
+## The optional return value @var{h} is a graphics handle to the image.
 ## @seealso{imshow, imagesc, colormap}
 ## @end deftypefn
 
@@ -95,7 +98,7 @@
 ## Adapted-By: jwe
 
 function h = __img__ (x, y, img, varargin)
-
+  
   newplot ();
 
   if (isempty (img))
@@ -113,6 +116,15 @@
   xdata = [x(1), x(end)];
   ydata = [y(1), y(end)];
 
+  dx = diff (x);
+  dy = diff (y);
+  dx = std (dx) / mean (abs (dx));
+  dy = std (dy) / mean (abs (dy));
+  tol = 100*eps;
+  if (any (dx > tol) || any (dy > tol))
+    warning ("Image does not map to non-linearly spaced coordinates")
+  endif
+
   ca = gca ();
 
   tmp = __go_image__ (ca, "cdata", img, "xdata", xdata, "ydata", ydata,
--- a/scripts/image/imagesc.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/image/imagesc.m	Wed Dec 07 19:06:13 2011 -0500
@@ -32,6 +32,7 @@
 ## values for the respective axes, or as values for each row and column
 ## of the matrix @var{A}.
 ##
+## The optional return value @var{h} is a graphics handle to the image.
 ## @seealso{image, imshow, caxis}
 ## @end deftypefn
 
--- a/scripts/image/imshow.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/image/imshow.m	Wed Dec 07 19:06:13 2011 -0500
@@ -23,6 +23,7 @@
 ## @deftypefnx {Function File} {} imshow (@var{rgb}, @dots{})
 ## @deftypefnx {Function File} {} imshow (@var{filename})
 ## @deftypefnx {Function File} {} imshow (@dots{}, @var{string_param1}, @var{value1}, @dots{})
+## @deftypefnx {Function File} {@var{h} =} imshow (@dots{})
 ## Display the image @var{im}, where @var{im} can be a 2-dimensional
 ## (gray-scale image) or a 3-dimensional (RGB image) matrix.
 ##
@@ -44,6 +45,8 @@
 ## @item "displayrange"
 ## @var{value1} is the display range as described above.
 ## @end table
+##
+## The optional return value @var{h} is a graphics handle to the image.
 ## @seealso{image, imagesc, colormap, gray2ind, rgb2ind}
 ## @end deftypefn
 
--- a/scripts/io/fileread.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/io/fileread.m	Wed Dec 07 19:06:13 2011 -0500
@@ -49,8 +49,8 @@
 %!test
 %! cstr = {"Hello World", "The answer is 42", "Goodbye World"};
 %! fname = tmpnam ();
-%! fid = fopen (fname, "wt");
-%! fprintf(fid, "%s\n", cstr{:})
+%! fid = fopen (fname, "w");
+%! fprintf (fid, "%s\n", cstr{:})
 %! fclose (fid);
 %! str = fileread (fname);
 %! assert (str', [cstr{1} "\n" cstr{2} "\n" cstr{3} "\n"]);
--- a/scripts/linear-algebra/krylov.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/linear-algebra/krylov.m	Wed Dec 07 19:06:13 2011 -0500
@@ -28,8 +28,8 @@
 ## Using Householder reflections to guard against loss of orthogonality.
 ##
 ## If @var{V} is a vector, then @var{h} contains the Hessenberg matrix
-## such that @xcode{a*u == u*h+rk*ek'}, in which @code{rk =
-## a*u(:,k)-u*h(:,k)}, and @xcode{ek'} is the vector
+## such that @nospell{@xcode{a*u == u*h+rk*ek'}}, in which @code{rk =
+## a*u(:,k)-u*h(:,k)}, and @nospell{@xcode{ek'}} is the vector
 ## @code{[0, 0, @dots{}, 1]} of length @code{k}.  Otherwise, @var{h} is
 ## meaningless.
 ##
--- a/scripts/miscellaneous/computer.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/miscellaneous/computer.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {[@var{c}, @var{maxsize}, @var{endian}] =} computer ()
+## @deftypefn  {Function File} {[@var{c}, @var{maxsize}, @var{endian}] =} computer ()
 ## @deftypefnx {Function File} {@var{arch} =} computer ("arch")
 ## 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
--- a/scripts/miscellaneous/ls.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/miscellaneous/ls.m	Wed Dec 07 19:06:13 2011 -0500
@@ -46,38 +46,49 @@
     ls_command ();
   endif
 
-  if (iscellstr (varargin))
-
-    args = tilde_expand (varargin);
+  if (! iscellstr (varargin))
+    error ("ls: all arguments must be character strings");
+  endif
 
-    cmd = sprintf ("%s ", __ls_command__, args{:});
-
-    if (page_screen_output () || nargout > 0)
-
-      [status, output] = system (cmd);
+  if (nargin > 0)
+    args = tilde_expand (varargin);
+    if (ispc () && ! isunix ())
+      ## shell (cmd.exe) on MinGW uses '^' as escape character
+      args = regexprep (args, '([^\w.*? -])', '^$1');
+    else
+      args = regexprep (args, '([^\w.*? -])', '\$1');
+    endif
+    args = sprintf ("%s ", args{:});
+  else
+    args = "";
+  endif
 
-      if (status == 0)
-        if (nargout == 0)
-          puts (output);
-        else
-          retval = strvcat (regexp (output, '\S+', 'match'){:});
-        endif
-      else
-        error ("ls: command exited abnormally with status %d\n", status);
-      endif
+  cmd = sprintf ("%s %s", __ls_command__, args);
+
+  if (page_screen_output () || nargout > 0)
+    [status, output] = system (cmd);
 
+    if (status != 0)
+      error ("ls: command exited abnormally with status %d\n", status);
+    elseif (nargout == 0)
+      puts (output);
     else
-      ## Just let the output flow if the pager is off.  That way the
-      ## output from things like "ls -R /" will show up immediately and
-      ## we won't have to buffer all the output.
-      system (cmd);
+      retval = strvcat (regexp (output, '\S+', 'match'){:});
     endif
-
   else
-    error ("ls: expecting all arguments to be character strings");
+    ## Just let the output flow if the pager is off.  That way the
+    ## output from things like "ls -R /" will show up immediately and
+    ## we won't have to buffer all the output.
+    system (cmd);
   endif
 
 endfunction
 
+
+%!test
+%! list = ls ();
+%! assert (ischar (list));
+%! assert (! isempty (list));
+
 %!error ls (1);
 
--- a/scripts/miscellaneous/menu.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/miscellaneous/menu.m	Wed Dec 07 19:06:13 2011 -0500
@@ -42,38 +42,29 @@
   ## Don't send the menu through the pager since doing that can cause
   ## major confusion.
 
-  save_page_screen_output = page_screen_output ();
-
-  unwind_protect
-
-    page_screen_output (0);
+  page_screen_output (0, "local");
 
-    if (! isempty (title))
-      disp (title);
-      printf ("\n");
-    endif
+  if (! isempty (title))
+    disp (title);
+    printf ("\n");
+  endif
 
-    nopt = nargin - 1;
+  nopt = nargin - 1;
 
-    while (1)
-      for i = 1:nopt
-        printf ("  [%2d] ", i);
-        disp (varargin{i});
-      endfor
-      printf ("\n");
-      s = input ("pick a number, any number: ", "s");
-      num = sscanf (s, "%d");
-      if (! isscalar (num) || num < 1 || num > nopt)
-        printf ("\nerror: input invalid or out of range\n\n");
-      else
-        break;
-      endif
-    endwhile
-
-  unwind_protect_cleanup
-
-    page_screen_output (save_page_screen_output);
-
-  end_unwind_protect
+  while (1)
+    for i = 1:nopt
+      printf ("  [%2d] ", i);
+      disp (varargin{i});
+    endfor
+    printf ("\n");
+    s = input ("pick a number, any number: ", "s");
+    num = sscanf (s, "%d");
+    if (! isscalar (num) || num < 1 || num > nopt)
+      printf ("\nerror: input invalid or out of range\n\n");
+    else
+      break;
+    endif
+  endwhile
 
 endfunction
+
--- a/scripts/miscellaneous/private/__xzip__.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/miscellaneous/private/__xzip__.m	Wed Dec 07 19:06:13 2011 -0500
@@ -99,13 +99,8 @@
   unwind_protect_cleanup
     cd (cwd);
     if (nargin == 4)
-      crr = confirm_recursive_rmdir ();
-      unwind_protect
-        confirm_recursive_rmdir (false);
-        rmdir (outdir, "s");
-      unwind_protect_cleanup
-        confirm_recursive_rmdir (crr);
-      end_unwind_protect
+      confirm_recursive_rmdir (false, "local");
+      rmdir (outdir, "s");
     endif
   end_unwind_protect
 
--- a/scripts/miscellaneous/recycle.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/miscellaneous/recycle.m	Wed Dec 07 19:06:13 2011 -0500
@@ -18,8 +18,8 @@
 
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {@var{current_state}} recycle ()
-## @deftypefnx  {Function File} {@var{old_state}} recycle (@var{new_state})
-## Display or set the preference for recycling deleted files.
+## @deftypefnx {Function File} {@var{old_state}} recycle (@var{new_state})
+## Query or set the preference for recycling deleted files.
 ##
 ## Recycling files instead of permanently deleting them is currently not
 ## implemented in Octave.  To help avoid accidental data loss it
@@ -51,7 +51,7 @@
         error ("recycle: invalid value of STATE = `%s'", state);
       endif
     else
-      erroor ("recycle: expecting STATE to be a character string");
+      error ("recycle: expecting STATE to be a character string");
     endif
   endif
 
--- a/scripts/miscellaneous/version.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/miscellaneous/version.m	Wed Dec 07 19:06:13 2011 -0500
@@ -20,7 +20,7 @@
 ## @deftypefn {Function File} {} version ()
 ## Return the version number of Octave, as a string.
 ##
-## This is an alias for the function @code{OCTAVE_VERSION} provided for
+## This is an alias for the function @w{@env{OCTAVE_VERSION}} provided for
 ## compatibility
 ## @seealso{OCTAVE_VERSION}.
 ## @end deftypefn
--- a/scripts/optimization/sqp.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/optimization/sqp.m	Wed Dec 07 19:06:13 2011 -0500
@@ -75,7 +75,7 @@
 ## formula is used to approximate the Hessian.
 ##
 ## When supplied, the gradient function @code{@var{phi}@{2@}} must accept
-## one vector argument and return a vector. When supplifed, the Hessian
+## one vector argument and return a vector.  When supplied, the Hessian
 ## function @code{@var{phi}@{3@}} must accept one vector argument and
 ## return a matrix.
 ##
@@ -83,7 +83,7 @@
 ## handles pointing to functions that compute the equality constraints
 ## and the inequality constraints, respectively.  If the problem does
 ## not have equality (or inequality) constraints, then use an empty
-## matrix ([]) for @var{g} (or @var{h}). When supplied, these equality
+## matrix ([]) for @var{g} (or @var{h}).  When supplied, these equality
 ## and inequality constraint functions must accept one vector argument
 ## and return a vector.
 ##
@@ -113,16 +113,16 @@
 ## and upper bounds on @var{x}.  These must be consistent with the
 ## equality and inequality constraints @var{g} and @var{h}.  If the
 ## arguments are vectors then @var{x}(i) is bound by @var{lb}(i) and
-## @var{ub}(i). A bound can also be a scalar in which case all elements
+## @var{ub}(i).  A bound can also be a scalar in which case all elements
 ## of @var{x} will share the same bound.  If only one bound (lb, ub) is
 ## specified then the other will default to (-@var{realmax},
 ## +@var{realmax}).
 ##
 ## The seventh argument @var{maxiter} specifies the maximum number of
-## iterations. The default value is 100.
+## iterations.  The default value is 100.
 ##
 ## The eighth argument @var{tol} specifies the tolerance for the
-## stopping criteria. The default value is @code{sqrt(eps)}.
+## stopping criteria.  The default value is @code{sqrt(eps)}.
 ##
 ## The value returned in @var{info} may be one of the following:
 ##
--- a/scripts/path/matlabroot.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/path/matlabroot.m	Wed Dec 07 19:06:13 2011 -0500
@@ -20,7 +20,7 @@
 ## @deftypefn {Function File} {} matlabroot ()
 ## Return the name of the top-level Octave installation directory.
 ##
-## This is an alias for the function @code{OCTAVE_HOME} provided
+## This is an alias for the function @w{@code{OCTAVE_HOME}} provided
 ## for compatibility.
 ## @seealso{OCTAVE_HOME}
 ## @end deftypefn
--- a/scripts/pkg/pkg.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/pkg/pkg.m	Wed Dec 07 19:06:13 2011 -0500
@@ -72,7 +72,7 @@
 ## @end table
 ##
 ## @item update
-## Check installed Octave-Forge pacakages against repository and update any
+## Check installed Octave-Forge packages against repository and update any
 ## outdated items.  This requires an internet connection and the cURL library.
 ## Usage:
 ##
@@ -2199,13 +2199,8 @@
 
 function [status_out, msg_out] = rm_rf (dir)
   if (exist (dir))
-    crr = confirm_recursive_rmdir ();
-    unwind_protect
-      confirm_recursive_rmdir (false);
-      [status, msg] = rmdir (dir, "s");
-    unwind_protect_cleanup
-      confirm_recursive_rmdir (crr);
-    end_unwind_protect
+    crr = confirm_recursive_rmdir (false, "local");
+    [status, msg] = rmdir (dir, "s");
   else
     status = 1;
     msg = "";
--- a/scripts/plot/__plt_get_axis_arg__.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/__plt_get_axis_arg__.m	Wed Dec 07 19:06:13 2011 -0500
@@ -33,7 +33,7 @@
     nogca = false;
   endif
 
-  ## Figure handles are integers, but object handles are non integer,
+  ## Figure handles are integers, but object handles are non-integer,
   ## therefore ignore integer scalars.
   if (nargin > 1 && length (varargin) > 0 && isnumeric (varargin{1})
       && numel (varargin{1}) == 1 && ishandle (varargin{1}(1))
--- a/scripts/plot/allchild.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/allchild.m	Wed Dec 07 19:06:13 2011 -0500
@@ -35,25 +35,23 @@
   shh = get (0, "showhiddenhandles");
   unwind_protect
     set (0, "showhiddenhandles", "on");
-    if (isscalar (handles))
-      h = get (handles, "children");
-    else
-      h = cell (size (handles));
-      for i = 1:numel (handles)
-        h{i} = get (handles, "children");
-      endfor
-    endif
+    h = get (handles, "children");
   unwind_protect_cleanup
     set (0, "showhiddenhandles", shh);
   end_unwind_protect
 
 endfunction
 
-%!test
+
+%!testif HAVE_FLTK
+%! toolkit = graphics_toolkit ();
+%! graphics_toolkit ("fltk");
 %! hf = figure ("visible", "off");
 %! unwind_protect
 %!   l = line;
-%!   assert(get(allchild(hf),'type'),{'axes'; 'uimenu'; 'uimenu'; 'uimenu'})
+%!   assert(get (allchild (hf),"type"),{"axes"; "uimenu"; "uimenu"; "uimenu"});
 %! unwind_protect_cleanup
 %!   close (hf);
+%!   graphics_toolkit (toolkit);
 %! end_unwind_protect
+
--- a/scripts/plot/area.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/area.m	Wed Dec 07 19:06:13 2011 -0500
@@ -33,9 +33,11 @@
 ## @code{1 : rows (@var{y})}.  A value @var{lvl} can be defined that determines
 ## where the base level of the shading under the curve should be defined.
 ##
-## Additional arguments to the @code{area} function are passed to the
-## @code{patch}.  The optional return value @var{h} provides a handle to
-## area series object representing the patches of the areas.
+## Additional arguments to the @code{area} function are passed to
+## @code{patch}.
+##
+## The optional return value @var{h} is a graphics handle to the hggroup
+## object representing the area patch objects.
 ## @seealso{plot, patch}
 ## @end deftypefn
 
--- a/scripts/plot/bar.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/bar.m	Wed Dec 07 19:06:13 2011 -0500
@@ -36,7 +36,7 @@
 ## argument, which can take the values @code{"grouped"} (the default),
 ## or @code{"stacked"}.
 ##
-## The optional return value @var{h} provides a handle to the "bar series"
+## The optional return value @var{h} is a handle to the created "bar series"
 ## object with one handle per column of the variable @var{y}.  This
 ## series allows common elements of the group of bar series objects to
 ## be changed in a single bar series and the same properties are changed
@@ -93,3 +93,7 @@
   varargout = cell (nargout, 1);
   [varargout{:}] = __bar__ (true, "bar", varargin{:});
 endfunction
+
+
+%% FIXME: Need demo or test for function
+
--- a/scripts/plot/barh.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/barh.m	Wed Dec 07 19:06:13 2011 -0500
@@ -36,13 +36,13 @@
 ## argument, which can take the values @code{"grouped"} (the default),
 ## or @code{"stacked"}.
 ##
-## The optional return value @var{h} provides a handle to the bar series
-## object.  See @code{bar} for a description of the use of the bar series.
-##
 ## The optional input handle @var{h} allows an axis handle to be passed.
 ## Properties of the patch graphics object can be changed using
 ## @var{prop}, @var{val} pairs.
 ##
+## The optional return value @var{h} is a graphics handle to the created
+## bar series object.  See @code{bar} for a description of the use of the
+## bar series.
 ## @seealso{bar, plot}
 ## @end deftypefn
 
@@ -52,3 +52,7 @@
   varargout = cell (nargout, 1);
   [varargout{:}] = __bar__ (false, "barh", varargin{:});
 endfunction
+
+
+%% FIXME: Need demo or test for function
+
--- a/scripts/plot/clabel.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/clabel.m	Wed Dec 07 19:06:13 2011 -0500
@@ -39,9 +39,10 @@
 ## on a contour (in points) to be specified.  The default is 144 points, or 2
 ## inches.
 ##
-## The returned value @var{h} is the set of text object that represent the
-## contour labels.  The "userdata" property of the text objects contains the
-## numerical value of the contour label.
+## The optional return value @var{h} is a vector of graphics handles to
+## the text objects representing each label.  
+## The "userdata" property of the text objects contains the numerical value of
+## the contour label.
 ##
 ## An example of the use of @code{clabel} is
 ##
@@ -128,12 +129,14 @@
   endif
 endfunction
 
-%!demo
-%! clf
-%! [c, h] = contour (peaks(), -4 : 6);
-%! clabel (c, h, -4 : 2 : 6, 'fontsize', 12);
 
 %!demo
 %! clf
-%! [c, h] = contourf (peaks(), -7 : 6);
-%! clabel (c, h, -6 : 2 : 6, 'fontsize', 12);
+%! [c, h] = contour (peaks(), -4:6);
+%! clabel (c, h, -4:2:6, "fontsize", 12);
+
+%!demo
+%! clf
+%! [c, h] = contourf (peaks(), -7:6);
+%! clabel (c, h, -6:2:6, "fontsize", 12);
+
--- a/scripts/plot/clf.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/clf.m	Wed Dec 07 19:06:13 2011 -0500
@@ -26,8 +26,10 @@
 ## graphics objects with visible handles (@code{handlevisibility} = on).
 ## If @var{hfig} is specified operate on it instead of the current figure.
 ## If the optional argument @code{"reset"} is specified, all objects including
-## those with hidden handles are deleted.  If an output value is
-## requested, return the handle of the figure window that was cleared.
+## those with hidden handles are deleted.
+## 
+## The optional return value @var{h} is the graphics handle of the figure
+## window that was cleared.
 ## @seealso{cla, close, delete}
 ## @end deftypefn
 
@@ -82,6 +84,7 @@
 
 endfunction
 
+
 %!test
 %! hf = figure ("visible", "off");
 %! unwind_protect
@@ -99,3 +102,4 @@
 %! unwind_protect_cleanup
 %!   close (hf);
 %! end_unwind_protect
+
--- a/scripts/plot/compass.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/compass.m	Wed Dec 07 19:06:13 2011 -0500
@@ -31,17 +31,17 @@
 ## The style to use for the plot can be defined with a line style @var{style}
 ## in a similar manner to the line styles used with the @code{plot} command.
 ##
-## The optional return value @var{h} provides a list of handles to the
-## the parts of the vector field (body, arrow and marker).
+## The optional return value @var{h} is a vector of graphics handles to the
+## line objects representing the drawn vectors.
 ##
 ## @example
 ## @group
-## a = toeplitz([1;randn(9,1)],[1,randn(1,9)]);
+## a = toeplitz ([1;randn(9,1)], [1,randn(1,9)]);
 ## compass (eig (a))
 ## @end group
 ## @end example
 ##
-## @seealso{plot, polar, quiver, feather}
+## @seealso{polar, quiver, feather, plot}
 ## @end deftypefn
 
 function retval = compass (varargin)
--- a/scripts/plot/ezcontour.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/ezcontour.m	Wed Dec 07 19:06:13 2011 -0500
@@ -35,8 +35,7 @@
 ##
 ## @var{n} is a scalar defining the number of points to use in each dimension.
 ##
-## The optional return value @var{h} provides a list of handles to the
-## the parts of the vector field (body, arrow and marker).
+## The optional return value @var{h} is a graphics handle to the created plot.
 ##
 ## @example
 ## @group
@@ -61,6 +60,8 @@
   endif
 endfunction
 
+
 %!demo
 %! f = @(x,y) sqrt(abs(x .* y)) ./ (1 + x.^2 + y.^2);
 %! ezcontour (f, [-3, 3]);
+
--- a/scripts/plot/ezcontourf.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/ezcontourf.m	Wed Dec 07 19:06:13 2011 -0500
@@ -35,8 +35,7 @@
 ##
 ## @var{n} is a scalar defining the number of points to use in each dimension.
 ##
-## The optional return value @var{h} provides a list of handles to the
-## the parts of the vector field (body, arrow and marker).
+## The optional return value @var{h} is a graphics handle to the created plot.
 ##
 ## @example
 ## @group
@@ -61,6 +60,7 @@
   endif
 endfunction
 
+
 %!demo
 %! f = @(x,y) sqrt(abs(x .* y)) ./ (1 + x.^2 + y.^2);
 %! ezcontourf (f, [-3, 3]);
--- a/scripts/plot/ezmesh.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/ezmesh.m	Wed Dec 07 19:06:13 2011 -0500
@@ -44,8 +44,8 @@
 ## If the argument 'circ' is given, then the function is plotted over a disk
 ## centered on the middle of the domain @var{dom}.
 ##
-## The optional return value @var{h} provides a list of handles to the
-## the parts of the vector field (body, arrow and marker).
+## The optional return value @var{h} is a graphics handle to the created 
+## surface object.
 ##
 ## @example
 ## @group
@@ -65,7 +65,7 @@
 ## @end group
 ## @end example
 ##
-## @seealso{ezplot, ezsurf, ezsurfc, ezmeshc}
+## @seealso{ezplot, ezmeshc, ezsurf, ezsurfc}
 ## @end deftypefn
 
 function retval = ezmesh (varargin)
@@ -81,6 +81,7 @@
   endif
 endfunction
 
+
 %!demo
 %! f = @(x,y) sqrt(abs(x .* y)) ./ (1 + x.^2 + y.^2);
 %! ezmesh (f, [-3, 3]);
@@ -90,3 +91,4 @@
 %! fy = @(s,t) sin (s) .* cos(t);
 %! fz = @(s,t) sin (t);
 %! ezmesh (fx, fy, fz, [-pi,pi,-pi/2,pi/2], 20);
+
--- a/scripts/plot/ezmeshc.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/ezmeshc.m	Wed Dec 07 19:06:13 2011 -0500
@@ -44,8 +44,9 @@
 ## If the argument 'circ' is given, then the function is plotted over a disk
 ## centered on the middle of the domain @var{dom}.
 ##
-## The optional return value @var{h} provides a list of handles to the
-## the parts of the vector field (body, arrow and marker).
+## The optional return value @var{h} is a 2-element vector with a graphics
+## handle for the created mesh plot and a second handle for the created contour
+## plot.
 ##
 ## @example
 ## @group
@@ -70,6 +71,8 @@
   endif
 endfunction
 
+
 %!demo
 %! f = @(x,y) sqrt(abs(x .* y)) ./ (1 + x.^2 + y.^2);
 %! ezmeshc (f, [-3, 3]);
+
--- a/scripts/plot/ezplot.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/ezplot.m	Wed Dec 07 19:06:13 2011 -0500
@@ -61,8 +61,7 @@
 ## @var{n} is a scalar defining the number of points to use in plotting
 ## the function.
 ##
-## The optional return value @var{h} provides a list of handles to the
-## the line objects plotted.
+## The optional return value @var{h} is a graphics handle to the created plot.
 ##
 ## @seealso{plot, ezplot3}
 ## @end deftypefn
@@ -80,6 +79,7 @@
   endif
 endfunction
 
+
 %!demo
 %! ezplot (@cos, @sin)
 
@@ -87,4 +87,5 @@
 %! ezplot ("1/x")
 
 %!demo
-%! ezplot (inline("x^2 - y^2 = 1"))
+%! ezplot (inline ("x^2 - y^2 = 1"))
+
--- a/scripts/plot/ezplot3.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/ezplot3.m	Wed Dec 07 19:06:13 2011 -0500
@@ -32,8 +32,7 @@
 ## If @var{dom} is a two element vector, it represents the minimum and maximum
 ## value of @var{t}.  @var{n} is a scalar defining the number of points to use.
 ##
-## The optional return value @var{h} provides a list of handles to the
-## the parts of the vector field (body, arrow and marker).
+## The optional return value @var{h} is a graphics handle to the created plot.
 ##
 ## @example
 ## @group
@@ -60,8 +59,10 @@
   endif
 endfunction
 
+
 %!demo
 %! fx = @(t) cos (t);
 %! fy = @(t) sin (t);
 %! fz = @(t) t;
 %! ezplot3 (fx, fy, fz, [0, 10*pi], 100);
+
--- a/scripts/plot/ezpolar.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/ezpolar.m	Wed Dec 07 19:06:13 2011 -0500
@@ -32,8 +32,7 @@
 ## value of both @var{t}.  @var{n} is a scalar defining the number of points to
 ## use.
 ##
-## The optional return value @var{h} provides a list of handles to the
-## the parts of the vector field (body, arrow and marker).
+## The optional return value @var{h} is a graphics handle to the created plot.
 ##
 ## @example
 ## ezpolar (@@(t) 1 + sin (t));
@@ -55,5 +54,7 @@
   endif
 endfunction
 
+
 %!demo
 %! ezpolar (@(t) 1 + sin (t));
+
--- a/scripts/plot/ezsurf.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/ezsurf.m	Wed Dec 07 19:06:13 2011 -0500
@@ -44,8 +44,8 @@
 ## If the argument 'circ' is given, then the function is plotted over a disk
 ## centered on the middle of the domain @var{dom}.
 ##
-## The optional return value @var{h} provides a list of handles to the
-## the parts of the vector field (body, arrow and marker).
+## The optional return value @var{h} is a graphics handle to the created
+## surface object.
 ##
 ## @example
 ## @group
@@ -81,6 +81,7 @@
   endif
 endfunction
 
+
 %!demo
 %! f = @(x,y) sqrt(abs(x .* y)) ./ (1 + x.^2 + y.^2);
 %! ezsurf (f, [-3, 3]);
@@ -90,3 +91,4 @@
 %! fy = @(s,t) sin (s) .* cos(t);
 %! fz = @(s,t) sin (t);
 %! ezsurf (fx, fy, fz, [-pi,pi,-pi/2,pi/2], 20);
+
--- a/scripts/plot/ezsurfc.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/ezsurfc.m	Wed Dec 07 19:06:13 2011 -0500
@@ -44,8 +44,9 @@
 ## If the argument 'circ' is given, then the function is plotted over a disk
 ## centered on the middle of the domain @var{dom}.
 ##
-## The optional return value @var{h} provides a list of handles to the
-## the parts of the vector field (body, arrow and marker).
+## The optional return value @var{h} is a 2-element vector with a graphics
+## for the created surface plot and a second handle for the created contour
+## plot.
 ##
 ## @example
 ## @group
@@ -70,6 +71,8 @@
   endif
 endfunction
 
+
 %!demo
 %! f = @(x,y) sqrt(abs(x .* y)) ./ (1 + x.^2 + y.^2);
 %! ezsurfc (f, [-3, 3]);
+
--- a/scripts/plot/feather.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/feather.m	Wed Dec 07 19:06:13 2011 -0500
@@ -31,8 +31,8 @@
 ## The style to use for the plot can be defined with a line style @var{style}
 ## in a similar manner to the line styles used with the @code{plot} command.
 ##
-## The optional return value @var{h} provides a list of handles to the
-## the parts of the vector field (body, arrow and marker).
+## The optional return value @var{h} is a vector of graphics handles to the
+## line objects representing the drawn vectors.
 ##
 ## @example
 ## @group
@@ -109,6 +109,8 @@
 
 endfunction
 
+
 %!demo
 %! phi = [0 : 15 : 360] * pi / 180;
 %! feather (sin (phi), cos (phi))
+
--- a/scripts/plot/fill.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/fill.m	Wed Dec 07 19:06:13 2011 -0500
@@ -22,7 +22,11 @@
 ## @deftypefnx {Function File} {} fill (@dots{}, @var{prop}, @var{val})
 ## @deftypefnx {Function File} {} fill (@var{h}, @dots{})
 ## @deftypefnx {Function File} {@var{h} =} fill (@dots{})
-## Create one or more filled patch objects, returning a patch object for each.
+## Create one or more filled patch objects.
+##
+## The optional return value @var{h} is an array of graphics handles to
+## the created patch objects.
+## @seealso{patch}
 ## @end deftypefn
 
 function retval = fill (varargin)
@@ -114,12 +118,14 @@
   endwhile
 endfunction
 
+
 %!demo
 %! clf
-%! t1 = (1/16:1/8:1)'*2*pi;
-%! t2 = ((1/16:1/8:1)' + 1/32)*2*pi;
-%! x1 = sin(t1) - 0.8;
-%! y1 = cos(t1);
-%! x2 = sin(t2) + 0.8;
-%! y2 = cos(t2);
-%! h = fill(x1,y1,'r',x2,y2,'g');
+%! t1 = (1/16:1/8:1)*2*pi;
+%! t2 = ((1/16:1/8:1) + 1/32)*2*pi;
+%! x1 = sin (t1) - 0.8;
+%! y1 = cos (t1);
+%! x2 = sin (t2) + 0.8;
+%! y2 = cos (t2);
+%! h = fill (x1,y1,'r', x2,y2,'g');
+
--- a/scripts/plot/findall.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/findall.m	Wed Dec 07 19:06:13 2011 -0500
@@ -21,7 +21,7 @@
 ## @deftypefnx {Function File} {@var{h} =} findall (@var{prop_name}, @var{prop_value})
 ## @deftypefnx {Function File} {@var{h} =} findall (@var{h}, @dots{})
 ## @deftypefnx {Function File} {@var{h} =} findall (@var{h}, "-depth", @var{d}, @dots{})
-## Find object with specified property values including hidden handles.
+## Find graphics object with specified property values including hidden handles.
 ##
 ## This function performs the same function as @code{findobj}, but it
 ## includes hidden objects in its search.  For full documentation, see
@@ -43,12 +43,18 @@
 
 endfunction
 
-%!test
+
+%!testif HAVE_FLTK
+%! toolkit = graphics_toolkit ();
+%! graphics_toolkit ("fltk");
 %! hf = figure ("visible", "off");
 %! unwind_protect
 %!   h = findall (hf);
-%!   all_handles = {"uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "uimenu"; "figure"};
-%!   assert (get (h, 'type'), all_handles)
+%!   all_handles(1:13,1) = {"uimenu"};
+%!   all_handles(14) = {"figure"};
+%!   assert (get (h, "type"), all_handles);
 %! unwind_protect_cleanup
 %!   close (hf);
+%!   graphics_toolkit (toolkit);
 %! end_unwind_protect
+
--- a/scripts/plot/findobj.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/findobj.m	Wed Dec 07 19:06:13 2011 -0500
@@ -24,7 +24,7 @@
 ## @deftypefnx {Function File} {@var{h} =} findobj ('flat', @dots{})
 ## @deftypefnx {Function File} {@var{h} =} findobj (@var{h}, @dots{})
 ## @deftypefnx {Function File} {@var{h} =} findobj (@var{h}, '-depth', @var{d}, @dots{})
-## Find object with specified property values.  The simplest form is
+## Find graphics object with specified property values.  The simplest form is
 ##
 ## @example
 ## findobj (@var{prop_name}, @var{prop_Value})
@@ -243,6 +243,7 @@
   h = reshape (h, [numel(h), 1]);
 endfunction
 
+
 %!test
 %! hf = figure ("visible", "off");
 %! unwind_protect
@@ -255,3 +256,4 @@
 %! unwind_protect_cleanup
 %!   close (hf);
 %! end_unwind_protect
+
--- a/scripts/plot/graphics_toolkit.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/graphics_toolkit.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,9 +17,10 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {} graphics_toolkit (@var{name})
+## @deftypefn  {Function File} {@var{name} =} graphics_toolkit ()
+## @deftypefnx {Function File} {@var{old_name} =} graphics_toolkit (@var{name})
 ## @deftypefnx {Function File} {} graphics_toolkit (@var{hlist}, @var{name})
-## Change the default graphics toolkit to @var{name}.  If the
+## Query or set the default graphics toolkit to @var{name}.  If the
 ## toolkit is not already loaded, it is first initialized by calling the
 ## function @code{__init_@var{name}__}.
 ##
@@ -28,44 +29,57 @@
 ## @seealso{available_graphics_toolkits}
 ## @end deftypefn
 
-function graphics_toolkit (varargin)
+function retval = graphics_toolkit (name, hlist = [])
 
-  name = "";
-  hlist = [];
+  if (nargin > 2)
+    print_usage ();
+  endif
 
-  if (nargin == 1)
-    if (ischar (varargin{1}))
-      name = varargin{1};
-    else
+  if (nargin == 0)
+    retval = get (0, "defaultfigure__graphics_toolkit__");
+    return;
+  elseif (nargin == 1)
+    if (! ischar (name))
       error ("graphics_toolkit: invalid graphics toolkit NAME");
     endif
   elseif (nargin == 2)
-    if (isnumeric (varargin{1}) && ischar (varargin{2}))
-      hlist = varargin{1};
-      name = varargin{2};
-    elseif (ischar (varargin{2}))
-      error ("graphics_toolkit: invalid handle list");
-    else
+    ## Swap input arguments
+    [hlist, name] = deal (name, hlist);
+    if (! all (isfigure (hlist)))
+      error ("graphics_toolkit: invalid figure handle list HLIST");
+    elseif (! ischar (name))
       error ("graphics_toolkit: invalid graphics toolkit NAME");
     endif
-  else
-    print_usage ();
   endif
 
   if (! any (strcmp (available_graphics_toolkits (), name)))
     feval (["__init_", name, "__"]);
     if (! any (strcmp (available_graphics_toolkits (), name)))
-      error ("graphics_toolkit: %s toolkit was not correctly registered",
-             name);
+      error ("graphics_toolkit: %s toolkit was not correctly registered", name);
     endif
   endif
 
   if (isempty (hlist))
     set (0, "defaultfigure__graphics_toolkit__", name);
   else
-    for h = hlist(:)'
-      set (h, "__graphics_toolkit__", name);
-    endfor
+    set (hlist, "__graphics_toolkit__", name);
+  endif
+
+  if (isargout (1))
+    retval = name;
   endif
 
 endfunction
+
+
+%!testif HAVE_FLTK
+%! unwind_protect
+%!   hf = figure ("visible", "off"); 
+%!   toolkit = graphics_toolkit ();
+%!   assert (get (0, "defaultfigure__graphics_toolkit__"), toolkit);
+%!   graphics_toolkit (hf, "fltk"); 
+%!   assert (get (hf, "__graphics_toolkit__"), "fltk");
+%! unwind_protect_cleanup
+%!   close (hf);
+%! end_unwind_protect
+
--- a/scripts/plot/guidata.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/guidata.m	Wed Dec 07 19:06:13 2011 -0500
@@ -18,7 +18,7 @@
 
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {@var{data} =} guidata (@var{handle})
-## @deftypefnx {Function File} guidata (@var{handle}, @var{data})
+## @deftypefnx {Function File} {} guidata (@var{handle}, @var{data})
 ## @end deftypefn
 
 ## Author: goffioul
--- a/scripts/plot/isonormals.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/isonormals.m	Wed Dec 07 19:06:13 2011 -0500
@@ -45,8 +45,8 @@
 ## given by the patch handle @var{p}.
 ##
 ## For example:
+## @c Set example in small font to prevent overfull line
 ##
-## @c Set example in small font to prevent overfull line
 ## @smallexample
 ## function [] = isofinish (p)
 ##   set (gca, "PlotBoxAspectRatioMode", "manual", ...
--- a/scripts/plot/isosurface.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/isosurface.m	Wed Dec 07 19:06:13 2011 -0500
@@ -70,8 +70,8 @@
 ## will directly draw a random isosurface geometry in a graphics window.
 ## Another example for an isosurface geometry with different additional
 ## coloring
+## @c Set example in small font to prevent overfull line
 ##
-## @c Set example in small font to prevent overfull line
 ## @smallexample
 ## N = 15;    # Increase number of vertices in each direction
 ## iso = .4;  # Change isovalue to .1 to display a sphere
--- a/scripts/plot/legend.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/legend.m	Wed Dec 07 19:06:13 2011 -0500
@@ -40,6 +40,9 @@
 ##
 ## @multitable @columnfractions 0.06 0.14 0.80
 ##
+## @headitem @tab @var{pos} @tab
+##   location of the legend
+##
 ## @item @tab north @tab
 ##   center top
 ##
@@ -375,13 +378,15 @@
               break;
             endif
           elseif (! warned)
-            warned = true;
-            warning ("legend: ignoring extra labels");
+            break;
           endif
         else
           error ("legend: expecting argument to be a character string");
         endif
       endfor
+      if (i < nargs && ! warned)
+        warning ("legend: ignoring extra labels");
+      endif
     else
       k = nkids;
       while (k > 0)
@@ -403,7 +408,7 @@
               if (isfield (hgobj, "displayname")
                   && ! isempty (hgobj.displayname))
                 hplots = [hplots, hgkids(j)];
-                text_strings = {text_strings{:}, hbobj.displayname};
+                text_strings = {text_strings{:}, hgobj.displayname};
                 break;
               endif
             endfor
@@ -813,22 +818,14 @@
 endfunction
 
 function updatelegendtext (h, d)
+  hax = get (h, "userdata").handle;
   kids = get (h, "children");
-  k = numel (kids);
-  in = get (h, "interpreter");
-  tc = get (h, "textcolor");
-  while (k > 0)
-    typ = get (kids(k), "type");
-    while (k > 0 && ! strcmp (typ, "text"))
-      typ = get (kids(--k), "type");
-    endwhile
-    if (k > 0)
-      set (kids (k), "interpreter", in, "color", tc);
-      if (--k == 0)
-        break;
-      endif
-    endif
-  endwhile
+  text_kids = findobj (kids, "-property", "interpreter", "type", "text");
+  interpreter = get (h, "interpreter");
+  textcolor = get (h, "textcolor");
+  set (kids, "interpreter", interpreter, "color", textcolor);
+  hobj = cell2mat (get (kids, "userdata"));
+  set (hobj, "interpreter", interpreter);
 endfunction
 
 function hideshowlegend (h, d, ca, pos1, pos2)
@@ -1083,7 +1080,7 @@
 %! clf
 %! rand_2x3_data1 = [0.341447, 0.171220, 0.284370; 0.039773, 0.731725, 0.779382];
 %! bar (rand_2x3_data1);
-%! ylim ([0 1.2]);
+%! ylim ([0 1.0]);
 %! legend ({"1st Bar", "2nd Bar", "3rd Bar"});
 
 %!demo
@@ -1092,6 +1089,7 @@
 %! bar (rand_2x3_data2);
 %! ylim ([0 1.2]);
 %! legend ("1st Bar", "2nd Bar", "3rd Bar");
+%! legend right
 
 %!demo
 %! clf
@@ -1130,21 +1128,34 @@
 
 %!demo
 %! clf
-%! x = 0:4;
+%! x = 1:5;
 %! subplot (2, 2, 1)
 %! plot (x, rand (numel (x)));
-%! legend (cellstr (num2str ((1:10)')), "location", "northwestoutside")
+%! legend (cellstr (num2str (x')), "location", "northwestoutside")
 %! legend boxon
 %! subplot (2, 2, 2)
 %! plot (x, rand (numel (x)));
-%! legend (cellstr (num2str ((1:10)')), "location", "northeastoutside")
+%! legend (cellstr (num2str (x')), "location", "northeastoutside")
 %! legend boxon
 %! subplot (2, 2, 3);
 %! plot (x, rand (numel (x)));
-%! legend (cellstr (num2str ((1:10)')), "location", "southwestoutside")
+%! legend (cellstr (num2str (x')), "location", "southwestoutside")
 %! legend boxon
 %! subplot (2, 2, 4)
 %! plot (x, rand (numel (x)));
-%! legend (cellstr (num2str ((1:10)')), "location", "southeastoutside")
+%! legend (cellstr (num2str (x')), "location", "southeastoutside")
 %! legend boxon
 
+%!demo
+%! clf
+%! plot (rand (2))
+%! title ("Warn of extra labels")
+%! legend ("Hello", "World", "interpreter", "foobar")
+
+%!demo
+%! clf
+%! plot (rand (2))
+%! title ("Turn off TeX interpreter")
+%! h = legend ("Hello_World", "foo^bar");
+%! set (h, "interpreter", "none")
+
--- a/scripts/plot/loglog.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/loglog.m	Wed Dec 07 19:06:13 2011 -0500
@@ -26,6 +26,8 @@
 ## Produce a two-dimensional plot using log scales for both axes.  See
 ## the documentation of @code{plot} for a description of the arguments
 ## that @code{loglog} will accept.
+##
+## The optional return value @var{h} is a graphics handle to the created plot.
 ## @seealso{plot, semilogx, semilogy}
 ## @end deftypefn
 
--- a/scripts/plot/mesh.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/mesh.m	Wed Dec 07 19:06:13 2011 -0500
@@ -32,6 +32,9 @@
 ## The color of the mesh is derived from the @code{colormap}
 ## and the value of @var{z}.  Optionally the color of the mesh can be
 ## specified independent of @var{z}, by adding a fourth matrix, @var{c}.
+##
+## The optional return value @var{h} is a graphics handle to the created
+## suface object.
 ## @seealso{colormap, contour, meshgrid, surf}
 ## @end deftypefn
 
@@ -58,3 +61,7 @@
   endif
 
 endfunction
+
+
+%% FIXME: Need demo or test for function
+
--- a/scripts/plot/module.mk	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/module.mk	Wed Dec 07 19:06:13 2011 -0500
@@ -190,8 +190,10 @@
   plot/uipanel.m \
   plot/uipushtool.m \
   plot/uiputfile.m \
+  plot/uiresume.m \
   plot/uitoggletool.m \
   plot/uitoolbar.m \
+  plot/uiwait.m \
   plot/view.m \
   plot/waitforbuttonpress.m \
   plot/whitebg.m \
--- a/scripts/plot/pareto.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/pareto.m	Wed Dec 07 19:06:13 2011 -0500
@@ -41,6 +41,10 @@
 ## @var{y} can be a string array, a cell array of strings or a numerical
 ## vector.
 ##
+## The optional return value @var{h} is a 2-element vector with a graphics
+## handle for the created bar plot and a second handle for the created line
+## plot.
+##
 ## An example of the use of @code{pareto} is
 ##
 ## @example
@@ -48,7 +52,7 @@
 ## Cheese = @{"Cheddar", "Swiss", "Camembert", ...
 ##           "Munster", "Stilton", "Blue"@};
 ## Sold = [105, 30, 70, 10, 15, 20];
-## pareto(Sold, Cheese);
+## pareto (Sold, Cheese);
 ## @end group
 ## @end example
 ## @end deftypefn
@@ -99,12 +103,13 @@
 
 endfunction
 
+
 %!demo
 %! clf
-%! colormap (jet (64))
+%! colormap (jet (64));
 %! Cheese = {"Cheddar", "Swiss", "Camembert", "Munster", "Stilton", "Blue"};
 %! Sold = [105, 30, 70, 10, 15, 20];
-%! pareto(Sold, Cheese);
+%! pareto (Sold, Cheese);
 
 %!demo
 %! clf
@@ -114,3 +119,4 @@
 %! SoldUnits = [54723 41114 16939 1576091 168000 687197 120222 168195, ...
 %!              1084118 55576]';
 %! pareto (Value.*SoldUnits, Codes);
+
--- a/scripts/plot/patch.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/patch.m	Wed Dec 07 19:06:13 2011 -0500
@@ -35,6 +35,10 @@
 ## If passed a structure @var{fv} contain the fields "vertices", "faces"
 ## and optionally "facevertexcdata", create the patch based on these
 ## properties.
+##
+## The optional return value @var{h} is a graphics handle to the created patch
+## object.
+## @seealso{fill}
 ## @end deftypefn
 
 ## Author: jwe
@@ -60,10 +64,10 @@
 %! clf
 %! t1 = (1/16:1/8:1)'*2*pi;
 %! t2 = ((1/16:1/8:1)' + 1/32)*2*pi;
-%! x1 = sin(t1) - 0.8;
-%! y1 = cos(t1);
-%! x2 = sin(t2) + 0.8;
-%! y2 = cos(t2);
+%! x1 = sin (t1) - 0.8;
+%! y1 = cos (t1);
+%! x2 = sin (t2) + 0.8;
+%! y2 = cos (t2);
 %! patch([x1,x2],[y1,y2],'r');
 
 %!demo
@@ -71,10 +75,10 @@
 %! clf
 %! t1 = (1/16:1/8:1)'*2*pi;
 %! t2 = ((1/16:1/16:1)' + 1/32)*2*pi;
-%! x1 = sin(t1) - 0.8;
-%! y1 = cos(t1);
-%! x2 = sin(t2) + 0.8;
-%! y2 = cos(t2);
+%! x1 = sin (t1) - 0.8;
+%! y1 = cos (t1);
+%! x2 = sin (t2) + 0.8;
+%! y2 = cos (t2);
 %! patch([[x1;NaN(8,1)],x2],[[y1;NaN(8,1)],y2],'r');
 
 %!demo
@@ -82,10 +86,10 @@
 %! clf
 %! t1 = (1/16:1/8:1)'*2*pi;
 %! t2 = ((1/16:1/16:1)' + 1/32)*2*pi;
-%! x1 = sin(t1) - 0.8;
-%! y1 = cos(t1);
-%! x2 = sin(t2) + 0.8;
-%! y2 = cos(t2);
+%! x1 = sin (t1) - 0.8;
+%! y1 = cos (t1);
+%! x2 = sin (t2) + 0.8;
+%! y2 = cos (t2);
 %! vert = [x1, y1; x2, y2];
 %! fac = [1:8,NaN(1,8);9:24];
 %! patch('Faces',fac,'Vertices',vert,'FaceColor','r');
@@ -95,10 +99,10 @@
 %! clf
 %! t1 = (1/16:1/8:1)'*2*pi;
 %! t2 = ((1/16:1/16:1)' + 1/32)*2*pi;
-%! x1 = sin(t1) - 0.8;
-%! y1 = cos(t1);
-%! x2 = sin(t2) + 0.8;
-%! y2 = cos(t2);
+%! x1 = sin (t1) - 0.8;
+%! y1 = cos (t1);
+%! x2 = sin (t2) + 0.8;
+%! y2 = cos (t2);
 %! vert = [x1, y1; x2, y2];
 %! fac = [1:8,NaN(1,8);9:24];
 %! patch('Faces',fac,'Vertices',vert,'FaceVertexCData', [0, 1, 0; 0, 0, 1]);
@@ -108,10 +112,10 @@
 %! clf
 %! t1 = (1/16:1/8:1)'*2*pi;
 %! t2 = ((1/16:1/8:1)' + 1/32)*2*pi;
-%! x1 = sin(t1) - 0.8;
-%! y1 = cos(t1);
-%! x2 = sin(t2) + 0.8;
-%! y2 = cos(t2);
+%! x1 = sin (t1) - 0.8;
+%! y1 = cos (t1);
+%! x2 = sin (t2) + 0.8;
+%! y2 = cos (t2);
 %! h = patch([x1,x2],[y1,y2],cat (3,[0,0],[1,0],[0,1]));
 %! pause (1);
 %! set (h, 'FaceColor', 'r');
@@ -127,9 +131,9 @@
 %!          2, 3, 5;
 %!          3, 4, 5;
 %!          4, 1, 5];
-%! patch('Vertices', vertices, 'Faces', faces, ...
-%!       'FaceVertexCData', jet(4), 'FaceColor', 'flat')
-%! view (-37.5, 30)
+%! patch ('Vertices', vertices, 'Faces', faces, ...
+%!        'FaceVertexCData', jet(4), 'FaceColor', 'flat');
+%! view (-37.5, 30);
 
 %!demo
 %! clf
@@ -142,37 +146,37 @@
 %!          2, 3, 5;
 %!          3, 4, 5;
 %!          4, 1, 5];
-%! patch('Vertices', vertices, 'Faces', faces, ...
-%!       'FaceVertexCData', jet(5), 'FaceColor', 'interp')
-%! view (-37.5, 30)
+%! patch ('Vertices', vertices, 'Faces', faces, ...
+%!        'FaceVertexCData', jet(5), 'FaceColor', 'interp');
+%! view (-37.5, 30);
 
 %!demo
 %! clf
-%! colormap (jet)
+%! colormap (jet);
 %! x = [0 1 1 0];
 %! y = [0 0 1 1];
-%! subplot (2, 1, 1)
-%! title ("Blue, Light-Green, and Red Horizontal Bars")
+%! subplot (2, 1, 1);
+%! title ("Blue, Light-Green, and Red Horizontal Bars");
 %! patch (x, y + 0, 1);
 %! patch (x, y + 1, 2);
 %! patch (x, y + 2, 3);
-%! subplot (2, 1, 2)
-%! title ("Blue, Light-Green, and Red Vertical Bars")
+%! subplot (2, 1, 2);
+%! title ("Blue, Light-Green, and Red Vertical Bars");
 %! patch (x + 0, y, 1 * ones (size (x)));
 %! patch (x + 1, y, 2 * ones (size (x)));
 %! patch (x + 2, y, 3 * ones (size (x)));
 
 %!demo
 %! clf
-%! colormap (jet)
+%! colormap (jet);
 %! x = [0 1 1 0];
 %! y = [0 0 1 1];
-%! subplot (2, 1, 1)
-%! title ("Blue horizontal bars: Dark to Light")
+%! subplot (2, 1, 1);
+%! title ("Blue horizontal bars: Dark to Light");
 %! patch (x, y + 0, 1, "cdatamapping", "direct");
 %! patch (x, y + 1, 9, "cdatamapping", "direct");
 %! patch (x, y + 2, 17, "cdatamapping", "direct");
-%! subplot (2, 1, 2)
+%! subplot (2, 1, 2);
 %! title ("Blue vertical bars: Dark to Light")
 %! patch (x + 0, y, 1 * ones (size (x)), "cdatamapping", "direct");
 %! patch (x + 1, y, 9 * ones (size (x)), "cdatamapping", "direct");
@@ -184,9 +188,9 @@
 %! x = [ 0 0; 1 1; 1 0 ];
 %! y = [ 0 0; 0 1; 1 1 ];
 %! p = patch (x, y, "facecolor", "b");
-%! title ("Two blue triangles")
-%! set (p, "cdatamapping", "direct", "facecolor", "flat", "cdata", [1 32])
-%! title ("Direct mapping of colors: Light-Green UL and Blue LR triangles")
+%! title ("Two blue triangles");
+%! set (p, "cdatamapping", "direct", "facecolor", "flat", "cdata", [1 32]);
+%! title ("Direct mapping of colors: Light-Green UL and Blue LR triangles");
 
 %!demo
 %! clf;
@@ -194,7 +198,7 @@
 %! x = [ 0 0; 1 1; 1 0 ];
 %! y = [ 0 0; 0 1; 1 1 ];
 %! p = patch (x, y, [1 32]);
-%! title ("Autoscaling of colors: Red UL and Blue LR triangles")
+%! title ("Autoscaling of colors: Red UL and Blue LR triangles");
 
 %!test
 %! hf = figure ("visible", "off");
@@ -203,8 +207,8 @@
 %!   assert (findobj (hf, "type", "patch"), h);
 %!   assert (get (h, "xdata"), [0; 1; 0], eps);
 %!   assert (get (h, "ydata"), [1; 1; 0], eps);
-%!   assert (isempty(get (h, "zdata")));
-%!   assert (isempty(get (h, "cdata")));
+%!   assert (isempty (get (h, "zdata")));
+%!   assert (isempty (get (h, "cdata")));
 %!   assert (get (h, "faces"), [1, 2, 3], eps);
 %!   assert (get (h, "vertices"), [0 1; 1 1; 0 0], eps);
 %!   assert (get (h, "type"), "patch");
@@ -228,3 +232,4 @@
 %! unwind_protect_cleanup
 %!   close (hf);
 %! end_unwind_protect
+
--- a/scripts/plot/pie.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/pie.m	Wed Dec 07 19:06:13 2011 -0500
@@ -22,7 +22,7 @@
 ## @deftypefnx {Function File} {} pie (@dots{}, @var{labels})
 ## @deftypefnx {Function File} {} pie (@var{h}, @dots{});
 ## @deftypefnx {Function File} {@var{h} =} pie (@dots{});
-## Produce a pie chart.
+## Produce a 2-D pie chart.
 ##
 ## Called with a single vector argument, produces a pie chart of the
 ## elements in @var{x}, with the size of the slice determined by percentage
@@ -34,7 +34,8 @@
 ## If given @var{labels} is a cell array of strings of the same length as
 ## @var{x}, giving the labels of each of the slices of the pie chart.
 ##
-## The optional return value @var{h} provides a handle to the patch object.
+## The optional return value @var{h} is a list of handles to the patch
+## and text objects generating the plot.
 ##
 ## @seealso{pie3, bar, stem}
 ## @end deftypefn
@@ -65,17 +66,19 @@
 
 endfunction
 
+
 %!demo
 %! pie ([3, 2, 1], [0, 0, 1]);
-%! colormap([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
+%! colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
 
 %!demo
 %! pie ([3, 2, 1], [0, 0, 1], {"Cheddar", "Swiss", "Camembert"});
-%! colormap([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
+%! colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
 %! axis ([-2,2,-2,2]);
 
 %!demo
 %! pie ([0.17, 0.34, 0.41], {"Cheddar", "Swiss", "Camembert"});
-%! colormap([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
+%! colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
 %! axis ([-2,2,-2,2]);
-%! title ("missing slice");
\ No newline at end of file
+%! title ("missing slice");
+
--- a/scripts/plot/pie3.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/pie3.m	Wed Dec 07 19:06:13 2011 -0500
@@ -35,8 +35,8 @@
 ## If given @var{labels} is a cell array of strings of the same length as
 ## @var{x}, giving the labels of each of the slices of the pie chart.
 ##
-## The optional return value @var{h} provides a handle list to patch, surface
-## and text objects generating this plot.
+## The optional return value @var{h} is a list of graphics handles to the patch,
+## surface, and text objects generating the plot.
 ##
 ## @seealso{pie, bar, stem}
 ## @end deftypefn
@@ -67,17 +67,19 @@
 
 endfunction
 
+
 %!demo
 %! pie3 ([5:-1:1], [0, 0, 1, 0, 0]);
-%! colormap([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
+%! colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
 
 %!demo
 %! pie3 ([3, 2, 1], [0, 0, 1], {"Cheddar", "Swiss", "Camembert"});
-%! colormap([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
+%! colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
 %! axis ([-2,2,-2,2]);
 
 %!demo
 %! pie3 ([0.17, 0.34, 0.41], {"Cheddar", "Swiss", "Camembert"});
-%! colormap([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
+%! colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
 %! axis ([-2,2,-2,2]);
 %! title ("missing slice");
+
--- a/scripts/plot/plot.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/plot.m	Wed Dec 07 19:06:13 2011 -0500
@@ -173,6 +173,8 @@
 ## If the first argument is an axis handle, then plot into these axes,
 ## rather than the current axis handle returned by @code{gca}.
 ##
+## The optional return value @var{h} is a graphics handle to the created plot.
+##
 ## @seealso{semilogx, semilogy, loglog, polar, mesh, contour, bar,
 ## stairs, errorbar, xlabel, ylabel, title, print}
 ## @end deftypefn
@@ -201,3 +203,7 @@
   endif
 
 endfunction
+
+
+%% FIXME: Need demo or test for function
+
--- a/scripts/plot/polar.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/polar.m	Wed Dec 07 19:06:13 2011 -0500
@@ -21,10 +21,13 @@
 ## @deftypefnx {Function File} {} polar (@var{theta}, @var{rho}, @var{fmt})
 ## @deftypefnx {Function File} {} polar (@var{h}, @dots{})
 ## @deftypefnx {Function File} {@var{h} =} polar (@dots{})
-## Make a two-dimensional plot given the polar coordinates @var{theta} and
+## Create a two-dimensional plot from polar coordinates @var{theta} and
 ## @var{rho}.
 ##
-## The optional third argument specifies the line type.
+## The optional argument @var{fmt} specifies the line format.
+##
+## The optional return value @var{h} is a graphics handle to the created plot.
+##
 ## @seealso{plot}
 ## @end deftypefn
 
--- a/scripts/plot/private/__bar__.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/private/__bar__.m	Wed Dec 07 19:06:13 2011 -0500
@@ -82,7 +82,7 @@
         [linespec, valid] = __pltopt__ (func, varargin{idx}, false);
         if (valid)
           have_line_spec = true;
-          newargs = [{linespec.color}, newargs];
+          newargs = [{"facecolor", linespec.color}, newargs]
           idx++;
           continue;
         endif
--- a/scripts/plot/private/__fltk_file_filter__.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/private/__fltk_file_filter__.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {@var{filterspec} =} __fltk_file_filter__ (@var{filter})
+## @deftypefn {Function File} {@var{filterspec} =} __fltk_file_filter__ (@var{filter})
 ## Undocumented internal function.
 ## @end deftypefn
 
--- a/scripts/plot/private/__go_draw_axes__.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/private/__go_draw_axes__.m	Wed Dec 07 19:06:13 2011 -0500
@@ -441,6 +441,7 @@
     while (! isempty (kids))
 
       obj = get (kids(end));
+
       if (isfield (obj, "units"))
         units = obj.units;
         unwind_protect
@@ -2302,10 +2303,38 @@
         warning ("latex markup not supported for text objects");
         warned_latex = true;
       endif
+    elseif (enhanced)
+      str = no_super_sub_scripts (str);
     endif
   endif
 endfunction
 
+function str = no_super_sub_scripts (str)
+  if (iscellstr (str))
+    labels = str;
+  else
+    labels = cellstr (str);
+  endif
+  for marker = "_^" 
+    for m = 1 : numel(labels)
+      n1 = strfind (labels{m}, sprintf ("\\%s", marker));
+      n2 = strfind (labels{m}, marker);
+      if (! isempty (n1))
+        n1 = n1 + 1;
+        n2 = setdiff (n2, n1);
+      end
+      for n = n2
+        labels{m} = [labels{m}(1:n2-1), "\\", labels{m}(n2:end)];
+      endfor
+    endfor
+  endfor
+  if (iscellstr (str))
+    str = labels;
+  else
+    str = char (labels);
+  endif
+endfunction
+
 function str = __tex2enhanced__ (str, fnt, it, bld)
   persistent sym = __setup_sym_table__ ();
   persistent flds = fieldnames (sym);
--- a/scripts/plot/private/__is_function__.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/private/__is_function__.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {@var{result} =} __is_function__ (@var{func})
+## @deftypefn {Function File} {@var{result} =} __is_function__ (@var{func})
 ## Undocumented internal function.
 ## @end deftypefn
 
--- a/scripts/plot/private/__next_line_style__.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/private/__next_line_style__.m	Wed Dec 07 19:06:13 2011 -0500
@@ -39,7 +39,10 @@
           style_index = 1;
         endif
       elseif (reset || isempty (style_rotation))
-        style_rotation = strsplit (get (gca (), "linestyleorder"), "|");
+        style_rotation = get (gca (), "linestyleorder");
+        if (ischar (style_rotation))
+          style_rotation = strsplit (style_rotation, "|");
+        endif
         num_styles = length (style_rotation);
         style_index = 1;
       endif
--- a/scripts/plot/private/__patch__.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/private/__patch__.m	Wed Dec 07 19:06:13 2011 -0500
@@ -29,6 +29,7 @@
 
 function [h, failed] = __patch__ (p, varargin)
 
+  h = NaN;
   failed = false;
 
   is_numeric_arg = cellfun (@isnumeric, varargin);
@@ -128,11 +129,29 @@
           else
             error ("patch: color value not valid");
           endif
-        elseif (size (c, ndims (c)) == 3)
+        elseif (isvector (c) && numel (c) == 3)
           args{7} = "facecolor";
           args{8} = c;
           args{9} = "cdata";
           args{10} = [];
+        elseif (ndims (c) == 3 && size (c, 3) == 3)
+          ## CDATA is specified as RGB data
+          if ((size (c, 1) == 1 && size (c, 2) == 1) ...
+              || (size (c, 1) == 1 && size (c, 2) == columns (x)))
+            ## Single patch color or per-face color
+            args{7} = "facecolor";
+            args{8} = "flat";
+            args{9} = "cdata";
+            args{10} = c;
+          elseif (size (c, 1) == rows (x) && size (c, 2) == columns (x))
+            ## Per-vertex color
+            args{7} = "facecolor";
+            args{8} = "interp";
+            args{9} = "cdata";
+            agrs{10} = c;
+          else
+            error ("patch: color value not valid");
+          endif
         else
           ## Color Vectors
           if (isempty (c))
@@ -231,11 +250,8 @@
       fc = [0, 1, 0];
     endif
     args = {"facecolor", fc, args{:}};
-  else
-    fc = args {idx};
   endif
 
-  nr = size (faces, 2);
   nc = size (faces, 1);
   idx = faces .';
   t1 = isnan (idx);
@@ -302,17 +318,19 @@
       fc = [0, 1, 0];
     endif
     args = {"facecolor", fc, args{:}};
-  else
-    fc = args {idx};
   endif
 
   [nr, nc] = size (x);
+  if (nr == 1 && nc > 1)
+    nr = nc;
+    nc = 1;
+  end
   if (!isempty (z))
     vert = [x(:), y(:), z(:)];
   else
     vert = [x(:), y(:)];
   endif
-  faces = reshape (1:numel(x), rows (x), columns (x));
+  faces = reshape (1:numel(x), nr, nc);
   faces = faces';
 
   if (ndims (c) == 3)
--- a/scripts/plot/private/__scatter__.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/private/__scatter__.m	Wed Dec 07 19:06:13 2011 -0500
@@ -195,18 +195,23 @@
     elseif (columns (c) == 1)
       h = render_size_color (hg, vert, s, c, marker, filled, true);
     else
-      [cc, idx] = unique_idx (c, "rows");
-      if (isscalar (s))
-        for i = 1:rows (x)
-          h = render_size_color (hg, vert(idx{i},:), s, cc(i,:),
+      ## We want to group points by colour. So first get all the unique colours
+      [cc, ~, c_to_cc] = unique (c, "rows");
+
+      for i = 1:rows (cc)
+        ## Now for each possible unique colour, get the logical index of
+        ## points that correspond to that colour
+        idx = (i == c_to_cc);
+
+        if (isscalar (s))
+          h = render_size_color (hg, vert(idx, :), s, c(idx,:),
                                  marker, filled, true);
-        endfor
-      else
-        for i = 1:rows (x)
-          h = render_size_color (hg, vert(idx{i},:), s(idx{i}), cc(i,:),
+        else
+          h = render_size_color (hg, vert(idx, :), s(idx), c(idx,:),
                                  marker, filled, true);
-        endfor
-      endif
+        endif
+      endfor
+
     endif
   endif
 
@@ -250,28 +255,6 @@
 
 endfunction
 
-function [y, idx] =  unique_idx (x, byrows)
-  if (nargin == 2)
-    [xx, idx] = sortrows (x);
-    n = rows (x);
-    jdx = find (any (xx(1:n-1,:) != xx(2:n,:), 2));
-    jdx(end+1) = n;
-    y = xx(jdx,:);
-  else
-    [xx, idx] = sort (x);
-    n = length (x);
-    jdx = find (xx(1:n-1,:) != xx(2:n,:));
-    jdx(end+1) = n;
-    y = xx(jdx);
-  endif
-
-  if (nargin == 2 || columns (x) == 1)
-    idx = mat2cell (idx, diff ([0; jdx]), 1);
-  else
-    idx = mat2cell (idx, 1, diff ([0, jdx]));
-  endif
-endfunction
-
 function h = render_size_color(hg, vert, s, c, marker, filled, isflat)
   if (isscalar (s))
     x = vert(:,1);
@@ -303,7 +286,7 @@
                           "marker", marker, "markersize", s,
                           "markeredgecolor", "none",
                           "markerfacecolor", "flat",
-                          "cdata", c, "facevertexcdata", c(:),
+                          "cdata", c, "facevertexcdata", c,
                           "linestyle", "none");
       else
         h = __go_patch__ (hg, "xdata", x, "ydata", y, "zdata", z,
@@ -312,15 +295,16 @@
                           "marker", marker, "markersize", s,
                           "markeredgecolor", "flat",
                           "markerfacecolor", "none",
-                          "cdata", c, "facevertexcdata", c(:),
+                          "cdata", c, "facevertexcdata", c,
                           "linestyle", "none");
       endif
     endif
   else
     ## FIXME: round the size to one decimal place. It's not quite right, though.
-    [ss, idx] = unique_idx (ceil (s*10) / 10);
+    [ss, ~, s_to_ss] = unique (ceil (s*10) / 10);
     for i = 1:rows (ss)
-      h = render_size_color (hg, vert(idx{i},:), ss(i), c,
+      idx = (i == s_to_ss);
+      h = render_size_color (hg, vert(idx,:), ss(i), c,
                              marker, filled, isflat);
     endfor
   endif
--- a/scripts/plot/private/__uigetdir_fltk__.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/private/__uigetdir_fltk__.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {@var{dirname} =} __uigetdir_fltk__ (@var{start_path}, @var{dialog_title})
+## @deftypefn {Function File} {@var{dirname} =} __uigetdir_fltk__ (@var{start_path}, @var{dialog_title})
 ## Undocumented internal function.
 ## @end deftypefn
 
--- a/scripts/plot/private/__uigetfile_fltk__.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/private/__uigetfile_fltk__.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} __uigetfile_fltk__ ()
+## @deftypefn {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} __uigetfile_fltk__ ()
 ## Undocumented internal function.
 ## @end deftypefn
 
--- a/scripts/plot/private/__uiobject_split_args__.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/private/__uiobject_split_args__.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {[@var{p}, @var{args}] =} __uiobject_split_args__ (@var{who}, @var{args}, @var{parent_type}, @var{use_gcf})
+## @deftypefn {Function File} {[@var{p}, @var{args}] =} __uiobject_split_args__ (@var{who}, @var{args}, @var{parent_type}, @var{use_gcf})
 ## @end deftypefn
 
 ## Author: goffioul
--- a/scripts/plot/private/__uiputfile_fltk__.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/private/__uiputfile_fltk__.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} __uiputfile_fltk__ ()
+## @deftypefn {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} __uiputfile_fltk__ ()
 ## Undocumented internal function.
 ## @end deftypefn
 
--- a/scripts/plot/quiver.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/quiver.m	Wed Dec 07 19:06:13 2011 -0500
@@ -34,7 +34,7 @@
 ## size(@var{u})}.
 ##
 ## The variable @var{s} is a scalar defining a scaling factor to use for
-##  the arrows of the field relative to the mesh spacing.  A value of 0
+## the arrows of the field relative to the mesh spacing.  A value of 0
 ## disables all scaling.  The default value is 1.
 ##
 ## The style to use for the plot can be defined with a line style @var{style}
@@ -43,9 +43,9 @@
 ## printed rather than arrows.  If the argument 'filled' is given then the
 ## markers as filled.
 ##
-## The optional return value @var{h} provides a quiver group that
-## regroups the components of the quiver plot (body, arrow and marker),
-## and allows them to be changed together
+## The optional return value @var{h} is a graphics handle to a quiver object.
+## A quiver object regroups the components of the quiver plot (body, arrow,
+## and marker), and allows them to be changed together.
 ##
 ## @example
 ## @group
@@ -81,14 +81,18 @@
 
 endfunction
 
+
 %!demo
 %! clf
-%! [x,y] = meshgrid(1:2:20);
-%! h = quiver(x,y,sin(2*pi*x/10),sin(2*pi*y/10));
+%! [x,y] = meshgrid (1:2:20);
+%! h = quiver (x,y, sin (2*pi*x/10), sin (2*pi*y/10));
 %! set (h, "maxheadsize", 0.33);
 
 %!demo
-%! axis("equal");
-%! x=linspace(0,3,80); y=sin(2*pi*x); theta=2*pi*x+pi/2;
-%! quiver(x,y,sin(theta)/10,cos(theta)/10);
+%! axis ("equal");
+%! x = linspace (0,3,80);
+%! y = sin (2*pi*x);
+%! theta = 2*pi*x + pi/2;
+%! quiver (x, y, sin (theta)/10, cos (theta)/10);
 %! hold on; plot(x,y,"r"); hold off;
+
--- a/scripts/plot/quiver3.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/quiver3.m	Wed Dec 07 19:06:13 2011 -0500
@@ -43,9 +43,9 @@
 ## printed rather than arrows.  If the argument 'filled' is given then the
 ## markers as filled.
 ##
-## The optional return value @var{h} provides a quiver group that
-## regroups the components of the quiver plot (body, arrow and marker),
-## and allows them to be changed together
+## The optional return value @var{h} is a graphics handle to a quiver object.
+## A quiver object regroups the components of the quiver plot (body, arrow,
+## and marker), and allows them to be changed together.
 ##
 ## @example
 ## @group
@@ -86,13 +86,13 @@
 
 %!demo
 %! clf
-%! colormap (jet (64))
-%! [x,y]=meshgrid (-1:0.1:1);
-%! z=sin(2*pi*sqrt(x.^2+y.^2));
-%! theta=2*pi*sqrt(x.^2+y.^2)+pi/2;
-%! quiver3(x,y,z,sin(theta),cos(theta),ones(size(z)));
+%! colormap (jet (64));
+%! [x,y] = meshgrid (-1:0.1:1);
+%! z = sin (2*pi * sqrt (x.^2+y.^2));
+%! theta = 2*pi * sqrt (x.^2+y.^2) + pi/2;
+%! quiver3 (x, y, z, sin (theta), cos (theta), ones (size (z)));
 %! hold on;
-%! mesh(x,y,z);
+%! mesh (x,y,z);
 %! hold off;
 
 %!demo
--- a/scripts/plot/rectangle.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/rectangle.m	Wed Dec 07 19:06:13 2011 -0500
@@ -44,9 +44,10 @@
 ## min (pos (1:2)) / max (pos (1:2)) * curv
 ## @end example
 ##
-## Other properties are passed to the underlying patch command.  If called
-## with an output argument, @code{rectangle} returns the handle to the
-## rectangle.
+## Other properties are passed to the underlying patch command. 
+## 
+## The optional return value @var{h} is a graphics handle to the created
+## rectangle object.
 ## @end deftypefn
 ## @seealso{patch}
 
--- a/scripts/plot/ribbon.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/ribbon.m	Wed Dec 07 19:06:13 2011 -0500
@@ -23,9 +23,10 @@
 ## Plot a ribbon plot for the columns of @var{y} vs.  @var{x}.  The
 ## optional parameter @var{width} specifies the width of a single ribbon
 ## (default is 0.75).  If @var{x} is omitted, a vector containing the
-## row numbers is assumed (1:rows(Y)).  If requested, return a vector
-## @var{h} of the handles to the surface objects.
-## @seealso{gca, colorbar}
+## row numbers is assumed (1:rows(Y)).
+##
+## The optional return value @var{h} is a vector of graphics handles to
+## the surface objects representing each ribbon.
 ## @end deftypefn
 
 ## Author: Kai Habel <kai.habel at gmx.de>
@@ -85,7 +86,9 @@
 
 endfunction
 
+
 %!demo
 %! [x, y, z] = sombrero ();
 %! [x, y] = meshgrid (x, y);
 %! ribbon (y, z);
+
--- a/scripts/plot/rose.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/rose.m	Wed Dec 07 19:06:13 2011 -0500
@@ -30,10 +30,10 @@
 ## @var{r} bins.  If @var{r} is a vector, then the center of each bin are
 ## defined by the values of @var{r}.
 ##
-## The optional return value @var{h} provides a list of handles to the
-## the parts of the vector field (body, arrow and marker).
+## The optional return value @var{h} is a vector of graphics handles to the
+## line objects representing each histogram.
 ##
-## If two output arguments are requested, then rather than plotting the
+## If two output arguments are requested then, rather than plotting the
 ## histogram, the polar vectors necessary to plot the histogram are
 ## returned.
 ##
@@ -44,8 +44,7 @@
 ## @end group
 ## @end example
 ##
-##
-## @seealso{plot, compass, polar, hist}
+## @seealso{polar, compass, hist}
 ## @end deftypefn
 
 function [thout, rout] = rose (varargin)
--- a/scripts/plot/scatter.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/scatter.m	Wed Dec 07 19:06:13 2011 -0500
@@ -44,7 +44,8 @@
 ## If the argument @code{"filled"} is given then the markers as filled.  All
 ## additional arguments are passed to the underlying patch command.
 ##
-## The optional return value @var{h} provides a handle to the patch object
+## The optional return value @var{h} is a graphics handle to the hggroup
+## object representing the points.
 ##
 ## @example
 ## @group
@@ -89,7 +90,7 @@
 %!demo
 %! x = randn (100, 1);
 %! y = randn (100, 1);
-%! scatter (x, y, [], sqrt(x.^2 + y.^2));
+%! scatter (x, y, [], sqrt (x.^2 + y.^2));
 
 %!demo
 %! rand_10x1_data1 = [0.171577, 0.404796, 0.025469, 0.335309, 0.047814, 0.898480, 0.639599, 0.700247, 0.497798, 0.737940];
@@ -115,3 +116,11 @@
 %! s = 10 - 10*log (x.^2 + y.^2);
 %! h = scatter (x, y, [], "r", "s");
 
+%!demo
+%! n = 500;
+%! x = rand (n,1);
+%! y = rand (n,1);
+%! idx = ceil (rand (n,1)*3);
+%! colors = eye(3)(idx, :);
+%! scatter (x,y,15, colors, "filled");
+
--- a/scripts/plot/scatter3.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/scatter3.m	Wed Dec 07 19:06:13 2011 -0500
@@ -41,7 +41,8 @@
 ## If the argument 'filled' is given then the markers as filled.  All
 ## additional arguments are passed to the underlying patch command.
 ##
-## The optional return value @var{h} provides a handle to the patch object
+## The optional return value @var{h} is a graphics handle to the hggroup
+## object representing the points.
 ##
 ## @example
 ## @group
--- a/scripts/plot/semilogx.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/semilogx.m	Wed Dec 07 19:06:13 2011 -0500
@@ -26,6 +26,8 @@
 ## Produce a two-dimensional plot using a logarithmic scale for the @var{x}
 ## axis.  See the documentation of @code{plot} for a description of the
 ## arguments that @code{semilogx} will accept.
+## 
+## The optional return value @var{h} is a graphics handle to the created plot.
 ## @seealso{plot, semilogy, loglog}
 ## @end deftypefn
 
@@ -60,6 +62,7 @@
 
 endfunction
 
+
 %!demo
 %! x = 1:0.01:10;
 %! y = (x .* (1 + rand (size (x)))) .^ 2;
@@ -70,28 +73,28 @@
 %! x = logspace (-5, 1, 10);
 %! y = logspace (-5, 1, 10);
 %!
-%! subplot (1, 2, 1)
-%! semilogx (x, y)
-%! xlabel ('semilogx (x, y)')
+%! subplot (1, 2, 1);
+%! semilogx (x, y);
+%! xlabel ("semilogx (x, y)");
 %!
-%! subplot (1, 2, 2)
-%! semilogx (-x, y)
-%! xlabel ('semilogx (-x, y)')
+%! subplot (1, 2, 2);
+%! semilogx (-x, y);
+%! xlabel ("semilogx (-x, y)");
 
 %!demo
 %! clf ();
 %! x = logspace (-5, 1, 10);
 %! y = logspace (-5, 1, 10);
 %!
-%! subplot (1, 2, 1)
-%! semilogx (x, y)
+%! subplot (1, 2, 1);
+%! semilogx (x, y);
 %! set (gca, "xdir", "reverse", "activepositionproperty", "outerposition")
 %! xlabel ({"semilogx (x, y)", "xdir = reversed"})
 %!
-%! subplot (1, 2, 2)
-%! semilogx (-x, y)
-%! set (gca, "xdir", "reverse", "activepositionproperty", "outerposition")
-%! xlabel ({"semilogx (-x, y)","xdir = reversed"})
+%! subplot (1, 2, 2);
+%! semilogx (-x, y);
+%! set (gca, "xdir", "reverse", "activepositionproperty", "outerposition");
+%! xlabel ({"semilogx (-x, y)", "xdir = reversed"});
 
 %!test
 %! hf = figure ("visible", "off");
@@ -102,7 +105,7 @@
 %!   assert (get (gca, "xscale"), "log");
 %!   assert (get (gca, "yscale"), "linear");
 %! unwind_protect_cleanup
-%! close (hf);
+%!   close (hf);
 %! end_unwind_protect
 
 %!test
@@ -110,9 +113,10 @@
 %! unwind_protect
 %!   a = logspace (-5, 1, 10);
 %!   b =-logspace (-5, 1, 10);
-%!   semilogx (a, b)
-%!   axis tight
+%!   semilogx (a, b);
+%!   axis tight;
 %!   assert (all (get (gca, "ytick") < 0));
 %! unwind_protect_cleanup
-%! close (hf);
+%!   close (hf);
 %! end_unwind_protect
+
--- a/scripts/plot/semilogy.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/semilogy.m	Wed Dec 07 19:06:13 2011 -0500
@@ -26,6 +26,8 @@
 ## Produce a two-dimensional plot using a logarithmic scale for the @var{y}
 ## axis.  See the documentation of @code{plot} for a description of the
 ## arguments that @code{semilogy} will accept.
+##
+## The optional return value @var{h} is a graphics handle to the created plot.
 ## @seealso{plot, semilogx, loglog}
 ## @end deftypefn
 
@@ -71,39 +73,39 @@
 %! x = logspace (-5, 1, 10);
 %! y = logspace (-5, 1, 10);
 %!
-%! subplot (2, 1, 1)
-%! semilogy (x, y)
-%! ylabel ('semilogy (x, y)')
+%! subplot (2, 1, 1);
+%! semilogy (x, y);
+%! ylabel ("semilogy (x, y)");
 %!
-%! subplot (2, 1, 2)
-%! semilogy (x, -y)
-%! ylabel ('semilogy (x, -y)')
+%! subplot (2, 1, 2);
+%! semilogy (x, -y);
+%! ylabel ("semilogy (x, -y)");
 
 %!demo
 %! clf ();
 %! x = logspace (-5, 1, 10);
 %! y = logspace (-5, 1, 10);
 %!
-%! subplot (2, 1, 1)
-%! semilogy (x, y)
-%! set (gca, "ydir", "reverse", "activepositionproperty", "outerposition")
-%! ylabel ({"semilogy (x, y)", "ydir = reversed"})
+%! subplot (2, 1, 1);
+%! semilogy (x, y);
+%! set (gca, "ydir", "reverse", "activepositionproperty", "outerposition");
+%! ylabel ({"semilogy (x, y)", "ydir = reversed"});
 %!
-%! subplot (2, 1, 2)
-%! semilogy (x, -y)
-%! set (gca, "ydir", "reverse", "activepositionproperty", "outerposition")
-%! ylabel ({"semilogy (x, -y)", "ydir = reversed"})
+%! subplot (2, 1, 2);
+%! semilogy (x, -y);
+%! set (gca, "ydir", "reverse", "activepositionproperty", "outerposition");
+%! ylabel ({"semilogy (x, -y)", "ydir = reversed"});
 
 %!test
 %! hf = figure ("visible", "off");
 %! unwind_protect
 %!   a = logspace (-5, 1, 10);
 %!   b = logspace (-5, 1, 10);
-%!   semilogy (a, b)
+%!   semilogy (a, b);
 %!   assert (get (gca, "yscale"), "log");
 %!   assert (get (gca, "xscale"), "linear");
 %! unwind_protect_cleanup
-%! close (hf);
+%!   close (hf);
 %! end_unwind_protect
 
 %!test
@@ -111,11 +113,10 @@
 %! unwind_protect
 %!   a = logspace (-5, 1, 10);
 %!   b =-logspace (-5, 1, 10);
-%!   semilogy (a, b)
-%!   axis tight
+%!   semilogy (a, b);
+%!   axis tight;
 %!   assert (all (get (gca, "ytick") < 0));
 %! unwind_protect_cleanup
-%! close (hf);
+%!   close (hf);
 %! end_unwind_protect
 
-
--- a/scripts/plot/shading.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/shading.m	Wed Dec 07 19:06:13 2011 -0500
@@ -73,24 +73,36 @@
 
 endfunction
 
+
 %!demo
 %! clf
 %! colormap (jet)
 %! sombrero
 %! shading faceted
-%! title("shading ""faceted""")
+%! title ('shading "faceted"')
+
+%!demo
+%! sombrero
+%! shading flat
+%! title ('shading "flat"')
 
 %!demo
 %! sombrero
 %! shading interp
-%! title("shading ""interp""")
+%! title ('shading "interp"')
 
 %!demo
 %! pcolor (peaks ())
 %! shading faceted
-%! title("shading ""faceted""")
+%! title ('shading "faceted"')
+
+%!demo
+%! pcolor (peaks ())
+%! shading flat
+%! title ('shading "flat"')
 
 %!demo
 %! pcolor (peaks ())
 %! shading interp
-%! title("shading ""interp""")
+%! title ('shading "interp"')
+
--- a/scripts/plot/slice.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/slice.m	Wed Dec 07 19:06:13 2011 -0500
@@ -55,8 +55,9 @@
 ## @end table
 ##
 ## The default method is @code{"linear"}.
-## The optional return value @var{h} is a vector of handles to the
-## surface graphic objects.
+##
+## The optional return value @var{h} is a graphics handle to the created
+## surface object.
 ##
 ## Examples:
 ##
@@ -179,10 +180,14 @@
 
 endfunction
 
+
 %!demo
 %! [x, y, z] = meshgrid (linspace (-8, 8, 32));
 %! v = sin (sqrt (x.^2 + y.^2 + z.^2)) ./ (sqrt (x.^2 + y.^2 + z.^2));
 %! slice (x, y, z, v, [], 0, []);
+
+%!demo
 %! [xi, yi] = meshgrid (linspace (-7, 7));
 %! zi = xi + yi;
 %! slice (x, y, z, v, xi, yi, zi);
+
--- a/scripts/plot/stem.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/stem.m	Wed Dec 07 19:06:13 2011 -0500
@@ -47,8 +47,8 @@
 ## @noindent
 ## plots 10 stems with heights from 2 to 20 in red;
 ##
-## The return value of @code{stem} is a vector of "stem series" graphics
-## handles, with one handle per column of the variable @var{y}.  This
+## The optional return value @var{h} is a vector of "stem series" graphics
+## handles with one handle per column of the variable @var{y}.  The
 ## handle regroups the elements of the stem graph together as the
 ## children of the "stem series" handle, allowing them to be altered
 ## together.  For example,
@@ -86,33 +86,34 @@
 
 endfunction
 
+
 %!demo
 %! x = 1:10;
 %! stem (x);
 
 %!demo
 %! x = 1:10;
-%! y = ones (1, length (x))*2.*x;
+%! y = 2*x;
 %! stem (x, y);
 
 %!demo
 %! x = 1:10;
-%! y = ones (size (x))*2.*x;
+%! y = 2*x;
 %! h = stem (x, y, "r");
 
 %!demo
 %! x = 1:10;
-%! y = ones (size (x))*2.*x;
+%! y = 2*x;
 %! h = stem (x, y, "-.k");
 
 %!demo
 %! x = 1:10;
-%! y = ones (size (x))*2.*x;
+%! y = 2*x;
 %! h = stem (x, y, "-.k.");
 
 %!demo
 %! x = 1:10;
-%! y = ones (size (x))*2.*x;
+%! y = 2*x;
 %! h = stem (x, y, "filled");
 
 %!demo
@@ -121,3 +122,4 @@
 %! h = stem (x, y);
 %! set (h(2), "color", "g");
 %! set (h(1), "basevalue", -1)
+
--- a/scripts/plot/surf.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/surf.m	Wed Dec 07 19:06:13 2011 -0500
@@ -32,6 +32,9 @@
 ## The color of the surface is derived from the @code{colormap} and
 ## the value of @var{z}.  Optionally the color of the surface can be
 ## specified independent of @var{z}, by adding a fourth matrix, @var{c}.
+##
+## The optional return value @var{h} is a graphics handle to the created
+## surface object.
 ## @seealso{colormap, contour, meshgrid, mesh}
 ## @end deftypefn
 
@@ -61,19 +64,21 @@
 
 endfunction
 
+
 %!demo
 %! clf
-%! [~,~,Z]=peaks;
-%! surf(Z);
+%! [~,~,Z] = peaks;
+%! surf (Z);
 
 %!demo
-%! [~,~,Z]=sombrero;
-%! [Fx,Fy] = gradient(Z);
-%! surf(Z,Fx+Fy);
+%! [~,~,Z] = sombrero;
+%! [Fx,Fy] = gradient (Z);
+%! surf (Z, Fx+Fy);
 %! shading interp;
 
 %!demo
-%! [X,Y,Z]=sombrero;
-%! [~,Fy] = gradient(Z);
-%! surf(X,Y,Z,Fy);
+%! [X,Y,Z] = sombrero;
+%! [~,Fy] = gradient (Z);
+%! surf (X, Y, Z, Fy);
 %! shading interp;
+
--- a/scripts/plot/surface.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/surface.m	Wed Dec 07 19:06:13 2011 -0500
@@ -33,6 +33,9 @@
 ## are missing, they are constructed from size of the matrix @var{z}.
 ##
 ## Any additional properties passed are assigned to the surface.
+## 
+## The optional return value @var{h} is a graphics handle to the created
+## surface object.
 ## @seealso{surf, mesh, patch, line}
 ## @end deftypefn
 
@@ -163,8 +166,7 @@
 
 endfunction
 
-## Mark file as being tested.  Tests for surface are in
-## surf.m, surfc.m, surfl.m, and pcolor.m
+## Functional tests for surface() are in surf.m, surfc.m, surfl.m, and pcolor.m
 
 %!test
 %! hf = figure ("visible", "off");
@@ -183,3 +185,4 @@
 %! unwind_protect_cleanup
 %!   close (hf);
 %! end_unwind_protect
+
--- a/scripts/plot/text.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/text.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,13 +17,17 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{label})
-## @deftypefnx {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{z}, @var{label})
-## @deftypefnx {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{label}, @var{p1}, @var{v1}, @dots{})
-## @deftypefnx {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{z}, @var{label}, @var{p1}, @var{v1}, @dots{})
+## @deftypefn  {Function File} {} text (@var{x}, @var{y}, @var{label})
+## @deftypefnx {Function File} {} text (@var{x}, @var{y}, @var{z}, @var{label})
+## @deftypefnx {Function File} {} text (@var{x}, @var{y}, @var{label}, @var{p1}, @var{v1}, @dots{})
+## @deftypefnx {Function File} {} text (@var{x}, @var{y}, @var{z}, @var{label}, @var{p1}, @var{v1}, @dots{})
+## @deftypefnx {Function File} {@var{h} =} text (@dots{})
 ## Create a text object with text @var{label} at position @var{x},
 ## @var{y}, @var{z} on the current axes.  Property-value pairs following
 ## @var{label} may be used to specify the appearance of the text.
+##
+## The optional return value @var{h} is a graphics handle to the created text
+## object.
 ## @end deftypefn
 
 ## Author: jwe
@@ -134,17 +138,17 @@
 %!       text (x(nh), y(nv), "Hello World", ...
 %!             "rotation", t, ...
 %!             "horizontalalignment", ha{nh}, ...
-%!             "verticalalignment", va{nv})
+%!             "verticalalignment", va{nv});
 %!     endfor
 %!   endfor
 %! endfor
 %! set (gca, "xtick", [0.25, 0.5, 0.75], ...
 %!           "xticklabel", ha, ...
 %!           "ytick", [0.25, 0.5, 0.75], ...
-%!           "yticklabel", va)
-%! axis ([0 1 0 1])
-%! xlabel ("horizontal alignment")
-%! ylabel ("vertical alignment")
+%!           "yticklabel", va);
+%! axis ([0 1 0 1]);
+%! xlabel ("horizontal alignment");
+%! ylabel ("vertical alignment");
 %! title ("text alignment and rotation (0:30:360 degrees)")
 
 %!demo
@@ -156,20 +160,20 @@
 %!   text (25, 25, 0, "Vertical Alignment = Bottom", ...
 %!                    "rotation", t, ...
 %!                    "horizontalalignment", "left", ...
-%!                    "verticalalignment", "bottom")
+%!                    "verticalalignment", "bottom");
 %! endfor
-%! caxis ([-100 100])
-%! title ("Vertically Aligned at Bottom")
+%! caxis ([-100 100]);
+%! title ("Vertically Aligned at Bottom");
 
 %!demo
 %! clf
-%! axis ([0 8 0 8])
-%! title (["1st title";"2nd title"])
-%! xlabel (["1st xlabel";"2nd xlabel"])
-%! ylabel (["1st ylabel";"2nd ylabel"])
+%! axis ([0 8 0 8]);
+%! title (["1st title";"2nd title"]);
+%! xlabel (["1st xlabel";"2nd xlabel"]);
+%! ylabel (["1st ylabel";"2nd ylabel"]);
 %! text (4, 4, {"Hello", "World"}, ...
 %!       "horizontalalignment", "center", ...
-%!       "verticalalignment", "middle")
+%!       "verticalalignment", "middle");
 %! grid on
 
 %!demo
@@ -177,74 +181,74 @@
 %! h = mesh (peaks, "edgecolor", 0.7 * [1 1 1], ...
 %!                  "facecolor", "none", ...
 %!                  "facealpha", 0);
-%! title (["1st title";"2nd title"])
-%! xlabel (["1st xlabel";"2nd xlabel"])
-%! ylabel (["1st ylabel";"2nd ylabel"])
-%! zlabel (["1st zlabel";"2nd zlabel"])
+%! title (["1st title";"2nd title"]);
+%! xlabel (["1st xlabel";"2nd xlabel"]);
+%! ylabel (["1st ylabel";"2nd ylabel"]);
+%! zlabel (["1st zlabel";"2nd zlabel"]);
 %! text (0, 0, 5, {"Hello", "World"}, ...
 %!       "horizontalalignment", "center", ...
-%!       "verticalalignment", "middle")
-%! hold on
-%! plot3 (0, 0, 5, "+k")
-%!
+%!       "verticalalignment", "middle");
+%! hold on;
+%! plot3 (0, 0, 5, "+k");
 
 %!demo
 %! clf
 %! h = text (0.5, 0.3, "char");
-%! assert ("char", class (get (h, "string")))
+%! assert ("char", class (get (h, "string")));
 %! h = text (0.5, 0.4, ["char row 1"; "char row 2"]);
-%! assert ("char", class (get (h, "string")))
+%! assert ("char", class (get (h, "string")));
 %! h = text (0.5, 0.6, {"cell2str (1,1)", "cell2str (1,2)"; "cell2str (2,1)", "cell2str (2,2)"});
-%! assert ("cell", class (get (h, "string")))
+%! assert ("cell", class (get (h, "string")));
 %! h = text (0.5, 0.8, "foobar");
-%! set (h, "string", 1:3)
+%! set (h, "string", 1:3);
 %! h = text ([0.1, 0.1], [0.3, 0.4], "one string & two objects");
-%! assert ("char", class (get (h(1), "string")))
-%! assert ("char", class (get (h(2), "string")))
+%! assert ("char", class (get (h(1), "string")));
+%! assert ("char", class (get (h(2), "string")));
 %! h = text ([0.1, 0.1], [0.5, 0.6], {"one cellstr & two objects"});
-%! assert ("cell", class (get (h(1), "string")))
-%! assert ("cell", class (get (h(2), "string")))
+%! assert ("cell", class (get (h(1), "string")));
+%! assert ("cell", class (get (h(2), "string")));
 %! h = text ([0.1, 0.1], [0.7, 0.8], {"cellstr 1 object 1", "cellstr 2 object 2"});
-%! assert ("char", class (get (h(1), "string")))
-%! assert ("char", class (get (h(2), "string")))
+%! assert ("char", class (get (h(1), "string")));
+%! assert ("char", class (get (h(2), "string")));
 %! h = text ([0.1, 0.1], [0.1, 0.2], ["1st string & 1st object"; "2nd string & 2nd object"]);
-%! assert ("char", class (get (h(1), "string")))
-%! assert ("char", class (get (h(2), "string")))
+%! assert ("char", class (get (h(1), "string")));
+%! assert ("char", class (get (h(2), "string")));
 %! h = text (0.7, 0.6, "single string");
-%! assert ("char", class (get (h, "string")))
+%! assert ("char", class (get (h, "string")));
 %! h = text (0.7, 0.5, {"single cell-string"});
-%! assert ("cell", class (get (h, "string")))
-%! xlabel (1:2)
-%! ylabel (1:2)
-%! title (1:2)
+%! assert ("cell", class (get (h, "string")));
+%! xlabel (1:2);
+%! ylabel (1:2);
+%! title (1:2);
 
 %!test
 %! hf = figure ("visible", "off");
 %! unwind_protect
 %!   h = text (0.5, 0.3, "char");
-%!   assert ("char", class (get (h, "string")))
+%!   assert ("char", class (get (h, "string")));
 %!   h = text (0.5, 0.4, ["char row 1"; "char row 2"]);
-%!   assert ("char", class (get (h, "string")))
+%!   assert ("char", class (get (h, "string")));
 %!   h = text (0.5, 0.6, {"cell2str (1,1)", "cell2str (1,2)"; "cell2str (2,1)", "cell2str (2,2)"});
-%!   assert ("cell", class (get (h, "string")))
+%!   assert ("cell", class (get (h, "string")));
 %!   h = text (0.5, 0.8, "foobar");
-%!   set (h, "string", 1:3)
+%!   set (h, "string", 1:3);
 %!   h = text ([0.1, 0.1], [0.3, 0.4], "one string & two objects");
-%!   assert ("char", class (get (h(1), "string")))
-%!   assert ("char", class (get (h(2), "string")))
+%!   assert ("char", class (get (h(1), "string")));
+%!   assert ("char", class (get (h(2), "string")));
 %!   h = text ([0.1, 0.1], [0.5, 0.6], {"one cellstr & two objects"});
-%!   assert ("cell", class (get (h(1), "string")))
-%!   assert ("cell", class (get (h(2), "string")))
+%!   assert ("cell", class (get (h(1), "string")));
+%!   assert ("cell", class (get (h(2), "string")));
 %!   h = text ([0.1, 0.1], [0.7, 0.8], {"cellstr 1 object 1", "cellstr 2 object 2"});
-%!   assert ("char", class (get (h(1), "string")))
-%!   assert ("char", class (get (h(2), "string")))
+%!   assert ("char", class (get (h(1), "string")));
+%!   assert ("char", class (get (h(2), "string")));
 %!   h = text ([0.1, 0.1], [0.1, 0.2], ["1st string & 1st object"; "2nd string & 2nd object"]);
-%!   assert ("char", class (get (h(1), "string")))
-%!   assert ("char", class (get (h(2), "string")))
+%!   assert ("char", class (get (h(1), "string")));
+%!   assert ("char", class (get (h(2), "string")));
 %!   h = text (0.7, 0.6, "single string");
-%!   assert ("char", class (get (h, "string")))
+%!   assert ("char", class (get (h, "string")));
 %!   h = text (0.7, 0.5, {"single cell-string"});
-%!   assert ("cell", class (get (h, "string")))
+%!   assert ("cell", class (get (h, "string")));
 %! unwind_protect_cleanup
 %!   close (hf);
 %! end_unwind_protect
+
--- a/scripts/plot/title.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/title.m	Wed Dec 07 19:06:13 2011 -0500
@@ -21,7 +21,9 @@
 ## @deftypefnx {Function File} {} title (@var{string}, @var{p1}, @var{v1}, @dots{})
 ## @deftypefnx {Function File} {} title (@var{h}, @dots{})
 ## @deftypefnx {Function File} {@var{h} =} title (@dots{})
-## Create a title object and return a handle to it.
+## Create a title object for a plot.
+##
+## The optional return value @var{h} is a graphics handle to the created object.
 ## @end deftypefn
 
 ## Author: jwe
@@ -42,27 +44,28 @@
 
 endfunction
 
+
 %!demo
 %! clf ();
-%! ax=axes();
-%! xl = get(ax,"title");
-%! title("Testing title")
-%! assert(get(xl,"string"),"Testing title")
+%! ax = axes();
+%! xl = get (ax,"title");
+%! title ("Testing title");
+%! assert (get (xl,"string"), "Testing title");
 
 %!demo
 %! clf ();
 %! plot3 ([0,1], [0,1], [0,1]);
 %! xl = get(gca (), "title");
-%! title("Testing title")
-%! assert(get(xl,"string"),"Testing title")
+%! title ("Testing title");
+%! assert (get (xl,"string"),"Testing title");
 
 %!test
 %! hf = figure ("visible", "off");
 %! unwind_protect
-%!   ax=axes();
-%!   xl = get(ax,"title");
-%!   title("Testing title")
-%!   assert(get(xl,"string"),"Testing title")
+%!   ax = axes();
+%!   xl = get (ax,"title");
+%!   title ("Testing title");
+%!   assert (get (xl,"string"), "Testing title");
 %! unwind_protect_cleanup
 %!   close (hf);
 %! end_unwind_protect
@@ -71,9 +74,10 @@
 %! hf = figure ("visible", "off");
 %! unwind_protect
 %!   plot3 ([0,1], [0,1], [0,1]);
-%!   xl = get(gca (), "title");
-%!   title("Testing title")
-%!   assert(get(xl,"string"),"Testing title")
+%!   xl = get (gca (), "title");
+%!   title("Testing title");
+%!   assert (get (xl,"string"), "Testing title");
 %! unwind_protect_cleanup
 %!   close (hf);
 %! end_unwind_protect
+
--- a/scripts/plot/trimesh.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/trimesh.m	Wed Dec 07 19:06:13 2011 -0500
@@ -22,8 +22,9 @@
 ## Plot a triangular mesh in 3D@.  The variable @var{tri} is the triangular
 ## meshing of the points @code{(@var{x}, @var{y})} which is returned
 ## from @code{delaunay}.  The variable @var{z} is value at the point
-## @code{(@var{x}, @var{y})}.  The output argument @var{h} is the graphic
-## handle of the plot.
+## @code{(@var{x}, @var{y})}.
+##
+## The optional return value @var{h} is a graphics handle to the created plot.
 ## @seealso{triplot, trisurf, delaunay3}
 ## @end deftypefn
 
--- a/scripts/plot/triplot.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/triplot.m	Wed Dec 07 19:06:13 2011 -0500
@@ -23,8 +23,9 @@
 ## Plot a triangular mesh in 2D@.  The variable @var{tri} is the triangular
 ## meshing of the points @code{(@var{x}, @var{y})} which is returned from
 ## @code{delaunay}.  If given, @var{linespec} determines the properties
-## to use for the lines.  The output argument @var{h} is the graphic handle
-## of the plot.
+## to use for the lines. 
+##
+## The optional return value @var{h} is a graphics handle to the created plot.
 ## @seealso{plot, trimesh, trisurf, delaunay}
 ## @end deftypefn
 
--- a/scripts/plot/trisurf.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/trisurf.m	Wed Dec 07 19:06:13 2011 -0500
@@ -22,8 +22,9 @@
 ## Plot a triangular surface in 3D@.  The variable @var{tri} is the triangular
 ## meshing of the points @code{(@var{x}, @var{y})} which is returned
 ## from @code{delaunay}.  The variable @var{z} is value at the point
-## @code{(@var{x}, @var{y})}.  The output argument @var{h} is the graphic
-## handle of the plot.
+## @code{(@var{x}, @var{y})}.
+##
+## The optional return value @var{h} is a graphics handle to the created plot.
 ## @seealso{triplot, trimesh, delaunay3}
 ## @end deftypefn
 
@@ -87,19 +88,19 @@
 %! y = rand (100, 1);
 %! z = x.^2 + y.^2;
 %! tri = delaunay (x, y);
-%! trisurf (tri, x, y, z)
+%! trisurf (tri, x, y, z);
 
 %!demo
 %! x = rand (100, 1);
 %! y = rand (100, 1);
 %! z = x.^2 + y.^2;
 %! tri = delaunay (x, y);
-%! trisurf (tri, x, y, z, "facecolor", "interp")
+%! trisurf (tri, x, y, z, "facecolor", "interp");
 
 %!demo
 %! x = rand (100, 1);
 %! y = rand (100, 1);
 %! z = x.^2 + y.^2;
 %! tri = delaunay (x, y);
-%! trisurf (tri, x, y, z, "facecolor", "interp", "edgecolor", "k")
+%! trisurf (tri, x, y, z, "facecolor", "interp", "edgecolor", "k");
 
--- a/scripts/plot/uicontextmenu.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/uicontextmenu.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {@var{handle} =} uicontextmenu ('Name', value, @dots{})
+## @deftypefn {Function File} {@var{handle} =} uicontextmenu ('Name', value, @dots{})
 ## @end deftypefn
 
 ## Author: goffioul
--- a/scripts/plot/uicontrol.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/uicontrol.m	Wed Dec 07 19:06:13 2011 -0500
@@ -19,7 +19,7 @@
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {@var{handle} =} uicontrol ('Name', value, @dots{})
 ## @deftypefnx {Function File} {@var{handle} =} uicontrol (@var{parent}, 'Name', value, @dots{})
-## @deftypefnx {Function File} uicontrol (@var{handle})
+## @deftypefnx {Function File} {} uicontrol (@var{handle})
 ## @end deftypefn
 
 ## Author: goffioul
--- a/scripts/plot/uimenu.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/uimenu.m	Wed Dec 07 19:06:13 2011 -0500
@@ -89,16 +89,19 @@
 
 endfunction
 
+
 %!demo
-%! surfl(peaks);
-%! colormap(copper);
-%! shading("interp");
-%! f = uimenu("label", "&File", "accelerator", "f");
-%! e = uimenu("label", "&Edit", "accelerator", "e");
-%! uimenu(f, "label", "Close", "accelerator", "q", "callback", "close (gcf)");
-%! uimenu(e, "label", "Toggle &Grid", "accelerator", "g", "callback", "grid (gca)");
+%! surfl (peaks);
+%! colormap (copper);
+%! shading ("interp");
+%! f = uimenu ("label", "&File", "accelerator", "f");
+%! e = uimenu ("label", "&Edit", "accelerator", "e");
+%! uimenu (f, "label", "Close", "accelerator", "q", "callback", "close (gcf)");
+%! uimenu (e, "label", "Toggle &Grid", "accelerator", "g", "callback", "grid (gca)");
 
-%!test
+%!testif HAVE_FLTK
+%! toolkit = graphics_toolkit ();
+%! graphics_toolkit ("fltk");
 %! hf = figure ("visible", "off");
 %! unwind_protect
 %!   ui = uimenu ("label", "mylabel");
@@ -110,10 +113,13 @@
 %!   assert (get (ui, "position"), 9);
 %! unwind_protect_cleanup
 %!   close (hf);
+%!   graphics_toolkit (toolkit);
 %! end_unwind_protect
 
 %% check for top level menus file, edit, and help
-%!test
+%!testif HAVE_FLTK
+%! toolkit = graphics_toolkit ();
+%! graphics_toolkit ("fltk");
 %! hf = figure ("visible", "off");
 %! unwind_protect
 %!   uif = findall (hf, "label", "&file");
@@ -124,9 +130,12 @@
 %!   assert (ishghandle (uih))
 %! unwind_protect_cleanup
 %!   close (hf);
+%!   graphics_toolkit (toolkit);
 %! end_unwind_protect
 
-%!test
+%!testif HAVE_FLTK
+%! toolkit = graphics_toolkit ();
+%! graphics_toolkit ("fltk");
 %! hf = figure ("visible", "off");
 %! unwind_protect
 %!   uie = findall (hf, "label", "&edit");
@@ -134,4 +143,6 @@
 %!   assert (ancestor (myui, "uimenu", "toplevel"), uie)
 %! unwind_protect_cleanup
 %!   close (hf);
+%!   graphics_toolkit (toolkit);
 %! end_unwind_protect
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/uiresume.m	Wed Dec 07 19:06:13 2011 -0500
@@ -0,0 +1,45 @@
+## Copyright (C) 2011 Michael Goffioul
+##
+## 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 3 of the License, 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, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} uiresume (@var{h})
+## Resume program execution suspended with @code{uiwait}.  The handle @var{h}
+## must be the same as the on specified in @code{uiwait}.  If the handle
+## is invalid or there is no @code{uiwait} call pending for the figure
+## with handle @var{h}, this function does nothing.
+## @seealso{uiwait}
+## @end deftypefn
+
+## Author: goffioul
+
+function uiresume (h)
+
+  if (! ishandle (h) || ! strcmp (get (h, "type"), "figure"))
+    error ("uiresume: invalid figure handle");
+  endif
+
+  try
+    uiwait_state = get (h, "__uiwait_state__");
+    if (strcmp (uiwait_state, "active"))
+      set (h, "__uiwait_state__", "triggered");
+    endif
+  catch
+    # Ignore exception
+  end_try_catch
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/uiwait.m	Wed Dec 07 19:06:13 2011 -0500
@@ -0,0 +1,80 @@
+## Copyright (C) 2011 Michael Goffioul
+##
+## 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 3 of the License, 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, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn  {Function File} {} uiwait
+## @deftypefnx {Function File} {} uiwait (@var{h})
+## @deftypefnx {Function File} {} uiwait (@var{h}, @var{timeout})
+## Suspend program execution until the figure with handle @var{h} is
+## deleted or @code{uiresume} is called.  When no figure handle is specified,
+## this function uses the current figure.
+##
+## If the figure handle is invalid or there is no current figure, this
+## functions returns immediately.
+##
+## When specified, @var{timeout} defines the number of seconds to wait
+## for the figure deletion or the @code{uiresume} call.  The timeout value
+## must be at least 1. If a smaller value is specified, a warning is issued
+## and a timeout value of 1 is used instead.  If a non-integer value is
+## specified, it is truncated towards 0. If @var{timeout} is not specified,
+## the program execution is suspended indefinitely.
+## @seealso{uiresume, waitfor}
+## @end deftypefn
+
+## Author: goffioul
+
+function uiwait (varargin)
+
+  h = [];
+  timeout = [];
+
+  if (nargin == 0)
+    h = get (0, "currentfigure");
+  else
+    h = varargin{1};
+    if (! ishandle (h) || ! strcmp (get (h, "type"), "figure"))
+      error ("uiwait: invalid figure handle");
+    endif
+    if (nargin > 1)
+      timeout = varargin{2};
+    endif
+  endif
+
+  if (! isempty (h))
+    unwind_protect
+      try
+        addproperty ("__uiwait_state__", h, "radio", "none|{active}|triggered");
+      catch
+        if (! strcmp (get (h, "__uiwait_state__"), "none"))
+          error ("uiwait: an active uiwait call for this figure already exists");
+        endif
+	set (h, "__uiwait_state__", "active");
+      end_try_catch
+      waitfor_args = {h, "__uiwait_state__", "triggered"};
+      if (! isempty (timeout))
+        waitfor_args(end+1:end+2) = {"timeout", timeout};
+      endif
+      waitfor (waitfor_args{:});
+    unwind_protect_cleanup
+      if (ishandle (h) && isprop (h, "__uiwait_state__"))
+        set (h, "__uiwait_state__", "none");
+      endif
+    end_unwind_protect
+  endif
+
+endfunction
--- a/scripts/plot/xlabel.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/xlabel.m	Wed Dec 07 19:06:13 2011 -0500
@@ -23,10 +23,10 @@
 ## @deftypefnx {Function File} {} ylabel (@dots{})
 ## @deftypefnx {Function File} {} zlabel (@dots{})
 ## Specify x-, y-, or z-axis labels for the current axis.  If @var{h} is
-## specified then label the axis defined by @var{h}.  The optional return
-## value @var{h} provides a handle to the created label.
-## @seealso{plot, semilogx, semilogy, loglog, polar, mesh, contour,
-## bar, stairs, title}
+## specified then label the axis defined by @var{h}.
+##
+## The optional return value @var{h} is a graphics handle to the created object.
+## @seealso{title, text}
 ## @end deftypefn
 
 ## Author: jwe
@@ -48,14 +48,16 @@
 
 endfunction
 
+
 %!test
 %! hf = figure ("visible", "off");
 %! unwind_protect
 %!   x = xlabel ("xlabel_string");
-%!   assert (get(gca, "xlabel"), x);
-%!   assert (get(x, "type"), "text");
-%!   assert (get(x, "visible"), "on");
-%!   assert (get(x, "string"), "xlabel_string");
+%!   assert (get (gca, "xlabel"), x);
+%!   assert (get (x, "type"), "text");
+%!   assert (get (x, "visible"), "on");
+%!   assert (get (x, "string"), "xlabel_string");
 %! unwind_protect_cleanup
 %!   close (hf);
 %! end_unwind_protect
+
--- a/scripts/plot/ylabel.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/ylabel.m	Wed Dec 07 19:06:13 2011 -0500
@@ -42,14 +42,16 @@
 
 endfunction
 
+
 %!test
 %! hf = figure ("visible", "off");
 %! unwind_protect
 %!   y = ylabel ("ylabel_string");
-%!   assert (get(gca, "ylabel"), y);
-%!   assert (get(y, "type"), "text");
-%!   assert (get(y, "visible"), "on");
-%!   assert (get(y, "string"), "ylabel_string");
+%!   assert (get (gca, "ylabel"), y);
+%!   assert (get (y, "type"), "text");
+%!   assert (get (y, "visible"), "on");
+%!   assert (get (y, "string"), "ylabel_string");
 %! unwind_protect_cleanup
 %!   close (hf);
 %! end_unwind_protect
+
--- a/scripts/plot/zlabel.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/plot/zlabel.m	Wed Dec 07 19:06:13 2011 -0500
@@ -42,14 +42,15 @@
 
 endfunction
 
+
 %!test
 %! hf = figure ("visible", "off");
 %! unwind_protect
 %!   z = zlabel ("zlabel_string");
-%!   assert (get(gca, "zlabel"), z);
-%!   assert (get(z, "type"), "text");
-%!   assert (get(z, "visible"), "off");
-%!   assert (get(z, "string"), "zlabel_string");
+%!   assert (get (gca, "zlabel"), z);
+%!   assert (get (z, "type"), "text");
+%!   assert (get (z, "visible"), "off");
+%!   assert (get (z, "string"), "zlabel_string");
 %! unwind_protect_cleanup
 %!   close (hf);
 %! end_unwind_protect
@@ -59,10 +60,11 @@
 %! plot3 (0, 0, 0);
 %! unwind_protect
 %!   z = zlabel ("zlabel_string");
-%!   assert (get(gca, "zlabel"), z);
-%!   assert (get(z, "type"), "text");
-%!   assert (get(z, "visible"), "off");
-%!   assert (get(z, "string"), "zlabel_string");
+%!   assert (get (gca, "zlabel"), z);
+%!   assert (get (z, "type"), "text");
+%!   assert (get (z, "visible"), "off");
+%!   assert (get (z, "string"), "zlabel_string");
 %! unwind_protect_cleanup
 %!   close (hf);
 %! end_unwind_protect
+
--- a/scripts/polynomial/compan.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/polynomial/compan.m	Wed Dec 07 19:06:13 2011 -0500
@@ -51,7 +51,7 @@
 ## @end ifnottex
 ## The eigenvalues of the companion matrix are equal to the roots of the
 ## polynomial.
-## @seealso{poly, roots, residue, conv, deconv, polyval, polyderiv,
+## @seealso{poly, roots, residue, conv, deconv, polyval, polyder,
 ## polyint}
 ## @end deftypefn
 
--- a/scripts/polynomial/deconv.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/polynomial/deconv.m	Wed Dec 07 19:06:13 2011 -0500
@@ -26,7 +26,7 @@
 ## If @var{y} and @var{a} are polynomial coefficient vectors, @var{b} will
 ## contain the coefficients of the polynomial quotient and @var{r} will be
 ## a remainder polynomial of lowest order.
-## @seealso{conv, poly, roots, residue, polyval, polyderiv, polyint}
+## @seealso{conv, poly, roots, residue, polyval, polyder, polyint}
 ## @end deftypefn
 
 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
--- a/scripts/polynomial/mkpp.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/polynomial/mkpp.m	Wed Dec 07 19:06:13 2011 -0500
@@ -22,7 +22,7 @@
 ##
 ## Construct a piece-wise polynomial (pp) structure from sample points
 ## @var{breaks} and coefficients @var{coefs}.  @var{breaks} must be a vector of
-## strictly increasing values. The number of intervals is given by
+## strictly increasing values.  The number of intervals is given by
 ## @code{@var{ni} = length (@var{breaks}) - 1}.
 ## When @var{m} is the polynomial order @var{coefs} must be of
 ## size: @var{ni} x @var{m} + 1.
@@ -33,11 +33,11 @@
 ## lowest (@var{0}).
 ##
 ## @var{coefs} may also be a multi-dimensional array, specifying a vector-valued
-## or array-valued polynomial. In that case the polynomial order is defined
+## or array-valued polynomial.  In that case the polynomial order is defined
 ## by the length of the last dimension of @var{coefs}.
 ## The size of first dimension(s) are given by the scalar or
-## vector @var{d}. If @var{d} is not given it is set to @code{1}.
-## In any case @var{coefs} is reshaped to a 2d matrix of
+## vector @var{d}.  If @var{d} is not given it is set to @code{1}.
+## In any case @var{coefs} is reshaped to a 2-D matrix of
 ## size @code{[@var{ni}*prod(@var{d} @var{m})] }
 ##
 ## @seealso{unmkpp, ppval, spline}
--- a/scripts/polynomial/mpoles.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/polynomial/mpoles.m	Wed Dec 07 19:06:13 2011 -0500
@@ -44,7 +44,7 @@
 ## @end group
 ## @end example
 ##
-## @seealso{poly, roots, conv, deconv, polyval, polyderiv, polyint, residue}
+## @seealso{poly, roots, conv, deconv, polyval, polyder, polyint, residue}
 ## @end deftypefn
 
 ## Author: Ben Abbott <bpabbott@mac.com>
--- a/scripts/polynomial/polygcd.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/polynomial/polygcd.m	Wed Dec 07 19:06:13 2011 -0500
@@ -39,7 +39,7 @@
 ## @result{} [ 0, 0, 0 ]
 ## @end group
 ## @end example
-## @seealso{poly, polyint, polyderiv, polyreduce, roots, conv, deconv,
+## @seealso{poly, polyint, polyder, polyreduce, roots, conv, deconv,
 ## residue, filter, polyval, polyvalm}
 ## @end deftypefn
 
--- a/scripts/polynomial/polyint.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/polynomial/polyint.m	Wed Dec 07 19:06:13 2011 -0500
@@ -22,7 +22,7 @@
 ## Return the coefficients of the integral of the polynomial whose
 ## coefficients are represented by the vector @var{p}.  The variable
 ## @var{k} is the constant of integration, which by default is set to zero.
-## @seealso{poly, polyderiv, polyreduce, roots, conv, deconv, residue,
+## @seealso{poly, polyder, polyreduce, roots, conv, deconv, residue,
 ## filter, polyval, polyvalm}
 ## @end deftypefn
 
--- a/scripts/polynomial/polyout.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/polynomial/polyout.m	Wed Dec 07 19:06:13 2011 -0500
@@ -35,7 +35,7 @@
 ## @var{nargout} is zero).
 ## @var{x} defaults to the string @code{"s"}.
 ## @seealso{polyval, polyvalm, poly, roots, conv, deconv, residue,
-## filter, polyderiv, polyint}
+## filter, polyder, polyint}
 ## @end deftypefn
 
 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu>
--- a/scripts/polynomial/polyreduce.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/polynomial/polyreduce.m	Wed Dec 07 19:06:13 2011 -0500
@@ -21,7 +21,7 @@
 ## Reduce a polynomial coefficient vector to a minimum number of terms by
 ## stripping off any leading zeros.
 ## @seealso{poly, roots, conv, deconv, residue, filter, polyval,
-## polyvalm, polyderiv, polyint}
+## polyvalm, polyder, polyint}
 ## @end deftypefn
 
 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
--- a/scripts/polynomial/polyval.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/polynomial/polyval.m	Wed Dec 07 19:06:13 2011 -0500
@@ -32,7 +32,7 @@
 ## prediction interval, the structured variable @var{s}, originating
 ## form `polyfit', must be present.
 ## @seealso{polyfit, polyvalm, poly, roots, conv, deconv, residue, filter,
-## polyderiv, polyint}
+## polyder, polyint}
 ## @end deftypefn
 
 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
--- a/scripts/polynomial/polyvalm.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/polynomial/polyvalm.m	Wed Dec 07 19:06:13 2011 -0500
@@ -27,7 +27,7 @@
 ##
 ## The argument @var{x} must be a square matrix.
 ## @seealso{polyval, poly, roots, conv, deconv, residue, filter,
-## polyderiv, polyint}
+## polyder, polyint}
 ## @end deftypefn
 
 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
--- a/scripts/polynomial/ppder.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/polynomial/ppder.m	Wed Dec 07 19:06:13 2011 -0500
@@ -18,8 +18,8 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {ppd =} ppder (pp, m)
-## Computes the piecewise @var{m}-th derivative of a piecewise polynomial
-## struct @var{pp}. If @var{m} is omitted the first derivate is
+## Compute the piecewise @var{m}-th derivative of a piecewise polynomial
+## struct @var{pp}.  If @var{m} is omitted the first derivate is
 ## calculated.
 ## @seealso{mkpp, ppval, ppint}
 ## @end deftypefn
--- a/scripts/polynomial/residue.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/polynomial/residue.m	Wed Dec 07 19:06:13 2011 -0500
@@ -18,7 +18,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {[@var{r}, @var{p}, @var{k}, @var{e}] =} residue (@var{b}, @var{a})
+## @deftypefn  {Function File} {[@var{r}, @var{p}, @var{k}, @var{e}] =} residue (@var{b}, @var{a})
 ## @deftypefnx {Function File} {[@var{b}, @var{a}] =} residue (@var{r}, @var{p}, @var{k})
 ## @deftypefnx {Function File} {[@var{b}, @var{a}] =} residue (@var{r}, @var{p}, @var{k}, @var{e})
 ## The first calling form computes the partial fraction expansion for the
@@ -136,7 +136,7 @@
 ## @end example
 ##
 ## @end ifnottex
-## @seealso{poly, roots, conv, deconv, mpoles, polyval, polyderiv, polyint}
+## @seealso{poly, roots, conv, deconv, mpoles, polyval, polyder, polyint}
 ## @end deftypefn
 
 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
--- a/scripts/prefs/addpref.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/prefs/addpref.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {} addpref (@var{group}, @var{pref}, @var{val})
+## @deftypefn {Function File} {} addpref (@var{group}, @var{pref}, @var{val})
 ## Add a preference @var{pref} and associated value @var{val} to the
 ## named preference group @var{group}.
 ##
@@ -27,7 +27,7 @@
 ## of character strings.  The corresponding value @var{val} may be any
 ## value, or, if @var{pref} is a cell array of strings, @var{val}
 ## must be a cell array of values with the same size as @var{pref}.
-## @seealso{pref, getpref, ispref, rmpref, setpref}
+## @seealso{setpref, getpref, ispref, rmpref}
 ## @end deftypefn
 
 ## Author: jwe
--- a/scripts/prefs/getpref.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/prefs/getpref.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {} getpref (@var{group}, @var{pref}, @var{default})
+## @deftypefn {Function File} {} getpref (@var{group}, @var{pref}, @var{default})
 ## Return the preference value corresponding to the named preference
 ## @var{pref} in the preference group @var{group}.
 ##
@@ -37,7 +37,7 @@
 ##
 ## If no arguments are specified, return a structure containing all
 ## groups of preferences and their values.
-## @seealso{addpref, ispref, rmpref, setpref}
+## @seealso{addpref, setpref, ispref, rmpref}
 ## @end deftypefn
 
 ## Author: jwe
--- a/scripts/prefs/ispref.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/prefs/ispref.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {} ispref (@var{group}, @var{pref})
+## @deftypefn {Function File} {} ispref (@var{group}, @var{pref})
 ## Return true if the named preference @var{pref} exists in the
 ## preference group @var{group}.
 ##
@@ -26,9 +26,9 @@
 ## The preference @var{pref} may be a character string or a cell array
 ## of character strings.
 ##
-## If @var{pref} is not specified, return true if the the preference
+## If @var{pref} is not specified, return true if the preference
 ## group @var{group} exists.
-## @seealso{addpref, getpref, rmpref, setpref}
+## @seealso{getpref, addpref, setpref, rmpref}
 ## @end deftypefn
 
 ## Author: jwe
--- a/scripts/prefs/private/loadprefs.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/prefs/private/loadprefs.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {} loadprefs ()
+## @deftypefn {Function File} {} loadprefs ()
 ## Undocumented internal function.
 ## @end deftypefn
 
--- a/scripts/prefs/private/prefsfile.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/prefs/private/prefsfile.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {} prefsfile ()
+## @deftypefn {Function File} {} prefsfile ()
 ## Undocumented internal function.
 ## @end deftypefn
 
--- a/scripts/prefs/private/saveprefs.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/prefs/private/saveprefs.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {} saveprefs ()
+## @deftypefn {Function File} {} saveprefs ()
 ## Undocumented internal function.
 ## @end deftypefn
 
--- a/scripts/prefs/rmpref.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/prefs/rmpref.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {} rmpref (@var{group}, @var{pref})
+## @deftypefn {Function File} {} rmpref (@var{group}, @var{pref})
 ## Remove the named preference @var{pref} from the preference group
 ## @var{group}.
 ##
@@ -30,7 +30,7 @@
 ## @var{group}.
 ##
 ## It is an error to remove a nonexistent preference or group.
-## @seealso{addpref, getpref, rmpref, setpref}
+## @seealso{addpref, ispref, setpref, getpref}
 ## @end deftypefn
 
 ## Author: jwe
--- a/scripts/prefs/setpref.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/prefs/setpref.m	Wed Dec 07 19:06:13 2011 -0500
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {} setpref (@var{group}, @var{pref}, @var{val})
+## @deftypefn {Function File} {} setpref (@var{group}, @var{pref}, @var{val})
 ## Set a preference @var{pref} to the given @var{val} in the named
 ## preference group @var{group}.
 ##
@@ -29,7 +29,7 @@
 ## must be a cell array of values with the same size as @var{pref}.
 ##
 ## If the named preference or group does not exist, it is added.
-## @seealso{pref, getpref, ispref, rmpref, setpref}
+## @seealso{addpref, getpref, ispref, rmpref}
 ## @end deftypefn
 
 ## Author: jwe
--- a/scripts/signal/fftshift.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/signal/fftshift.m	Wed Dec 07 19:06:13 2011 -0500
@@ -31,7 +31,8 @@
 ## f = [ -(ceil((N-1)/2):-1:1)*df 0 (1:floor((N-1)/2))*df ]
 ## @end example
 ##
-## where @math{df} = 1 / @math{dt}.
+## @noindent
+## where @nospell{@math{df}} = 1 / @math{dt}.
 ##
 ## If @var{x} is a matrix, the same holds for rows and columns.  If
 ## @var{x} is an array, then the same holds along each dimension.
--- a/scripts/sparse/bicg.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/sparse/bicg.m	Wed Dec 07 19:06:13 2011 -0500
@@ -16,17 +16,19 @@
 
 ## -*- texinfo -*-
 ##
-## @deftypefn {Function File} {@var{x} =} bicg (@var{A}, @var{b}, @var{rtol}, @var{maxit}, @var{M1}, @var{M2}, @var{x0})
+## @deftypefn  {Function File} {@var{x} =} bicg (@var{A}, @var{b}, @var{rtol}, @var{maxit}, @var{M1}, @var{M2}, @var{x0})
 ## @deftypefnx {Function File} {@var{x} =} bicg (@var{A}, @var{b}, @var{rtol}, @var{maxit}, @var{P})
-## @deftypefnx {Function File} {[@var{x}, @var{flag}, @var{relres}, @var{iter}, @var{resvec}] =} bicg (@var{A}, @var{b}, ...)
+## @deftypefnx {Function File} {[@var{x}, @var{flag}, @var{relres}, @var{iter}, @var{resvec}] =} bicg (@var{A}, @var{b}, @dots{})
 ## Solve @code{A x = b} using the Bi-conjugate gradient iterative method.
 ##
 ## @itemize @minus
 ## @item @var{rtol} is the relative tolerance, if not given
 ## or set to [] the default value 1e-6 is used.
+##
 ## @item @var{maxit} the maximum number of outer iterations,
 ## if not given or set to [] the default value
 ## @code{min (20, numel (b))} is used.
+##
 ## @item @var{x0} the initial guess, if not given or set to []
 ## the default value @code{zeros (size (b))} is used.
 ## @end itemize
@@ -41,22 +43,27 @@
 ## @code{g(x, 'notransp') = M1 \ x} or @code{g(x, 'notransp') = M2 \ x} and
 ## @code{g(x, 'transp') = M1' \ x} or @code{g(x, 'transp') = M2' \ x}.
 ##
-## If colled with more than one output parameter
+## If called with more than one output parameter
 ##
 ## @itemize @minus
 ## @item @var{flag} indicates the exit status:
 ## @itemize @minus
 ## @item 0: iteration converged to the within the chosen tolerance
+##
 ## @item 1: the maximum number of iterations was reached before convergence
+##
 ## @item 3: the algorithm reached stagnation
 ## @end itemize
 ## (the value 2 is unused but skipped for compatibility).
+##
 ## @item @var{relres} is the final value of the relative residual.
+##
 ## @item @var{iter} is the number of iterations performed.
+##
 ## @item @var{resvec} is a vector containing the relative residual at each iteration.
 ## @end itemize
 ##
-## @seealso{bicgstab,cgs,gmres,pcg}
+## @seealso{bicgstab, cgs, gmres, pcg}
 ##
 ## @end deftypefn
 
--- a/scripts/sparse/bicgstab.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/sparse/bicgstab.m	Wed Dec 07 19:06:13 2011 -0500
@@ -19,17 +19,20 @@
 
 ## -*- texinfo -*-
 ##
-## @deftypefn {Function File} {@var{x} =} bicgstab (@var{A}, @var{b}, @var{rtol}, @var{maxit}, @var{M1}, @var{M2}, @var{x0})
+## @deftypefn  {Function File} {@var{x} =} bicgstab (@var{A}, @var{b}, @var{rtol}, @var{maxit}, @var{M1}, @var{M2}, @var{x0})
 ## @deftypefnx {Function File} {@var{x} =} bicgstab (@var{A}, @var{b}, @var{rtol}, @var{maxit}, @var{P})
-## @deftypefnx {Function File} {[@var{x}, @var{flag}, @var{relres}, @var{iter}, @var{resvec}] =} bicgstab (@var{A}, @var{b}, ...)
-## Solve @code{A x = b} using the stabilizied Bi-conjugate gradient iterative method.
+## @deftypefnx {Function File} {[@var{x}, @var{flag}, @var{relres}, @var{iter}, @var{resvec}] =} bicgstab (@var{A}, @var{b}, @dots{})
+## Solve @code{A x = b} using the stabilizied Bi-conjugate gradient iterative
+## method.
 ##
 ## @itemize @minus
 ## @item @var{rtol} is the relative tolerance, if not given or set to
 ## [] the default value 1e-6 is used.
+##
 ## @item @var{maxit} the maximum number of outer iterations, if not
 ## given or set to [] the default value @code{min (20, numel (b))} is
 ## used.
+##
 ## @item @var{x0} the initial guess, if not given or set to [] the
 ## default value @code{zeros (size (b))} is used.
 ## @end itemize
@@ -38,8 +41,9 @@
 ## inline function @code{f} such that @code{f(x) = A*x}.
 ##
 ## The preconditioner @var{P} is given as @code{P = M1 * M2}.
-## Both @var{M1} and @var{M2} can be passed as a matrix or as a function handle or
-## inline function @code{g} such that @code{g(x) = M1 \ x} or @code{g(x) = M2 \ x}.
+## Both @var{M1} and @var{M2} can be passed as a matrix or as a function
+## handle or inline function @code{g} such that @code{g(x) = M1 \ x} or
+## @code{g(x) = M2 \ x}.
 ##
 ## If called with more than one output parameter
 ##
@@ -47,16 +51,21 @@
 ## @item @var{flag} indicates the exit status:
 ## @itemize @minus
 ## @item 0: iteration converged to the within the chosen tolerance
+##
 ## @item 1: the maximum number of iterations was reached before convergence
+##
 ## @item 3: the algorithm reached stagnation
 ## @end itemize
 ## (the value 2 is unused but skipped for compatibility).
+##
 ## @item @var{relres} is the final value of the relative residual.
+##
 ## @item @var{iter} is the number of iterations performed.
+##
 ## @item @var{resvec} is a vector containing the relative residual at each iteration.
 ## @end itemize
 ##
-## @seealso{bicg,cgs,gmres,pcg}
+## @seealso{bicg, cgs, gmres, pcg}
 ##
 ## @end deftypefn
 
--- a/scripts/sparse/cgs.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/sparse/cgs.m	Wed Dec 07 19:06:13 2011 -0500
@@ -19,18 +19,20 @@
 
 ## -*- texinfo -*-
 ##
-## @deftypefn {Function File} {@var{x} =} cgs (@var{A}, @var{b}, @var{rtol}, @var{maxit}, @var{M1}, @var{M2}, @var{x0})
+## @deftypefn  {Function File} {@var{x} =} cgs (@var{A}, @var{b}, @var{rtol}, @var{maxit}, @var{M1}, @var{M2}, @var{x0})
 ## @deftypefnx {Function File} {@var{x} =} cgs (@var{A}, @var{b}, @var{rtol}, @var{maxit}, @var{P})
-## @deftypefnx {Function File} {[@var{x}, @var{flag}, @var{relres}, @var{iter}, @var{resvec}] =} cgs (@var{A}, @var{b}, ...)
+## @deftypefnx {Function File} {[@var{x}, @var{flag}, @var{relres}, @var{iter}, @var{resvec}] =} cgs (@var{A}, @var{b}, @dots{})
 ## Solve @code{A x = b}, where @var{A} is a square matrix, using the
 ## Conjugate Gradients Squared method.
 ##
 ## @itemize @minus
 ## @item @var{rtol} is the relative tolerance, if not given or set to []
 ## the default value 1e-6 is used.
+##
 ## @item @var{maxit} the maximum number of outer iterations, if not
 ## given or set to [] the default value @code{min (20, numel (b))} is
 ## used.
+##
 ## @item @var{x0} the initial guess, if not given or set to [] the
 ## default value @code{zeros (size (b))} is used.
 ## @end itemize
@@ -49,17 +51,22 @@
 ## @item @var{flag} indicates the exit status:
 ## @itemize @minus
 ## @item 0: iteration converged to the within the chosen tolerance
+##
 ## @item 1: the maximum number of iterations was reached before convergence
+##
 ## @item 3: the algorithm reached stagnation
 ## @end itemize
 ## (the value 2 is unused but skipped for compatibility).
+##
 ## @item @var{relres} is the final value of the relative residual.
+##
 ## @item @var{iter} is the number of iterations performed.
+##
 ## @item @var{resvec} is a vector containing the relative residual at
 ## each iteration.
 ## @end itemize
 ##
-## @seealso{pcg,bicgstab,bicg,gmres}
+## @seealso{pcg, bicgstab, bicg, gmres}
 ## @end deftypefn
 
 function [x, flag, relres, iter, resvec] = cgs (A, b, tol, maxit, M1, M2, x0)
--- a/scripts/sparse/gmres.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/sparse/gmres.m	Wed Dec 07 19:06:13 2011 -0500
@@ -51,13 +51,19 @@
 ## @item @var{flag} indicates the exit status:
 ## @table @asis
 ## @item 0 : iteration converged to within the specified tolerance
+##
 ## @item 1 : maximum number of iterations exceeded
+##
 ## @item 2 : unused, but skipped for compatibility
+##
 ## @item 3 : algorithm reached stagnation
 ## @end table
+##
 ## @item @var{relres} is the final value of the relative residual.
+##
 ## @item @var{iter} is a vector containing the number of outer iterations and
 ## total iterations performed.
+##
 ## @item @var{resvec} is a vector containing the relative residual at each
 ## iteration.
 ## @end itemize
--- a/scripts/sparse/private/__sprand_impl__.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/sparse/private/__sprand_impl__.m	Wed Dec 07 19:06:13 2011 -0500
@@ -21,7 +21,7 @@
 ## public domain.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __sprand_impl__ (@var{s}, @var{randfun})
+## @deftypefn  {Function File} {} __sprand_impl__ (@var{s}, @var{randfun})
 ## @deftypefnx {Function File} {} __sprand_impl__ (@var{m}, @var{n}, @var{d}, @var{funname}, @var{randfun})
 ## Undocumented internal function.
 ## @end deftypefn
--- a/scripts/special-matrix/hadamard.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/special-matrix/hadamard.m	Wed Dec 07 19:06:13 2011 -0500
@@ -66,9 +66,9 @@
 
   ## Find k if n = 2^k*p.
   k = 0;
-  while (n > 1 && floor (n/2) == n/2)
+  while (n > 1 && fix (n/2) == n/2)
     k++;
-    n = n/2;
+    n /= 2;
   endwhile
 
   ## Find base hadamard.
@@ -90,7 +90,7 @@
     case 5
       h = h20 ();
     case 7
-      h = hnormalize (h28 ());
+      h = h28 ();
     otherwise
       error ("hadamard: N must be 2^k*p, for p = 1, 12, 20 or 28");
   endswitch
@@ -98,15 +98,16 @@
   ## Build H(2^k*n) from kron(H(2^k),H(n)).
   h2 = [1,1;1,-1];
   while (true)
-    if (floor (k/2) != k/2)
+    if (fix (k/2) != k/2)
       h = kron (h2, h);
     endif
-    k = floor (k/2);
+    k = fix (k/2);
     if (k == 0)
       break;
     endif
     h2 = kron (h2, h2);
   endwhile
+
 endfunction
 
 function h = h12 ()
@@ -117,7 +118,6 @@
   h(2:end,2:end) = toeplitz (tu, tl);
 endfunction
 
-
 function h = h20 ()
   tu = [+1,-1,-1,+1,+1,+1,+1,-1,+1,-1,+1,-1,-1,-1,-1,+1,+1,-1,-1];
   tl = [+1,-1,-1,+1,+1,-1,-1,-1,-1,+1,-1,+1,-1,+1,+1,+1,+1,-1,-1];
@@ -126,53 +126,50 @@
   h(2:end,2:end) = fliplr (toeplitz (tu, tl));
 endfunction
 
-function h = hnormalize (h)
-  ## Make sure each row and column starts with +1.
-  h(h(:,1)==-1,:) *= -1;
-  h(:,h(1,:)==-1) *= -1;
-endfunction
-
 function h = h28 ()
   ## Williamson matrix construction from
   ## http://www.research.att.com/~njas/hadamard/had.28.will.txt
-  s = ["+------++----++-+--+-+--++--";
-       "-+-----+++-----+-+--+-+--++-";
-       "--+-----+++---+-+-+----+--++";
-       "---+-----+++---+-+-+-+--+--+";
-       "----+-----+++---+-+-+++--+--";
-       "-----+-----++++--+-+--++--+-";
-       "------++----++-+--+-+--++--+";
-       "--++++-+-------++--+++-+--+-";
-       "---++++-+-----+-++--+-+-+--+";
-       "+---+++--+----++-++--+-+-+--";
-       "++---++---+----++-++--+-+-+-";
-       "+++---+----+----++-++--+-+-+";
-       "++++--------+-+--++-++--+-+-";
-       "-++++--------+++--++--+--+-+";
-       "-+-++-++--++--+--------++++-";
-       "+-+-++--+--++--+--------++++";
-       "-+-+-++--+--++--+----+---+++";
-       "+-+-+-++--+--+---+---++---++";
-       "++-+-+-++--+------+--+++---+";
-       "-++-+-+-++--+------+-++++---";
-       "+-++-+---++--+------+-++++--";
-       "-++--++-+-++-+++----++------";
-       "+-++--++-+-++-+++-----+-----";
-       "++-++---+-+-++-+++-----+----";
-       "-++-++-+-+-+-+--+++-----+---";
-       "--++-++++-+-+----+++-----+--";
-       "+--++-+-++-+-+----+++-----+-";
-       "++--++-+-++-+-+----++------+"];
-  ## Without this, the assignment of -1 will not work properly
-  ## (compatibility forces LHS(idx) = ANY_VAL to keep the LHS logical
-  ## instead of widening to a type that can represent ANY_VAL).
-  h = double (s == "+");
-  h(!h) = -1;
+  ## Normalized so that each row and column starts with +1
+  h = [1 1  1  1  1  1  1  1  1 1  1  1  1 1 1 1 1 1  1 1 1 1 1  1 1  1 1  1
+       1 1 -1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 1 1 1 1 -1 1 1 1 1 -1 1 -1 1 -1
+       1 -1 1 -1 -1 -1 -1 1 -1 1 1 -1 -1 1 -1 -1 -1 -1 1 1 -1 1 -1 1 1 1 1 1
+       1 -1 -1 1 -1 -1 -1 1 1 1 1 1 -1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 1 -1 1
+       1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 1 1 -1 -1 -1 1 1 1 -1 1 -1 1 -1 -1 -1
+       1 -1 -1 -1 -1 1 -1 1 1 -1 -1 1 1 -1 -1 -1 1 1 -1 -1 -1 1 1 1 1 1 1 -1
+       1 -1 -1 -1 -1 -1 1 -1 1 -1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 -1 1 -1 1 -1 1
+       1 -1 1 1 1 1 -1 -1 1 -1 -1 -1 -1 1 1 1 -1 -1 -1 -1 1 -1 -1 1 1 1 1 -1
+       1 -1 -1 1 1 1 1 1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 1 1 1 -1 -1 1 -1 1
+       1 1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 -1 1 -1 -1 -1 -1 -1 1 1 1 -1 -1 1 1 1
+       1 -1 1 1 1 -1 -1 -1 -1 1 -1 1 1 -1 -1 -1 1 1 -1 1 1 -1 -1 1 1 -1 -1 1
+       1 -1 -1 1 1 1 -1 -1 -1 1 1 -1 1 -1 -1 1 1 -1 1 1 -1 -1 1 -1 -1 1 1 -1
+       1 -1 -1 -1 1 1 1 -1 -1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 1 1 1 1 -1 -1 1
+       1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1
+       1 1 -1 1 1 -1 1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 -1 1 -1 1 -1 1 -1 -1 1 -1
+       1 1 -1 1 -1 -1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 1 -1 1 -1 1 1 1 1 -1 -1
+       1 1 -1 1 -1 1 1 1 1 1 -1 -1 1 -1 1 -1 -1 -1 -1 1 -1 -1 -1 -1 1 -1 1 1
+       1 1 -1 1 -1 1 -1 1 -1 1 -1 1 1 1 -1 1 -1 -1 1 -1 1 1 -1 1 -1 -1 -1 -1
+       1 -1 1 -1 1 -1 1 1 1 1 1 -1 1 -1 -1 1 -1 1 -1 -1 1 1 -1 -1 -1 -1 1 -1
+       1 1 1 -1 1 -1 1 1 -1 1 -1 -1 1 1 1 -1 1 -1 -1 -1 -1 -1 1 1 -1 1 -1 -1
+       1 1 -1 -1 1 -1 1 -1 -1 -1 -1 1 1 1 -1 1 -1 1 1 -1 -1 -1 -1 -1 1 1 1 1
+       1 1 1 -1 -1 1 1 1 -1 -1 1 1 -1 -1 -1 1 1 -1 -1 1 1 -1 -1 -1 1 1 -1 -1
+       1 1 -1 -1 1 1 -1 1 -1 -1 1 -1 -1 -1 1 -1 1 1 1 -1 1 -1 -1 1 -1 -1 1 1
+       1 -1 1 -1 -1 1 1 -1 1 1 -1 1 -1 1 -1 -1 1 -1 1 -1 1 -1 1 -1 -1 -1 1 1
+       1 1 1 -1 1 1 -1 -1 1 1 -1 1 -1 -1 1 -1 -1 1 1 1 -1 1 -1 -1 -1 1 -1 -1
+       1 -1 1 1 -1 1 1 -1 -1 -1 1 -1 1 1 1 -1 1 1 1 -1 -1 1 -1 -1 1 -1 -1 -1
+       1 1 1 -1 -1 1 -1 -1 1 -1 1 -1 1 1 -1 1 -1 1 -1 1 -1 -1 1 1 -1 -1 -1 1
+       1 -1 1 1 -1 -1 1 1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 -1 -1 1 1 -1 -1 1 -1];
 endfunction
 
-%!assert(hadamard(1),1)
-%!assert(hadamard(2),[1,1;1,-1])
+
+%!assert (hadamard (1), 1)
+%!assert (hadamard (2), [1,1;1,-1])
 %!test
-%!  for n=[1,2,4,8,12,24,48,20,28,2^9]
-%!    h=hadamard(n); assert(norm(h*h'-n*eye(n)),0);
-%!  end
+%! for n = [1,2,4,8,12,24,48,20,28,2^9]
+%!   h = hadamard(n);
+%!   assert (norm (h*h' - n*eye (n)), 0);
+%! endfor
+
+%!error hadamard ()
+%!error hadamard (1,2)
+%!error <N must be 2\^k\*p> hadamard (5)
+
--- a/scripts/special-matrix/hankel.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/special-matrix/hankel.m	Wed Dec 07 19:06:13 2011 -0500
@@ -49,69 +49,50 @@
 
 function retval = hankel (c, r)
 
-  if (nargin == 1)
-    r = resize (resize (c, 0), size(c));
-  elseif (nargin != 2)
+  if (nargin < 1 || nargin > 2)
     print_usage ();
   endif
 
-  [c_nr, c_nc] = size (c);
-  [r_nr, r_nc] = size (r);
-
-  if ((c_nr != 1 && c_nc != 1) || (r_nr != 1 && r_nc != 1))
-    error ("hankel: expecting vector arguments");
-  endif
-
   if (nargin == 1)
-    r (1) = c (length (c));
-  endif
+
+    if (! isvector (c))
+      error ("hankel: C must be a vector");
+    endif
 
-  if (c_nc != 1)
-    c = c.';
-  endif
+    nr = length (c);
+    nc = nr;
+    data = [c(:) ; zeros(nr, 1)];
+
+  else
 
-  if (r_nr != 1)
-    r = r.';
-  endif
+    if (! (isvector (c) && isvector (r))) 
+      error ("hankel: C and R must be vectors");
+    elseif (r(1) != c(end))
+      warning ("hankel: column wins anti-diagonal conflict");
+    endif
 
-  nc = length (r);
-  nr = length (c);
+    nr = length (c);
+    nc = length (r);
+    data = [c(:) ; r(2:end)(:)];
 
-  if (r (1) != c (nr))
-    warning ("hankel: column wins anti-diagonal conflict");
   endif
-
-  ## This should probably be done with the colon operator...
-
-  retval = resize (resize (c, 0), nr, nc);
-
-  for i = 1:min (nr, nc)
-    retval (1:nr-i+1, i) = c (i:nr);
-  endfor
-
-  tmp = 1;
-  if (nc <= nr)
-    tmp = nr - nc + 2;
-  endif
-
-  for i = nr:-1:tmp
-    retval (i, 2+nr-i:nc) = r (2:nc-nr+i);
-  endfor
+   
+  slices = cellslices (data, 1:nc, nr:1:nc+nr-1);
+  retval = horzcat (slices{:});
 
 endfunction
 
-%!assert(hankel(1:3),[1,2,3;2,3,0;3,0,0])
-%!assert(hankel(1),[1]);
-%!assert(hankel(1:3,3:6),[1,2,3,4;2,3,4,5;3,4,5,6]);
-%!assert(hankel(1:3,3:4),[1,2;2,3;3,4]);
-%!assert(hankel(1:3,4:6),[1,2,3;2,3,5;3,5,6]);
 
-%!assert((hankel (1) == 1 && hankel ([1, 2]) == [1, 2; 2, 0]
-%! && hankel ([1, 2], [2; -1; -3]) == [1, 2, -1; 2, -1, -3]));
-
-%!error hankel ([1, 2; 3, 4], [1, 2; 3, 4]);
+%!assert (hankel (1), [1])
+%!assert (hankel ([1, 2]), [1, 2; 2, 0])
+%!assert (hankel ([1, 2], [2; -1; -3]), [1, 2, -1; 2, -1, -3])
+%!assert (hankel (1:3), [1,2,3;2,3,0;3,0,0])
+%!assert (hankel (1:3,3:6), [1,2,3,4;2,3,4,5;3,4,5,6])
+%!assert (hankel (1:3,3:4), [1,2;2,3;3,4])
+%!assert (hankel (1:3,4:6), [1,2,3;2,3,5;3,5,6])
 
 %!error hankel ();
+%!error hankel (1, 2, 3);
+%!error <C must be a vector> hankel ([1, 2; 3, 4])
+%!error <C and R must be vectors> hankel (1:4, [1, 2; 3, 4])
 
-%!error hankel (1, 2, 3);
-
--- a/scripts/special-matrix/invhilb.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/special-matrix/invhilb.m	Wed Dec 07 19:06:13 2011 -0500
@@ -77,57 +77,52 @@
 
   if (nargin != 1)
     print_usage ();
+  elseif (! isscalar (n))
+    error ("invhilb: N must be a scalar integer");
   endif
 
-  nmax = length (n);
-  if (nmax == 1)
+  ## The point about the second formula above is that when vectorized,
+  ## p(k) is evaluated for k=1:n which involves O(n) calls to bincoeff
+  ## instead of O(n^2).
+  ##
+  ## We evaluate the expression as (-1)^(i+j)*(p(i)*p(j))/(i+j-1) except
+  ## when p(i)*p(j) would overflow.  In cases where p(i)*p(j) is an exact
+  ## machine number, the result is also exact.  Otherwise we calculate
+  ## (-1)^(i+j)*p(i)*(p(j)/(i+j-1)).
+  ##
+  ## The Octave bincoeff routine uses transcendental functions (gammaln
+  ## and exp) rather than multiplications, for the sake of speed.
+  ## However, it rounds the answer to the nearest integer, which
+  ## justifies the claim about exactness made above.
 
-    ## The point about the second formula above is that when vectorized,
-    ## p(k) is evaluated for k=1:n which involves O(n) calls to bincoeff
-    ## instead of O(n^2).
-    ##
-    ## We evaluate the expression as (-1)^(i+j)*(p(i)*p(j))/(i+j-1) except
-    ## when p(i)*p(j) would overflow.  In cases where p(i)*p(j) is an exact
-    ## machine number, the result is also exact.  Otherwise we calculate
-    ## (-1)^(i+j)*p(i)*(p(j)/(i+j-1)).
-    ##
-    ## The Octave bincoeff routine uses transcendental functions (gammaln
-    ## and exp) rather than multiplications, for the sake of speed.
-    ## However, it rounds the answer to the nearest integer, which
-    ## justifies the claim about exactness made above.
-
-    retval = zeros (n);
-    k = [1:n];
-    p = k .* bincoeff (k+n-1, k-1) .* bincoeff (n, k);
-    p(2:2:n) = -p(2:2:n);
-    if (n < 203)
-      for l = 1:n
-        retval(l,:) = (p(l) * p) ./ [l:l+n-1];
-      endfor
-    else
-      for l = 1:n
-        retval(l,:) = p(l) * (p ./ [l:l+n-1]);
-      endfor
-    endif
+  retval = zeros (n);
+  k = [1:n];
+  p = k .* bincoeff (k+n-1, k-1) .* bincoeff (n, k);
+  p(2:2:n) = -p(2:2:n);
+  if (n < 203)
+    for l = 1:n
+      retval(l,:) = (p(l) * p) ./ [l:l+n-1];
+    endfor
   else
-    error ("invhilb: expecting scalar argument, found something else");
+    for l = 1:n
+      retval(l,:) = p(l) * (p ./ [l:l+n-1]);
+    endfor
   endif
 
 endfunction
 
+
+%!assert (invhilb (1), 1)
+%!assert (invhilb (2), [4, -6; -6, 12])
 %!test
-%! result4 = [16, -120, 240, -140;
-%! -120, 1200, -2700, 1680;
-%! 240, -2700, 6480, -4200;
-%! -140, 1680, -4200, 2800];
-%!
-%! assert((invhilb (1) == 1 && invhilb (2) == [4, -6; -6, 12]
-%! && invhilb (4) == result4
-%! && abs (invhilb (7) * hilb (7) - eye (7)) < sqrt (eps)));
+%! result4 = [16  , -120 , 240  , -140;
+%!            -120, 1200 , -2700, 1680;
+%!            240 , -2700, 6480 , -4200;
+%!            -140, 1680 , -4200, 2800];
+%! assert (invhilb (4), result4);
+%!assert (abs (invhilb (7) * hilb (7) - eye (7)) < sqrt (eps))
 
-%!error invhilb ([1, 2]);
+%!error invhilb ()
+%!error invhilb (1, 2)
+%!error <N must be a scalar integer> invhilb ([1, 2])
 
-%!error invhilb ();
-
-%!error invhilb (1, 2);
-
--- a/scripts/special-matrix/magic.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/special-matrix/magic.m	Wed Dec 07 19:06:13 2011 -0500
@@ -32,8 +32,8 @@
     print_usage ();
   endif
 
-  if (n != floor (n) || n < 0 || n == 2)
-    error ("magic: N must be an positive integer not equal to 2");
+  if (n != fix (n) || n < 0 || n == 2)
+    error ("magic: N must be a positive integer not equal to 2");
   endif
 
   if (n == 0)
@@ -45,7 +45,7 @@
     shift = floor ((0:n*n-1)/n);
     c = mod ([1:n*n] - shift + (n-3)/2, n);
     r = mod ([n*n:-1:1] + 2*shift, n);
-    A (c*n+r+1) = 1:n*n;
+    A(c*n+r+1) = 1:n*n;
     A = reshape (A, n, n);
 
   elseif (mod (n, 4) == 0)
@@ -64,7 +64,7 @@
     A = magic (m);
     A = [A, A+2*m*m; A+3*m*m, A+m*m];
     k = (m-1)/2;
-    if (k>1)
+    if (k > 1)
       I = 1:m;
       J = [2:k, n-k+2:n];
       A([I,I+m],J) = A([I+m,I],J);
@@ -78,11 +78,20 @@
 
 endfunction
 
+
 %!test
 %! for i=3:30
-%!   A=magic(i);
-%!   assert(norm(diff([sum(diag(A)),sum(diag(flipud(A))),sum(A),sum(A')])),0)
+%!   A = magic (i);
+%!   assert (norm(diff([sum(diag(A)),sum(diag(flipud(A))),sum(A),sum(A')])),0);
 %! endfor
-%!assert(isempty(magic(0)));
-%!assert(magic(1),1);
-%!error magic(2)
+
+%!assert (isempty (magic (0)))
+%!assert (magic(1), 1)
+
+%% Test input validation
+%!error magic ()
+%!error magic (1, 2)
+%!error <N must be a positive integer not equal to 2> magic (1.5)
+%!error <N must be a positive integer not equal to 2> magic (-1)
+%!error <N must be a positive integer not equal to 2> magic (2)
+
--- a/scripts/special-matrix/pascal.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/special-matrix/pascal.m	Wed Dec 07 19:06:13 2011 -0500
@@ -36,57 +36,55 @@
 ## Author: Peter Ekberg
 ##         (peda)
 
-function retval = pascal (n, t)
-
-  if (nargin > 2) || (nargin == 0)
-    print_usage ();
-  endif
+function retval = pascal (n, t = 0)
 
-  if (nargin == 1)
-    t = 0;
-  endif
-
-  if (! isscalar (n) || ! isscalar (t))
-    error ("pascal: expecting scalar arguments, found something else");
-  endif
-
-  if (t < -1 || t > 2)
+  if (nargin < 1 || nargin > 2)
+    print_usage ();
+  elseif (! (isscalar (n) && isscalar (t)))
+    error ("pascal: N and T must be scalars");
+  elseif (! any (t == [-1, 0, 1, 2]))
     error ("pascal: expecting T to be -1, 0, 1, or 2, found %d", t);
   endif
 
   retval = zeros (n);
-  retval(:,1) = 1;
+  if (n > 0)
+    retval(:,1) = 1;
+  endif
 
   if (t == -1)
     for j = 2:n
-      retval(j:n,j) = cumsum (retval (j-1:n-1,j-1));
+      retval(j:n,j) = cumsum (retval(j-1:n-1,j-1));
     endfor
   else
     for j = 2:n
-      retval(j:n,j) = -cumsum (retval (j-1:n-1,j-1));
+      retval(j:n,j) = -cumsum (retval(j-1:n-1,j-1));
     endfor
   endif
 
   if (t == 0)
     retval = retval*retval';
   elseif (t == 2)
-    retval = retval';
-    retval = retval(n:-1:1,:);
-    retval(:,n) = -retval(:,n);
-    retval(n,:) = -retval(n,:);
-    if (rem(n,2) != 1)
-      retval = -retval;
+    retval = rot90 (retval, 3);
+    if (rem (n,2) != 1)
+      retval *= -1;
     endif
   endif
 
 endfunction
 
-%!assert (pascal(3,-1), [1,0,0;1,1,0;1,2,1])
-%!assert (pascal(3,0), [1,1,1;1,2,3;1,3,6])
-%!assert (pascal(3,0), pascal(3))
-%!assert (pascal(3,1), [1,0,0;1,-1,0;1,-2,1])
-%!assert (pascal(3,2), [0,0,-1;0,-1,2;-1,-1,1])
-%!error (pascal(3,4))
-%!error (pascal(3,-2))
-%!error (pascal())
-%!error (pascal(1,2,3))
+
+%!assert (pascal (3,-1), [1,0,0;1,1,0;1,2,1])
+%!assert (pascal (3,0), [1,1,1;1,2,3;1,3,6])
+%!assert (pascal (3,0), pascal (3))
+%!assert (pascal (3,1), [1,0,0;1,-1,0;1,-2,1])
+%!assert (pascal (3,2), [1,1,1;-2,-1,0;1,0,0])
+%!assert (pascal (0,2), [])
+
+%% Test input validation
+%!error pascal ()
+%!error pascal (1,2,3)
+%!error <N and T must be scalars> pascal ([1 2])
+%!error <N and T must be scalars> pascal (1, [1 2])
+%!error <expecting T to be> pascal (3,-2)
+%!error <expecting T to be> pascal (3,4)
+
--- a/scripts/special-matrix/toeplitz.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/special-matrix/toeplitz.m	Wed Dec 07 19:06:13 2011 -0500
@@ -58,50 +58,55 @@
 
 function retval = toeplitz (c, r)
 
-  if (nargin == 1)
-    r = c;
-  elseif (nargin != 2)
+  if (nargin < 1 || nargin > 2)
     print_usage ();
   endif
 
-  if (! (isvector (c) && isvector (r)))
-    error ("toeplitz: expecting vector arguments");
+  if (nargin == 1)
+    if (! isvector (c))
+      error ("toeplitz: C must be a vector");
+    endif
+
+    r = c;
+    nr = length (c);
+    nc = nr;
+  else
+    if (! (isvector (c) && isvector (r))) 
+      error ("toeplitz: C and R must be vectors");
+    elseif (r(1) != c(1))
+      warning ("toeplitz: column wins anti-diagonal conflict");
+    endif
+
+    nr = length (c);
+    nc = length (r);
   endif
 
-  nc = length (r);
-  nr = length (c);
-
   if (nr == 0 || nc == 0)
     ## Empty matrix.
     retval = zeros (nr, nc, class (c));
     return;
   endif
 
-  if (r (1) != c (1))
-    warning ("toeplitz: column wins diagonal conflict");
-  endif
-
   ## If we have a single complex argument, we want to return a
   ## Hermitian-symmetric matrix (actually, this will really only be
   ## Hermitian-symmetric if the first element of the vector is real).
-
   if (nargin == 1 && iscomplex (c))
     c = conj (c);
     c(1) = conj (c(1));
   endif
 
-  if (issparse(c) && issparse(r))
-    c = c(:).';
-    r = r(:).';
-    cidx = find(c);
-    ridx = find(r);
+  if (issparse (c) && issparse (r))
+    c = c(:).';  ## enforce row vector
+    r = r(:).';  ## enforce row vector
+    cidx = find (c);
+    ridx = find (r);
 
     ## Ignore the first element in r.
     ridx = ridx(ridx > 1);
 
     ## Form matrix.
-    retval = spdiags(repmat(c(cidx),nr,1),1-cidx,nr,nc)+...
-        spdiags(repmat(r(ridx),nr,1),ridx-1,nr,nc);
+    retval = spdiags(repmat (c(cidx),nr,1),1-cidx,nr,nc) + ...
+             spdiags(repmat (r(ridx),nr,1),ridx-1,nr,nc);
   else
     ## Concatenate data into a single column vector.
     data = [r(end:-1:2)(:); c(:)];
@@ -112,15 +117,18 @@
     ## Form matrix.
     retval = horzcat (slices{:});
   endif
+
 endfunction
 
-%!assert((toeplitz (1) == 1
-%! && toeplitz ([1, 2, 3], [1; -3; -5]) == [1, -3, -5; 2, 1, -3; 3, 2, 1]
-%! && toeplitz ([1, 2, 3], [1; -3i; -5i]) == [1, -3i, -5i; 2, 1, -3i; 3, 2, 1]));
+
+%!assert (toeplitz (1), [1])
+%!assert (toeplitz ([1, 2, 3], [1; -3; -5]), [1, -3, -5; 2, 1, -3; 3, 2, 1])
+%!assert (toeplitz ([1, 2, 3], [1; -3i; -5i]), [1, -3i, -5i; 2, 1, -3i; 3, 2, 1])
 
-%!error toeplitz ([1, 2; 3, 4], 1);
+%% Test input validation
+%!error toeplitz ()
+%!error toeplitz (1, 2, 3)
+%!error <C must be a vector> toeplitz ([1, 2; 3, 4])
+%!error <C and R must be vectors> toeplitz ([1, 2; 3, 4], 1)
+%!error <C and R must be vectors> toeplitz (1, [1, 2; 3, 4])
 
-%!error toeplitz ();
-
-%!error toeplitz (1, 2, 3);
-
--- a/scripts/special-matrix/wilkinson.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/special-matrix/wilkinson.m	Wed Dec 07 19:06:13 2011 -0500
@@ -35,7 +35,7 @@
     print_usage ();
   endif
 
-  if (! (isscalar (n) && (n == fix (n)) && n >= 0))
+  if (! (isscalar (n) && n >= 0 && (n == fix (n))))
     error ("wilkinson: N must be a non-negative integer");
   endif
 
@@ -45,10 +45,17 @@
 
 endfunction
 
-%!assert (wilkinson(0), [])
-%!assert (wilkinson(1), 0)
-%!assert (wilkinson(2), [0.5,1;1,0.5])
-%!assert (wilkinson(3), [1,1,0;1,0,1;0,1,1])
-%!assert (wilkinson(4), [1.5,1,0,0;1,0.5,1,0;0,1,0.5,1;0,0,1,1.5])
-%!error (wilkinson())
-%!error (wilkinson(1,2))
+
+%!assert (wilkinson (0), [])
+%!assert (wilkinson (1), 0)
+%!assert (wilkinson (2), [0.5,1;1,0.5])
+%!assert (wilkinson (3), [1,1,0;1,0,1;0,1,1])
+%!assert (wilkinson (4), [1.5,1,0,0;1,0.5,1,0;0,1,0.5,1;0,0,1,1.5])
+
+%% Test input validation
+%!error wilkinson ()
+%!error wilkinson (1,2)
+%!error <N must be a non-negative integer> wilkinson (ones (2))
+%!error <N must be a non-negative integer> wilkinson (-1)
+%!error <N must be a non-negative integer> wilkinson (1.5)
+
--- a/scripts/statistics/base/quantile.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/statistics/base/quantile.m	Wed Dec 07 19:06:13 2011 -0500
@@ -89,8 +89,8 @@
 ## @end itemize
 ##
 ## Examples:
+## @c Set example in small font to prevent overfull line
 ##
-## @c Set example in small font to prevent overfull line
 ## @smallexample
 ## @group
 ## x = randi (1000, [10, 1]);  # Create empirical data in range 1-1000
--- a/scripts/statistics/distributions/binocdf.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/statistics/distributions/binocdf.m	Wed Dec 07 19:06:13 2011 -0500
@@ -21,7 +21,8 @@
 ## @deftypefn {Function File} {} binocdf (@var{x}, @var{n}, @var{p})
 ## For each element of @var{x}, compute the cumulative distribution function
 ## (CDF) at @var{x} of the binomial distribution with parameters @var{n} and
-## @var{p}.
+## @var{p}, where @var{n} is the number of trials and @var{p} is the
+## probability of success.
 ## @end deftypefn
 
 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
--- a/scripts/statistics/distributions/binoinv.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/statistics/distributions/binoinv.m	Wed Dec 07 19:06:13 2011 -0500
@@ -21,7 +21,8 @@
 ## @deftypefn {Function File} {} binoinv (@var{x}, @var{n}, @var{p})
 ## For each element of @var{x}, compute the quantile (the inverse of
 ## the CDF) at @var{x} of the binomial distribution with parameters 
-## @var{n} and @var{p}.
+## @var{n} and @var{p}, where @var{n} is the number of trials and
+## @var{p} is the probability of success.
 ## @end deftypefn
 
 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
--- a/scripts/statistics/distributions/binopdf.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/statistics/distributions/binopdf.m	Wed Dec 07 19:06:13 2011 -0500
@@ -21,7 +21,8 @@
 ## @deftypefn {Function File} {} binopdf (@var{x}, @var{n}, @var{p})
 ## For each element of @var{x}, compute the probability density function
 ## (PDF) at @var{x} of the binomial distribution with parameters @var{n}
-## and @var{p}.
+## and @var{p}, where @var{n} is the number of trials and @var{p} is the
+## probability of success.
 ## @end deftypefn
 
 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
--- a/scripts/statistics/distributions/binornd.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/statistics/distributions/binornd.m	Wed Dec 07 19:06:13 2011 -0500
@@ -22,8 +22,9 @@
 ## @deftypefnx {Function File} {} binornd (@var{n}, @var{p}, @var{r})
 ## @deftypefnx {Function File} {} binornd (@var{n}, @var{p}, @var{r}, @var{c}, @dots{})
 ## @deftypefnx {Function File} {} binornd (@var{n}, @var{p}, [@var{sz}])
-## Return a matrix of random samples from the binonmial distribution with
-## parameters @var{n} and @var{p}.
+## Return a matrix of random samples from the binomial distribution with
+## parameters @var{n} and @var{p}, where @var{n} is the number of trials
+## and @var{p} is the probability of success.
 ##
 ## When called with a single size argument, return a square matrix with
 ## the dimension specified.  When called with more than one scalar argument the
--- a/scripts/statistics/distributions/gamcdf.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/statistics/distributions/gamcdf.m	Wed Dec 07 19:06:13 2011 -0500
@@ -20,8 +20,8 @@
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} gamcdf (@var{x}, @var{a}, @var{b})
 ## For each element of @var{x}, compute the cumulative distribution
-## function (CDF) at @var{x} of the Gamma distribution with parameters
-## @var{a} and @var{b}.
+## function (CDF) at @var{x} of the Gamma distribution with shape
+## parameter @var{a} and scale @var{b}.
 ## @end deftypefn
 
 ## Author: TT <Teresa.Twaroch@ci.tuwien.ac.at>
--- a/scripts/statistics/distributions/gaminv.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/statistics/distributions/gaminv.m	Wed Dec 07 19:06:13 2011 -0500
@@ -20,8 +20,8 @@
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} gaminv (@var{x}, @var{a}, @var{b})
 ## For each element of @var{x}, compute the quantile (the inverse of
-## the CDF) at @var{x} of the Gamma distribution with parameters @var{a}
-## and @var{b}.
+## the CDF) at @var{x} of the Gamma distribution with shape parameter
+## @var{a} and scale @var{b}.
 ## @end deftypefn
 
 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
--- a/scripts/statistics/distributions/gampdf.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/statistics/distributions/gampdf.m	Wed Dec 07 19:06:13 2011 -0500
@@ -20,8 +20,8 @@
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} gampdf (@var{x}, @var{a}, @var{b})
 ## For each element of @var{x}, return the probability density function
-## (PDF) at @var{x} of the Gamma distribution with parameters @var{a}
-## and @var{b}.
+## (PDF) at @var{x} of the Gamma distribution with shape parameter
+## @var{a} and scale @var{b}.
 ## @end deftypefn
 
 ## Author: TT <Teresa.Twaroch@ci.tuwien.ac.at>
--- a/scripts/statistics/distributions/gamrnd.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/statistics/distributions/gamrnd.m	Wed Dec 07 19:06:13 2011 -0500
@@ -23,7 +23,7 @@
 ## @deftypefnx {Function File} {} gamrnd (@var{a}, @var{b}, @var{r}, @var{c}, @dots{})
 ## @deftypefnx {Function File} {} gamrnd (@var{a}, @var{b}, [@var{sz}])
 ## Return a matrix of random samples from the Gamma distribution with
-## parameters @var{a} and @var{b}.
+## shape parameter @var{a} and scale @var{b}.
 ##
 ## When called with a single size argument, return a square matrix with
 ## the dimension specified.  When called with more than one scalar argument the
--- a/scripts/strings/deblank.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/strings/deblank.m	Wed Dec 07 19:06:13 2011 -0500
@@ -24,6 +24,7 @@
 ## string element.
 ##
 ## Examples:
+##
 ## @example
 ## @group
 ## deblank ("    abc  ")
--- a/scripts/strings/str2num.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/strings/str2num.m	Wed Dec 07 19:06:13 2011 -0500
@@ -35,7 +35,7 @@
 ## @end example
 ##
 ## The optional second output, @var{state}, is logically true when the
-## coversion is successful.  If the conversion fails the numeric output,
+## conversion is successful.  If the conversion fails the numeric output,
 ## @var{x}, is empty and @var{state} is false.
 ##
 ## @strong{Caution:} As @code{str2num} uses the @code{eval} function
--- a/scripts/strings/strsplit.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/strings/strsplit.m	Wed Dec 07 19:06:13 2011 -0500
@@ -28,7 +28,9 @@
 ## boundaries.
 ##
 ## Example:
+##
 ## @example
+## @group
 ## strsplit ("a,b,c", ",")
 ##        @result{}
 ##           @{
@@ -44,7 +46,6 @@
 ##             [1,2] = b
 ##             [1,3] = cde
 ##           @}
-## @group
 ## @end group
 ## @end example
 ## @seealso{strtok}
--- a/scripts/testfun/test.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/testfun/test.m	Wed Dec 07 19:06:13 2011 -0500
@@ -677,13 +677,14 @@
 %!xtest error("This test is known to fail")
 
 ### example from toeplitz
-%!shared msg
-%! msg="expecting vector arguments";
-%!fail ('toeplitz([])', msg);
-%!fail ('toeplitz([1,2],[])', msg);
-%!fail ('toeplitz([1,2;3,4])', msg);
-%!fail ('toeplitz([1,2],[1,2;3,4])', msg);
-%!fail ('toeplitz ([1,2;3,4],[1,2])', msg);
+%!shared msg1,msg2
+%! msg1="C must be a vector";
+%! msg2="C and R must be vectors";
+%!fail ('toeplitz([])', msg1);
+%!fail ('toeplitz([1,2;3,4])', msg1);
+%!fail ('toeplitz([1,2],[])', msg2);
+%!fail ('toeplitz([1,2],[1,2;3,4])', msg2);
+%!fail ('toeplitz ([1,2;3,4],[1,2])', msg2);
 % !fail ('toeplitz','usage: toeplitz'); # usage doesn't generate an error
 % !fail ('toeplitz(1, 2, 3)', 'usage: toeplitz');
 %!test  assert (toeplitz ([1,2,3], [1,4]), [1,4; 2,1; 3,2]);
--- a/scripts/time/addtodate.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/scripts/time/addtodate.m	Wed Dec 07 19:06:13 2011 -0500
@@ -18,7 +18,8 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {@var{d} =} addtodate (@var{d}, @var{q}, @var{f})
-## Add @var{q} amount of time (with units @var{f}) to the serial datenum, @var{d}.
+## Add @var{q} amount of time (with units @var{f}) to the serial datenum,
+## @var{d}.
 ##
 ## @var{f} must be one of "year", "month", "day", "hour", "minute", "second",
 ## or "millisecond".
--- a/src/DLD-FUNCTIONS/__init_fltk__.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/__init_fltk__.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -749,9 +749,6 @@
     status->hide ();
     uimenu->hide ();
     this->hide ();
-    delete canvas;
-    delete status;
-    delete uimenu;
   }
 
   double number (void) { return fp.get___myhandle__ ().value (); }
--- a/src/DLD-FUNCTIONS/__voronoi__.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/__voronoi__.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -65,6 +65,8 @@
 {
   octave_value_list retval;
 
+  std::string caller = args(0).string_value ();
+
 #ifdef HAVE_QHULL
 
   retval(0) = 0.0;
@@ -76,8 +78,6 @@
       return retval;
     }
 
-  std::string caller = args(0).string_value ();
-
   Matrix points = args(1).matrix_value ();
   const octave_idx_type dim = points.columns ();
   const octave_idx_type num_points = points.rows ();
--- a/src/DLD-FUNCTIONS/betainc.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/betainc.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -322,12 +322,12 @@
 %! assert(v3, v4, sqrt(eps ('single')));
 
 %% test/octave.test/arith/betainc-2.m
-%!error <Invalid call to betainc.*> betainc();
+%!error <Invalid call to betainc> betainc();
 
 %% test/octave.test/arith/betainc-3.m
-%!error <Invalid call to betainc.*> betainc(1);
+%!error <Invalid call to betainc> betainc(1);
 
 %% test/octave.test/arith/betainc-4.m
-%!error <Invalid call to betainc.*> betainc(1,2);
+%!error <Invalid call to betainc> betainc(1,2);
 
 */
--- a/src/DLD-FUNCTIONS/bsxfun.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/bsxfun.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -315,13 +315,13 @@
 The binary singleton expansion function applier does what its name\n\
 suggests: applies a binary function @var{f} element-by-element to two\n\
 array arguments @var{A} and @var{B}, and expands as necessary\n\
-singleton dimensions in either input argument. @var{f} is a function\n\
+singleton dimensions in either input argument.  @var{f} is a function\n\
 handle, inline function, or string containing the name of the function\n\
-to evaluate. The function @var{f} must be capable of accepting two\n\
+to evaluate.  The function @var{f} must be capable of accepting two\n\
 column-vector arguments of equal length, or one column vector argument\n\
 and a scalar.\n\
 \n\
-The dimensions of @var{A} and @var{B} must be equal or singleton. The\n\
+The dimensions of @var{A} and @var{B} must be equal or singleton.  The\n\
 singleton dimensions of the arrays will be expanded to the same\n\
 dimensionality as the other array.\n\
 @seealso{arrayfun, cellfun}\n\
--- a/src/DLD-FUNCTIONS/cellfun.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/cellfun.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -380,7 +380,6 @@
     }
 
   octave_value func = args(0);
-  bool symbol_table_lookup = false;
 
   if (! args(1).is_cell ())
     {
@@ -418,8 +417,6 @@
 
           if (func.is_undefined ())
             error ("cellfun: invalid function NAME: %s", name.c_str ());
-
-          symbol_table_lookup = true;
         }
 
       if (error_state || ! retval.empty ())
@@ -429,35 +426,50 @@
   if (func.is_function_handle () || func.is_inline_function ()
       || func.is_function ())
     {
+
       // The following is an optimisation because the symbol table can
       // give a more specific function class, so this can result in
       // fewer polymorphic function calls as the function gets called
       // for each value of the array.
+      {
+        if (func.is_function_handle ())
+          {
+            octave_fcn_handle* f = func.fcn_handle_value ();
 
-      if (! symbol_table_lookup )
-        {
-          if (func.is_function_handle ())
-            {
-              octave_fcn_handle* f = func.fcn_handle_value ();
+            // Overloaded function handles need to check the type of the
+            // arguments for each element of the array, so they cannot
+            // be optimised this way.
+            if (f -> is_overloaded ())
+              goto nevermind;
+          }
+
+        std::string name = func.function_value () -> name ();
+        octave_value f = symbol_table::find_function (name);
 
-              // Overloaded function handles need to check the type of
-              // the arguments for each element of the array, so they
-              // cannot be optimised this way.
+        if (f.is_defined ())
+          {
+            //Except for these two which are special cases...
+            if (name != "size" && name != "class")
+              {
+                //Try first the optimised code path for built-in functions
+                octave_value_list tmp_args = args;
+                tmp_args(0) = name;
+                retval = try_cellfun_internal_ops (tmp_args, nargin);
+                if (error_state || ! retval.empty ())
+                  return retval;
+              }
 
-              if (f -> is_overloaded ())
-                goto nevermind;
-            }
-          octave_value f = symbol_table::find_function (func.function_value ()
-                                                         -> name ());
-          if (f.is_defined ())
+            //Okay, we tried, doesn't work, let's do the best we can
+            //instead and avoid polymorphic calls for each element of
+            //the array.
             func = f;
-        }
-
+          }
+      }
     nevermind:
 
       bool uniform_output = true;
       octave_value error_handler;
-      
+
       get_mapper_fun_options (args, nargin, uniform_output, error_handler);
 
       if (error_state)
@@ -2295,6 +2307,7 @@
 \n\
 The position of the index is determined by @var{dim}.  If not specified,\n\
 slicing is done along the first non-singleton dimension.\n\
+@seealso{cell2mat, cellindexmat, cellfun}\n\
 @end deftypefn")
 {
   octave_value retval;
@@ -2408,7 +2421,7 @@
   endfor\n\
 @end group\n\
 @end example\n\
-@seealso{cellfun, cellslices}\n\
+@seealso{cellslices, cellfun}\n\
 @end deftypefn")
 {
   octave_value retval;
--- a/src/DLD-FUNCTIONS/chol.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/chol.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -61,12 +61,13 @@
 }
 
 DEFUN_DLD (chol, args, nargout,
-  "-*- texinfo -*-\n\
+"-*- texinfo -*-\n\
 @deftypefn  {Loadable Function} {@var{R} =} chol (@var{A})\n\
 @deftypefnx {Loadable Function} {[@var{R}, @var{p}] =} chol (@var{A})\n\
 @deftypefnx {Loadable Function} {[@var{R}, @var{p}, @var{Q}] =} chol (@var{S})\n\
 @deftypefnx {Loadable Function} {[@var{R}, @var{p}, @var{Q}] =} chol (@var{S}, 'vector')\n\
 @deftypefnx {Loadable Function} {[@var{L}, @dots{}] =} chol (@dots{}, 'lower')\n\
+@deftypefnx {Loadable Function} {[@var{L}, @dots{}] =} chol (@dots{}, 'upper')\n\
 @cindex Cholesky factorization\n\
 Compute the Cholesky@tie{}factor, @var{R}, of the symmetric positive definite\n\
 matrix @var{A}, where\n\
@@ -128,6 +129,9 @@
 \n\
 @end ifnottex\n\
 \n\
+For full matrices, if the 'lower' flag is set only the lower triangular part of the matrix \
+is used for the factorization, otherwise the upper triangular part is used.\n\
+\n\
 In general the lower triangular factorization is significantly faster for\n\
 sparse matrices.\n\
 @seealso{cholinv, chol2inv}\n\
@@ -155,6 +159,10 @@
           if (tmp.compare ("vector") == 0)
             vecout = true;
           else if (tmp.compare ("lower") == 0)
+            // FIXME currently the option "lower" is handled by transposing the
+            //  matrix, factorizing it with the lapack function DPOTRF ('U', ...)
+            //  and finally transposing the factor. It would be more efficient to use
+            //  DPOTRF ('L', ...) in this case.
             LLt = true;
           else if (tmp.compare ("upper") == 0)
             LLt = false;
@@ -251,7 +259,13 @@
               if (! error_state)
                 {
                   octave_idx_type info;
-                  FloatCHOL fact (m, info);
+
+                  FloatCHOL fact;
+                  if (LLt)
+                    fact = FloatCHOL (m.transpose (), info);
+                  else
+                    fact = FloatCHOL (m, info);
+
                   if (nargout == 2 || info == 0)
                     {
                       retval(1) = info;
@@ -271,7 +285,13 @@
               if (! error_state)
                 {
                   octave_idx_type info;
-                  FloatComplexCHOL fact (m, info);
+
+                  FloatComplexCHOL fact;
+                  if (LLt)
+                    fact = FloatComplexCHOL (m.transpose (), info);
+                  else
+                    fact = FloatComplexCHOL (m, info);
+
                   if (nargout == 2 || info == 0)
                     {
                       retval(1) = info;
@@ -296,7 +316,13 @@
               if (! error_state)
                 {
                   octave_idx_type info;
-                  CHOL fact (m, info);
+                  
+                  CHOL fact;
+                  if (LLt)
+                     fact = CHOL (m.transpose (), info);
+                  else
+                    fact = CHOL (m, info);
+
                   if (nargout == 2 || info == 0)
                     {
                       retval(1) = info;
@@ -316,7 +342,13 @@
               if (! error_state)
                 {
                   octave_idx_type info;
-                  ComplexCHOL fact (m, info);
+                  
+                  ComplexCHOL fact;
+                  if (LLt)
+                    fact = ComplexCHOL (m.transpose (), info);
+                  else
+                    fact = ComplexCHOL (m, info);
+
                   if (nargout == 2 || info == 0)
                     {
                       retval(1) = info;
@@ -344,8 +376,8 @@
 
 %!error chol ([1, 2; 3, 4]);
 %!error chol ([1, 2; 3, 4; 5, 6]);
-%!error <Invalid call to chol.*> chol ();
-%!error <unexpected second or third input.*> chol (1, 2);
+%!error <Invalid call to chol> chol ();
+%!error <unexpected second or third input> chol (1, 2);
 
  */
 
@@ -993,6 +1025,78 @@
 %! assert(norm(triu(R1)-R1,Inf) == 0)
 %! assert(norm(A1(p,p) - single(Ac),Inf) < 2e1*eps('single'))
 %!
+
+%!test
+%! cu = chol (triu (A), 'upper');
+%! cl = chol (tril (A), 'lower');
+%! assert (cu, cl', eps)
+%!
+%!test
+%! cca  = chol (Ac);
+%!
+%! ccal  = chol (Ac, 'lower');
+%! ccal2 = chol (tril (Ac), 'lower');
+%!
+%! ccau  = chol (Ac, 'upper');
+%! ccau2 = chol (triu (Ac), 'upper');
+%!
+%! assert (cca'*cca,     Ac, eps)
+%! assert (ccau'*ccau,   Ac, eps)
+%! assert (ccau2'*ccau2, Ac, eps)
+%!
+%! assert (cca, ccal',  eps)
+%! assert (cca, ccau,   eps)
+%! assert (cca, ccal2', eps)
+%! assert (cca, ccau2,  eps)
+%!
+%!test
+%! cca  = chol (single (Ac));
+%!
+%! ccal  = chol (single (Ac), 'lower');
+%! ccal2 = chol (tril (single (Ac)), 'lower');
+%!
+%! ccau  = chol (single (Ac), 'upper');
+%! ccau2 = chol (triu (single (Ac)), 'upper');
+%!
+%! assert (cca'*cca,     single (Ac), eps ('single'))
+%! assert (ccau'*ccau,   single (Ac), eps ('single'))
+%! assert (ccau2'*ccau2, single (Ac), eps ('single'))
+%!
+%! assert (cca, ccal',  eps ('single'))
+%! assert (cca, ccau,   eps ('single'))
+%! assert (cca, ccal2', eps ('single'))
+%! assert (cca, ccau2,  eps ('single'))
+
+%!test
+%! a = [12,  2,  3,  4;
+%!       2, 14,  5,  3;
+%!       3,  5, 16,  6;
+%!       4,  3,  6, 16];
+%!
+%! b = [0,  1,  2,  3;
+%!     -1,  0,  1,  2;
+%!     -2, -1,  0,  1;
+%!     -3, -2, -1,  0];
+%!
+%! ca = a + i*b;
+%!   
+%! cca  = chol (ca);
+%!
+%! ccal  = chol (ca, 'lower');
+%! ccal2 = chol (tril (ca), 'lower');
+%!
+%! ccau  = chol (ca, 'upper');
+%! ccau2 = chol (triu (ca), 'upper');
+%!
+%! assert (cca'*cca,     ca, 16*eps)
+%! assert (ccau'*ccau,   ca, 16*eps)
+%! assert (ccau2'*ccau2, ca, 16*eps)
+%!
+%! assert (cca, ccal',  16*eps)
+%! assert (cca, ccau,   16*eps)
+%! assert (cca, ccal2', 16*eps)
+%! assert (cca, ccau2,  16*eps)
+
 */
 
 DEFUN_DLD (choldelete, args, ,
--- a/src/DLD-FUNCTIONS/dassl.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/dassl.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -558,6 +558,6 @@
 %! dassl_options ("absolute tolerance", eps);
 %! assert(dassl_options ("absolute tolerance") == eps);
 
-%!error <Invalid call to dassl_options.*> dassl_options ("foo", 1, 2);
+%!error <Invalid call to dassl_options> dassl_options ("foo", 1, 2);
 
 */
--- a/src/DLD-FUNCTIONS/det.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/det.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -248,8 +248,8 @@
 
 %!assert(det ([1, 2; 3, 4]), -2, 10 * eps);
 %!assert(det (single([1, 2; 3, 4])), single(-2), 10 * eps ('single'));
-%!error <Invalid call to det.*> det ();
-%!error <Invalid call to det.*> det (1, 2);
+%!error <Invalid call to det> det ();
+%!error <Invalid call to det> det (1, 2);
 %!error det ([1, 2; 3, 4; 5, 6]);
 
 */
--- a/src/DLD-FUNCTIONS/eig.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/eig.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -325,8 +325,8 @@
 %! assert(A * v(:, 1), d(1, 1) * B * v(:, 1), sqrt (eps));
 %! assert(A * v(:, 2), d(2, 2) * B * v(:, 2), sqrt (eps));
 
-%!error <Invalid call to eig.*> eig ();
-%!error <Invalid call to eig.*> eig ([1, 2; 3, 4], [4, 3; 2, 1], 1);
+%!error <Invalid call to eig> eig ();
+%!error <Invalid call to eig> eig ([1, 2; 3, 4], [4, 3; 2, 1], 1);
 %!error eig ([1, 2; 3, 4], 2);
 %!error eig ([1, 2; 3, 4; 5, 6]);
 %!error eig ("abcd");
--- a/src/DLD-FUNCTIONS/find.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/find.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -617,6 +617,6 @@
 %!assert (find ([2 0 1 0 5 0], Inf), [1, 3, 5])
 %!assert (find ([2 0 1 0 5 0], Inf, "last"), [1, 3, 5])
 
-%!error <Invalid call to find.*> find ();
+%!error <Invalid call to find> find ();
 
 */
--- a/src/DLD-FUNCTIONS/gcd.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/gcd.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -522,7 +522,7 @@
 %!assert(gcd (uint64(200), uint64(300), uint64(50), uint64(35)), uint64(5))
 %!assert(gcd (18-i, -29+3i), -3-4i)
 
-%!error <Invalid call to gcd.*> gcd ();
+%!error <Invalid call to gcd> gcd ();
 
 %!test
 %! s.a = 1;
--- a/src/DLD-FUNCTIONS/hess.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/hess.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -184,8 +184,8 @@
 %! [p, h] = hess (a);
 %! assert(p * h * p', a, sqrt(eps ('single')));
 
-%!error <Invalid call to hess.*> hess ();
-%!error <Invalid call to hess.*> hess ([1, 2; 3, 4], 2);
+%!error <Invalid call to hess> hess ();
+%!error <Invalid call to hess> hess ([1, 2; 3, 4], 2);
 %!error hess ([1, 2; 3, 4; 5, 6]);
 
 */
--- a/src/DLD-FUNCTIONS/inv.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/inv.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -228,8 +228,8 @@
 %!assert(inv ([1, 2; 3, 4]), [-2, 1; 1.5, -0.5], sqrt (eps))
 %!assert(inv (single([1, 2; 3, 4])), single([-2, 1; 1.5, -0.5]), sqrt (eps ('single')))
 
-%!error <Invalid call to inv.*> inv ();
-%!error <Invalid call to inv.*> inv ([1, 2; 3, 4], 2);
+%!error <Invalid call to inv> inv ();
+%!error <Invalid call to inv> inv ([1, 2; 3, 4], 2);
 %!error inv ([1, 2; 3, 4; 5, 6]);
 
  */
--- a/src/DLD-FUNCTIONS/kron.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/kron.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -239,7 +239,7 @@
 
 
 DEFUN_DLD (kron, args, , "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} kron (@var{A}, @var{B})\n\
+@deftypefn  {Loadable Function} {} kron (@var{A}, @var{B})\n\
 @deftypefnx {Loadable Function} {} kron (@var{A1}, @var{A2}, @dots{})\n\
 Form the Kronecker product of two or more matrices, defined block by \n\
 block as\n\
--- a/src/DLD-FUNCTIONS/lsode.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/lsode.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -541,6 +541,6 @@
 %! lsode_options ("absolute tolerance", eps);
 %! assert(lsode_options ("absolute tolerance") == eps);
 
-%!error <Invalid call to lsode_options.*> lsode_options ("foo", 1, 2);
+%!error <Invalid call to lsode_options> lsode_options ("foo", 1, 2);
 
 */
--- a/src/DLD-FUNCTIONS/lu.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/lu.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -580,7 +580,7 @@
 %! assert(u, single([5, 6; 0, 4/5]), sqrt (eps('single')));
 %! assert(p(:,:), single([0, 0, 1; 1, 0, 0; 0 1 0]), sqrt (eps('single')));
 
-%!error <Invalid call to lu.*> lu ();
+%!error <Invalid call to lu> lu ();
 %!error lu ([1, 2; 3, 4], 2);
 
  */
--- a/src/DLD-FUNCTIONS/max.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/max.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -367,10 +367,10 @@
 %!assert(all (min ([4, i; -2, 2]) == [-2, i]));
 
 %% test/octave.test/arith/min-3.m
-%!error <Invalid call to min.*> min ();
+%!error <Invalid call to min> min ();
 
 %% test/octave.test/arith/min-4.m
-%!error <Invalid call to min.*> min (1, 2, 3, 4);
+%!error <Invalid call to min> min (1, 2, 3, 4);
 
 %!test
 %! x = reshape (1:8,[2,2,2]);
@@ -446,10 +446,10 @@
 %!assert(all (max ([4, i 4.999; -2, 2, 3+4i]) == [4, 2, 3+4i]));
 
 %% test/octave.test/arith/max-3.m
-%!error <Invalid call to max.*> max ();
+%!error <Invalid call to max> max ();
 
 %% test/octave.test/arith/max-4.m
-%!error <Invalid call to max.*> max (1, 2, 3, 4);
+%!error <Invalid call to max> max (1, 2, 3, 4);
 
 %!test
 %! x = reshape (1:8,[2,2,2]);
--- a/src/DLD-FUNCTIONS/qr.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/qr.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -497,8 +497,8 @@
 %! assert (q * r, a * p, sqrt (eps));
 %! assert (qe * re, a(:, pe), sqrt (eps));
 
-%!error <Invalid call to qr.*> qr ();
-%!error <Invalid call to qr.*> qr ([1, 2; 3, 4], 0, 2);
+%!error <Invalid call to qr> qr ();
+%!error <Invalid call to qr> qr ([1, 2; 3, 4], 0, 2);
 
 %!function retval = testqr (q, r, a, p)
 %!  tol = 100*eps (class(q));
@@ -615,8 +615,8 @@
 %! assert (q * r, a * p, sqrt (eps('single')));
 %! assert (qe * re, a(:, pe), sqrt (eps('single')));
 
-%!error <Invalid call to qr.*> qr ();
-%!error <Invalid call to qr.*> qr ([1, 2; 3, 4], 0, 2);
+%!error <Invalid call to qr> qr ();
+%!error <Invalid call to qr> qr ([1, 2; 3, 4], 0, 2);
 
 %!test
 %!
@@ -1174,7 +1174,7 @@
 @var{R}@tie{}upper trapezoidal, return the QR@tie{}factorization of\n\
 @w{[A(:,1:j-1) A(:,j+1:n)]}, i.e., @var{A} with one column deleted\n\
 (if @var{orient} is \"col\"), or the QR@tie{}factorization of\n\
-@w{[A(1:j-1,:);A(:,j+1:n)]}, i.e., @var{A} with one row deleted (if\n\
+@w{[A(1:j-1,:);A(j+1:n,:)]}, i.e., @var{A} with one row deleted (if\n   \
 @var{orient} is \"row\").\n\
 \n\
 The default value of @var{orient} is \"col\".\n\
--- a/src/DLD-FUNCTIONS/quad.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/quad.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -494,14 +494,14 @@
 %!  [v, ier, nfun, err] = quad ("f", single(0.001), single(3));
 %! assert((ier == 0 || ier == 1) && abs (v - 1.98194120273598) < sqrt (eps ("single")) && nfun > 0);
 
-%!error <Invalid call to quad.*> quad ();
+%!error <Invalid call to quad> quad ();
 
-%!error <Invalid call to quad.*> quad ("f", 1, 2, 3, 4, 5);
+%!error <Invalid call to quad> quad ("f", 1, 2, 3, 4, 5);
 
 %!test
 %! quad_options ("absolute tolerance", eps);
 %! assert(quad_options ("absolute tolerance") == eps);
 
-%!error <Invalid call to quad_options.*> quad_options (1, 2, 3);
+%!error <Invalid call to quad_options> quad_options (1, 2, 3);
 
 */
--- a/src/DLD-FUNCTIONS/regexp.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/regexp.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -941,6 +941,7 @@
 A structure containing the text of each matched named token, with the name\n\
 being used as the fieldname.  A named token is denoted by\n\
 @code{(?<name>@dots{})}.\n\
+\n\
 @item sp\n\
 A cell array of the text not returned by match.\n\
 @end table\n\
--- a/src/DLD-FUNCTIONS/schur.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/schur.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -289,7 +289,7 @@
 %!test
 %! fail("schur ([1, 2; 3, 4], 2)","warning");
 
-%!error <Invalid call to schur.*> schur ();
+%!error <Invalid call to schur> schur ();
 %!error schur ([1, 2, 3; 4, 5, 6]);
 
 */
--- a/src/DLD-FUNCTIONS/sub2ind.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/sub2ind.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -125,9 +125,9 @@
 /*
 
 # Test input validation
-%!error <sub2ind: dimension vector .*> sub2ind([10 10.5], 1, 1);
-%!error <subscript indices .*> sub2ind([10 10], 1.5, 1);
-%!error <subscript indices .*> sub2ind([10 10], 1, 1.5);
+%!error <sub2ind: dimension vector > sub2ind([10 10.5], 1, 1);
+%!error <subscript indices > sub2ind([10 10], 1.5, 1);
+%!error <subscript indices > sub2ind([10 10], 1, 1.5);
 
 # Test evaluation
 %!shared s1, s2, s3, in
@@ -140,9 +140,9 @@
 
 # Test low index
 %!assert (sub2ind([10 10 10], 1, 1, 1), 1);
-%!error <subscript indices .*> sub2ind([10 10 10], 0, 1, 1);
-%!error <subscript indices .*> sub2ind([10 10 10], 1, 0, 1);
-%!error <subscript indices .*> sub2ind([10 10 10], 1, 1, 0);
+%!error <subscript indices > sub2ind([10 10 10], 0, 1, 1);
+%!error <subscript indices > sub2ind([10 10 10], 1, 0, 1);
+%!error <subscript indices > sub2ind([10 10 10], 1, 1, 0);
 
 # Test high index
 %!assert (sub2ind([10 10 10], 10, 10, 10), 1000);
--- a/src/DLD-FUNCTIONS/svd.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/svd.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -398,9 +398,9 @@
 %! assert (size (s), [0, 0]);
 %! assert (size (v), [0, 0]);
 
-%!error <Invalid call to svd.*> svd ();
-%!error <Invalid call to svd.*> svd ([1, 2; 4, 5], 2, 3);
-%!error <Invalid call to svd.*> [u, v] = svd ([1, 2; 3, 4]);
+%!error <Invalid call to svd> svd ();
+%!error <Invalid call to svd> svd ([1, 2; 4, 5], 2, 3);
+%!error <Invalid call to svd> [u, v] = svd ([1, 2; 3, 4]);
 
 */
 
@@ -408,9 +408,14 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Loadable Function} {@var{val} =} svd_driver ()\n\
 @deftypefnx {Loadable Function} {@var{old_val} =} svd_driver (@var{new_val})\n\
+@deftypefnx {Loadable Function} {} svd_driver (@var{new_val}, \"local\")\n\
 Query or set the underlying @sc{lapack} driver used by @code{svd}.\n\
 Currently recognized values are \"gesvd\" and \"gesdd\".  The default\n\
 is \"gesvd\".\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{svd}\n\
 @end deftypefn")
 {
--- a/src/DLD-FUNCTIONS/syl.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/syl.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -213,8 +213,8 @@
 %!assert(syl ([1, 2; 3, 4], [5, 6; 7, 8], [9, 10; 11, 12]), [-1/2, -2/3; -2/3, -1/2], sqrt (eps));
 %!assert(syl (single([1, 2; 3, 4]), single([5, 6; 7, 8]), single([9, 10; 11, 12])), single([-1/2, -2/3; -2/3, -1/2]), sqrt (eps('single')));
 
-%!error <Invalid call to syl.*> syl ();
-%!error <Invalid call to syl.*> syl (1, 2, 3, 4);
+%!error <Invalid call to syl> syl ();
+%!error <Invalid call to syl> syl (1, 2, 3, 4);
 %!error syl ([1, 2; 3, 4], [1, 2, 3; 4, 5, 6], [4, 3]);
 
 */
--- a/src/DLD-FUNCTIONS/time.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/time.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -186,9 +186,9 @@
 %! && isfield (ts, "isdst")
 %! && isfield (ts, "yday")));
 
-%!error <Invalid call to gmtime.*> gmtime ();
+%!error <Invalid call to gmtime> gmtime ();
 
-%!error <Invalid call to gmtime.*> gmtime (1, 2);
+%!error <Invalid call to gmtime> gmtime (1, 2);
 
 */
 
@@ -250,9 +250,9 @@
 %! && isfield (ts, "isdst")
 %! && isfield (ts, "yday")));
 
-%!error <Invalid call to localtime.*> localtime ();
+%!error <Invalid call to localtime> localtime ();
 
-%!error <Invalid call to localtime.*> localtime (1, 2);
+%!error <Invalid call to localtime> localtime (1, 2);
 
 */
 
@@ -301,9 +301,9 @@
 %! t = time ();
 %! assert(fix (mktime (localtime (t))) == fix (t));
 
-%!error <Invalid call to mktime.*> mktime ();
+%!error <Invalid call to mktime> mktime ();
 
-%!error <Invalid call to mktime.*> mktime (1, 2, 3);
+%!error <Invalid call to mktime> mktime (1, 2, 3);
 
 %% These tests fail on systems with mktime functions of limited
 %% intelligence:
@@ -505,9 +505,9 @@
 %! && ischar (strftime ("%c%C%d%e%D%h%j", localtime (time ())))
 %! && ischar (strftime ("%m%U%w%W%x%y%Y", localtime (time ())))));
 
-%!error <Invalid call to strftime.*> strftime ();
+%!error <Invalid call to strftime> strftime ();
 
-%!error <Invalid call to strftime.*> strftime ("foo", localtime (time ()), 1);
+%!error <Invalid call to strftime> strftime ("foo", localtime (time ()), 1);
 
 */
 
--- a/src/DLD-FUNCTIONS/urlwrite.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/DLD-FUNCTIONS/urlwrite.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -46,6 +46,7 @@
 #include "ov-cell.h"
 #include "pager.h"
 #include "oct-map.h"
+#include "oct-refcount.h"
 #include "unwind-prot.h"
 
 #ifdef HAVE_CURL
@@ -141,7 +142,7 @@
         return !ascii;
       }
 
-    size_t count;
+    octave_refcount<size_t> count;
     std::string host;
     bool valid;
     bool ascii;
@@ -805,8 +806,8 @@
 
   frame.add_fcn (cleanup_urlwrite, filename);
 
-  bool res;
-  curl_handle curl = curl_handle (url, method, param, ofile, res);
+  bool ok;
+  curl_handle curl = curl_handle (url, method, param, ofile, ok);
 
   ofile.close ();
 
@@ -817,7 +818,7 @@
 
   if (nargout > 0)
     {
-      if (res)
+      if (ok)
         {
           retval(2) = std::string ();
           retval(1) = true;
@@ -831,7 +832,7 @@
         }
     }
 
-  if (nargout < 2 && res)
+  if (nargout < 2 && ! ok)
     error ("urlwrite: curl: %s", curl.lasterror ().c_str ());
 
 #else
@@ -939,18 +940,18 @@
 
   std::ostringstream buf;
 
-  bool res;
-  curl_handle curl = curl_handle (url, method, param, buf, res);
+  bool ok;
+  curl_handle curl = curl_handle (url, method, param, buf, ok);
 
   if (nargout > 0)
     {
       retval(0) = buf.str ();
-      retval(1) = res;
+      retval(1) = ok;
       // Return empty string if no error occured.
-      retval(2) = res ? "" : curl.lasterror ();
+      retval(2) = ok ? "" : curl.lasterror ();
     }
 
-  if (nargout < 2 && !res)
+  if (nargout < 2 && ! ok)
     error ("urlread: curl: %s", curl.lasterror().c_str());
 
 #else
--- a/src/Makefile.am	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/Makefile.am	Wed Dec 07 19:06:13 2011 -0500
@@ -286,6 +286,7 @@
   parse.h \
   pr-output.h \
   procstream.h \
+  profiler.h \
   sighandlers.h \
   siglist.h \
   sparse-xdiv.h \
@@ -311,7 +312,6 @@
   defaults.h \
   graphics.h \
   oct-conf.h \
-  profiler.h \
   mxarray.h \
   version.h
 
--- a/src/bitfcns.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/bitfcns.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -410,10 +410,10 @@
 @deftypefn  {Built-in Function} {} bitshift (@var{a}, @var{k})\n\
 @deftypefnx {Built-in Function} {} bitshift (@var{a}, @var{k}, @var{n})\n\
 Return a @var{k} bit shift of @var{n}-digit unsigned\n\
-integers in @var{a}.  A positive @var{k} leads to a left shift.\n\
+integers in @var{a}.  A positive @var{k} leads to a left shift;\n\
 A negative value to a right shift.  If @var{n} is omitted it defaults\n\
 to log2(bitmax)+1.\n\
-@var{n} must be in the range [1,log2(bitmax)+1] usually [1,33]\n\
+@var{n} must be in the range [1,log2(bitmax)+1] usually [1,33].\n\
 \n\
 @example\n\
 @group\n\
--- a/src/comment-list.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/comment-list.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -25,6 +25,7 @@
 #endif
 
 #include "lo-utils.h"
+#include "singleton-cleanup.h"
 
 #include "comment-list.h"
 #include "error.h"
@@ -52,7 +53,12 @@
   bool retval = true;
 
   if (! instance)
-    instance = new octave_comment_buffer ();
+    {
+      instance = new octave_comment_buffer ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
--- a/src/comment-list.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/comment-list.h	Wed Dec 07 19:06:13 2011 -0500
@@ -105,6 +105,8 @@
   octave_comment_buffer (void)
     : comment_list (new octave_comment_list ()) { }
 
+  ~octave_comment_buffer (void) { delete comment_list; }
+
   static bool instance_ok (void);
 
   static void append
@@ -122,6 +124,8 @@
   octave_comment_list *comment_list;
 
   static octave_comment_buffer *instance;
+
+  static void cleanup_instance (void) { delete instance; instance = 0; }
 };
 
 #endif
--- a/src/data.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/data.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -149,8 +149,8 @@
 %! && all (x, 1) == [0, 1, 1]
 %! && all (x, 2) == [0; 1; 1]));
 
-%!error <Invalid call to all.*> all ();
-%!error <Invalid call to all.*> all (1, 2, 3);
+%!error <Invalid call to all> all ();
+%!error <Invalid call to all> all (1, 2, 3);
 
  */
 
@@ -205,8 +205,8 @@
 %! && any (x, 1) == [0, 0, 1]
 %! && any (x, 2) == [0; 0; 1]));
 
-%!error <Invalid call to any.*> any ();
-%!error <Invalid call to any.*> any (1, 2, 3);
+%!error <Invalid call to any> any ();
+%!error <Invalid call to any> any (1, 2, 3);
 
  */
 
@@ -293,8 +293,8 @@
 %! x = single([1, 3, 1, 1, 1, 1, 3, 1]);
 %! assert(atan2 (y, x), v, sqrt (eps('single')));
 
-%!error <Invalid call to atan2.*> atan2 ();
-%!error <Invalid call to atan2.*> atan2 (1, 2, 3);
+%!error <Invalid call to atan2> atan2 ();
+%!error <Invalid call to atan2> atan2 (1, 2, 3);
 
 */
 
@@ -1079,7 +1079,7 @@
 %!assert (cumprod (single([i, 2+i, -3+2i, 4])), single([i, -1+2i, -1-8i, -4-32i]));
 %!assert (cumprod (single([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single([1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i]));
 
-%!error <Invalid call to cumprod.*> cumprod ();
+%!error <Invalid call to cumprod> cumprod ();
 
 %!assert (cumprod ([2, 3; 4, 5], 1), [2, 3; 8, 15]);
 %!assert (cumprod ([2, 3; 4, 5], 2), [2, 6; 4, 20]);
@@ -1230,7 +1230,7 @@
 %!assert (cumsum (single([i, 2+i, -3+2i, 4])), single([i, 2+2i, -1+4i, 3+4i]));
 %!assert (cumsum (single([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single([1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i]));
 
-%!error <Invalid call to cumsum.*> cumsum ();
+%!error <Invalid call to cumsum> cumsum ();
 
 %!assert (cumsum ([1, 2; 3, 4], 1), [1, 2; 4, 6]);
 %!assert (cumsum ([1, 2; 3, 4], 2), [1, 3; 3, 7]);
@@ -1342,8 +1342,8 @@
 %!assert(diag (int8([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), int8([1; 2; 3]));
 
 %% Test input validation
-%!error <Invalid call to diag.*> diag ();
-%!error <Invalid call to diag.*> diag (1,2,3,4);
+%!error <Invalid call to diag> diag ();
+%!error <Invalid call to diag> diag (1,2,3,4);
 %!error diag (ones (2), 3, 3);
 %!error diag (1:3, -4, 3);
 
@@ -1373,7 +1373,7 @@
 %!assert (prod (single([i, 2+i, -3+2i, 4])), single(-4 - 32i));
 %!assert (prod (single([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single([-1+i, -8+8i, -27+27i]));
 
-%!error <Invalid call to prod.*> prod ();
+%!error <Invalid call to prod> prod ();
 
 %!assert (prod ([1, 2; 3, 4], 1), [3, 8]);
 %!assert (prod ([1, 2; 3, 4], 2), [2; 12]);
@@ -2413,14 +2413,17 @@
   @var{a}(@var{idx1}, @var{idx2}, @dots{})\n\
 @end example\n\
 \n\
-Note that the indices do not have to be numerical. For example\n\
+Note that the indices do not have to be numerical.  For example,\n\
 \n\
 @example\n\
+@group\n\
   @var{a} = 1;\n\
   @var{b} = ones (2, 3);\n\
   numel (@var{a}, @var{b});\n\
+@end group\n\
 @end example\n\
 \n\
+@noindent\n\
 will return 6, as this is the number of ways to index with @var{b}.\n\
 \n\
 This method is also called when an object appears as lvalue with cs-list\n\
@@ -2815,7 +2818,7 @@
 %!assert(sum (single([i, 2+i, -3+2i, 4])), single(3+4i));
 %!assert(sum (single([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single([2+2i, 4+4i, 6+6i]));
 
-%!error <Invalid call to sum.*> sum ();
+%!error <Invalid call to sum> sum ();
 
 %!assert (sum ([1, 2; 3, 4], 1), [4, 6]);
 %!assert (sum ([1, 2; 3, 4], 2), [3; 7]);
@@ -2890,7 +2893,7 @@
 %!assert(sumsq (single([-1; -2; 4i])), single(21));
 %!assert(sumsq (single([1, 2, 3; 2, 3, 4; 4i, 6i, 2])), single([21, 49, 29]));
 
-%!error <Invalid call to sumsq.*> sumsq ();
+%!error <Invalid call to sumsq> sumsq ();
 
 %!assert (sumsq ([1, 2; 3, 4], 1), [10, 20]);
 %!assert (sumsq ([1, 2; 3, 4], 2), [5; 25]);
@@ -3402,8 +3405,8 @@
 %! s.a = 1;
 %! assert(ismatrix (s), false);
 
-%!error <Invalid call to ismatrix.*> ismatrix ();
-%!error <Invalid call to ismatrix.*> ismatrix ([1, 2; 3, 4], 2);
+%!error <Invalid call to ismatrix> ismatrix ();
+%!error <Invalid call to ismatrix> ismatrix ([1, 2; 3, 4], 2);
 
  */
 
@@ -4620,7 +4623,7 @@
 %!assert (eye(3,'int8'), int8([1, 0, 0; 0, 1, 0; 0, 0, 1]));
 %!assert (eye(2, 3,'int8'), int8([1, 0, 0; 0, 1, 0]));
 
-%!error <Invalid call to eye.*> eye (1, 2, 3);
+%!error <Invalid call to eye> eye (1, 2, 3);
 
  */
 
@@ -4743,8 +4746,8 @@
 
 % assert(linspace ([1, 2; 3, 4], 5, 6), linspace (1, 5, 6));
 
-%!error <Invalid call to linspace.*> linspace ();
-%!error <Invalid call to linspace.*> linspace (1, 2, 3, 4);
+%!error <Invalid call to linspace> linspace ();
+%!error <Invalid call to linspace> linspace (1, 2, 3, 4);
 
 %!test
 %! fail("linspace ([1, 2; 3, 4], 5, 6)","warning");
@@ -4977,7 +4980,7 @@
 %! s.a = 1;
 %! fail("reshape (s, 2, 3)");
 
-%!error <Invalid call to reshape.*> reshape ();
+%!error <Invalid call to reshape> reshape ();
 %!error reshape (1, 2, 3, 4);
 
  */
@@ -6154,8 +6157,8 @@
 %! [v, i] = sort (a);
 %! assert (i, [1, 4, 2, 5, 3])
 
-%!error <Invalid call to sort.*> sort ();
-%!error <Invalid call to sort.*> sort (1, 2, 3, 4);
+%!error <Invalid call to sort> sort ();
+%!error <Invalid call to sort> sort (1, 2, 3, 4);
 
 */
 
--- a/src/debug.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/debug.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -32,6 +32,7 @@
 #include <string>
 
 #include "file-stat.h"
+#include "singleton-cleanup.h"
 
 #include "defun.h"
 #include "error.h"
@@ -250,6 +251,28 @@
     }
 }
 
+bool
+bp_table::instance_ok (void)
+{
+  bool retval = true;
+
+  if (! instance)
+    {
+      instance = new bp_table ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
+
+  if (! instance)
+    {
+      ::error ("unable to create breakpoint table!");
+      retval = false;
+    }
+
+  return retval;
+}
+
 bp_table::intmap
 bp_table::do_add_breakpoint (const std::string& fname,
                              const bp_table::intmap& line)
--- a/src/debug.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/debug.h	Wed Dec 07 19:06:13 2011 -0500
@@ -55,21 +55,7 @@
   typedef fname_line_map::const_iterator const_fname_line_map_iterator;
   typedef fname_line_map::iterator fname_line_map_iterator;
 
-  static bool instance_ok (void)
-  {
-    bool retval = true;
-
-    if (! instance)
-      instance = new bp_table ();
-
-    if (! instance)
-      {
-        ::error ("unable to create breakpoint table!");
-        retval = false;
-      }
-
-    return retval;
-  }
+  static bool instance_ok (void);
 
   // Add a breakpoint at the nearest executable line.
   static intmap add_breakpoint (const std::string& fname = "",
@@ -127,6 +113,8 @@
 
   static bp_table *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   intmap do_add_breakpoint (const std::string& fname, const intmap& lines);
 
   int do_remove_breakpoint (const std::string&, const intmap& lines);
--- a/src/defaults.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/defaults.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -408,11 +408,16 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} EDITOR ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} EDITOR (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} EDITOR (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the editor to\n\
 use with the @code{edit_history} command.  The default value is taken from\n\
 the environment variable @w{@env{EDITOR}} when Octave starts.  If the\n\
 environment variable is not initialized, @w{@env{EDITOR}} will be set to\n\
 @code{\"emacs\"}.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{edit_history}\n\
 @end deftypefn")
 {
@@ -434,11 +439,16 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} EXEC_PATH ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} EXEC_PATH (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} EXEC_PATH (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies a colon separated\n\
 list of directories to append to the shell PATH when executing external\n\
 programs.  The initial value of is taken from the environment variable\n\
 @w{@env{OCTAVE_EXEC_PATH}}, but that value can be overridden by\n\
 the command line argument @option{--exec-path PATH}.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   octave_value retval = SET_NONEMPTY_INTERNAL_STRING_VARIABLE (EXEC_PATH);
@@ -464,8 +474,13 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} IMAGE_PATH ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} IMAGE_PATH (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} IMAGE_PATH (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies a colon separated\n\
 list of directories in which to search for image files.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (IMAGE_PATH);
--- a/src/dirfns.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/dirfns.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -87,7 +87,7 @@
   return cd_ok;
 }
 
-DEFUN (cd, args, ,
+DEFUN (cd, args, nargout,
   "-*- texinfo -*-\n\
 @deftypefn  {Command} {} cd dir\n\
 @deftypefnx {Command} {} chdir dir\n\
@@ -127,10 +127,18 @@
     }
   else
     {
-      std::string home_dir = octave_env::get_home_directory ();
+      // Behave like Unixy shells for "cd" by itself, but be Matlab
+      // compatible if doing "current_dir = cd".
 
-      if (home_dir.empty () || ! octave_change_to_directory (home_dir))
-        return retval;
+      if (nargout == 0)
+        {
+          std::string home_dir = octave_env::get_home_directory ();
+
+          if (home_dir.empty () || ! octave_change_to_directory (home_dir))
+            return retval;
+        }
+      else
+        retval = octave_value (octave_env::get_current_directory ());
     }
 
   return retval;
@@ -764,8 +772,13 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} confirm_recursive_rmdir ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} confirm_recursive_rmdir (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} confirm_recursive_rmdir (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether Octave\n\
 will ask for confirmation before recursively removing a directory tree.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (confirm_recursive_rmdir);
--- a/src/display.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/display.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -27,13 +27,15 @@
 #include <cstdlib>
 
 #if defined (OCTAVE_USE_WINDOWS_API)
-#include <Windows.h>
+#include <windows.h>
 #elif defined (HAVE_FRAMEWORK_CARBON)
 #include <Carbon/Carbon.h>
 #elif defined (HAVE_X_WINDOWS)
 #include <X11/Xlib.h>
 #endif
 
+#include "singleton-cleanup.h"
+
 #include "display.h"
 #include "error.h"
 
@@ -118,6 +120,8 @@
                 }
               else
                 warning ("X11 display has no default screen");
+
+              XCloseDisplay (display);
             }
           else
             warning ("unable to open X11 DISPLAY");
@@ -138,7 +142,12 @@
   bool retval = true;
 
   if (! instance)
-    instance = new display_info (query);
+    {
+      instance = new display_info (query);
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
--- a/src/display.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/display.h	Wed Dec 07 19:06:13 2011 -0500
@@ -73,6 +73,8 @@
 
   static display_info *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   // Height, width, and depth of the display.
   int ht;
   int wd;
--- a/src/dynamic-ld.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/dynamic-ld.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -27,9 +27,10 @@
 #include <iostream>
 #include <list>
 
+#include "file-stat.h"
 #include "oct-env.h"
 #include "oct-time.h"
-#include "file-stat.h"
+#include "singleton-cleanup.h"
 
 #include <defaults.h>
 
@@ -78,6 +79,8 @@
 
   static octave_shlib_list *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   static bool instance_ok (void);
 
   // List of libraries we have loaded.
@@ -148,7 +151,12 @@
   bool retval = true;
 
   if (! instance)
-    instance = new octave_shlib_list ();
+    {
+      instance = new octave_shlib_list ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
@@ -213,6 +221,8 @@
 
   static octave_mex_file_list *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   static bool instance_ok (void);
 
   // List of libraries we have loaded.
@@ -258,7 +268,12 @@
   bool retval = true;
 
   if (! instance)
-    instance = new octave_mex_file_list ();
+    {
+      instance = new octave_mex_file_list ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
@@ -295,7 +310,12 @@
   bool retval = true;
 
   if (! instance)
-    instance = new octave_dynamic_loader ();
+    {
+      instance = new octave_dynamic_loader ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
--- a/src/dynamic-ld.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/dynamic-ld.h	Wed Dec 07 19:06:13 2011 -0500
@@ -64,6 +64,8 @@
 
   static octave_dynamic_loader *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   static bool instance_ok (void);
 
   octave_function *
--- a/src/error.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/error.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -119,9 +119,6 @@
 // TRUE means warning messages are turned off.
 bool discard_warning_messages = false;
 
-// The message buffer.
-static std::ostringstream *error_message_buffer = 0;
-
 void
 reset_error_handler (void)
 {
@@ -263,16 +260,7 @@
         Vlast_error_stack = initialize_last_error_stack ();
     }
 
-  if (buffer_error_messages)
-    {
-      if (error_message_buffer)
-        msg_string = "error: " + msg_string;
-      else
-        error_message_buffer = new std::ostringstream ();
-
-      *error_message_buffer << msg_string;
-    }
-  else
+  if (! buffer_error_messages)
     {
       octave_diary << msg_string;
       os << msg_string;
@@ -1774,8 +1762,13 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} beep_on_error ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} beep_on_error (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} beep_on_error (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether Octave will try\n\
 to ring the terminal bell before printing an error message.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (beep_on_error);
@@ -1785,10 +1778,15 @@
     "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} debug_on_error ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} debug_on_error (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} debug_on_error (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether Octave will try\n\
 to enter the debugger when an error is encountered.  This will also\n\
 inhibit printing of the normal traceback message (you will only see\n\
 the top-level error message).\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (debug_on_error);
@@ -1798,8 +1796,13 @@
     "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} debug_on_warning ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} debug_on_warning (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} debug_on_warning (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether Octave will try\n\
 to enter the debugger when a warning is encountered.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (debug_on_warning);
--- a/src/file-io.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/file-io.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -46,6 +46,7 @@
 #include <stack>
 #include <vector>
 
+#include <fcntl.h>
 #include <sys/types.h>
 #include <unistd.h>
 
@@ -1203,7 +1204,7 @@
 string @var{string} instead of from a stream.  Reaching the end of the\n\
 string is treated as an end-of-file condition.  In addition to the values\n\
 returned by @code{fscanf}, the index of the next character to be read\n\
-is returned in in @var{pos}.\n\
+is returned in @var{pos}.\n\
 @seealso{fscanf, scanf, sprintf}\n\
 @end deftypefn")
 {
@@ -1981,7 +1982,7 @@
 filename unique.  The file is then created with mode read/write and\n\
 permissions that are system dependent (on GNU/Linux systems, the permissions\n\
 will be 0600 for versions of glibc 2.0.7 and later).  The file is opened\n\
-with the @w{@code{O_EXCL}} flag.\n\
+in binary mode and with the @w{@code{O_EXCL}} flag.\n\
 \n\
 If the optional argument @var{delete} is supplied and is true,\n\
 the file will be deleted automatically when Octave exits, or when\n\
@@ -2011,7 +2012,7 @@
           OCTAVE_LOCAL_BUFFER (char, tmp, tmpl8.size () + 1);
           strcpy (tmp, tmpl8.c_str ());
 
-          int fd = gnulib::mkstemp (tmp);
+          int fd = gnulib::mkostemp (tmp, O_BINARY);
 
           if (fd < 0)
             {
@@ -2020,7 +2021,7 @@
             }
           else
             {
-              const char *fopen_mode = "w+";
+              const char *fopen_mode = "w+b";
 
               FILE *fid = fdopen (fd, fopen_mode);
 
--- a/src/gl-render.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/gl-render.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -30,6 +30,7 @@
 
 #include <lo-mappers.h>
 #include "oct-locbuf.h"
+#include "oct-refcount.h"
 #include "gl-render.h"
 #include "txt-eng.h"
 #include "txt-eng-ft.h"
@@ -2460,7 +2461,7 @@
   if (props.get_string ().is_empty ())
     return;
 
-  const Matrix pos = xform.scale (props.get_data_position ());
+  Matrix pos = xform.scale (props.get_data_position ());
   const Matrix bbox = props.get_extent_matrix ();
 
   // FIXME: handle margin and surrounding box
@@ -2468,7 +2469,7 @@
 
   glEnable (GL_BLEND);
   glEnable (GL_ALPHA_TEST);
-  glRasterPos3d (pos(0), pos(1), pos(2));
+  glRasterPos3d (pos(0), pos(1), pos.numel () > 2 ? pos(2) : 0.0);
   glBitmap(0, 0, 0, 0, bbox(0), bbox(1), 0);
   glDrawPixels (bbox(2), bbox(3),
                 GL_RGBA, GL_UNSIGNED_BYTE, props.get_pixels ().data ());
--- a/src/graphics.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/graphics.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -27,6 +27,7 @@
 #include <cctype>
 #include <cfloat>
 #include <cstdlib>
+#include <ctime>
 
 #include <algorithm>
 #include <list>
@@ -35,17 +36,19 @@
 #include <string>
 #include <sstream>
 
+#include "cmd-edit.h"
 #include "file-ops.h"
 #include "file-stat.h"
-
-#include "cmd-edit.h"
+#include "oct-locbuf.h"
+#include "singleton-cleanup.h"
+
+#include "cutils.h"
 #include "defun.h"
 #include "display.h"
 #include "error.h"
 #include "graphics.h"
 #include "input.h"
 #include "ov.h"
-#include "oct-locbuf.h"
 #include "oct-obj.h"
 #include "oct-map.h"
 #include "ov-fcn-handle.h"
@@ -2384,7 +2387,7 @@
 xinitialize (const graphics_handle& h)
 {
   graphics_object go = gh_manager::get_object (h);
-  
+
   if (go)
     go.initialize ();
 }
@@ -2484,7 +2487,10 @@
 {
   const std::set<std::string>& dynprops = dynamic_property_names ();
 
-  return dynprops.find (pname) != dynprops.end ();
+  if (dynprops.find (pname) != dynprops.end ())
+    return true;
+  else
+    return all_props.find (pname) != all_props.end ();
 }
 
 void
@@ -5113,8 +5119,22 @@
 
       // FIXME: bbox should be stored in axes::properties
       Matrix bbox = get_extent (false);
-      ColumnVector p = xform.untransform (bbox(0)+bbox(2)/2, (bbox(1)-10),
-                                          (x_zlim(0)+x_zlim(1))/2, true);
+
+      ColumnVector p =
+        graphics_xform::xform_vector (bbox(0)+bbox(2)/2,
+                                      bbox(1)-10,
+                                      (x_zlim(0)+x_zlim(1))/2);
+
+      if (x2Dtop)
+        {
+          Matrix ext (1, 2, 0.0);
+          ext = get_ticklabel_extents (get_xtick ().matrix_value (),
+                                       get_xticklabel ().all_strings (),
+                                       get_xlim ().matrix_value ());
+          p(1) -= ext(1);
+        }
+
+      p = xform.untransform (p(0), p(1), p(2), true);
 
       title_props.set_position (p.extract_n(0, 3).transpose ());
       title_props.set_positionmode ("auto");
@@ -7074,7 +7094,7 @@
 
   // FIXME: parsed content should be cached for efficiency
   // FIXME: support multiline text
-  
+
   elt = text_parser_none ().parse (get_string_string ());
 #ifdef HAVE_FONTCONFIG
   text_renderer.set_font (get_fontname (),
@@ -7105,7 +7125,7 @@
   graphics_object parent_obj = gh_manager::get_object (get_parent ());
   Matrix parent_bbox = parent_obj.get_properties ().get_boundingbox (true),
          parent_size = parent_bbox.extract_n (0, 2, 1, 2);
-  
+
   pos = convert_position (pos, cached_units, get_units (), parent_size);
   set_position (pos);
 
@@ -7276,7 +7296,7 @@
   graphics_object parent_obj = gh_manager::get_object (get_parent ());
   Matrix parent_bbox = parent_obj.get_properties ().get_boundingbox (true),
          parent_size = parent_bbox.extract_n (0, 2, 1, 2);
-  
+
   pos = convert_position (pos, old_units, get_units (), parent_size);
   set_position (pos);
 }
@@ -7376,6 +7396,16 @@
   graphics_toolkit::default_toolkit ();
 }
 
+void
+gh_manager::create_instance (void)
+{
+  instance = new gh_manager ();
+
+#if 0
+  singleton_cleanup_list::add (cleanup_instance);
+#endif
+}
+
 graphics_handle
 gh_manager::do_make_graphics_handle (const std::string& go_name,
                                      const graphics_handle& p,
@@ -7456,7 +7486,7 @@
                   const octave_value& data = Matrix ())
       : base_graphics_event (), handle (h), callback_name (name),
         callback (), callback_data (data) { }
-  
+
   callback_event (const graphics_handle& h, const octave_value& cb,
                   const octave_value& data = Matrix ())
       : base_graphics_event (), handle (h), callback_name (),
@@ -7627,7 +7657,7 @@
   else
     {
       gh_manager::auto_lock guard;
-      
+
       do_post_event (graphics_event::create_callback_event (h, l));
     }
 }
@@ -7665,18 +7695,19 @@
 
       octave_value cb = cb_arg;
 
-      if (cb.is_function_handle ())
+      if (cb.is_function () || cb.is_function_handle ())
         fcn = cb.function_value ();
       else if (cb.is_string ())
         {
           int status;
           std::string s = cb.string_value ();
 
-          eval_string (s, false, status);
+          eval_string (s, false, status, 0);
         }
       else if (cb.is_cell () && cb.length () > 0
                && (cb.rows () == 1 || cb.columns () == 1)
-               && cb.cell_value ()(0).is_function_handle ())
+               && (cb.cell_value ()(0).is_function ()
+                   || cb.cell_value ()(0).is_function_handle ()))
         {
           Cell c = cb.cell_value ();
 
@@ -7772,69 +7803,66 @@
 {
   graphics_event e;
   bool old_Vdrawnow_requested = Vdrawnow_requested;
-  unwind_protect frame;
- 
-  static int process_events_executing = 0;
- 
-  frame.protect_var (process_events_executing);
-
-  if (++process_events_executing <= 1)
-    {
-      do
-        {
-          e = graphics_event ();
-
-          gh_manager::lock ();
-
-          if (! event_queue.empty ())
+  bool events_executed = false;
+
+  do
+    {
+      e = graphics_event ();
+
+      gh_manager::lock ();
+
+      if (! event_queue.empty ())
+        {
+          if (callback_objects.empty () || force)
             {
-              if (callback_objects.empty () || force)
+              e = event_queue.front ();
+
+              event_queue.pop_front ();
+            }
+          else
+            {
+              const graphics_object& go = callback_objects.front ();
+
+              if (go.get_properties ().is_interruptible ())
                 {
                   e = event_queue.front ();
 
                   event_queue.pop_front ();
                 }
-              else
-                {
-                  const graphics_object& go = callback_objects.front ();
-
-                  if (go.get_properties ().is_interruptible ())
-                    {
-                      e = event_queue.front ();
-
-                      event_queue.pop_front ();
-                    }
-                }
             }
-
-          gh_manager::unlock ();
-
-          if (e.ok ())
-            e.execute ();
-        }
-      while (e.ok ());
-
-      gh_manager::lock ();
-
-      if (event_queue.empty () && event_processing == 0)
-        command_editor::remove_event_hook (gh_manager::process_events);
+        }
 
       gh_manager::unlock ();
 
-      flush_octave_stdout ();
-
-      if (Vdrawnow_requested && ! old_Vdrawnow_requested)
-        {
-          feval ("drawnow");
-
-          Vdrawnow_requested = false;
-        }
+      if (e.ok ())
+        {
+          e.execute ();
+          events_executed = true;
+        }
+    }
+  while (e.ok ());
+
+  gh_manager::lock ();
+
+  if (event_queue.empty () && event_processing == 0)
+    command_editor::remove_event_hook (gh_manager::process_events);
+
+  gh_manager::unlock ();
+
+  if (events_executed)
+    flush_octave_stdout ();
+
+  if (Vdrawnow_requested && ! old_Vdrawnow_requested)
+    {
+      feval ("drawnow");
+
+      Vdrawnow_requested = false;
     }
 
   return 0;
 }
 
-void 
+void
 gh_manager::do_enable_event_processing (bool enable)
 {
   gh_manager::auto_lock guard;
@@ -8139,6 +8167,8 @@
 
   int nargin = args.length ();
 
+  bool use_cell_format = false;
+
   if (nargin == 1 || nargin == 2)
     {
       if (args(0).is_empty())
@@ -8153,8 +8183,6 @@
         {
           octave_idx_type len = hcv.length ();
 
-          vals.resize (dim_vector (len, 1));
-
           if (nargin == 1 && len > 1)
             {
               std::string t0 = get_graphics_object_type (hcv(0));
@@ -8180,31 +8208,74 @@
 
           if (! error_state)
             {
-              for (octave_idx_type n = 0; n < len; n++)
+              if (nargin > 1 && args(1).is_cellstr ())
                 {
-                  graphics_object obj = gh_manager::get_object (hcv(n));
-
-                  if (obj)
+                  Array<std::string> plist = args(1).cellstr_value ();
+
+                  if (! error_state)
                     {
-                      if (nargin == 1)
-                        vals(n) = obj.get ();
-                      else
+                      octave_idx_type plen = plist.numel ();
+
+                      use_cell_format = true;
+
+                      vals.resize (dim_vector (len, plen));
+
+                      for (octave_idx_type n = 0; ! error_state && n < len; n++)
                         {
-                          caseless_str property = args(1).string_value ();
-
-                          if (! error_state)
-                            vals(n) = obj.get (property);
+                          graphics_object obj = gh_manager::get_object (hcv(n));
+
+                          if (obj)
+                            {
+                              for (octave_idx_type m = 0; ! error_state && m < plen; m++)
+                                {
+                                  caseless_str property = plist(m);
+
+                                  vals(n, m) = obj.get (property);
+                                }
+                            }
                           else
                             {
-                              error ("get: expecting property name as second argument");
+                              error ("get: invalid handle (= %g)", hcv(n));
                               break;
                             }
                         }
                     }
                   else
+                    error ("get: expecting property name or cell array of property names as second argument");
+                }
+              else
+                {
+                  caseless_str property;
+
+                  if (nargin > 1)
                     {
-                      error ("get: invalid handle (= %g)", hcv(n));
-                      break;
+                      property = args(1).string_value ();
+
+                      if (error_state)
+                        error ("get: expecting property name or cell array of property names as second argument");
+                    }
+
+                  vals.resize (dim_vector (len, 1));
+
+                  if (! error_state)
+                    {
+                      for (octave_idx_type n = 0; ! error_state && n < len; n++)
+                        {
+                          graphics_object obj = gh_manager::get_object (hcv(n));
+
+                          if (obj)
+                            {
+                              if (nargin == 1)
+                                vals(n) = obj.get ();
+                              else
+                                vals(n) = obj.get (property);
+                            }
+                          else
+                            {
+                              error ("get: invalid handle (= %g)", hcv(n));
+                              break;
+                            }
+                        }
                     }
                 }
             }
@@ -8217,23 +8288,28 @@
 
   if (! error_state)
     {
-      octave_idx_type len = vals.numel ();
-
-      if (len == 0)
-        retval = Matrix ();
-      else if (len == 1)
-        retval = vals(0);
-      else if (len > 1 && nargin == 1)
-        {
-          OCTAVE_LOCAL_BUFFER (octave_scalar_map, tmp, len);
-
-          for (octave_idx_type n = 0; n < len; n++)
-            tmp[n] = vals(n).scalar_map_value ();
-
-          retval = octave_map::cat (0, len, tmp);
-        }
+      if (use_cell_format)
+        retval = vals;
       else
-        retval = vals;
+        {
+          octave_idx_type len = vals.numel ();
+
+          if (len == 0)
+            retval = Matrix ();
+          else if (len == 1)
+            retval = vals(0);
+          else if (len > 1 && nargin == 1)
+            {
+              OCTAVE_LOCAL_BUFFER (octave_scalar_map, tmp, len);
+
+              for (octave_idx_type n = 0; n < len; n++)
+                tmp[n] = vals(n).scalar_map_value ();
+
+              retval = octave_map::cat (0, len, tmp);
+            }
+          else
+            retval = vals;
+        }
     }
 
   return retval;
@@ -9419,3 +9495,392 @@
 
   return ret;
 }
+
+static bool
+compare_property_values (const octave_value& o1, const octave_value& o2)
+{
+  octave_value_list args (2);
+
+  args(0) = o1;
+  args(1) = o2;
+
+  octave_value_list result = feval ("isequal", args, 1);
+
+  if (! error_state && result.length () > 0)
+    return result(0).bool_value ();
+
+  return false;
+}
+
+static std::map<uint32_t, bool> waitfor_results;
+
+static void
+cleanup_waitfor_id (uint32_t id)
+{
+  waitfor_results.erase (id);
+}
+
+static void
+do_cleanup_waitfor_listener (const octave_value& listener,
+                             listener_mode mode = POSTSET)
+{
+  Cell c = listener.cell_value ();
+
+  if (c.numel () >= 4)
+    {
+      double h = c(2).double_value ();
+
+      if (! error_state)
+        {
+          caseless_str pname = c(3).string_value ();
+
+          if (! error_state)
+            {
+              gh_manager::auto_lock guard;
+
+              graphics_handle handle = gh_manager::lookup (h);
+
+              if (handle.ok ())
+                {
+                  graphics_object go = gh_manager::get_object (handle);
+
+                  if (go.get_properties ().has_property (pname))
+                    {
+                      go.get_properties ()
+                        .delete_listener (pname, listener, mode);
+                      if (mode == POSTSET)
+                        go.get_properties ()
+                          .delete_listener (pname, listener, PERSISTENT);
+                    }
+                }
+            }
+        }
+    }
+}
+
+static void
+cleanup_waitfor_postset_listener(const octave_value& listener)
+{ do_cleanup_waitfor_listener (listener, POSTSET); }
+
+static void
+cleanup_waitfor_predelete_listener(const octave_value& listener)
+{ do_cleanup_waitfor_listener (listener, PREDELETE); }
+
+static octave_value_list
+waitfor_listener (const octave_value_list& args, int)
+{
+  if (args.length () > 3)
+    {
+      uint32_t id = args(2).uint32_scalar_value ().value ();
+
+      if (! error_state)
+        {
+          if (args.length () > 5)
+            {
+              double h = args(0).double_value ();
+
+              if (! error_state)
+                {
+                  caseless_str pname = args(4).string_value ();
+
+                  if (! error_state)
+                    {
+                      gh_manager::auto_lock guard;
+
+                      graphics_handle handle = gh_manager::lookup (h);
+
+                      if (handle.ok ())
+                        {
+                          graphics_object go = gh_manager::get_object (handle);
+                          octave_value pvalue = go.get (pname);
+
+                          if (compare_property_values (pvalue, args(5)))
+                            waitfor_results[id] = true;
+                        }
+                    }
+                }
+            }
+          else
+            waitfor_results[id] = true;
+        }
+    }
+
+  return octave_value_list ();
+}
+
+static octave_value_list
+waitfor_del_listener (const octave_value_list& args, int)
+{
+  if (args.length () > 2)
+    {
+      uint32_t id = args(2).uint32_scalar_value ().value ();
+
+      if (! error_state)
+        waitfor_results[id] = true;
+    }
+
+  return octave_value_list ();
+}
+
+DEFUN (waitfor, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {} waitfor (@var{h})\n\
+@deftypefnx {Built-in Function} {} waitfor (@var{h}, @var{prop})\n\
+@deftypefnx {Built-in Function} {} waitfor (@var{h}, @var{prop}, @var{value})\n\
+@deftypefnx {Built-in Function} {} waitfor (@dots{}, \"timeout\", @var{timeout})\n\
+Suspend the execution of the current program until a condition is\n\
+satisfied on the graphics handle @var{h}.  While the program is suspended\n\
+graphics events are still being processed normally, allowing callbacks to\n\
+modify the state of graphics objects.  This function is reentrant and can be\n\
+called from a callback, while another @code{waitfor} call is pending at\n\
+top-level.\n\
+\n\
+In the first form, program execution is suspended until the graphics object\n\
+@var{h} is destroyed.  If the graphics handle is invalid, the function\n\
+returns immediately.\n\
+\n\
+In the second form, execution is suspended until the graphics object is\n\
+destroyed or the property named @var{prop} is modified.  If the graphics\n\
+handle is invalid or the property does not exist, the function returns\n\
+immediately.\n\
+\n\
+In the third form, execution is suspended until the graphics object is\n\
+destroyed or the property named @var{prop} is set to @var{value}.  The\n\
+function @code{isequal} is used to compare property values.  If the graphics\n\
+handle is invalid, the property does not exist or the property is already\n\
+set to @var{value}, the function returns immediately.\n\
+\n\
+An optional timeout can be specified using the property @code{timeout}.\n\
+This timeout value is the number of seconds to wait for the condition to be\n\
+true.  @var{timeout} must be at least 1. If a smaller value is specified, a\n\
+warning is issued and a value of 1 is used instead.  If the timeout value is\n\
+not an integer, it is truncated towards 0.\n\
+\n\
+To define a condition on a property named @code{timeout}, use the string\n\
+@code{\\timeout} instead.\n\
+\n\
+In all cases, typing CTRL-C stops program execution immediately.\n\
+@seealso{isequal}\n\
+@end deftypefn")
+{
+  if (args.length () > 0)
+    {
+      double h = args(0).double_value ();
+
+      if (! error_state)
+        {
+          caseless_str pname;
+
+          unwind_protect frame;
+
+          static uint32_t id_counter = 0;
+          uint32_t id = 0;
+
+          int max_arg_index = 0;
+          int timeout_index = -1;
+
+          int timeout = 0;
+
+          if (args.length () > 1)
+            {
+              pname = args(1).string_value ();
+              if (! error_state
+                  && ! pname.empty ()
+                  && ! pname.compare ("timeout"))
+                {
+                  if (pname.compare ("\\timeout"))
+                    pname = "timeout";
+
+                  static octave_value wf_listener;
+
+                  if (! wf_listener.is_defined ())
+                    wf_listener =
+                      octave_value (new octave_builtin (waitfor_listener,
+                                                        "waitfor_listener"));
+
+                  max_arg_index++;
+                  if (args.length () > 2)
+                    {
+                      if (args(2).is_string ())
+                        {
+                          caseless_str s = args(2).string_value ();
+
+                          if (! error_state)
+                            {
+                              if (s.compare ("timeout"))
+                                timeout_index = 2;
+                              else
+                                max_arg_index++;
+                            }
+                        }
+                      else
+                        max_arg_index++;
+                    }
+
+                  Cell listener (1, max_arg_index >= 2 ? 5 : 4);
+
+                  id = id_counter++;
+                  frame.add_fcn (cleanup_waitfor_id, id);
+                  waitfor_results[id] = false;
+
+                  listener(0) = wf_listener;
+                  listener(1) = octave_uint32 (id);
+                  listener(2) = h;
+                  listener(3) = pname;
+
+                  if (max_arg_index >= 2)
+                    listener(4) = args(2);
+
+                  octave_value ov_listener (listener);
+
+                  gh_manager::auto_lock guard;
+
+                  graphics_handle handle = gh_manager::lookup (h);
+
+                  if (handle.ok ())
+                    {
+                      graphics_object go = gh_manager::get_object (handle);
+
+                      if (max_arg_index >= 2
+                          && compare_property_values (go.get (pname),
+                                                      args(2)))
+                        waitfor_results[id] = true;
+                      else
+                        {
+
+                          frame.add_fcn (cleanup_waitfor_postset_listener,
+                                         ov_listener);
+                          go.add_property_listener (pname, ov_listener,
+                                                    POSTSET);
+                          go.add_property_listener (pname, ov_listener,
+                                                    PERSISTENT);
+
+                          if (go.get_properties ()
+                              .has_dynamic_property (pname))
+                            {
+                              static octave_value wf_del_listener;
+
+                              if (! wf_del_listener.is_defined ())
+                                wf_del_listener =
+                                  octave_value (new octave_builtin
+                                                (waitfor_del_listener,
+                                                 "waitfor_del_listener"));
+
+                              Cell del_listener (1, 4);
+
+                              del_listener(0) = wf_del_listener;
+                              del_listener(1) = octave_uint32 (id);
+                              del_listener(2) = h;
+                              del_listener(3) = pname;
+
+                              octave_value ov_del_listener (del_listener);
+
+                              frame.add_fcn (cleanup_waitfor_predelete_listener,
+                                             ov_del_listener);
+                              go.add_property_listener (pname, ov_del_listener,
+                                                        PREDELETE);
+                            }
+                        }
+                    }
+                }
+              else if (error_state || pname.empty ())
+                error ("waitfor: invalid property name, expected a non-empty string value");
+            }
+
+          if (! error_state
+              && timeout_index < 0
+              && args.length () > (max_arg_index + 1))
+            {
+              caseless_str s = args(max_arg_index + 1).string_value ();
+
+              if (! error_state)
+                {
+                  if (s.compare ("timeout"))
+                    timeout_index = max_arg_index + 1;
+                  else
+                    error ("waitfor: invalid parameter `%s'", s.c_str ());
+                }
+              else
+                error ("waitfor: invalid parameter, expected `timeout'");
+            }
+
+          if (! error_state && timeout_index >= 0)
+            {
+              if (args.length () > (timeout_index + 1))
+                {
+                  timeout = static_cast<int>
+                    (args(timeout_index + 1).scalar_value ());
+
+                  if (! error_state)
+                    {
+                      if (timeout < 1)
+                        {
+                          warning ("waitfor: the timeout value must be >= 1, using 1 instead");
+                          timeout = 1;
+                        }
+                    }
+                  else
+                    error ("waitfor: invalid timeout value, expected a value >= 1");
+                }
+              else
+                error ("waitfor: missing timeout value");
+            }
+
+          // FIXME: There is still a "hole" in the following loop. The code
+          //        assumes that an object handle is unique, which is a fair
+          //        assumptions, except for figures. If a figure is destroyed
+          //        then recreated with the same figure ID, within the same
+          //        run of event hooks, then the figure destruction won't be
+          //        caught and the loop will not stop. This is an unlikely
+          //        possibility in practice, though.
+          //
+          //        Using deletefcn callback is also unreliable as it could be
+          //        modified during a callback execution and the waitfor loop
+          //        would not stop.
+          //
+          //        The only "good" implementation would require object
+          //        listeners, similar to property listeners.
+
+          time_t start = 0;
+
+          if (timeout > 0)
+            start = time (0);
+
+          while (! error_state)
+            {
+              if (true)
+                {
+                  gh_manager::auto_lock guard;
+
+                  graphics_handle handle = gh_manager::lookup (h);
+
+                  if (handle.ok ())
+                    {
+                      if (! pname.empty () && waitfor_results[id])
+                        break;
+                    }
+                  else
+                    break;
+                }
+
+              octave_usleep (100000);
+
+              OCTAVE_QUIT;
+
+              command_editor::run_event_hooks ();
+
+              if (timeout > 0)
+                {
+                  if (start + timeout < time (0))
+                    break;
+                }
+            }
+        }
+      else
+        error ("waitfor: invalid handle value.");
+    }
+  else
+    print_usage ();
+
+  return octave_value ();
+}
--- a/src/graphics.h.in	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/graphics.h.in	Wed Dec 07 19:06:13 2011 -0500
@@ -42,6 +42,7 @@
 #include "gripes.h"
 #include "oct-map.h"
 #include "oct-mutex.h"
+#include "oct-refcount.h"
 #include "ov.h"
 #include "txt-eng-ft.h"
 
@@ -333,7 +334,7 @@
 
 class property;
 
-enum listener_mode { POSTSET, PERSISTENT };
+enum listener_mode { POSTSET, PERSISTENT, PREDELETE };
 
 class base_property
 {
@@ -482,7 +483,7 @@
 
 private:
   int id;
-  int count;
+  octave_refcount<int> count;
   std::string name;
   graphics_handle parent;
   bool hidden;
@@ -661,6 +662,8 @@
           else
             replace = true;
 
+          desired_type = string_t;
+
           if (replace)
             {
               str = strings;
@@ -690,6 +693,8 @@
                 }
             }
 
+          desired_type = cell_t;
+
           if (replace)
             {
               str = strings;
@@ -1906,7 +1911,7 @@
 
   ~property (void)
     {
-      if (--rep->count <= 0)
+      if (--rep->count == 0)
         delete rep;
     }
 
@@ -1961,7 +1966,7 @@
 
   property& operator = (const property& p)
     {
-      if (rep && --rep->count <= 0)
+      if (rep && --rep->count == 0)
         delete rep;
 
       rep = p.rep;
@@ -2129,7 +2134,7 @@
 
 private:
   std::string name;
-  int count;
+  octave_refcount<int> count;
 
 private:
   void gripe_invalid (const std::string& fname) const
@@ -2735,7 +2740,7 @@
 
 protected:
   // A reference count.
-  int count;
+  octave_refcount<int> count;
 
   // A flag telling whether this object is a valid object
   // in the backend context.
@@ -5093,7 +5098,7 @@
   virtual void execute (void) = 0;
 
 private:
-  int count;
+  octave_refcount<int> count;
 };
 
 class
@@ -5165,12 +5170,14 @@
 
 public:
 
+  static void create_instance (void);
+
   static bool instance_ok (void)
   {
     bool retval = true;
 
     if (! instance)
-      instance = new gh_manager ();
+      create_instance ();
 
     if (! instance)
       {
@@ -5182,6 +5189,8 @@
     return retval;
   }
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   static graphics_handle get_handle (bool integer_figure_handle)
   {
     return instance_ok ()
--- a/src/help.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/help.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -642,13 +642,6 @@
 @seealso{global}\n\
 @end deftypefn"),
 
-  pair_type ("replot",
-    "-*- texinfo -*-\n\
-@deftypefn {Keyword} {} replot\n\
-Replot a graphic.\n\
-@seealso{plot}\n\
-@end deftypefn"),
-
   pair_type ("return",
     "-*- texinfo -*-\n\
 @deftypefn {Keyword} {} return\n\
@@ -1268,6 +1261,7 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} doc_cache_file ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} doc_cache_file (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} doc_cache_file (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the name of the\n\
 Octave documentation cache file.  A cache file significantly improves\n\
 the performance of the @code{lookfor} command.  The default value is \n\
@@ -1277,6 +1271,10 @@
 The default value may be overridden by the environment variable\n\
 @w{@env{OCTAVE_DOC_CACHE_FILE}}, or the command line argument\n\
 @samp{--doc-cache-file NAME}.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{lookfor, info_program, doc, help, makeinfo_program}\n\
 @end deftypefn")
 {
@@ -1287,6 +1285,7 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} info_file ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} info_file (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} info_file (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the name of the\n\
 Octave info file.  The default value is\n\
 @file{@var{octave-home}/info/octave.info}, in\n\
@@ -1294,6 +1293,10 @@
 The default value may be overridden by the environment variable\n\
 @w{@env{OCTAVE_INFO_FILE}}, or the command line argument\n\
 @samp{--info-file NAME}.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{info_program, doc, help, makeinfo_program}\n\
 @end deftypefn")
 {
@@ -1304,6 +1307,7 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} info_program ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} info_program (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} info_program (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the name of the\n\
 info program to run.  The default value is\n\
 @file{@var{octave-home}/libexec/octave/@var{version}/exec/@var{arch}/info}\n\
@@ -1313,6 +1317,10 @@
 default value may be overridden by the environment variable\n\
 @w{@env{OCTAVE_INFO_PROGRAM}}, or the command line argument\n\
 @samp{--info-program NAME}.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{info_file, doc, help, makeinfo_program}\n\
 @end deftypefn")
 {
@@ -1323,9 +1331,14 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} makeinfo_program ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} makeinfo_program (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} makeinfo_program (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the name of the\n\
 program that Octave runs to format help text containing\n\
 Texinfo markup commands.  The default value is @code{makeinfo}.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{info_file, info_program, doc, help}\n\
 @end deftypefn")
 {
@@ -1336,9 +1349,14 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} suppress_verbose_help_message ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} suppress_verbose_help_message (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} suppress_verbose_help_message (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether Octave\n\
 will add additional help information to the end of the output from\n\
 the @code{help} command and usage messages for built-in commands.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (suppress_verbose_help_message);
--- a/src/input.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/input.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -749,17 +749,15 @@
 
       if (retval == 0 && global_command)
         {
-          global_command->accept (*current_evaluator);
+          unwind_protect inner_frame;
 
-          // FIXME -- To avoid a memory leak, global_command should be
-          // deleted, I think.  But doing that here causes trouble if
-          // an error occurs while executing a debugging command
-          // (dbstep, for example). It's not clear to me why that
-          // happens.
-          //
-          // delete global_command;
-          //
-          // global_command = 0;
+          // Use an unwind-protect cleanup function so that the
+          // global_command list will be deleted in the event of an
+          // interrupt.
+
+          inner_frame.add_fcn (cleanup_statement_list, &global_command);
+
+          global_command->accept (*current_evaluator);
 
           if (octave_completion_matches_called)
             octave_completion_matches_called = false;
@@ -1360,6 +1358,7 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} PS1 ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} PS1 (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} PS1 (@var{new_val}, \"local\")\n\
 Query or set the primary prompt string.  When executing interactively,\n\
 Octave displays the primary prompt when it is ready to read a command.\n\
 \n\
@@ -1385,6 +1384,10 @@
 \n\
 @noindent\n\
 will give the default Octave prompt a red coloring.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{PS2, PS4}\n\
 @end deftypefn")
 {
@@ -1395,12 +1398,17 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} PS2 ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} PS2 (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} PS2 (@var{new_val}, \"local\")\n\
 Query or set the secondary prompt string.  The secondary prompt is\n\
 printed when Octave is expecting additional input to complete a\n\
 command.  For example, if you are typing a @code{for} loop that spans several\n\
 lines, Octave will print the secondary prompt at the beginning of\n\
 each line after the first.  The default value of the secondary prompt\n\
 string is @code{\"> \"}.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{PS1, PS4}\n\
 @end deftypefn")
 {
@@ -1411,10 +1419,15 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} PS4 ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} PS4 (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} PS4 (@var{new_val}, \"local\")\n\
 Query or set the character string used to prefix output produced\n\
 when echoing commands is enabled.\n\
 The default value is @code{\"+ \"}.\n\
 @xref{Diary and Echo Commands}, for a description of echoing commands.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{echo, echo_executing_commands, PS1, PS2}\n\
 @end deftypefn")
 {
@@ -1425,9 +1438,14 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} completion_append_char ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} completion_append_char (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} completion_append_char (@var{new_val}, \"local\")\n\
 Query or set the internal character variable that is appended to\n\
 successful command-line completion attempts.  The default\n\
 value is @code{\" \"} (a single space).\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (completion_append_char);
@@ -1437,6 +1455,7 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} echo_executing_commands ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} echo_executing_commands (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} echo_executing_commands (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls the echo state.\n\
 It may be the sum of the following values:\n\
 \n\
@@ -1456,6 +1475,10 @@
 \n\
 The value of @code{echo_executing_commands} may be set by the @kbd{echo}\n\
 command or the command line option @option{--echo-commands}.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (echo_executing_commands);
@@ -1506,6 +1529,7 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} filemarker ()\n\
 @deftypefnx {Built-in Function} {} filemarker (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} filemarker (@var{new_val}, \"local\")\n\
 Query or set the character used to separate filename from the\n\
 the subfunction names contained within the file.  This can be used in\n\
 a generic manner to interact with subfunctions.  For example,\n\
@@ -1526,6 +1550,10 @@
 \n\
 @noindent\n\
 will set a breakpoint at the first line of the subfunction @code{mysubfunc}.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   char tmp = Vfilemarker;
--- a/src/lex.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/lex.h	Wed Dec 07 19:06:13 2011 -0500
@@ -43,6 +43,10 @@
 // Delete a buffer.
 extern OCTINTERP_API void delete_buffer (YY_BUFFER_STATE buf);
 
+extern OCTINTERP_API void clear_all_buffers (void);
+
+extern OCTINTERP_API void cleanup_parser (void);
+
 // Is the given string a keyword?
 extern bool is_keyword (const std::string& s);
 
--- a/src/lex.ll	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/lex.ll	Wed Dec 07 19:06:13 2011 -0500
@@ -1416,6 +1416,22 @@
   yy_delete_buffer (buf);
 }
 
+// Delete all buffers from the stack.
+void
+clear_all_buffers (void)
+{                 
+  while (current_buffer ())
+    octave_pop_buffer_state ();
+}
+
+void
+cleanup_parser (void)
+{
+  reset_parser ();
+
+  clear_all_buffers ();
+}
+
 // Restore a buffer (for unwind-prot).
 
 void
--- a/src/load-path.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/load-path.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -32,6 +32,7 @@
 #include "file-stat.h"
 #include "oct-env.h"
 #include "pathsearch.h"
+#include "singleton-cleanup.h"
 
 #include "defaults.h"
 #include "defun.h"
@@ -290,7 +291,12 @@
   bool retval = true;
 
   if (! instance)
-    instance = new load_path ();
+    {
+      instance = new load_path ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
--- a/src/load-path.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/load-path.h	Wed Dec 07 19:06:13 2011 -0500
@@ -443,6 +443,8 @@
 
   static load_path *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   static hook_fcn_ptr add_hook;
 
   static hook_fcn_ptr remove_hook;
--- a/src/load-save.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/load-save.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -649,7 +649,7 @@
   std::string orig_fname = "";
 
   // Function called with Matlab-style ["filename", options] syntax
-  if (argv[1].at(0) != '-')
+  if (argc > 1 && argv[1].at(0) != '-')
     {
       orig_fname = argv[1];
       i++;
@@ -1475,6 +1475,7 @@
 @table @code\n\
 @item -append\n\
 Append to the destination instead of overwriting.\n\
+\n\
 @item -ascii\n\
 Save a single matrix in a text file without header or any other information.\n\
 \n\
@@ -1747,9 +1748,14 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} crash_dumps_octave_core ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} crash_dumps_octave_core (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} crash_dumps_octave_core (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether Octave tries\n\
 to save all current variables to the file \"octave-core\" if it\n\
 crashes or receives a hangup, terminate or similar signal.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{octave_core_file_limit, octave_core_file_name, octave_core_file_options}\n\
 @end deftypefn")
 {
@@ -1760,10 +1766,15 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} default_save_options ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} default_save_options (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} default_save_options (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the default options\n\
 for the @code{save} command, and defines the default format.\n\
 Typical values include @code{\"-ascii\"}, @code{\"-text -zip\"}.\n\
 The default value is @option{-text}.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{save}\n\
 @end deftypefn")
 {
@@ -1774,6 +1785,7 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} octave_core_file_limit ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} octave_core_file_limit (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} octave_core_file_limit (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the maximum amount\n\
 of memory (in kilobytes) of the top-level workspace that Octave will\n\
 attempt to save when writing data to the crash dump file (the name of\n\
@@ -1782,6 +1794,10 @@
 then @var{octave_core_file_limit} will be approximately the maximum\n\
 size of the file.  If a text file format is used, then the file could\n\
 be much larger than the limit.  The default value is -1 (unlimited)\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_options}\n\
 @end deftypefn")
 {
@@ -1792,9 +1808,14 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} octave_core_file_name ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} octave_core_file_name (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} octave_core_file_name (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the name of the file\n\
 used for saving data from the top-level workspace if Octave aborts.\n\
 The default value is @code{\"octave-core\"}\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_options}\n\
 @end deftypefn")
 {
@@ -1805,11 +1826,16 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} octave_core_file_options ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} octave_core_file_options (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} octave_core_file_options (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the options used for\n\
 saving the workspace data if Octave aborts.  The value of\n\
 @code{octave_core_file_options} should follow the same format as the\n\
 options for the @code{save} function.  The default value is Octave's binary\n\
 format.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_limit}\n\
 @end deftypefn")
 {
@@ -1820,6 +1846,7 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} save_header_format_string ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} save_header_format_string (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} save_header_format_string (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the format\n\
 string used for the comment line written at the beginning of\n\
 text-format data files saved by Octave.  The format string is\n\
@@ -1833,6 +1860,10 @@
 @smallexample\n\
 \"# Created by Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>\"\n\
 @end smallexample\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{strftime, save}\n\
 @end deftypefn")
 {
--- a/src/ls-oct-ascii.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/ls-oct-ascii.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -419,8 +419,13 @@
     "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} save_precision ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} save_precision (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} save_precision (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the number of\n\
 digits to keep when saving data in text format.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE_WITH_LIMITS (save_precision, -1, INT_MAX);
--- a/src/mappers.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/mappers.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -67,20 +67,20 @@
 }
 
 /*
-%!assert(abs (1), 1);
-%!assert(abs (-3.5), 3.5);
-%!assert(abs (3+4i), 5);
-%!assert(abs (3-4i), 5);
-%!assert(abs ([1.1, 3i; 3+4i, -3-4i]), [1.1, 3; 5, 5]);
+%!assert (abs (1), 1)
+%!assert (abs (-3.5), 3.5)
+%!assert (abs (3+4i), 5)
+%!assert (abs (3-4i), 5)
+%!assert (abs ([1.1, 3i; 3+4i, -3-4i]), [1.1, 3; 5, 5])
 
-%!assert(abs (single(1)), single(1));
-%!assert(abs (single(-3.5)), single(3.5));
-%!assert(abs (single(3+4i)), single(5));
-%!assert(abs (single(3-4i)), single(5));
-%!assert(abs (single([1.1, 3i; 3+4i, -3-4i])), single([1.1, 3; 5, 5]));
+%!assert (abs (single (1)), single (1))
+%!assert (abs (single (-3.5)), single (3.5))
+%!assert (abs (single (3+4i)), single (5))
+%!assert (abs (single (3-4i)), single (5))
+%!assert (abs (single ([1.1, 3i; 3+4i, -3-4i])), single ([1.1, 3; 5, 5]))
 
-%!error abs ();
-%!error abs (1, 2);
+%!error abs ()
+%!error abs (1, 2)
 */
 
 DEFUN (acos, args, ,
@@ -100,22 +100,22 @@
 }
 
 /*
-%!test
+%!shared rt2, rt3
 %! rt2 = sqrt (2);
 %! rt3 = sqrt (3);
-%! v = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
-%! x = [1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1];
-%! assert(acos (x), v, sqrt(eps));
 
 %!test
-%! rt2 = sqrt (2);
-%! rt3 = sqrt (3);
-%! v = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
+%! x = [1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1];
+%! v = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
+%! assert (acos (x), v, sqrt (eps));
+
+%!test
 %! x = single ([1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1]);
-%! assert(acos (x), v, sqrt(eps('single')));
+%! v = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
+%! assert (acos (x), v, sqrt (eps ('single')));
 
-%!error acos ();
-%!error acos (1, 2);
+%!error acos ()
+%!error acos (1, 2)
 */
 
 DEFUN (acosh, args, ,
@@ -136,17 +136,17 @@
 
 /*
 %!test
+%! x = [1, 0, -1, 0];
 %! v = [0, pi/2*i, pi*i, pi/2*i];
-%! x = [1, 0, -1, 0];
-%! assert(acosh (x), v, sqrt(eps));
+%! assert (acosh (x), v, sqrt (eps));
 
 %!test
-%! v = single([0, pi/2*i, pi*i, pi/2*i]);
-%! x = single([1, 0, -1, 0]);
-%! assert(acosh (x), v, sqrt (eps('single')));
+%! x = single ([1, 0, -1, 0]);
+%! v = single ([0, pi/2*i, pi*i, pi/2*i]);
+%! assert (acosh (x), v, sqrt (eps ('single')));
 
-%!error acosh ();
-%!error acosh (1, 2);
+%!error acosh ()
+%!error acosh (1, 2)
 */
 
 DEFUN (angle, args, ,
@@ -197,26 +197,26 @@
 }
 
 /*
-%!assert(arg (1), 0);
-%!assert(arg (i), pi/2);
-%!assert(arg (-1), pi);
-%!assert(arg (-i), -pi/2);
-%!assert(arg ([1, i; -1, -i]), [0, pi/2; pi, -pi/2]);
+%!assert (arg (1), 0)
+%!assert (arg (i), pi/2)
+%!assert (arg (-1), pi)
+%!assert (arg (-i), -pi/2)
+%!assert (arg ([1, i; -1, -i]), [0, pi/2; pi, -pi/2])
 
-%!assert(arg (single(1)), single(0));
-%!assert(arg (single(i)), single(pi/2));
+%!assert (arg (single (1)), single (0))
+%!assert (arg (single (i)), single (pi/2))
 %!test
 %! if (ismac ())
 %!   ## Avoid failing for a MacOS feature
-%!   assert(arg (single(-1)), single(pi), 2*eps(single(1)));
+%!   assert (arg (single (-1)), single (pi), 2*eps (single (1)));
 %! else
-%!   assert(arg (single(-1)), single(pi));
+%!   assert (arg (single (-1)), single (pi));
 %! endif
-%!assert(arg (single(-i)), single(-pi/2));
-%!assert(arg (single([1, i; -1, -i])), single([0, pi/2; pi, -pi/2]), 2e1*eps('single'));
+%!assert (arg (single (-i)), single (-pi/2))
+%!assert (arg (single ([1, i; -1, -i])), single ([0, pi/2; pi, -pi/2]), 2e1*eps ('single'))
 
-%!error arg ();
-%!error arg (1, 2);
+%!error arg ()
+%!error arg (1, 2)
 */
 
 DEFUN (asin, args, ,
@@ -239,11 +239,12 @@
 %!test
 %! rt2 = sqrt (2);
 %! rt3 = sqrt (3);
+%! x = [0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0];
 %! v = [0, pi/6, pi/4, pi/3, pi/2, pi/3, pi/4, pi/6, 0];
-%! x = [0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0];
-%! assert(all (abs (asin (x) - v) < sqrt (eps)));
-%!error asin ();
-%!error asin (1, 2);
+%! assert (all (abs (asin (x) - v) < sqrt (eps)));
+
+%!error asin ()
+%!error asin (1, 2)
 */
 
 DEFUN (asinh, args, ,
@@ -266,15 +267,15 @@
 %!test
 %! v = [0, pi/2*i, 0, -pi/2*i];
 %! x = [0, i, 0, -i];
-%! assert(asinh (x), v,  sqrt (eps));
+%! assert (asinh (x), v,  sqrt (eps));
 
 %!test
-%! v = single([0, pi/2*i, 0, -pi/2*i]);
-%! x = single([0, i, 0, -i]);
-%! assert(asinh (x), v,  sqrt (eps('single')));
+%! v = single ([0, pi/2*i, 0, -pi/2*i]);
+%! x = single ([0, i, 0, -i]);
+%! assert (asinh (x), v,  sqrt (eps ('single')));
 
-%!error asinh ();
-%!error asinh (1, 2);
+%!error asinh ()
+%!error asinh (1, 2)
 */
 
 DEFUN (atan, args, ,
@@ -294,22 +295,22 @@
 }
 
 /*
-%!test
+%!shared rt2, rt3
 %! rt2 = sqrt (2);
 %! rt3 = sqrt (3);
-%! v = [0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0];
-%! x = [0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0];
-%! assert(atan (x), v, sqrt (eps));
 
 %!test
-%! rt2 = sqrt (2);
-%! rt3 = sqrt (3);
-%! v = single([0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]);
-%! x = single([0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0]);
-%! assert(atan (x), v, sqrt (eps('single')));
+%! v = [0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0];
+%! x = [0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0];
+%! assert (atan (x), v, sqrt (eps));
 
-%!error atan ();
-%!error atan (1, 2);
+%!test
+%! v = single ([0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]);
+%! x = single ([0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0]);
+%! assert (atan (x), v, sqrt (eps ('single')));
+
+%!error atan ()
+%!error atan (1, 2)
 */
 
 DEFUN (atanh, args, ,
@@ -332,15 +333,15 @@
 %!test
 %! v = [0, 0];
 %! x = [0, 0];
-%! assert(atanh (x), v, sqrt (eps));
+%! assert (atanh (x), v, sqrt (eps));
 
 %!test
-%! v = single([0, 0]);
-%! x = single([0, 0]);
-%! assert(atanh (x), v, sqrt (eps('single')));
+%! v = single ([0, 0]);
+%! x = single ([0, 0]);
+%! assert (atanh (x), v, sqrt (eps ('single')));
 
-%!error atanh ();
-%!error atanh (1, 2);
+%!error atanh ()
+%!error atanh (1, 2)
 */
 
 DEFUN (cbrt, args, ,
@@ -370,6 +371,9 @@
 %!assert (cbrt (NaN), NaN)
 %!assert (cbrt (2^300), 2^100)
 %!assert (cbrt (125*2^300), 5*2^100)
+
+%!error cbrt ()
+%!error cbrt (1, 2)
 */
 
 DEFUN (ceil, args, ,
@@ -399,19 +403,19 @@
 
 /*
 %% double precision
-%!assert(ceil ([2, 1.1, -1.1, -1]), [2, 2, -1, -1]);
+%!assert (ceil ([2, 1.1, -1.1, -1]), [2, 2, -1, -1])
 
-%% compelx double precison
-%!assert(ceil ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i]), [2+2i, 2+2i, -1-i, -1-i]);
+%% complex double precison
+%!assert (ceil ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i]), [2+2i, 2+2i, -1-i, -1-i])
 
 %% single precision
-%!assert(ceil (single([2, 1.1, -1.1, -1])), single([2, 2, -1, -1]));
+%!assert (ceil (single ([2, 1.1, -1.1, -1])), single ([2, 2, -1, -1]))
 
-%% compelx single preci
-%!assert(ceil (single ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i])), single([2+2i, 2+2i, -1-i, -1-i]));
+%% complex single precision
+%!assert (ceil (single ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i])), single ([2+2i, 2+2i, -1-i, -1-i]))
 
-%!error ceil ();
-%!error ceil (1, 2);
+%!error ceil ()
+%!error ceil (1, 2)
 */
 
 DEFUN (conj, args, ,
@@ -437,20 +441,20 @@
 }
 
 /*
-%!assert(conj (1), 1);
-%!assert(conj (i), -i)
-%!assert(conj (1+i), 1-i)
-%!assert(conj (1-i), 1+i)
-%!assert(conj ([-1, -i; -1+i, -1-i]), [-1, i; -1-i, -1+i]);
+%!assert (conj (1), 1)
+%!assert (conj (i), -i)
+%!assert (conj (1+i), 1-i)
+%!assert (conj (1-i), 1+i)
+%!assert (conj ([-1, -i; -1+i, -1-i]), [-1, i; -1-i, -1+i])
 
-%!assert(conj (single(1)), single(1));
-%!assert(conj (single(i)), single(-i))
-%!assert(conj (single(1+i)), single(1-i))
-%!assert(conj (single(1-i)), single(1+i))
-%!assert(conj (single([-1, -i; -1+i, -1-i])), single([-1, i; -1-i, -1+i]));
+%!assert (conj (single (1)), single (1))
+%!assert (conj (single (i)), single (-i))
+%!assert (conj (single (1+i)), single (1-i))
+%!assert (conj (single (1-i)), single (1+i))
+%!assert (conj (single ([-1, -i; -1+i, -1-i])), single ([-1, i; -1-i, -1+i]))
 
-%!error conj ();
-%!error conj (1, 2);
+%!error conj ()
+%!error conj (1, 2)
 */
 
 DEFUN (cos, args, ,
@@ -470,22 +474,24 @@
 }
 
 /*
-%!test
+%!shared rt2, rt3
 %! rt2 = sqrt (2);
 %! rt3 = sqrt (3);
+
+%!test
 %! x = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
 %! v = [1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1];
-%! assert(cos (x), v, sqrt (eps));
+%! assert (cos (x), v, sqrt (eps));
 
 %!test
 %! rt2 = sqrt (2);
 %! rt3 = sqrt (3);
-%! x = single([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
-%! v = single([1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1]);
-%! assert(cos (x), v, sqrt (eps('single')));
+%! x = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
+%! v = single ([1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1]);
+%! assert (cos (x), v, sqrt (eps ('single')));
 
-%!error cos ();
-%!error cos (1, 2);
+%!error cos ()
+%!error cos (1, 2)
 */
 
 DEFUN (cosh, args, ,
@@ -508,15 +514,15 @@
 %!test
 %! x = [0, pi/2*i, pi*i, 3*pi/2*i];
 %! v = [1, 0, -1, 0];
-%! assert(cosh (x), v, sqrt (eps));
+%! assert (cosh (x), v, sqrt (eps));
 
 %!test
-%! x = single([0, pi/2*i, pi*i, 3*pi/2*i]);
-%! v = single([1, 0, -1, 0]);
-%! assert(cosh (x), v, sqrt (eps ('single')));
+%! x = single ([0, pi/2*i, pi*i, 3*pi/2*i]);
+%! v = single ([1, 0, -1, 0]);
+%! assert (cosh (x), v, sqrt (eps ('single')));
 
-%!error cosh ();
-%!error cosh (1, 2);
+%!error cosh ()
+%!error cosh (1, 2)
 */
 
 DEFUN (erf, args, ,
@@ -556,28 +562,31 @@
 
 /*
 %!test
-%! a = -1i*sqrt(-1/(6.4187*6.4187));
-%! assert (erf(a), erf(real(a)));
+%! a = -1i*sqrt (-1/(6.4187*6.4187));
+%! assert (erf (a), erf (real (a)));
 
 %!test
-%! x=[0,.5,1];
-%! v=[0, .520499877813047, .842700792949715];
-%! assert(all(abs(erf(x)-v)<1.e-10) &&  all(abs(erf(-x)+v)<1.e-10) && all(abs(erfc(x)+v-1)<1.e-10) && all(abs(erfinv(v)-x)<1.e-10));
+%! x = [0,.5,1];
+%! v = [0, .520499877813047, .842700792949715];
+%! assert (all (abs (erf (x)-v) < 1.e-10));
+%! assert (all (abs (erf (-x)+v) < 1.e-10));
+%! assert (all (abs (erfc (x)+v-1) < 1.e-10));
+%! assert (all (abs (erfinv (v)-x) < 1.e-10));
 
 %!test
-%! a = -1i*sqrt(single (-1/(6.4187*6.4187)));
-%! assert (erf(a), erf(real(a)));
+%! a = -1i*sqrt (single (-1/(6.4187*6.4187)));
+%! assert (erf (a), erf (real (a)));
 
 %!test
-%! x=single ([0,.5,1]);
-%! v=single ([0, .520499877813047, .842700792949715]);
-%! assert(all(abs(erf(x)-v)<1.e-6) &&  all(abs(erf(-x)+v)<1.e-6) && all(abs(erfc(x)+v-1)<1.e-6) && all(abs(erfinv(v)-x)<1.e-6));
+%! x = single ([0,.5,1]);
+%! v = single ([0, .520499877813047, .842700792949715]);
+%! assert (all (abs (erf (x)-v) < 1.e-6));
+%! assert (all (abs (erf (-x)+v) < 1.e-6));
+%! assert (all (abs (erfc (x)+v-1) < 1.e-6));
+%! assert (all (abs (erfinv (v)-x) < 1.e-6));
 
-%% test/octave.test/arith/erf-2.m
-%!error erf();
-
-%% test/octave.test/arith/erf-3.m
-%!error erf(1,2);
+%!error erf ()
+%!error erf (1, 2)
 */
 
 DEFUN (erfinv, args, ,
@@ -613,6 +622,9 @@
 %% exceptional
 %!assert (erfinv ([-1, 1, 1.1, -2.1]), [-Inf, Inf, NaN, NaN])
 %!error erfinv (1+2i)
+
+%!error erfinv ()
+%!error erfinv (1, 2)
 */
 
 DEFUN (erfc, args, ,
@@ -639,8 +651,11 @@
 
 /*
 %!test
-%! a = -1i*sqrt(-1/(6.4187*6.4187));
-%! assert (erfc(a), erfc(real(a)));
+%! a = -1i*sqrt (-1/(6.4187*6.4187));
+%! assert (erfc (a), erfc (real (a)));
+
+%!error erfc ()
+%!error erfc (1, 2)
 */
 
 DEFUN (erfcx, args, ,
@@ -671,6 +686,13 @@
   return retval;
 }
 
+/*
+%% FIXME: Need a test for erfcx
+
+%!error erfcx ()
+%!error erfcx (1, 2)
+*/
+
 DEFUN (exp, args, ,
     "-*- texinfo -*-\n\
 @deftypefn {Mapping Function} {} exp (@var{x})\n\
@@ -696,16 +718,16 @@
 }
 
 /*
-%!assert(exp ([0, 1, -1, -1000]), [1, e, 1/e, 0], sqrt (eps));
-%!assert(exp (1+i), e * (cos (1) + sin (1) * i), sqrt (eps));
-%!assert(exp (single([0, 1, -1, -1000])), single([1, e, 1/e, 0]), sqrt (eps('single')));
-%!assert(exp (single(1+i)), single (e * (cos (1) + sin (1) * i)), sqrt (eps('single')));
+%!assert (exp ([0, 1, -1, -1000]), [1, e, 1/e, 0], sqrt (eps))
+%!assert (exp (1+i), e * (cos (1) + sin (1) * i), sqrt (eps))
+%!assert (exp (single ([0, 1, -1, -1000])), single ([1, e, 1/e, 0]), sqrt (eps ('single')))
+%!assert (exp (single (1+i)), single (e * (cos (1) + sin (1) * i)), sqrt (eps ('single')))
 
-%!error exp ();
-%!error exp (1, 2);
+%!assert (exp ([Inf, -Inf, NaN]), [Inf 0 NaN])
+%!assert (exp (single ([Inf, -Inf, NaN])), single ([Inf 0 NaN]))
 
-%!assert(exp (Inf) == Inf && exp (-Inf) == 0 && isnan (exp (NaN)));
-%!assert(exp (Inf ('single')) == Inf('single') && exp (-Inf('single')) == 0 && isnan (exp (NaN('single'))));
+%!error exp ()
+%!error exp (1, 2)
 */
 
 DEFUN (expm1, args, ,
@@ -731,6 +753,16 @@
   return retval;
 }
 
+/*
+%!assert (expm1 (2*eps), 2*eps, 1e-29)
+
+%!assert (expm1 ([Inf, -Inf, NaN]), [Inf -1 NaN])
+%!assert (expm1 (single ([Inf, -Inf, NaN])), single ([Inf -1 NaN]))
+
+%!error expm1 ()
+%!error expm1 (1, 2)
+*/
+
 DEFUN (isfinite, args, ,
     "-*- texinfo -*-\n\
 @deftypefn  {Mapping Function} {} isfinite (@var{x})\n\
@@ -758,13 +790,16 @@
 }
 
 /*
-%!assert(!(finite (Inf)));
-%!assert(!(finite (NaN)));
-%!assert(finite (rand(1,10)));
+%!assert (!finite (Inf))
+%!assert (!finite (NaN))
+%!assert (finite (rand (1,10)))
 
-%!assert(!(finite (single(Inf))));
-%!assert(!(finite (single(NaN))));
-%!assert(finite (single(rand(1,10))));
+%!assert (!finite (single (Inf)))
+%!assert (!finite (single (NaN)))
+%!assert (finite (single (rand (1,10))))
+
+%!error finite ()
+%!error finite (1, 2)
 */
 
 DEFUN (fix, args, ,
@@ -793,13 +828,13 @@
 }
 
 /*
-%!assert(fix ([1.1, 1, -1.1, -1]), [1, 1, -1, -1]);
-%!assert(fix ([1.1+1.1i, 1+i, -1.1-1.1i, -1-i]), [1+i, 1+i, -1-i, -1-i]);
-%!assert(fix (single([1.1, 1, -1.1, -1])), single([1, 1, -1, -1]));
-%!assert(fix (single([1.1+1.1i, 1+i, -1.1-1.1i, -1-i])), single([1+i, 1+i, -1-i, -1-i]));
+%!assert (fix ([1.1, 1, -1.1, -1]), [1, 1, -1, -1])
+%!assert (fix ([1.1+1.1i, 1+i, -1.1-1.1i, -1-i]), [1+i, 1+i, -1-i, -1-i])
+%!assert (fix (single ([1.1, 1, -1.1, -1])), single ([1, 1, -1, -1]))
+%!assert (fix (single ([1.1+1.1i, 1+i, -1.1-1.1i, -1-i])), single ([1+i, 1+i, -1-i, -1-i]))
 
-%!error fix ();
-%!error fix (1, 2);
+%!error fix ()
+%!error fix (1, 2)
 */
 
 DEFUN (floor, args, ,
@@ -828,13 +863,13 @@
 }
 
 /*
-%!assert(floor ([2, 1.1, -1.1, -1]), [2, 1, -2, -1]);
-%!assert(floor ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i]), [2+2i, 1+i, -2-2i, -1-i]);
-%!assert(floor (single ([2, 1.1, -1.1, -1])), single ([2, 1, -2, -1]));
-%!assert(floor (single([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i])), single([2+2i, 1+i, -2-2i, -1-i]));
+%!assert (floor ([2, 1.1, -1.1, -1]), [2, 1, -2, -1])
+%!assert (floor ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i]), [2+2i, 1+i, -2-2i, -1-i])
+%!assert (floor (single ([2, 1.1, -1.1, -1])), single ([2, 1, -2, -1]))
+%!assert (floor (single ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i])), single ([2+2i, 1+i, -2-2i, -1-i]))
 
-%!error floor ();
-%!error floor (1, 2);
+%!error floor ()
+%!error floor (1, 2)
 */
 
 DEFUN (gamma, args, ,
@@ -874,31 +909,31 @@
 
 /*
 %!test
-%! a = -1i*sqrt(-1/(6.4187*6.4187));
-%! assert (gamma(a), gamma(real(a)));
+%! a = -1i*sqrt (-1/(6.4187*6.4187));
+%! assert (gamma (a), gamma (real (a)));
 
 %!test
 %! x = [.5, 1, 1.5, 2, 3, 4, 5];
 %! v = [sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24];
-%! assert(gamma(x), v, sqrt(eps))
+%! assert (gamma (x), v, sqrt (eps));
 
 %!test
-%! a = single(-1i*sqrt(-1/(6.4187*6.4187)));
-%! assert (gamma(a), gamma(real(a)));
+%! a = single (-1i*sqrt (-1/(6.4187*6.4187)));
+%! assert (gamma (a), gamma (real (a)));
 
 %!test
-%! x = single([.5, 1, 1.5, 2, 3, 4, 5]);
-%! v = single([sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]);
-%! assert(gamma(x), v, sqrt(eps('single')))
+%! x = single ([.5, 1, 1.5, 2, 3, 4, 5]);
+%! v = single ([sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]);
+%! assert (gamma (x), v, sqrt (eps ('single')));
 
 %!test
 %! x = [-1, 0, 1, Inf];
 %! v = [Inf, Inf, 1, Inf];
-%! assert (gamma(x), v);
-%! assert (gamma(single (x)), single (v));
+%! assert (gamma (x), v);
+%! assert (gamma (single (x)), single (v));
 
-%!error gamma();
-%!error gamma(1,2);
+%!error gamma ()
+%!error gamma (1, 2)
 */
 
 DEFUN (imag, args, ,
@@ -918,18 +953,18 @@
 }
 
 /*
-%!assert(imag (1), 0);
-%!assert(imag (i), 1);
-%!assert(imag (1+i), 1);
-%!assert(imag ([i, 1; 1, i]), full (eye (2)));
+%!assert (imag (1), 0)
+%!assert (imag (i), 1)
+%!assert (imag (1+i), 1)
+%!assert (imag ([i, 1; 1, i]), full (eye (2)))
 
-%!assert(imag (single(1)), single(0));
-%!assert(imag (single(i)), single(1));
-%!assert(imag (single(1+i)), single(1));
-%!assert(imag (single([i, 1; 1, i])), full (eye (2,'single')));
+%!assert (imag (single (1)), single (0))
+%!assert (imag (single (i)), single (1))
+%!assert (imag (single (1+i)), single (1))
+%!assert (imag (single ([i, 1; 1, i])), full (eye (2,'single')))
 
-%!error imag ();
-%!error imag (1, 2);
+%!error imag ()
+%!error imag (1, 2)
 */
 
 DEFUNX ("isalnum", Fisalnum, args, ,
@@ -952,15 +987,15 @@
 
 /*
 %!test
-%! charset = setstr (0:127);
-%! result = zeros (1, 128);
-%! result ((toascii("A"):toascii("Z"))+1) = 1;
-%! result ((toascii("0"):toascii("9"))+1) = 1;
-%! result ((toascii("a"):toascii("z"))+1) = 1;
-%! assert(all (isalnum (charset) == result));
+%! charset = char (0:127);
+%! result = false (1, 128);
+%! result(toascii ("A":"Z") + 1) = true;
+%! result(toascii ("0":"9") + 1) = true;
+%! result(toascii ("a":"z") + 1) = true;
+%! assert (all (isalnum (charset) == result));
 
-%!error isalnum (1, 2);
-%!error isalnum ();
+%!error isalnum ()
+%!error isalnum (1, 2)
 */
 
 DEFUNX ("isalpha", Fisalpha, args, ,
@@ -983,14 +1018,14 @@
 
 /*
 %!test
-%! charset = setstr (0:127);
-%! result = zeros (1, 128);
-%! result ((toascii("A"):toascii("Z"))+1) = 1;
-%! result ((toascii("a"):toascii("z"))+1) = 1;
-%! assert(all (isalpha (charset) == result));
+%! charset = char (0:127);
+%! result = false (1, 128);
+%! result(toascii ("A":"Z") + 1) = true;
+%! result(toascii ("a":"z") + 1) = true;
+%! assert (all (isalpha (charset) == result));
 
-%!error isalpha (1, 2);
-%!error isalpha ();
+%!error isalpha ()
+%!error isalpha (1, 2)
 */
 
 DEFUNX ("isascii", Fisascii, args, ,
@@ -1012,12 +1047,12 @@
 
 /*
 %!test
-%! charset = setstr (0:127);
-%! result = ones (1, 128);
-%! assert(all (isascii (charset) == result));
+%! charset = char (0:127);
+%! result = true (1, 128);
+%! assert (all (isascii (charset) == result));
 
-%!error isascii (1, 2);
-%!error isascii ();
+%!error isascii ()
+%!error isascii (1, 2)
 */
 
 DEFUNX ("iscntrl", Fiscntrl, args, ,
@@ -1038,16 +1073,15 @@
 }
 
 /*
-%% test/octave.test/string/iscntrl-1.m
 %!test
-%! charset = setstr (0:127);
-%! result = zeros (1, 128);
-%! result (1:32) = 1;
-%! result (128) = 1;
-%! assert(all (iscntrl (charset) == result));
+%! charset = char (0:127);
+%! result = false (1, 128);
+%! result(1:32) = true;
+%! result(128) = true;
+%! assert (all (iscntrl (charset) == result));
 
-%!error iscntrl (1, 2);
-%!error iscntrl ();
+%!error iscntrl ()
+%!error iscntrl (1, 2)
 */
 
 DEFUNX ("isdigit", Fisdigit, args, ,
@@ -1069,13 +1103,13 @@
 
 /*
 %!test
-%! charset = setstr (0:127);
-%! result = zeros (1, 128);
-%! result ((toascii("0"):toascii("9"))+1) = 1;
-%! assert(all (isdigit (charset) == result));
+%! charset = char (0:127);
+%! result = false (1, 128);
+%! result(toascii ("0":"9") + 1) = true;
+%! assert (all (isdigit (charset) == result));
 
-%!error isdigit (1, 2);
-%!error isdigit ();
+%!error isdigit ()
+%!error isdigit (1, 2)
 */
 
 DEFUN (isinf, args, ,
@@ -1104,17 +1138,20 @@
 }
 
 /*
-%!assert(isinf (Inf));
-%!assert(!isinf (NaN));
-%!assert(!(isinf (NA)));
-%!assert(isinf (rand(1,10)), false(1,10));
-%!assert(isinf([NaN -Inf -1 0 1 Inf NA]), [false, true, false, false, false, true, false]);
+%!assert (isinf (Inf))
+%!assert (!isinf (NaN))
+%!assert (!isinf (NA))
+%!assert (isinf (rand(1,10)), false (1,10))
+%!assert (isinf ([NaN -Inf -1 0 1 Inf NA]), [false, true, false, false, false, true, false])
 
-%!assert(isinf (single(Inf)));
-%!assert(!(isinf (single(NaN))));
-%!assert(!(isinf (single(NA))));
-%!assert(isinf (single(rand(1,10))), false(1,10));
-%!assert(isinf(single([NaN -Inf -1 0 1 Inf NA])), [false, true, false, false, false, true, false]);
+%!assert (isinf (single (Inf)))
+%!assert (!isinf (single (NaN)))
+%!assert (!isinf (single (NA)))
+%!assert (isinf (single (rand(1,10))), false (1,10))
+%!assert (isinf (single ([NaN -Inf -1 0 1 Inf NA])), [false, true, false, false, false, true, false])
+
+%!error isinf ()
+%!error isinf (1, 2)
 */
 
 DEFUNX ("isgraph", Fisgraph, args, ,
@@ -1137,13 +1174,13 @@
 
 /*
 %!test
-%! charset = setstr (0:127);
-%! result = zeros (1, 128);
-%! result (34:127) = 1;
-%! assert(all (isgraph (charset) == result));
+%! charset = char (0:127);
+%! result = false (1, 128);
+%! result(34:127) = true;
+%! assert (all (isgraph (charset) == result));
 
-%!error isgraph (1, 2);
-%!error isgraph ();
+%!error isgraph ()
+%!error isgraph (1, 2)
 */
 
 DEFUNX ("islower", Fislower, args, ,
@@ -1165,13 +1202,13 @@
 
 /*
 %!test
-%! charset = setstr (0:127);
-%! result = zeros (1, 128);
-%! result ((toascii("a"):toascii("z"))+1) = 1;
-%! assert(all (islower (charset) == result));
+%! charset = char (0:127);
+%! result = false (1, 128);
+%! result(toascii ("a":"z") + 1) = true;
+%! assert (all (islower (charset) == result));
 
-%!error islower (1, 2);
-%!error islower ();
+%!error islower ()
+%!error islower (1, 2)
 */
 
 DEFUN (isna, args, ,
@@ -1200,17 +1237,20 @@
 }
 
 /*
-%!assert(!(isna (Inf)));
-%!assert(!isna (NaN));
-%!assert(isna (NA));
-%!assert(isna (rand(1,10)), false(1,10));
-%!assert(isna([NaN -Inf -1 0 1 Inf NA]), [false, false, false, false, false, false, true]);
+%!assert (!isna (Inf))
+%!assert (!isna (NaN))
+%!assert (isna (NA))
+%!assert (isna (rand(1,10)), false (1,10))
+%!assert (isna ([NaN -Inf -1 0 1 Inf NA]), [false, false, false, false, false, false, true])
 
-%!assert(!(isna (single(Inf))));
-%!assert(!isna (single(NaN)));
-%!assert(isna (single(NA)));
-%!assert(isna (single(rand(1,10))), false(1,10));
-%!assert(isna(single([NaN -Inf -1 0 1 Inf NA])), [false, false, false, false, false, false, true]);
+%!assert (!isna (single (Inf)))
+%!assert (!isna (single (NaN)))
+%!assert (isna (single (NA)))
+%!assert (isna (single (rand(1,10))), false (1,10))
+%!assert (isna (single ([NaN -Inf -1 0 1 Inf NA])), [false, false, false, false, false, false, true])
+
+%!error isna ()
+%!error isna (1, 2)
 */
 
 DEFUN (isnan, args, ,
@@ -1239,17 +1279,20 @@
 }
 
 /*
-%!assert(!(isnan (Inf)));
-%!assert(isnan (NaN));
-%!assert(isnan (NA));
-%!assert(isnan (rand(1,10)), false(1,10));
-%!assert(isnan([NaN -Inf -1 0 1 Inf NA]), [true, false, false, false, false, false, true]);
+%!assert (!isnan (Inf))
+%!assert (isnan (NaN))
+%!assert (isnan (NA))
+%!assert (isnan (rand(1,10)), false (1,10))
+%!assert (isnan ([NaN -Inf -1 0 1 Inf NA]), [true, false, false, false, false, false, true])
 
-%!assert(!(isnan (single(Inf))));
-%!assert(isnan (single(NaN)));
-%!assert(isnan (single(NA)));
-%!assert(isnan (single(rand(1,10))), false(1,10));
-%!assert(isnan(single([NaN -Inf -1 0 1 Inf NA])), [true, false, false, false, false, false, true]);
+%!assert (!isnan (single (Inf)))
+%!assert (isnan (single (NaN)))
+%!assert (isnan (single (NA)))
+%!assert (isnan (single (rand(1,10))), false (1,10))
+%!assert (isnan (single ([NaN -Inf -1 0 1 Inf NA])), [true, false, false, false, false, false, true])
+
+%!error isnan ()
+%!error isnan (1, 2)
 */
 
 DEFUNX ("isprint", Fisprint, args, ,
@@ -1272,16 +1315,13 @@
 
 /*
 %!test
-%! charset = setstr (0:127);
-%! result = zeros (1, 128);
-%! result (33:127) = 1;
-%! if (ispc () && ! isunix ())
-%!   result(10) = 1;
-%! endif
-%! assert(all (isprint (charset) == result));
+%! charset = char (0:127);
+%! result = false (1, 128);
+%! result(33:127) = true;
+%! assert (all (isprint (charset) == result));
 
-%!error isprint (1, 2);
-%!error isprint ();
+%!error isprint ()
+%!error isprint (1, 2)
 */
 
 DEFUNX ("ispunct", Fispunct, args, ,
@@ -1303,16 +1343,16 @@
 
 /*
 %!test
-%! charset = setstr (0:127);
-%! result = zeros (1, 128);
-%! result (34:48) = 1;
-%! result (59:65) = 1;
-%! result (92:97) = 1;
-%! result (124:127) = 1;
-%! assert(all (ispunct (charset) == result));
+%! charset = char (0:127);
+%! result = false (1, 128);
+%! result(34:48) = true;
+%! result(59:65) = true;
+%! result(92:97) = true;
+%! result(124:127) = true;
+%! assert (all (ispunct (charset) == result));
 
-%!error ispunct (1, 2);
-%!error ispunct ();
+%!error ispunct ()
+%!error ispunct (1, 2)
 */
 
 DEFUNX ("isspace", Fisspace, args, ,
@@ -1335,13 +1375,13 @@
 
 /*
 %!test
-%! charset = setstr (0:127);
-%! result = zeros (1, 128);
-%! result (toascii (" \f\n\r\t\v")+1) = 1;
-%! assert(all (isspace (charset) == result));
+%! charset = char (0:127);
+%! result = false (1, 128);
+%! result(toascii (" \f\n\r\t\v") + 1) = true;
+%! assert (all (isspace (charset) == result));
 
-%!error isspace (1, 2);
-%!error isspace ();
+%!error isspace ()
+%!error isspace (1, 2)
 */
 
 DEFUNX ("isupper", Fisupper, args, ,
@@ -1363,13 +1403,13 @@
 
 /*
 %!test
-%! charset = setstr (0:127);
-%! result = zeros (1, 128);
-%! result ((toascii("A"):toascii("Z"))+1) = 1;
-%! assert(all (isupper (charset) == result));
+%! charset = char (0:127);
+%! result = false (1, 128);
+%! result(toascii ("A":"Z") + 1) = true;
+%! assert (all (isupper (charset) == result));
 
-%!error isupper (1, 2);
-%!error isupper ();
+%!error isupper ()
+%!error isupper (1, 2)
 */
 
 DEFUNX ("isxdigit", Fisxdigit, args, ,
@@ -1391,15 +1431,15 @@
 
 /*
 %!test
-%! charset = setstr (0:127);
-%! result = zeros (1, 128);
-%! result ((toascii("A"):toascii("F"))+1) = 1;
-%! result ((toascii("0"):toascii("9"))+1) = 1;
-%! result ((toascii("a"):toascii("f"))+1) = 1;
-%! assert(all (isxdigit (charset) == result));
+%! charset = char (0:127);
+%! result = false (1, 128);
+%! result(toascii ("A":"F") + 1) = true;
+%! result(toascii ("0":"9") + 1) = true;
+%! result(toascii ("a":"f") + 1) = true;
+%! assert (all (isxdigit (charset) == result));
 
-%!error isxdigit (1, 2);
-%!error isxdigit ();
+%!error isxdigit ()
+%!error isxdigit (1, 2)
 */
 
 DEFUN (lgamma, args, ,
@@ -1421,31 +1461,31 @@
 
 /*
 %!test
-%! a = -1i*sqrt(-1/(6.4187*6.4187));
+%! a = -1i*sqrt (-1/(6.4187*6.4187));
 %! assert (lgamma(a), lgamma(real(a)));
 
 %!test
 %! x = [.5, 1, 1.5, 2, 3, 4, 5];
 %! v = [sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24];
-%! assert(lgamma(x), log(v), sqrt(eps))
+%! assert (lgamma(x), log(v), sqrt (eps))
 
 %!test
-%! a = single(-1i*sqrt(-1/(6.4187*6.4187)));
+%! a = single (-1i*sqrt (-1/(6.4187*6.4187)));
 %! assert (lgamma(a), lgamma(real(a)));
 
 %!test
-%! x = single([.5, 1, 1.5, 2, 3, 4, 5]);
-%! v = single([sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]);
-%! assert(lgamma(x), log(v), sqrt(eps ('single')))
+%! x = single ([.5, 1, 1.5, 2, 3, 4, 5]);
+%! v = single ([sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]);
+%! assert (lgamma(x), log(v), sqrt (eps ('single')))
 
 %!test
 %! x = [-1, 0, 1, Inf];
 %! v = [Inf, Inf, 0, Inf];
 %! assert (lgamma(x), v);
-%! assert (lgamma(single (x)), single(v));
+%! assert (lgamma(single (x)), single (v));
 
-%!error lgamma();
-%!error lgamma(1,2);
+%!error lgamma()
+%!error lgamma(1,2)
 */
 
 DEFUN (log, args, ,
@@ -1473,14 +1513,14 @@
 }
 
 /*
-%!assert(log ([1, e, e^2]), [0, 1, 2], sqrt (eps));
-%!assert(log ([-0.5, -1.5, -2.5]), log([0.5, 1.5, 2.5]) + pi*1i, sqrt (eps));
+%!assert (log ([1, e, e^2]), [0, 1, 2], sqrt (eps))
+%!assert (log ([-0.5, -1.5, -2.5]), log([0.5, 1.5, 2.5]) + pi*1i, sqrt (eps))
 
-%!assert(log (single([1, e, e^2])), single([0, 1, 2]), sqrt (eps('single')));
-%!assert(log (single([-0.5, -1.5, -2.5])), single(log([0.5, 1.5, 2.5]) + pi*1i), 4*eps('single'));
+%!assert (log (single ([1, e, e^2])), single ([0, 1, 2]), sqrt (eps ('single')))
+%!assert (log (single ([-0.5, -1.5, -2.5])), single (log([0.5, 1.5, 2.5]) + pi*1i), 4*eps ('single'))
 
-%!error log ();
-%!error log (1, 2);
+%!error log ()
+%!error log (1, 2)
 */
 
 DEFUN (log10, args, ,
@@ -1500,11 +1540,11 @@
 }
 
 /*
-%!assert(log10 ([0.01, 0.1, 1, 10, 100]), [-2, -1, 0, 1, 2], sqrt (eps));
-%!assert(log10 (single([0.01, 0.1, 1, 10, 100])), single([-2, -1, 0, 1, 2]), sqrt (eps ('single')));
+%!assert (log10 ([0.01, 0.1, 1, 10, 100]), [-2, -1, 0, 1, 2], sqrt (eps))
+%!assert (log10 (single ([0.01, 0.1, 1, 10, 100])), single ([-2, -1, 0, 1, 2]), sqrt (eps ('single')))
 
-%!error log10 ();
-%!error log10 (1, 2);
+%!error log10 ()
+%!error log10 (1, 2)
 */
 
 DEFUN (log1p, args, ,
@@ -1530,6 +1570,14 @@
   return retval;
 }
 
+/*
+%!assert (log1p ([0, 2*eps, -2*eps]), [0, 2*eps, -2*eps], 1e-29)
+%!assert (log1p (single ([0, 2*eps, -2*eps])), single([0, 2*eps, -2*eps]), 1e-29)
+
+%!error log1p ()
+%!error log1p (1, 2)
+*/
+
 DEFUN (real, args, ,
     "-*- texinfo -*-\n\
 @deftypefn {Mapping Function} {} real (@var{z})\n\
@@ -1547,25 +1595,25 @@
 }
 
 /*
-%!assert(real (1), 1);
-%!assert(real (i), 0);
-%!assert(real (1+i), 1);
-%!assert(real ([1, i; i, 1]), full (eye (2)));
+%!assert (real (1), 1)
+%!assert (real (i), 0)
+%!assert (real (1+i), 1)
+%!assert (real ([1, i; i, 1]), full (eye (2)))
 
-%!assert(real (single(1)), single(1));
-%!assert(real (single(i)), single(0));
-%!assert(real (single(1+i)), single(1));
-%!assert(real (single([1, i; i, 1])), full (eye (2,'single')));
+%!assert (real (single (1)), single (1))
+%!assert (real (single (i)), single (0))
+%!assert (real (single (1+i)), single (1))
+%!assert (real (single ([1, i; i, 1])), full (eye (2,'single')))
 
-%!error real ();
-%!error real (1, 2);
+%!error real ()
+%!error real (1, 2)
 */
 
 DEFUN (round, args, ,
     "-*- texinfo -*-\n\
 @deftypefn {Mapping Function} {} round (@var{x})\n\
 Return the integer nearest to @var{x}.  If @var{x} is complex, return\n\
-@code{round (real (@var{x})) + round (imag (@var{x})) * I}. If there\n\
+@code{round (real (@var{x})) + round (imag (@var{x})) * I}.  If there\n\
 are two nearest integers, return the one further away from zero.\n\
 \n\
 @example\n\
@@ -1587,24 +1635,24 @@
 }
 
 /*
-%!assert(round (1), 1);
-%!assert(round (1.1), 1);
-%!assert(round (5.5), 6);
-%!assert(round (i), i);
-%!assert(round (2.5+3.5i), 3+4i);
-%!assert(round (-2.6), -3);
-%!assert(round ([1.1, -2.4; -3.7, 7.1]), [1, -2; -4, 7]);
+%!assert (round (1), 1)
+%!assert (round (1.1), 1)
+%!assert (round (5.5), 6)
+%!assert (round (i), i)
+%!assert (round (2.5+3.5i), 3+4i)
+%!assert (round (-2.6), -3)
+%!assert (round ([1.1, -2.4; -3.7, 7.1]), [1, -2; -4, 7])
 
-%!assert(round (single(1)), single(1));
-%!assert(round (single(1.1)), single(1));
-%!assert(round (single(5.5)), single(6));
-%!assert(round (single(i)), single(i));
-%!assert(round (single(2.5+3.5i)), single(3+4i));
-%!assert(round (single(-2.6)), single(-3));
-%!assert(round (single([1.1, -2.4; -3.7, 7.1])), single([1, -2; -4, 7]));
+%!assert (round (single (1)), single (1))
+%!assert (round (single (1.1)), single (1))
+%!assert (round (single (5.5)), single (6))
+%!assert (round (single (i)), single (i))
+%!assert (round (single (2.5+3.5i)), single (3+4i))
+%!assert (round (single (-2.6)), single (-3))
+%!assert (round (single ([1.1, -2.4; -3.7, 7.1])), single ([1, -2; -4, 7]))
 
-%!error round ();
-%!error round (1, 2);
+%!error round ()
+%!error round (1, 2)
 */
 
 DEFUN (roundb, args, ,
@@ -1625,6 +1673,29 @@
   return retval;
 }
 
+/*
+%!assert (roundb (1), 1)
+%!assert (roundb (1.1), 1)
+%!assert (roundb (1.5), 2)
+%!assert (roundb (4.5), 4)
+%!assert (roundb (i), i)
+%!assert (roundb (2.5+3.5i), 2+4i)
+%!assert (roundb (-2.6), -3)
+%!assert (roundb ([1.1, -2.4; -3.7, 7.1]), [1, -2; -4, 7])
+
+%!assert (roundb (single (1)), single (1))
+%!assert (roundb (single (1.1)), single (1))
+%!assert (roundb (single (1.5)), single (2))
+%!assert (roundb (single (4.5)), single (4))
+%!assert (roundb (single (i)), single (i))
+%!assert (roundb (single (2.5+3.5i)), single (2+4i))
+%!assert (roundb (single (-2.6)), single (-3))
+%!assert (roundb (single ([1.1, -2.4; -3.7, 7.1])), single ([1, -2; -4, 7]))
+
+%!error roundb ()
+%!error roundb (1, 2)
+*/
+
 DEFUN (sign, args, ,
     "-*- texinfo -*-\n\
 @deftypefn {Mapping Function} {} sign (@var{x})\n\
@@ -1659,18 +1730,18 @@
 }
 
 /*
-%!assert(sign (-2) , -1);
-%!assert(sign (3), 1);
-%!assert(sign (0), 0);
-%!assert(sign ([1, -pi; e, 0]), [1, -1; 1, 0]);
+%!assert (sign (-2) , -1)
+%!assert (sign (0), 0)
+%!assert (sign (3), 1)
+%!assert (sign ([1, -pi; e, 0]), [1, -1; 1, 0])
 
-%!assert(sign (single(-2)) , single(-1));
-%!assert(sign (single(3)), single(1));
-%!assert(sign (single(0)), single(0));
-%!assert(sign (single([1, -pi; e, 0])), single([1, -1; 1, 0]));
+%!assert (sign (single (-2)) , single (-1))
+%!assert (sign (single (0)), single (0))
+%!assert (sign (single (3)), single (1))
+%!assert (sign (single ([1, -pi; e, 0])), single ([1, -1; 1, 0]))
 
-%!error sign ();
-%!error sign (1, 2);
+%!error sign ()
+%!error sign (1, 2)
 */
 
 DEFUN (sin, args, ,
@@ -1690,22 +1761,22 @@
 }
 
 /*
-%!test
+%!shared rt2, rt3
 %! rt2 = sqrt (2);
 %! rt3 = sqrt (3);
-%! x = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
-%! v = [0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0];
-%! assert(sin (x), v, sqrt (eps));
 
 %!test
-%! rt2 = sqrt (2);
-%! rt3 = sqrt (3);
-%! x = single([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
-%! v = single([0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0]);
-%! assert(sin (x), v, sqrt (eps('single')));
+%! x = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
+%! v = [0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0];
+%! assert (sin (x), v, sqrt (eps));
 
-%!error sin ();
-%!error sin (1, 2);
+%!test
+%! x = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
+%! v = single ([0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0]);
+%! assert (sin (x), v, sqrt (eps ('single')));
+
+%!error sin ()
+%!error sin (1, 2)
 */
 
 DEFUN (sinh, args, ,
@@ -1728,15 +1799,15 @@
 %!test
 %! x = [0, pi/2*i, pi*i, 3*pi/2*i];
 %! v = [0, i, 0, -i];
-%! assert(sinh (x), v, sqrt (eps));
+%! assert (sinh (x), v, sqrt (eps));
 
 %!test
-%! x = single([0, pi/2*i, pi*i, 3*pi/2*i]);
-%! v = single([0, i, 0, -i]);
-%! assert(sinh (x), v, sqrt (eps('single')));
+%! x = single ([0, pi/2*i, pi*i, 3*pi/2*i]);
+%! v = single ([0, i, 0, -i]);
+%! assert (sinh (x), v, sqrt (eps ('single')));
 
-%!error sinh ();
-%!error sinh (1, 2);
+%!error sinh ()
+%!error sinh (1, 2)
 */
 
 DEFUN (sqrt, args, ,
@@ -1758,18 +1829,18 @@
 }
 
 /*
-%!assert(sqrt (4), 2)
-%!assert(sqrt (-1), i)
-%!assert(sqrt (1+i), exp (0.5 * log (1+i)), sqrt (eps));
-%!assert(sqrt([4, -4; i, 1-i]), [2, 2i; exp(0.5 * log (i)), exp(0.5 * log (1-i))], sqrt(eps));
+%!assert (sqrt (4), 2)
+%!assert (sqrt (-1), i)
+%!assert (sqrt (1+i), exp (0.5 * log (1+i)), sqrt (eps))
+%!assert (sqrt ([4, -4; i, 1-i]), [2, 2i; exp(0.5 * log (i)), exp(0.5 * log (1-i))], sqrt (eps))
 
-%!assert(sqrt (single(4)), single(2))
-%!assert(sqrt (single(-1)), single(i))
-%!assert(sqrt (single(1+i)), single(exp (0.5 * log (1+i))), sqrt (eps('single')));
-%!assert(sqrt(single([4, -4; i, 1-i])), single([2, 2i; exp(0.5 * log (i)), exp(0.5 * log (1-i))]), sqrt(eps('single')));
+%!assert (sqrt (single (4)), single (2))
+%!assert (sqrt (single (-1)), single (i))
+%!assert (sqrt (single (1+i)), single (exp (0.5 * log (1+i))), sqrt (eps ('single')))
+%!assert (sqrt (single ([4, -4; i, 1-i])), single ([2, 2i; exp(0.5 * log (i)), exp(0.5 * log (1-i))]), sqrt (eps ('single')))
 
-%!error sqrt ();
-%!error sqrt (1, 2);
+%!error sqrt ()
+%!error sqrt (1, 2)
 */
 
 DEFUN (tan, args, ,
@@ -1789,22 +1860,22 @@
 }
 
 /*
-%!test
+%!shared rt2, rt3
 %! rt2 = sqrt (2);
 %! rt3 = sqrt (3);
-%! x = [0, pi/6, pi/4, pi/3, 2*pi/3, 3*pi/4, 5*pi/6, pi];
-%! v = [0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0];
-%! assert(tan (x), v,  sqrt (eps));
 
 %!test
-%! rt2 = sqrt (2);
-%! rt3 = sqrt (3);
-%! x = single([0, pi/6, pi/4, pi/3, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
-%! v = single([0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0]);
-%! assert(tan (x), v,  sqrt (eps('single')));
+%! x = [0, pi/6, pi/4, pi/3, 2*pi/3, 3*pi/4, 5*pi/6, pi];
+%! v = [0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0];
+%! assert (tan (x), v,  sqrt (eps));
 
-%!error tan ();
-%!error tan (1, 2);
+%!test
+%! x = single ([0, pi/6, pi/4, pi/3, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
+%! v = single ([0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0]);
+%! assert (tan (x), v,  sqrt (eps ('single')));
+
+%!error tan ()
+%!error tan (1, 2)
 */
 
 DEFUN (tanh, args, ,
@@ -1827,15 +1898,15 @@
 %!test
 %! x = [0, pi*i];
 %! v = [0, 0];
-%! assert(tanh (x), v, sqrt (eps));
+%! assert (tanh (x), v, sqrt (eps));
 
 %!test
-%! x = single([0, pi*i]);
-%! v = single([0, 0]);
-%! assert(tanh (x), v, sqrt (eps('single')));
+%! x = single ([0, pi*i]);
+%! v = single ([0, 0]);
+%! assert (tanh (x), v, sqrt (eps ('single')));
 
-%!error tanh ();
-%!error tanh (1, 2);
+%!error tanh ()
+%!error tanh (1, 2)
 */
 
 DEFUNX ("toascii", Ftoascii, args, ,
@@ -1863,14 +1934,15 @@
 }
 
 /*
-%!assert(toascii (char (0:127)), 0:127);
-%!assert(toascii (" ":"@"), 32:64);
-%!assert(toascii ("A":"Z"), 65:90);
-%!assert(toascii ("[":"`"), 91:96);
-%!assert(toascii ("a":"z"), 97:122);
-%!assert(toascii ("{":"~"), 123:126);
-%!error toascii (1, 2);
-%!error toascii (1, 2);
+%!assert (toascii (char (0:127)), 0:127)
+%!assert (toascii (" ":"@"), 32:64)
+%!assert (toascii ("A":"Z"), 65:90)
+%!assert (toascii ("[":"`"), 91:96)
+%!assert (toascii ("a":"z"), 97:122)
+%!assert (toascii ("{":"~"), 123:126)
+
+%!error toascii ()
+%!error toascii (1, 2)
 */
 
 DEFUNX ("tolower", Ftolower, args, ,
@@ -1902,26 +1974,26 @@
 DEFALIAS (lower, tolower);
 
 /*
-%!error <Invalid call to tolower.*> tolower();
-%!error <Invalid call to tolower.*> lower();
-%!error tolower (1, 2);
-%!assert(tolower("OCTAVE"), "octave");
-%!assert(tolower("123OCTave!_&"), "123octave!_&");
-%!assert(tolower({"ABC", "DEF", {"GHI", {"JKL"}}}), {"abc", "def", {"ghi", {"jkl"}}});
-%!assert(tolower(["ABC"; "DEF"]), ["abc"; "def"]);
-%!assert(tolower({["ABC"; "DEF"]}), {["abc";"def"]});
-%!assert(tolower(68), "d");
-%!assert(tolower({[68, 68; 68, 68]}), {["dd";"dd"]});
+%!assert (tolower("OCTAVE"), "octave")
+%!assert (tolower("123OCTave!_&"), "123octave!_&")
+%!assert (tolower({"ABC", "DEF", {"GHI", {"JKL"}}}), {"abc", "def", {"ghi", {"jkl"}}})
+%!assert (tolower(["ABC"; "DEF"]), ["abc"; "def"])
+%!assert (tolower({["ABC"; "DEF"]}), {["abc";"def"]})
+%!assert (tolower(68), "d")
+%!assert (tolower({[68, 68; 68, 68]}), {["dd";"dd"]})
 %!test
 %!  a(3,3,3,3) = "D";
 %!  assert(tolower(a)(3,3,3,3), "d");
 
 %!test
-%! charset = setstr (0:127);
+%! charset = char (0:127);
 %! result = charset;
-%! result ((toascii("A"):toascii("Z"))+1) \
-%! = result ((toascii("a"):toascii("z"))+1);
-%! assert(all (tolower (charset) == result));
+%! result(toascii ("A":"Z") + 1) = result(toascii ("a":"z") + 1);
+%! assert (all (tolower (charset) == result));
+
+%!error <Invalid call to tolower> tolower()
+%!error <Invalid call to tolower> lower()
+%!error tolower (1, 2)
 */
 
 DEFUNX ("toupper", Ftoupper, args, ,
@@ -1953,25 +2025,25 @@
 DEFALIAS (upper, toupper);
 
 /*
-%!error <Invalid call to toupper.*> toupper();
-%!error <Invalid call to toupper.*> upper();
-%!error toupper (1, 2);
-%!assert(toupper("octave"), "OCTAVE");
-%!assert(toupper("123OCTave!_&"), "123OCTAVE!_&");
-%!assert(toupper({"abc", "def", {"ghi", {"jkl"}}}), {"ABC", "DEF", {"GHI", {"JKL"}}});
-%!assert(toupper(["abc"; "def"]), ["ABC"; "DEF"]);
-%!assert(toupper({["abc"; "def"]}), {["ABC";"DEF"]});
-%!assert(toupper(100), "D");
-%!assert(toupper({[100, 100; 100, 100]}), {["DD";"DD"]});
+%!assert (toupper ("octave"), "OCTAVE")
+%!assert (toupper ("123OCTave!_&"), "123OCTAVE!_&")
+%!assert (toupper ({"abc", "def", {"ghi", {"jkl"}}}), {"ABC", "DEF", {"GHI", {"JKL"}}})
+%!assert (toupper (["abc"; "def"]), ["ABC"; "DEF"])
+%!assert (toupper ({["abc"; "def"]}), {["ABC";"DEF"]})
+%!assert (toupper (100), "D")
+%!assert (toupper ({[100, 100; 100, 100]}), {["DD";"DD"]})
 %!test
 %!  a(3,3,3,3) = "d";
-%!  assert(toupper(a)(3,3,3,3), "D");
+%!  assert(toupper (a)(3,3,3,3), "D");
 %!test
-%! charset = setstr (0:127);
+%! charset = char (0:127);
 %! result = charset;
-%! result ((toascii("a"):toascii("z"))+1) \
-%! = result ((toascii("A"):toascii("Z"))+1);
-%! assert(all (toupper (charset) == result));
+%! result(toascii  ("a":"z") + 1) = result(toascii  ("A":"Z") + 1);
+%! assert (all (toupper (charset) == result));
+
+%!error <Invalid call to toupper> toupper()
+%!error <Invalid call to toupper> upper()
+%!error toupper (1, 2)
 */
 
 DEFALIAS (gammaln, lgamma);
--- a/src/oct-errno.cc.in	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/oct-errno.cc.in	Wed Dec 07 19:06:13 2011 -0500
@@ -27,6 +27,8 @@
 
 #include <cerrno>
 
+#include "singleton-cleanup.h"
+
 #include "oct-errno.h"
 #include "oct-map.h"
 #include "error.h"
@@ -292,7 +294,12 @@
   bool retval = true;
 
   if (! instance)
-    instance = new octave_errno ();
+    {
+      instance = new octave_errno ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
--- a/src/oct-errno.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/oct-errno.h	Wed Dec 07 19:06:13 2011 -0500
@@ -43,6 +43,8 @@
 
   static bool instance_ok (void);
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   static int lookup (const std::string& name);
 
   static octave_scalar_map list (void);
--- a/src/oct-hist.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/oct-hist.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -734,6 +734,7 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} history_timestamp_format_string ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} history_timestamp_format_string (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} history_timestamp_format_string (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the format string\n\
 for the comment line that is written to the history file when Octave\n\
 exits.  The format string is passed to @code{strftime}.  The default\n\
@@ -742,6 +743,10 @@
 @example\n\
 \"# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>\"\n\
 @end example\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{strftime, history_file, history_size, saving_history}\n\
 @end deftypefn")
 {
@@ -752,8 +757,13 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} saving_history ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} saving_history (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} saving_history (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether commands entered\n\
 on the command line are saved in the history file.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{history_control, history_file, history_size, history_timestamp_format_string}\n\
 @end deftypefn")
 {
--- a/src/oct-map.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/oct-map.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -755,14 +755,19 @@
 
       // Try the fast case.
       bool all_same = true;
-      for (octave_idx_type i = 0; i < n; i++)
+
+      if (nf > 0)
         {
-          all_same = map_list[idx].xkeys.is_same (map_list[i].xkeys);
-          if (! all_same)
-            break;
+          for (octave_idx_type i = 0; i < n; i++)
+            {
+              all_same = map_list[idx].xkeys.is_same (map_list[i].xkeys);
+
+              if (! all_same)
+                break;
+            }
         }
 
-      if (all_same)
+      if (all_same && nf > 0)
         do_cat (dim, n, map_list, retval);
       else
         {
--- a/src/oct-map.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/oct-map.h	Wed Dec 07 19:06:13 2011 -0500
@@ -53,8 +53,8 @@
 
   static fields_rep *nil_rep (void)
     {
-      static fields_rep *nr = new fields_rep ();
-      return nr;
+      static fields_rep nr;
+      return &nr;
     }
 
 public:
@@ -73,8 +73,12 @@
     {
       if (rep->count > 1)
         {
-          --rep->count;
-          rep = new fields_rep (*rep);
+          fields_rep *r = new fields_rep (*rep);
+
+          if (--rep->count == 0)
+            delete rep;
+
+          rep = r;
         }
     }
 
--- a/src/oct-obj.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/oct-obj.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -29,6 +29,10 @@
 #include "oct-obj.h"
 #include "Cell.h"
 
+// We are likely to have a lot of octave_value_list objects to allocate,
+// so make the grow_size large.
+DEFINE_OCTAVE_ALLOCATOR2(octave_value_list, 1024);
+
 octave_value_list::octave_value_list (const std::list<octave_value_list>& lst)
 {
   octave_idx_type n = 0, nel = 0;
@@ -59,9 +63,6 @@
 
 }
 
-octave_allocator
-octave_value_list::allocator (sizeof (octave_value_list));
-
 octave_value_list&
 octave_value_list::prepend (const octave_value& val)
 {
--- a/src/oct-obj.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/oct-obj.h	Wed Dec 07 19:06:13 2011 -0500
@@ -66,26 +66,6 @@
 
   ~octave_value_list (void) { }
 
-  void *operator new (size_t size)
-    { return allocator.alloc (size); }
-
-  void operator delete (void *p, size_t size)
-    { allocator.free (p, size); }
-
-  // FIXME -- without this, I have errors with the stack of
-  // octave_value_list objects in ov-usr-fcn.h.  Why?
-  void *operator new (size_t size, void *p)
-    { return ::operator new (size, p); }
-
-  void operator delete (void *p, void *)
-    {
-#if defined (HAVE_PLACEMENT_DELETE)
-      ::operator delete (p, static_cast<void *> (0));
-#else
-      ::operator delete (p);
-#endif
-    }
-
   octave_value_list& operator = (const octave_value_list& obj)
     {
       if (this != &obj)
@@ -167,8 +147,6 @@
 
 private:
 
-  static octave_allocator allocator;
-
   Array<octave_value> data;
 
   // This list of strings can be used to tag each element of data with
@@ -185,6 +163,8 @@
 
   const octave_value& elem (octave_idx_type n) const
     { return data(n); }
+
+  DECLARE_OCTAVE_ALLOCATOR
 };
 
 #endif
--- a/src/oct-parse.yy	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/oct-parse.yy	Wed Dec 07 19:06:13 2011 -0500
@@ -3565,7 +3565,11 @@
 
           int status = yyparse ();
 
-          delete global_command;
+          // Use an unwind-protect cleanup function so that the
+          // global_command list will be deleted in the event of an
+          // interrupt.
+
+          frame.add_fcn (cleanup_statement_list, &global_command);
 
           fcn_ptr = primary_fcn_ptr;
 
@@ -4345,6 +4349,14 @@
         {
           if (command_list)
             {
+              unwind_protect inner_frame;
+
+              // Use an unwind-protect cleanup function so that the
+              // global_command list will be deleted in the event of an
+              // interrupt.
+
+              inner_frame.add_fcn (cleanup_statement_list, &command_list);
+
               tree_statement *stmt = 0;
 
               if (command_list->length () == 1
@@ -4381,10 +4393,6 @@
               else
                 error ("eval: invalid use of statement list");
 
-              delete command_list;
-
-              command_list = 0;
-
               if (error_state
                   || tree_return_command::returning
                   || tree_break_command::breaking
@@ -4428,6 +4436,16 @@
   return eval_string (s, silent, parse_status, nargout);
 }
 
+void
+cleanup_statement_list (tree_statement_list **lst)
+{
+  if (*lst)
+    {
+      delete *lst;
+      *lst = 0;
+    }
+}
+
 DEFUN (eval, args, nargout,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} eval (@var{try}, @var{catch})\n\
--- a/src/oct-stream.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/oct-stream.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -40,8 +40,9 @@
 #include "lo-ieee.h"
 #include "lo-mappers.h"
 #include "lo-utils.h"
+#include "quit.h"
+#include "singleton-cleanup.h"
 #include "str-vec.h"
-#include "quit.h"
 
 #include "error.h"
 #include "gripes.h"
@@ -3916,7 +3917,12 @@
   bool retval = true;
 
   if (! instance)
-    instance = new octave_stream_list ();
+    {
+      instance = new octave_stream_list ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
--- a/src/oct-stream.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/oct-stream.h	Wed Dec 07 19:06:13 2011 -0500
@@ -37,6 +37,7 @@
 #include "data-conv.h"
 #include "lo-utils.h"
 #include "mach-info.h"
+#include "oct-refcount.h"
 
 class
 OCTINTERP_API
@@ -427,7 +428,7 @@
 private:
 
   // A reference count.
-  octave_idx_type count;
+  octave_refcount<octave_idx_type> count;
 
   // The permission bits for the file.  Should be some combination of
   // std::ios::open_mode bits.
@@ -689,6 +690,8 @@
 
   static octave_stream_list *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   int do_insert (octave_stream& os);
 
   octave_stream do_lookup (int fid, const std::string& who = std::string ()) const;
--- a/src/ov-base.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/ov-base.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -1530,6 +1530,7 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} sparse_auto_mutate ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} sparse_auto_mutate (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} sparse_auto_mutate (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether Octave will\n\
 automatically mutate sparse matrices to real matrices to save memory.\n\
 For example:\n\
@@ -1547,6 +1548,10 @@
 @result{} matrix\n\
 @end group\n\
 @end example\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (sparse_auto_mutate);
--- a/src/ov-range.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/ov-range.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -649,10 +649,15 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} allow_noninteger_range_as_index ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} allow_noninteger_range_as_index (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} allow_noninteger_range_as_index (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether non-integer\n\
 ranges are allowed as indices.  This might be useful for @sc{matlab}\n\
 compatibility; however, it is still not entirely compatible because\n\
 @sc{matlab} treats the range expression differently in different contexts.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (allow_noninteger_range_as_index);
--- a/src/ov-struct.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/ov-struct.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -2216,8 +2216,13 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} struct_levels_to_print ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} struct_levels_to_print (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} struct_levels_to_print (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the number of\n\
 structure levels to display.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE_WITH_LIMITS (struct_levels_to_print,
@@ -2228,11 +2233,16 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} print_struct_array_contents ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} print_struct_array_contents (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} print_struct_array_contents (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies whether to print struct\n\
 array contents.  If true, values of struct array elements are printed.\n\
 This variable does not affect scalar structures.  Their elements\n\
 are always printed.  In both cases, however, printing will be limited to\n\
 the number of levels specified by @var{struct_levels_to_print}.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (print_struct_array_contents);
--- a/src/ov-typeinfo.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/ov-typeinfo.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -24,10 +24,12 @@
 #include <config.h>
 #endif
 
-#include "ov-typeinfo.h"
+#include "Array.h"
+#include "singleton-cleanup.h"
 
 #include "defun.h"
 #include "error.h"
+#include "ov-typeinfo.h"
 
 const int
 octave_value_typeinfo::init_tab_sz (16);
@@ -35,14 +37,20 @@
 octave_value_typeinfo *
 octave_value_typeinfo::instance (0);
 
-#include <Array.h>
-
 bool
 octave_value_typeinfo::instance_ok (void)
 {
   bool retval = true;
+
   if (! instance)
-    instance = new octave_value_typeinfo ();
+    {
+      instance = new octave_value_typeinfo ();
+
+#if 0
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+#endif
+    }
 
   if (! instance)
     {
--- a/src/ov-typeinfo.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/ov-typeinfo.h	Wed Dec 07 19:06:13 2011 -0500
@@ -208,12 +208,16 @@
       type_conv_ops (dim_vector (init_tab_sz, init_tab_sz), 0),
       widening_ops (dim_vector (init_tab_sz, init_tab_sz), 0)  { }
 
+  ~octave_value_typeinfo (void) { }
+
 private:
 
   static const int init_tab_sz;
 
   static octave_value_typeinfo *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   int num_types;
 
   Array<std::string> types;
--- a/src/ov-usr-fcn.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/ov-usr-fcn.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -775,9 +775,14 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} optimize_subsasgn_calls ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} optimize_subsasgn_calls (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} optimize_subsasgn_calls (@var{new_val}, \"local\")\n\
 Query or set the internal flag for subsasgn method call optimizations.\n\
 If true, Octave will attempt to eliminate the redundant copying when calling\n\
 subsasgn method of a user-defined class.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (optimize_subsasgn_calls);
--- a/src/ov.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/ov.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -2714,6 +2714,83 @@
 %!assert (sizeof ({"foo", "bar", "baaz"}), 10)
 */
 
+static void
+decode_subscripts (const char* name, const octave_value& arg,
+                   std::string& type_string,
+                   std::list<octave_value_list>& idx)
+{
+  const octave_map m = arg.map_value ();
+
+  if (! error_state
+      && m.nfields () == 2 && m.contains ("type") && m.contains ("subs"))
+    {
+      octave_idx_type nel = m.numel ();
+
+      type_string = std::string (nel, '\0');
+      idx = std::list<octave_value_list> ();
+
+      if (nel == 0)
+        return;
+
+      const Cell type = m.contents ("type");
+      const Cell subs = m.contents ("subs");
+
+      for (int k = 0; k < nel; k++)
+        {
+          std::string item = type(k).string_value ();
+
+          if (! error_state)
+            {
+              if (item == "{}")
+                type_string[k] = '{';
+              else if (item == "()")
+                type_string[k] = '(';
+              else if (item == ".")
+                type_string[k] = '.';
+              else
+                {
+                  error("%s: invalid indexing type `%s'", name, item.c_str ());
+                  return;
+                }
+            }
+          else
+            {
+              error ("%s: expecting type(%d) to be a character string",
+                     name, k+1);
+              return;
+            }
+
+          octave_value_list idx_item;
+
+          if (subs(k).is_string ())
+            idx_item(0) = subs(k);
+          else if (subs(k).is_cell ())
+            {
+              Cell subs_cell = subs(k).cell_value ();
+
+              for (int n = 0; n < subs_cell.length (); n++)
+                {
+                  if (subs_cell(n).is_string ()
+                      && subs_cell(n).string_value () == ":")
+                    idx_item(n) = octave_value(octave_value::magic_colon_t);
+                  else
+                    idx_item(n) = subs_cell(n);
+                }
+            }
+          else
+            {
+              error ("%s: expecting subs(%d) to be a character string or cell array",
+                     name, k+1);
+              return;
+            }
+
+          idx.push_back (idx_item);
+        }
+    }
+  else
+    error ("%s: second argument must be a structure with fields `type' and `subs'", name);
+}
+
 DEFUN (subsref, args, nargout,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} subsref (@var{val}, @var{idx})\n\
@@ -2746,6 +2823,9 @@
 \n\
 @noindent\n\
 Note that this is the same as writing @code{val(:,1:2)}.\n\
+\n\
+If @var{idx} is an empty structure array with fields @samp{type}\n\
+and @samp{subs}, return @var{val}.\n\
 @seealso{subsasgn, substruct}\n\
 @end deftypefn")
 {
@@ -2760,8 +2840,12 @@
 
       if (! error_state)
         {
-          octave_value tmp = args(0);
-          retval = tmp.subsref (type, idx, nargout);
+          octave_value arg0 = args(0);
+
+          if (type.empty ())
+            retval = arg0;
+          else
+            retval = arg0.subsref (type, idx, nargout);
         }
     }
   else
@@ -2798,6 +2882,9 @@
 @end example\n\
 \n\
 Note that this is the same as writing @code{val(:,1:2) = 0}.\n\
+\n\
+If @var{idx} is an empty structure array with fields @samp{type}\n\
+and @samp{subs}, return @var{rhs}.\n\
 @seealso{subsref, substruct}\n\
 @end deftypefn")
 {
@@ -2810,12 +2897,24 @@
 
       decode_subscripts ("subsasgn", args(1), type, idx);
 
-      octave_value arg0 = args(0);
-
-      arg0.make_unique ();
-
       if (! error_state)
-        retval = arg0.subsasgn (type, idx, args(2));
+        {
+          if (type.empty ())
+            {
+              // Regularize a null matrix if stored into a variable.
+
+              retval = args(2).storable_value ();
+            }
+          else
+            {
+              octave_value arg0 = args(0);
+
+              arg0.make_unique ();
+
+              if (! error_state)
+                retval= arg0.subsasgn (type, idx, args(2));
+            }
+        }
     }
   else
     print_usage ();
@@ -2826,15 +2925,18 @@
 /*
 %!test
 %! a = reshape ([1:25], 5,5);
-%! idx1 = substruct ( "()", {3, 3});
-%! idx2 = substruct ( "()", {2:2:5, 2:2:5});
-%! idx3 = substruct ( "()", {":", [1,5]});
-%! assert (subsref (a, idx1), 13)
-%! assert (subsref (a, idx2), [7 17; 9 19])
-%! assert (subsref (a, idx3), [1:5; 21:25]')
+%! idx1 = substruct ("()", {3, 3});
+%! idx2 = substruct ("()", {2:2:5, 2:2:5});
+%! idx3 = substruct ("()", {":", [1,5]});
+%! idx4 = struct ("type", {}, "subs", {});
+%! assert (subsref (a, idx1), 13);
+%! assert (subsref (a, idx2), [7 17; 9 19]);
+%! assert (subsref (a, idx3), [1:5; 21:25]');
+%! assert (subsref (a, idx4), a);
 %! a = subsasgn (a, idx1, 0);
 %! a = subsasgn (a, idx2, 0);
 %! a = subsasgn (a, idx3, 0);
+%!# a = subsasgn (a, idx4, 0);
 %! b = [0    6   11   16    0
 %!      0    0   12    0    0
 %!      0    8    0   18    0
@@ -2844,23 +2946,26 @@
 
 %!test
 %! c = num2cell (reshape ([1:25],5,5));
-%! idx1 = substruct  ( "{}", {3, 3});
-%! idx2 = substruct  ( "()", {2:2:5, 2:2:5});
-%! idx3 = substruct  ( "()", {":", [1,5]});
-%! idx2p = substruct  ( "{}", {2:2:5, 2:2:5});
-%! idx3p = substruct  ( "{}", {":", [1,5]});
-%! assert ({ subsref(c, idx1) }, {13})
-%! assert ({ subsref(c, idx2p) }, {7 9 17 19})
-%! assert ({ subsref(c, idx3p) }, num2cell ([1:5, 21:25]))
+%! idx1 = substruct  ("{}", {3, 3});
+%! idx2 = substruct  ("()", {2:2:5, 2:2:5});
+%! idx3 = substruct  ("()", {":", [1,5]});
+%! idx2p = substruct ("{}", {2:2:5, 2:2:5});
+%! idx3p = substruct ("{}", {":", [1,5]});
+%! idx4 = struct ("type", {}, "subs", {});
+%! assert ({ subsref(c, idx1) }, {13});
+%! assert ({ subsref(c, idx2p) }, {7 9 17 19});
+%! assert ({ subsref(c, idx3p) }, num2cell ([1:5, 21:25]));
+%! assert (subsref(c, idx4), c);
 %! c = subsasgn (c, idx1, 0);
 %! c = subsasgn (c, idx2, 0);
 %! c = subsasgn (c, idx3, 0);
+%!# c = subsasgn (c, idx4, 0);
 %! d = {0    6   11   16    0
 %!      0    0   12    0    0
 %!      0    8    0   18    0
 %!      0    0   14    0    0
 %!      0   10   15   20    0};
-%! assert (c,d);
+%! assert (c, d);
 
 %!test
 %! s.a = "ohai";
@@ -2869,16 +2974,19 @@
 %! idx1 = substruct (".", "a");
 %! idx2 = substruct (".", "b");
 %! idx3 = substruct (".", "c");
-%! assert (subsref (s, idx1), "ohai")
-%! assert (subsref (s, idx2), "dere")
-%! assert (subsref (s, idx3), 42)
+%! idx4 = struct ("type", {}, "subs", {});
+%! assert (subsref (s, idx1), "ohai");
+%! assert (subsref (s, idx2), "dere");
+%! assert (subsref (s, idx3), 42);
+%! assert (subsref (s, idx4), s);
 %! s = subsasgn (s, idx1, "Hello");
 %! s = subsasgn (s, idx2, "There");
 %! s = subsasgn (s, idx3, 163);
+%!# s = subsasgn (s, idx4, 163);
 %! t.a = "Hello";
 %! t.b = "There";
 %! t.c = 163;
-%! assert (s, t)
+%! assert (s, t);
 
 */
 
--- a/src/ov.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/ov.h	Wed Dec 07 19:06:13 2011 -0500
@@ -315,8 +315,12 @@
     {
       if (rep->count > 1)
         {
-          --rep->count;
-          rep = rep->unique_clone ();
+	  octave_base_value *r = rep->unique_clone ();
+
+          if (--rep->count == 0)
+            delete rep;
+
+          rep = r;
         }
     }
 
@@ -327,8 +331,12 @@
     {
       if (rep->count > obsolete_copies + 1)
         {
-          --rep->count;
-          rep = rep->unique_clone ();
+          octave_base_value *r = rep->unique_clone ();
+
+          if (--rep->count == 0)
+            delete rep;
+
+          rep = r;
         }
     }
 
--- a/src/pager.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/pager.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -30,16 +30,16 @@
 
 #include "cmd-edit.h"
 #include "oct-env.h"
+#include "singleton-cleanup.h"
 
-#include "procstream.h"
-
-#include <defaults.h>
+#include "defaults.h"
 #include "defun.h"
 #include "error.h"
 #include "gripes.h"
 #include "input.h"
 #include "oct-obj.h"
 #include "pager.h"
+#include "procstream.h"
 #include "sighandlers.h"
 #include "unwind-prot.h"
 #include "utils.h"
@@ -311,27 +311,24 @@
   delete pb;
 }
 
-octave_pager_stream&
+std::ostream&
 octave_pager_stream::stream (void)
 {
-  if (! instance)
-    instance = new octave_pager_stream ();
-
-  return *instance;
+  return instance_ok () ? *instance : std::cout;
 }
 
 void
 octave_pager_stream::flush_current_contents_to_diary (void)
 {
-  if (pb)
-    pb->flush_current_contents_to_diary ();
+  if (instance_ok ())
+    instance->flush_current_contents_to_diary ();
 }
 
 void
 octave_pager_stream::set_diary_skip (void)
 {
-  if (pb)
-    pb->set_diary_skip ();
+  if (instance_ok ())
+    instance->do_set_diary_skip ();
 }
 
 // Reinitialize the pager buffer to avoid hanging on to large internal
@@ -342,10 +339,22 @@
 void
 octave_pager_stream::reset (void)
 {
-  if (! instance)
-    instance = new octave_pager_stream ();
+  if (instance_ok ())
+    instance->do_reset ();
+}
 
-  instance->do_reset ();
+void
+octave_pager_stream::do_flush_current_contents_to_diary (void)
+{
+  if (pb)
+    pb->flush_current_contents_to_diary ();
+}
+
+void
+octave_pager_stream::do_set_diary_skip (void)
+{
+  if (pb)
+    pb->set_diary_skip ();
 }
 
 void
@@ -357,6 +366,29 @@
   setf (unitbuf);
 }
 
+bool
+octave_pager_stream::instance_ok (void)
+{
+  bool retval = true;
+
+  if (! instance)
+    {
+      instance = new octave_pager_stream ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
+
+  if (! instance)
+    {
+      ::error ("unable to create pager_stream object!");
+
+      retval = false;
+    }
+
+  return retval;
+}
+
 octave_diary_stream *octave_diary_stream::instance = 0;
 
 octave_diary_stream::octave_diary_stream (void) : std::ostream (0), db (0)
@@ -372,13 +404,10 @@
   delete db;
 }
 
-octave_diary_stream&
+std::ostream&
 octave_diary_stream::stream (void)
 {
-  if (! instance)
-    instance = new octave_diary_stream ();
-
-  return *instance;
+  return instance_ok () ? *instance : std::cout;
 }
 
 // Reinitialize the diary buffer to avoid hanging on to large internal
@@ -389,10 +418,8 @@
 void
 octave_diary_stream::reset (void)
 {
-  if (! instance)
-    instance = new octave_diary_stream ();
-
-  instance->do_reset ();
+  if (instance_ok ())
+    instance->do_reset ();
 }
 
 void
@@ -404,6 +431,29 @@
   setf (unitbuf);
 }
 
+bool
+octave_diary_stream::instance_ok (void)
+{
+  bool retval = true;
+
+  if (! instance)
+    {
+      instance = new octave_diary_stream ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
+
+  if (! instance)
+    {
+      ::error ("unable to create diary_stream object!");
+
+      retval = false;
+    }
+
+  return retval;
+}
+
 void
 flush_octave_stdout (void)
 {
@@ -437,7 +487,7 @@
   //
   // will do the right thing.
 
-  octave_stdout.flush_current_contents_to_diary ();
+  octave_pager_stream::flush_current_contents_to_diary ();
 
   if (external_diary_file.is_open ())
     {
@@ -454,7 +504,7 @@
   // If there is pending output in the pager buf, it should not go
   // into the diary file.
 
-  octave_stdout.set_diary_skip ();
+  octave_pager_stream::set_diary_skip ();
 
   external_diary_file.open (diary_file.c_str (), std::ios::app);
 
@@ -591,10 +641,15 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} page_output_immediately ()\n\
 @deftypefnx {Built-in Function} {@var{val} =} page_output_immediately (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} page_output_immediately (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether Octave sends\n\
 output to the pager as soon as it is available.  Otherwise, Octave\n\
 buffers its output and waits until just before the prompt is printed to\n\
 flush it to the pager.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (page_output_immediately);
@@ -604,11 +659,16 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} page_screen_output ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} page_screen_output (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} page_screen_output (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether output intended\n\
 for the terminal window that is longer than one page is sent through a\n\
 pager.  This allows you to view one screenful at a time.  Some pagers\n\
 (such as @code{less}---see @ref{Installation}) are also capable of moving\n\
 backward on the output.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (page_screen_output);
@@ -618,11 +678,16 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} PAGER ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} PAGER (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} PAGER (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the program to use\n\
 to display terminal output on your system.  The default value is\n\
 normally @code{\"less\"}, @code{\"more\"}, or\n\
 @code{\"pg\"}, depending on what programs are installed on your system.\n\
 @xref{Installation}.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{more, page_screen_output, page_output_immediately, PAGER_FLAGS}\n\
 @end deftypefn")
 {
@@ -633,8 +698,13 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} PAGER_FLAGS ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} PAGER_FLAGS (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} PAGER_FLAGS (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the options to pass\n\
 to the pager.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{PAGER}\n\
 @end deftypefn")
 {
--- a/src/pager.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/pager.h	Wed Dec 07 19:06:13 2011 -0500
@@ -62,20 +62,28 @@
 
   ~octave_pager_stream (void);
 
-  void flush_current_contents_to_diary (void);
+  static void flush_current_contents_to_diary (void);
 
-  void set_diary_skip (void);
+  static void set_diary_skip (void);
 
-  static octave_pager_stream& stream (void);
+  static std::ostream& stream (void);
 
   static void reset (void);
 
 private:
 
+  void do_flush_current_contents_to_diary (void);
+
+  void do_set_diary_skip (void);
+
   void do_reset (void);
 
   static octave_pager_stream *instance;
 
+  static bool instance_ok (void);
+
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   octave_pager_buf *pb;
 
   // No copying!
@@ -110,7 +118,7 @@
 
   ~octave_diary_stream (void);
 
-  static octave_diary_stream& stream (void);
+  static std::ostream& stream (void);
 
   static void reset (void);
 
@@ -120,6 +128,10 @@
 
   static octave_diary_stream *instance;
 
+  static bool instance_ok (void);
+
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   octave_diary_buf *db;
 
   // No copying!
--- a/src/parse.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/parse.h	Wed Dec 07 19:06:13 2011 -0500
@@ -36,6 +36,7 @@
 class tree;
 class tree_matrix;
 class tree_identifier;
+class tree_statement_list;
 class octave_function;
 
 #include "oct-obj.h"
@@ -113,4 +114,6 @@
 extern OCTINTERP_API octave_value
 eval_string (const std::string&, bool silent, int& parse_status);
 
+extern OCTINTERP_API void cleanup_statement_list (tree_statement_list **lst);
+
 #endif
--- a/src/pr-output.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/pr-output.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -3952,6 +3952,7 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} fixed_point_format ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} fixed_point_format (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} fixed_point_format (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether Octave will\n\
 use a scaled format to print matrix values such that the largest\n\
 element may be written with a single leading digit with the scaling\n\
@@ -3976,6 +3977,10 @@
 Notice that first value appears to be zero when it is actually 1.  For\n\
 this reason, you should be careful when setting\n\
 @code{fixed_point_format} to a nonzero value.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{format, output_max_field_width, output_precision}\n\
 @end deftypefn")
 {
@@ -3986,6 +3991,7 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} print_empty_dimensions ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} print_empty_dimensions (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} print_empty_dimensions (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether the\n\
 dimensions of empty matrices are printed along with the empty matrix\n\
 symbol, @samp{[]}.  For example, the expression\n\
@@ -4000,6 +4006,10 @@
 @example\n\
 ans = [](3x0)\n\
 @end example\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{format}\n\
 @end deftypefn")
 {
@@ -4010,6 +4020,7 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} split_long_rows ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} split_long_rows (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} split_long_rows (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether rows of a matrix\n\
 may be split when displayed to a terminal window.  If the rows are split,\n\
 Octave will display the matrix in a series of smaller pieces, each of\n\
@@ -4033,6 +4044,10 @@
   0.44672  0.94303  0.56564  0.82150\n\
 @end group\n\
 @end example\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{format}\n\
 @end deftypefn")
 {
@@ -4043,8 +4058,13 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} output_max_field_width ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} output_max_field_width (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} output_max_field_width (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the maximum width\n\
 of a numeric output field.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{format, fixed_point_format, output_precision}\n\
 @end deftypefn")
 {
@@ -4055,8 +4075,13 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} output_precision ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} output_precision (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} output_precision (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the minimum number of\n\
 significant figures to display for numeric output.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{format, fixed_point_format, output_max_field_width}\n\
 @end deftypefn")
 {
--- a/src/pt-binop.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/pt-binop.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -282,6 +282,7 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} do_braindead_shortcircuit_evaluation ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} do_braindead_shortcircuit_evaluation (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} do_braindead_shortcircuit_evaluation (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether Octave will\n\
 do short-circuit evaluation of @samp{|} and @samp{&} operators inside the\n\
 conditions of if or while statements.\n\
@@ -291,6 +292,10 @@
 \n\
 To obtain short-circuit behavior for logical expressions in new programs,\n\
 you should always use the @samp{&&} and @samp{||} operators.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (do_braindead_shortcircuit_evaluation);
--- a/src/pt-const.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/pt-const.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -34,8 +34,7 @@
 
 // We are likely to have a lot of tree_constant objects to allocate,
 // so make the grow_size large.
-octave_allocator
-tree_constant::allocator (sizeof (tree_constant), 1024);
+DEFINE_OCTAVE_ALLOCATOR2 (tree_constant, 1024);
 
 void
 tree_constant::print (std::ostream& os, bool pr_as_read_syntax, bool pr_orig_text)
--- a/src/pt-const.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/pt-const.h	Wed Dec 07 19:06:13 2011 -0500
@@ -55,10 +55,6 @@
 
   bool has_magic_end (void) const { return false; }
 
-  void *operator new (size_t size) { return allocator.alloc (size); }
-
-  void operator delete (void *p, size_t size) { allocator.free (p, size); }
-
   // Type.  It would be nice to eliminate the need for this.
 
   bool is_constant (void) const { return true; }
@@ -91,9 +87,6 @@
 
 private:
 
-  // For custom memory management.
-  static octave_allocator allocator;
-
   // The actual value that this constant refers to.
   octave_value val;
 
@@ -105,6 +98,8 @@
   tree_constant (const tree_constant&);
 
   tree_constant& operator = (const tree_constant&);
+
+  DECLARE_OCTAVE_ALLOCATOR
 };
 
 #endif
--- a/src/pt-eval.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/pt-eval.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -1196,9 +1196,14 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} max_recursion_depth ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} max_recursion_depth (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} max_recursion_depth (@var{new_val}, \"local\")\n\
 Query or set the internal limit on the number of times a function may\n\
 be called recursively.  If the limit is exceeded, an error message is\n\
 printed and control returns to the top level.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (max_recursion_depth);
@@ -1219,10 +1224,15 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} silent_functions ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} silent_functions (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} silent_functions (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether internal\n\
 output from a function is suppressed.  If this option is disabled,\n\
 Octave will display the results produced by evaluating expressions\n\
 within a function body that are not terminated with a semicolon.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (silent_functions);
--- a/src/pt-idx.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/pt-idx.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -113,6 +113,13 @@
       delete *p;
       args.erase (p);
     }
+
+  while (! dyn_field.empty ())
+    {
+      std::list<tree_expression *>::iterator p = dyn_field.begin ();
+      delete *p;
+      dyn_field.erase (p);
+    }
 }
 
 bool
--- a/src/pt-loop.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/pt-loop.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -91,6 +91,7 @@
 
 tree_simple_for_command::~tree_simple_for_command (void)
 {
+  delete lhs;
   delete expr;
   delete maxproc;
   delete list;
@@ -119,6 +120,7 @@
 
 tree_complex_for_command::~tree_complex_for_command (void)
 {
+  delete lhs;
   delete expr;
   delete list;
   delete lead_comm;
--- a/src/pt-mat.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/pt-mat.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -1391,6 +1391,7 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} string_fill_char ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} string_fill_char (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} string_fill_char (@var{new_val}, \"local\")\n\
 Query or set the internal variable used to pad all rows of a character\n\
 matrix to the same length.  It must be a single character.  The default\n\
 value is @code{\" \"} (a single space).  For example:\n\
@@ -1404,6 +1405,10 @@
         \"strings\"\n\
 @end group\n\
 @end example\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (string_fill_char);
--- a/src/sighandlers.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/sighandlers.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -35,6 +35,7 @@
 #include "cmd-edit.h"
 #include "oct-syscalls.h"
 #include "quit.h"
+#include "singleton-cleanup.h"
 
 #include "debug.h"
 #include "defun.h"
@@ -804,7 +805,12 @@
   bool retval = true;
 
   if (! instance)
-    instance = new octave_child_list_rep ();
+    {
+      instance = new octave_child_list_rep ();
+
+      if (instance)
+        singleton_cleanup_list::add (cleanup_instance);
+    }
 
   if (! instance)
     {
@@ -955,10 +961,15 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} debug_on_interrupt ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} debug_on_interrupt (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} debug_on_interrupt (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether Octave will try\n\
 to enter debugging mode when it receives an interrupt signal (typically\n\
 generated with @kbd{C-c}).  If a second interrupt signal is received\n\
 before reaching the debugging mode, a normal interrupt will occur.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (debug_on_interrupt);
@@ -979,9 +990,14 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} sighup_dumps_octave_core ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} sighup_dumps_octave_core (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} sighup_dumps_octave_core (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether Octave tries\n\
 to save all current variables to the file \"octave-core\" if it receives\n\
 a hangup signal.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (sighup_dumps_octave_core);
@@ -1002,9 +1018,14 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} sigterm_dumps_octave_core ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} sigterm_dumps_octave_core (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} sigterm_dumps_octave_core (@var{new_val}, \"local\")\n\
 Query or set the internal variable that controls whether Octave tries\n\
 to save all current variables to the file \"octave-core\" if it receives\n\
 a terminate signal.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (sigterm_dumps_octave_core);
--- a/src/sighandlers.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/sighandlers.h	Wed Dec 07 19:06:13 2011 -0500
@@ -170,6 +170,8 @@
   static bool instance_ok (void);
 
   static octave_child_list_rep *instance;
+
+  static void cleanup_instance (void) { delete instance; instance = 0; }
 };
 
 #endif
--- a/src/strfns.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/strfns.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -332,8 +332,8 @@
 %!assert(ischar ("test"), logical (1));
 %!assert(ischar (["test"; "ing"]), logical (1));
 %!assert(ischar (struct ("foo", "bar")), logical (0));
-%!error <Invalid call to ischar.*> ischar ();
-%!error <Invalid call to ischar.*> ischar ("test", 1);
+%!error <Invalid call to ischar> ischar ();
+%!error <Invalid call to ischar> ischar ("test", 1);
 */
 
 static octave_value
@@ -589,8 +589,8 @@
 }
 
 /*
-%!error <Invalid call to strcmp.*> strcmp ();
-%!error <Invalid call to strcmp.*> strcmp ("foo", "bar", 3);
+%!error <Invalid call to strcmp> strcmp ();
+%!error <Invalid call to strcmp> strcmp ("foo", "bar", 3);
 %!
 %!shared x
 %!  x = char (zeros (0, 2));
@@ -712,8 +712,8 @@
 }
 
 /*
-%!error <Invalid call to strncmp.*> strncmp ();
-%!error <Invalid call to strncmp.*> strncmp ("abc", "def");
+%!error <Invalid call to strncmp> strncmp ();
+%!error <Invalid call to strncmp> strncmp ("abc", "def");
 %!assert (strncmp ("abce", "abc", 3) == 1)
 %!assert (strncmp (100, 100, 1) == 0)
 %!assert (all (strncmp ("abce", {"abcd", "bca", "abc"}, 3) == [1, 0, 1]))
@@ -922,9 +922,9 @@
 }
 
 /*
-%!error <Invalid call to list_in_columns.*> list_in_columns ();
-%!error <Invalid call to list_in_columns.*> list_in_columns (["abc", "def"], 20, 2);
-%!error <invalid conversion from string to real scalar.*> list_in_columns (["abc", "def"], "a");
+%!error <Invalid call to list_in_columns> list_in_columns ();
+%!error <Invalid call to list_in_columns> list_in_columns (["abc", "def"], 20, 2);
+%!error <invalid conversion from string to real scalar> list_in_columns (["abc", "def"], "a");
 %!test
 %!  input  = {"abc", "def", "ghijkl", "mnop", "qrs", "tuv"};
 %!  result = "abc     mnop\ndef     qrs\nghijkl  tuv\n";
--- a/src/symtab.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/symtab.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -25,24 +25,25 @@
 #include <config.h>
 #endif
 
+#include "file-ops.h"
+#include "file-stat.h"
 #include "oct-env.h"
 #include "oct-time.h"
-#include "file-ops.h"
-#include "file-stat.h"
+#include "singleton-cleanup.h"
 
+#include "debug.h"
 #include "defun.h"
 #include "dirfns.h"
 #include "input.h"
 #include "load-path.h"
-#include "symtab.h"
 #include "ov-fcn.h"
 #include "ov-usr-fcn.h"
 #include "pager.h"
 #include "parse.h"
 #include "pt-arg-list.h"
+#include "symtab.h"
 #include "unwind-prot.h"
 #include "utils.h"
-#include "debug.h"
 
 symbol_table *symbol_table::instance = 0;
 
@@ -70,6 +71,14 @@
 static int Vignore_function_time_stamp = 1;
 
 void
+symbol_table::scope_id_cache::create_instance (void)
+{
+  instance = new scope_id_cache ();
+
+  singleton_cleanup_list::add (cleanup_instance);
+}
+
+void
 symbol_table::symbol_record::symbol_record_rep::dump
   (std::ostream& os, const std::string& prefix) const
 {
@@ -674,7 +683,7 @@
                   octave_value& fval = q->second;
 
                   if (fval.is_defined ())
-                    out_of_date_check (fval);
+                    out_of_date_check (fval, "", false);
 
                   if (fval.is_defined ())
                     return fval;
--- a/src/symtab.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/symtab.h	Wed Dec 07 19:06:13 2011 -0500
@@ -37,6 +37,7 @@
 class octave_user_function;
 
 #include "oct-obj.h"
+#include "oct-refcount.h"
 #include "ov.h"
 
 class
@@ -81,12 +82,14 @@
       return instance_ok () ? instance->do_scopes () : std::list<scope_id> ();
     }
 
+    static void create_instance (void);
+
     static bool instance_ok (void)
     {
       bool retval = true;
 
       if (! instance)
-        instance = new scope_id_cache ();
+        create_instance ();
 
       if (! instance)
         {
@@ -108,6 +111,8 @@
 
     static scope_id_cache *instance;
 
+    static void cleanup_instance (void) { delete instance; instance = 0; }
+
     // The next available scope not in the free list.
     scope_id next_available;
 
@@ -383,7 +388,7 @@
 
       fcn_info *finfo;
 
-      size_t count;
+      octave_refcount<size_t> count;
 
     private:
 
@@ -724,7 +729,7 @@
 
       octave_value built_in_function;
 
-      size_t count;
+      octave_refcount<size_t> count;
 
     private:
 
--- a/src/sysdep.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/sysdep.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -110,8 +110,11 @@
 {
   std::string bin_dir;
 
-  HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE |
-				       TH32CS_SNAPMODULE32, 0);
+  HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE
+#ifdef TH32CS_SNAPMODULE32
+                                       | TH32CS_SNAPMODULE32
+#endif
+                                       , 0);
 
   if (h != INVALID_HANDLE_VALUE)
     {
@@ -893,7 +896,7 @@
 %!   setenv ("HOME", "foobar");
 %! endif
 %! home = getenv ("HOME");
-%! assert (tilde_expand ("~/foobar"), [home filesep() "foobar"]);
+%! assert (tilde_expand ("~/foobar"), strcat (home, "/foobar"));
 %! assert (tilde_expand ("/foo/bar"), "/foo/bar");
 %! assert (tilde_expand ("foo/bar"), "foo/bar");
 */
--- a/src/toplev.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/toplev.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -44,25 +44,26 @@
 #include "lo-error.h"
 #include "lo-mappers.h"
 #include "oct-env.h"
+#include "oct-locbuf.h"
 #include "quit.h"
+#include "singleton-cleanup.h"
 #include "str-vec.h"
-#include "oct-locbuf.h"
 
-#include <defaults.h>
+#include "defaults.h"
 #include "defun.h"
 #include "error.h"
 #include "file-io.h"
 #include "input.h"
 #include "lex.h"
-#include <oct-conf.h>
+#include "oct-conf.h"
 #include "oct-hist.h"
 #include "oct-map.h"
 #include "oct-obj.h"
+#include "ov.h"
 #include "pager.h"
 #include "parse.h"
 #include "pathsearch.h"
 #include "procstream.h"
-#include "ov.h"
 #include "pt-eval.h"
 #include "pt-jump.h"
 #include "pt-stmt.h"
@@ -73,7 +74,7 @@
 #include "unwind-prot.h"
 #include "utils.h"
 #include "variables.h"
-#include <version.h>
+#include "version.h"
 
 void (*octave_exit) (int) = ::exit;
 
@@ -97,6 +98,19 @@
 
 octave_call_stack *octave_call_stack::instance = 0;
 
+void
+octave_call_stack::create_instance (void)
+{
+  instance = new octave_call_stack ();
+
+  if (instance)
+    {
+      instance->do_push (0, symbol_table::top_scope (), 0);
+
+      singleton_cleanup_list::add (cleanup_instance);
+    }
+}
+
 int
 octave_call_stack::do_current_line (void) const
 {
@@ -571,11 +585,13 @@
             {
               if (global_command)
                 {
-                  global_command->accept (*current_evaluator);
+                  // Use an unwind-protect cleanup function so that the
+                  // global_command list will be deleted in the event of
+                  // an interrupt.
 
-                  delete global_command;
+                  frame.add_fcn (cleanup_statement_list, &global_command);
 
-                  global_command = 0;
+                  global_command->accept (*current_evaluator);
 
                   octave_quit ();
 
@@ -672,10 +688,16 @@
   do_octave_atexit ();
 
   // Clean up symbol table.
-  SAFE_CALL (symbol_table::cleanup, ());
+  SAFE_CALL (symbol_table::cleanup, ())
+
+  SAFE_CALL (cleanup_parser, ())
 
   SAFE_CALL (sysdep_cleanup, ())
 
+  SAFE_CALL (singleton_cleanup_list::cleanup, ())
+
+  SAFE_CALL (octave_chunk_buffer::clear, ())
+
   if (octave_exit)
     (*octave_exit) (retval == EOF ? 0 : retval);
 }
@@ -705,9 +727,13 @@
 
       if (! error_state)
         {
-          quitting_gracefully = true;
+          // Instead of simply calling exit, we simulate an interrupt
+          // with a request to exit cleanly so that no matter where the
+          // call to quit occurs, we will run the unwind_protect stack,
+          // clear the OCTAVE_LOCAL_BUFFER allocations, etc. before
+          // exiting.
 
-          // Simulate interrupt.
+          quitting_gracefully = true;
 
           octave_interrupt_state = -1;
 
--- a/src/toplev.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/toplev.h	Wed Dec 07 19:06:13 2011 -0500
@@ -112,22 +112,20 @@
   typedef std::deque<call_stack_elt>::reverse_iterator reverse_iterator;
   typedef std::deque<call_stack_elt>::const_reverse_iterator const_reverse_iterator;
 
+  static void create_instance (void);
+  
   static bool instance_ok (void)
   {
     bool retval = true;
 
     if (! instance)
-      {
-        instance = new octave_call_stack ();
+      create_instance ();
 
-        if (instance)
-          instance->do_push (0, symbol_table::top_scope (), 0);
-        else
-          {
-            ::error ("unable to create call stack object!");
+    if (! instance)
+      {
+        ::error ("unable to create call stack object!");
 
-            retval = false;
-          }
+        retval = false;
       }
 
     return retval;
@@ -300,6 +298,8 @@
 
   static octave_call_stack *instance;
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   int do_current_line (void) const;
 
   int do_current_column (void) const;
--- a/src/txt-eng-ft.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/txt-eng-ft.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -24,14 +24,16 @@
 #include <config.h>
 #endif
 
-#if HAVE_FREETYPE
+#if defined (HAVE_FREETYPE)
 
-#if HAVE_FONTCONFIG
+#if defined (HAVE_FONTCONFIG)
 #include <fontconfig/fontconfig.h>
 #endif
 
 #include <iostream>
 
+#include "singleton-cleanup.h"
+
 #include "error.h"
 #include "pr-output.h"
 #include "txt-eng-ft.h"
@@ -72,7 +74,12 @@
       bool retval = true;
 
       if (! instance)
-        instance = new ft_manager ();
+        {
+          instance = new ft_manager ();
+
+          if (instance)
+            singleton_cleanup_list::add (cleanup_instance);
+        }
 
       if (! instance)
         {
@@ -84,6 +91,8 @@
       return retval;
     }
 
+  static void cleanup_instance (void) { delete instance; instance = 0; }
+
   static FT_Face get_font (const std::string& name, const std::string& weight,
                            const std::string& angle, double size)
     { return (instance_ok ()
@@ -102,37 +111,39 @@
 
   ft_manager& operator = (const ft_manager&);
 
-  ft_manager (void) : library ()
-#if HAVE_FONTCONFIG
-    , fc_init_done (false)
-#endif
+  ft_manager (void)
+    : library (), freetype_initialized (false), fontconfig_initialized (false)
     {
       if (FT_Init_FreeType (&library))
-        {
-          ::error ("unable to initialize freetype library");
-        }
+        ::error ("unable to initialize freetype library");
+      else
+        freetype_initialized = true;
 
-#if HAVE_FONTCONFIG
-      fc_init_done = false;
+#if defined (HAVE_FONTCONFIG)
       if (! FcInit ())
-        {
-          ::error ("unable to initialize fontconfig library");
-        }
+        ::error ("unable to initialize fontconfig library");
       else
-        {
-          fc_init_done = true;
-        }
+        fontconfig_initialized = true;
 #endif
     }
 
   ~ft_manager (void)
     {
-#if HAVE_FONTCONFIG
-      FcFini ();
-      fc_init_done = false;
+      if (freetype_initialized)
+        FT_Done_FreeType (library);
+
+#if defined (HAVE_FONTCONFIG)
+      // FIXME -- Skip the call to FcFini because it can trigger the
+      // assertion
+      //
+      //   octave: fccache.c:507: FcCacheFini: Assertion `fcCacheChains[i] == ((void *)0)' failed.
+      //
+      // if (fontconfig_initialized)
+      //   FcFini ();
 #endif
     }
 
+
   FT_Face do_get_font (const std::string& name, const std::string& weight,
                        const std::string& angle, double size)
     {
@@ -140,8 +151,8 @@
 
       std::string file;
 
-#if HAVE_FONTCONFIG
-      if (fc_init_done)
+#if defined (HAVE_FONTCONFIG)
+      if (fontconfig_initialized)
         {
           int fc_weight, fc_angle;
 
@@ -218,9 +229,8 @@
 
 private:
   FT_Library library;
-#if HAVE_FONTCONFIG
-  bool fc_init_done;
-#endif
+  bool freetype_initialized;
+  bool fontconfig_initialized;
 };
 
 ft_manager* ft_manager::instance = 0;
--- a/src/utils.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/utils.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -36,6 +36,8 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include "vasnprintf.h"
+
 #include "quit.h"
 
 #include "dir-ops.h"
@@ -1162,79 +1164,6 @@
   return retval;
 }
 
-void
-decode_subscripts (const char* name, const octave_value& arg,
-                   std::string& type_string,
-                   std::list<octave_value_list>& idx)
-{
-  const octave_map m = arg.map_value ();
-
-  if (! error_state
-      && m.nfields () == 2 && m.contains ("type") && m.contains ("subs"))
-    {
-      const Cell type = m.contents ("type");
-      const Cell subs = m.contents ("subs");
-
-      octave_idx_type nel = type.numel ();
-
-      type_string = std::string (nel, '\0');
-
-      for (int k = 0; k < nel; k++)
-        {
-          std::string item = type(k).string_value ();
-
-          if (! error_state)
-            {
-              if (item == "{}")
-                type_string[k] = '{';
-              else if (item == "()")
-                type_string[k] = '(';
-              else if (item == ".")
-                type_string[k] = '.';
-              else
-                {
-                  error("%s: invalid indexing type `%s'", name, item.c_str ());
-                  return;
-                }
-            }
-          else
-            {
-              error ("%s: expecting type(%d) to be a character string",
-                     name, k+1);
-              return;
-            }
-
-          octave_value_list idx_item;
-
-          if (subs(k).is_string ())
-            idx_item(0) = subs(k);
-          else if (subs(k).is_cell ())
-            {
-              Cell subs_cell = subs(k).cell_value ();
-
-              for (int n = 0; n < subs_cell.length (); n++)
-                {
-                  if (subs_cell(n).is_string ()
-                      && subs_cell(n).string_value () == ":")
-                    idx_item(n) = octave_value(octave_value::magic_colon_t);
-                  else
-                    idx_item(n) = subs_cell(n);
-                }
-            }
-          else
-            {
-              error ("%s: expecting subs(%d) to be a character string or cell array",
-                     name, k+1);
-              return;
-            }
-
-          idx.push_back (idx_item);
-        }
-    }
-  else
-    error ("%s: second argument must be a structure with fields `type' and `subs'", name);
-}
-
 Matrix
 identity_matrix (octave_idx_type nr, octave_idx_type nc)
 {
@@ -1267,10 +1196,10 @@
   return m;
 }
 
-int
+size_t
 octave_format (std::ostream& os, const char *fmt, ...)
 {
-  int retval = -1;
+  size_t retval;
 
   va_list args;
   va_start (args, fmt);
@@ -1282,123 +1211,43 @@
   return retval;
 }
 
-int
+size_t
 octave_vformat (std::ostream& os, const char *fmt, va_list args)
 {
-  int retval = -1;
+  std::string s = octave_vasprintf (fmt, args);
 
-#if defined (__GNUG__) && !CXX_ISO_COMPLIANT_LIBRARY
+  os << s;
 
-  std::streambuf *sb = os.rdbuf ();
+  return s.length ();
+}
 
-  if (sb)
-    {
-      BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
+std::string
+octave_vasprintf (const char *fmt, va_list args)
+{
+  std::string retval;
+
+  char *result;
 
-      retval = sb->vform (fmt, args);
+  int status = gnulib::vasprintf (&result, fmt, args);
 
-      END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
+  if (status >= 0)
+    {
+      retval = result;
+      ::free (result);
     }
 
-#else
-
-  char *s = octave_vsnprintf (fmt, args);
-
-  if (s)
-    {
-      os << s;
-
-      retval = strlen (s);
-    }
-
-#endif
-
   return retval;
 }
 
-// We manage storage.  User should not free it, and its contents are
-// only valid until next call to vsnprintf.
-
-// Interrupts might happen if someone makes a call with something that
-// will require a very large buffer.  If we are interrupted in that
-// case, we should make the buffer size smaller for the next call.
-
-#define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_FOR_VSNPRINTF \
-  BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_1; \
-  delete [] buf; \
-  buf = 0; \
-  size = initial_size; \
-  octave_rethrow_exception (); \
-  BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_2
-
-#if defined __GNUC__ && defined __va_copy
-#define SAVE_ARGS(saved_args, args) __va_copy (saved_args, args)
-#elif defined va_copy
-#define SAVE_ARGS(saved_args, args) va_copy (saved_args, args)
-#else
-#define SAVE_ARGS(saved_args, args) saved_args = args
-#endif
-
-char *
-octave_vsnprintf (const char *fmt, va_list args)
+std::string
+octave_asprintf (const char *fmt, ...)
 {
-  static const size_t initial_size = 100;
-
-  static size_t size = initial_size;
-
-  static char *buf = 0;
-
-  volatile int nchars = 0;
-
-  if (! buf)
-    buf = new char [size];
-
-  if (! buf)
-    return 0;
-
-  while (1)
-    {
-      va_list saved_args;
-
-      SAVE_ARGS (saved_args, args);
-
-      BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_FOR_VSNPRINTF;
-
-      nchars = octave_raw_vsnprintf (buf, size, fmt, saved_args);
-
-      va_end (saved_args);
-
-      END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
-
-      // Cast to avoid signed/unsigned comparison is safe due to
-      // short-circuiting
-      if (nchars > -1 && static_cast<size_t>(nchars) < size)
-        break;
-      else
-        {
-          delete [] buf;
-
-          size = nchars + 1;;
-
-          buf = new char [size];
-
-          if (! buf)
-            return 0;
-        }
-    }
-
-  return buf;
-}
-
-char *
-octave_snprintf (const char *fmt, ...)
-{
-  char *retval = 0;
+  std::string retval;
 
   va_list args;
   va_start (args, fmt);
 
-  retval = octave_vsnprintf (fmt, args);
+  retval = octave_vasprintf (fmt, args);
 
   va_end (args);
 
--- a/src/utils.h	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/utils.h	Wed Dec 07 19:06:13 2011 -0500
@@ -97,26 +97,22 @@
 extern OCTINTERP_API octave_idx_type
 dims_to_numel (const dim_vector& dims, const octave_value_list& idx);
 
-extern OCTINTERP_API void
-decode_subscripts (const char* name, const octave_value& arg,
-                   std::string& type_string,
-                   std::list<octave_value_list>& idx);
-
 extern OCTINTERP_API Matrix
 identity_matrix (octave_idx_type nr, octave_idx_type nc);
 
 extern OCTINTERP_API FloatMatrix
 float_identity_matrix (octave_idx_type nr, octave_idx_type nc);
 
-extern OCTINTERP_API int
+extern OCTINTERP_API size_t
 octave_format (std::ostream& os, const char *fmt, ...);
 
-extern OCTINTERP_API int
+extern OCTINTERP_API size_t
 octave_vformat (std::ostream& os, const char *fmt, va_list args);
 
-extern OCTINTERP_API char *octave_vsnprintf (const char *fmt, va_list args);
+extern OCTINTERP_API std::string
+octave_vasprintf (const char *fmt, va_list args);
 
-extern OCTINTERP_API char *octave_snprintf (const char *fmt, ...);
+extern OCTINTERP_API std::string octave_asprintf (const char *fmt, ...);
 
 extern OCTINTERP_API void octave_sleep (double seconds);
 
--- a/src/variables.cc	Tue Nov 29 05:16:09 2011 +0000
+++ b/src/variables.cc	Wed Dec 07 19:06:13 2011 -0500
@@ -2462,6 +2462,7 @@
   "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} whos_line_format ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} whos_line_format (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} whos_line_format (@var{new_val}, \"local\")\n\
 Query or set the format string used by the command @code{whos}.\n\
 \n\
 A full format string is:\n\
@@ -2523,6 +2524,10 @@
 \n\
 The default format is\n\
 @code{\"  %a:4; %ln:6; %cs:16:6:1;  %rb:12;  %lc:-1;\\n\"}.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @seealso{whos}\n\
 @end deftypefn")
 {
@@ -2535,8 +2540,13 @@
     "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{val} =} missing_function_hook ()\n\
 @deftypefnx {Built-in Function} {@var{old_val} =} missing_function_hook (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} missing_function_hook (@var{new_val}, \"local\")\n\
 Query or set the internal variable that specifies the function to call when\n\
 an unknown identifier is requested.\n\
+\n\
+When called from inside a function with the \"local\" option, the variable is\n\
+changed locally for the function and any subroutines it calls.  The original\n\
+variable value is restored when exiting the function.\n\
 @end deftypefn")
 {
   return SET_INTERNAL_VARIABLE (missing_function_hook);
--- a/test/classes/module.mk	Tue Nov 29 05:16:09 2011 +0000
+++ b/test/classes/module.mk	Wed Dec 07 19:06:13 2011 -0500
@@ -1,63 +1,63 @@
 classes_FCN_FILES = \
-  @Blork/Blork.m \
-  @Blork/bleek.m \
-  @Blork/display.m \
-  @Blork/get.m \
-  @Blork/set.m \
-  @Cork/Cork.m \
-  @Cork/click.m \
-  @Cork/display.m \
-  @Cork/get.m \
-  @Cork/set.m \
-  @Dork/Dork.m \
-  @Dork/bling.m \
-  @Dork/display.m \
-  @Dork/gack.m \
-  @Dork/get.m \
-  @Dork/getStash.m \
-  @Dork/private/myStash.m \
-  @Dork/set.m \
-  @Gork/Gork.m \
-  @Gork/cork.m \
-  @Gork/display.m \
-  @Gork/gark.m \
-  @Gork/get.m \
-  @Gork/set.m \
-  @Gork/subsasgn.m \
-  @Gork/subsref.m \
-  @Pork/Pork.m \
-  @Pork/bling.m \
-  @Pork/display.m \
-  @Pork/get.m \
-  @Pork/gurk.m \
-  @Pork/private/myStash.m \
-  @Pork/set.m \
-  @Sneetch/Sneetch.m \
-  @Sneetch/display.m \
-  @Snork/Snork.m \
-  @Snork/cack.m \
-  @Snork/display.m \
-  @Snork/end.m \
-  @Snork/get.m \
-  @Snork/getStash.m \
-  @Snork/gick.m \
-  @Snork/loadobj.m \
-  @Snork/private/myStash.m \
-  @Snork/saveobj.m \
-  @Snork/set.m \
-  @Snork/subsasgn.m \
-  @Snork/subsindex.m \
-  @Snork/subsref.m \
-  @Spork/Spork.m \
-  @Spork/cack.m \
-  @Spork/display.m \
-  @Spork/geek.m \
-  @Spork/get.m \
-  @Spork/getStash.m \
-  @Spork/loadobj.m \
-  @Spork/private/myStash.m \
-  @Spork/saveobj.m \
-  @Spork/set.m \
-  test_classes.m
+  classes/@Blork/Blork.m \
+  classes/@Blork/bleek.m \
+  classes/@Blork/display.m \
+  classes/@Blork/get.m \
+  classes/@Blork/set.m \
+  classes/@Cork/Cork.m \
+  classes/@Cork/click.m \
+  classes/@Cork/display.m \
+  classes/@Cork/get.m \
+  classes/@Cork/set.m \
+  classes/@Dork/Dork.m \
+  classes/@Dork/bling.m \
+  classes/@Dork/display.m \
+  classes/@Dork/gack.m \
+  classes/@Dork/get.m \
+  classes/@Dork/getStash.m \
+  classes/@Dork/private/myStash.m \
+  classes/@Dork/set.m \
+  classes/@Gork/Gork.m \
+  classes/@Gork/cork.m \
+  classes/@Gork/display.m \
+  classes/@Gork/gark.m \
+  classes/@Gork/get.m \
+  classes/@Gork/set.m \
+  classes/@Gork/subsasgn.m \
+  classes/@Gork/subsref.m \
+  classes/@Pork/Pork.m \
+  classes/@Pork/bling.m \
+  classes/@Pork/display.m \
+  classes/@Pork/get.m \
+  classes/@Pork/gurk.m \
+  classes/@Pork/private/myStash.m \
+  classes/@Pork/set.m \
+  classes/@Sneetch/Sneetch.m \
+  classes/@Sneetch/display.m \
+  classes/@Snork/Snork.m \
+  classes/@Snork/cack.m \
+  classes/@Snork/display.m \
+  classes/@Snork/end.m \
+  classes/@Snork/get.m \
+  classes/@Snork/getStash.m \
+  classes/@Snork/gick.m \
+  classes/@Snork/loadobj.m \
+  classes/@Snork/private/myStash.m \
+  classes/@Snork/saveobj.m \
+  classes/@Snork/set.m \
+  classes/@Snork/subsasgn.m \
+  classes/@Snork/subsindex.m \
+  classes/@Snork/subsref.m \
+  classes/@Spork/Spork.m \
+  classes/@Spork/cack.m \
+  classes/@Spork/display.m \
+  classes/@Spork/geek.m \
+  classes/@Spork/get.m \
+  classes/@Spork/getStash.m \
+  classes/@Spork/loadobj.m \
+  classes/@Spork/private/myStash.m \
+  classes/@Spork/saveobj.m \
+  classes/@Spork/set.m \
+  classes/test_classes.m
 
 FCN_FILES += $(classes_FCN_FILES)
--- a/test/ctor-vs-method/module.mk	Tue Nov 29 05:16:09 2011 +0000
+++ b/test/ctor-vs-method/module.mk	Wed Dec 07 19:06:13 2011 -0500
@@ -6,6 +6,6 @@
   ctor-vs-method/@parent/method.m \
   ctor-vs-method/@parent/parent.m \
   ctor-vs-method/__trace__.m \
-  test_ctor_vs_method.m
+  ctor-vs-method/test_ctor_vs_method.m
 
 FCN_FILES += $(ctor_vs_method_FCN_FILES)
--- a/test/fcn-handle-derived-resolution/module.mk	Tue Nov 29 05:16:09 2011 +0000
+++ b/test/fcn-handle-derived-resolution/module.mk	Wed Dec 07 19:06:13 2011 -0500
@@ -6,6 +6,6 @@
   fcn-handle-derived-resolution/@other/other.m \
   fcn-handle-derived-resolution/@parent/numel.m \
   fcn-handle-derived-resolution/@parent/parent.m \
-  test_fcn_handle_derived_resolution.m
+  fcn-handle-derived-resolution/test_fcn_handle_derived_resolution.m
 
 FCN_FILES += $(fcn_handle_derived_resolution_FCN_FILES)
--- a/test/test_io.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/test/test_io.m	Wed Dec 07 19:06:13 2011 -0500
@@ -237,10 +237,10 @@
 %!assert(puts (1),-1);
 
 %% test/octave.test/io/puts-3.m
-%!error <Invalid call to puts.*> puts ();
+%!error <Invalid call to puts> puts ();
 
 %% test/octave.test/io/puts-4.m
-%!error <Invalid call to puts.*> puts (1, 2);
+%!error <Invalid call to puts> puts (1, 2);
 
 %!assert (sscanf ('123456', '%10c'), '123456')
 %!assert (sscanf ('123456', '%10s'), '123456')
@@ -279,13 +279,13 @@
 %! && v2 == [1; 2] && c2 == 2 && ischar (m2)));
 
 %% test/octave.test/io/sscanf-2.m
-%!error <Invalid call to sscanf.*> sscanf ();
+%!error <Invalid call to sscanf> sscanf ();
 
 %% test/octave.test/io/sscanf-3.m
 %!error sscanf (1, 2);
 
 %% test/octave.test/io/sscanf-4.m
-%!error <Invalid call to sscanf.*> sscanf ("foo", "bar", "C", 1);
+%!error <Invalid call to sscanf> sscanf ("foo", "bar", "C", 1);
 
 %% test/octave.test/io/sscanf-5.m
 %!test
@@ -310,7 +310,7 @@
 %!error printf (1);
 
 %% test/octave.test/io/printf-3.m
-%!error <Invalid call to printf.*> printf ();
+%!error <Invalid call to printf> printf ();
 
 %% test/octave.test/io/sprintf-1.m
 %!test
@@ -322,7 +322,7 @@
 %!error sprintf (1);
 
 %% test/octave.test/io/sprintf-3.m
-%!error <Invalid call to sprintf.*> sprintf ();
+%!error <Invalid call to sprintf> sprintf ();
 
 %% test/octave.test/io/fopen-1.m
 %!test
@@ -393,16 +393,16 @@
 %! assert(prog_output_assert("error:.*"));
 
 %% test/octave.test/io/fopen-5.m
-%!error <Invalid call to fopen.*> fopen ();
+%!error <Invalid call to fopen> fopen ();
 
 %% test/octave.test/io/fopen-6.m
-%!error <Invalid call to fopen.*> fopen ("foo", "wb", "native", 1);
+%!error <Invalid call to fopen> fopen ("foo", "wb", "native", 1);
 
 %% test/octave.test/io/fclose-1.m
 %!error fclose (0);
 
 %% test/octave.test/io/fclose-2.m
-%!error <Invalid call to fclose.*> fclose (1, 2);
+%!error <Invalid call to fclose> fclose (1, 2);
 
 %% test/octave.test/io/tmpnam-1.m
 %!assert(ischar (tmpnam ()));
@@ -414,7 +414,7 @@
 %!warning tmpnam ("foo", 1);
 
 %% test/octave.test/io/tmpnam-4.m
-%!error <Invalid call to tmpnam.*> tmpnam (1, 2, 3);
+%!error <Invalid call to tmpnam> tmpnam (1, 2, 3);
 
 %% test/octave.test/io/binary-io-1.m
 %!test
@@ -499,37 +499,37 @@
 %! unlink (nm);
 
 %% test/octave.test/io/fputs-1.m
-%!error <Invalid call to fputs.*> fputs ();
+%!error <Invalid call to fputs> fputs ();
 
 %% test/octave.test/io/fputs-2.m
-%!error <Invalid call to fputs.*> fputs (1, "foo", 1);
+%!error <Invalid call to fputs> fputs (1, "foo", 1);
 
 %% test/octave.test/io/fputs-3.m
 %!assert(fputs (1, 1),-1);
 
 %% test/octave.test/io/fgetl-1.m
-%!error <Invalid call to fgetl.*> fgetl ();
+%!error <Invalid call to fgetl> fgetl ();
 
 %% test/octave.test/io/fgetl-2.m
-%!error <Invalid call to fgetl.*> fgetl (1, 2, 3);
+%!error <Invalid call to fgetl> fgetl (1, 2, 3);
 
 %% test/octave.test/io/fgetl-3.m
 %!error fgetl ("foo", 1);
 
 %% test/octave.test/io/fgets-1.m
-%!error <Invalid call to fgets.*> fgets ();
+%!error <Invalid call to fgets> fgets ();
 
 %% test/octave.test/io/fgets-2.m
-%!error <Invalid call to fgets.*> fgets (1, 2, 3);
+%!error <Invalid call to fgets> fgets (1, 2, 3);
 
 %% test/octave.test/io/fgets-3.m
 %!error fgets ("foo", 1);
 
 %% test/octave.test/io/fprintf-1.m
-%!error <Invalid call to fprintf.*> fprintf ();
+%!error <Invalid call to fprintf> fprintf ();
 
 %% test/octave.test/io/fprintf-2.m
-%!error <Invalid call to fprintf.*> fprintf (1);
+%!error <Invalid call to fprintf> fprintf (1);
 
 %% test/octave.test/io/fprintf-3.m
 %!test
@@ -543,37 +543,37 @@
 %!error fprintf (-1, "foo");
 
 %% test/octave.test/io/fscanf-1.m
-%!error <Invalid call to fscanf.*> fscanf ();
+%!error <Invalid call to fscanf> fscanf ();
 
 %% test/octave.test/io/fscanf-2.m
-%!error <Invalid call to fscanf.*> fscanf (1);
+%!error <Invalid call to fscanf> fscanf (1);
 
 %% test/octave.test/io/fscanf-3.m
 %!error fscanf ("foo", "bar");
 
 %% test/octave.test/io/fread-1.m
-%!error <Invalid call to fread.*> fread ();
+%!error <Invalid call to fread> fread ();
 
 %% test/octave.test/io/fread-2.m
-%!error <Invalid call to fread.*> fread (1, 2, "char", 1, "native", 2);
+%!error <Invalid call to fread> fread (1, 2, "char", 1, "native", 2);
 
 %% test/octave.test/io/fread-3.m
 %!error fread ("foo");
 
 %% test/octave.test/io/fwrite-1.m
-%!error <Invalid call to fwrite.*> fwrite ();
+%!error <Invalid call to fwrite> fwrite ();
 
 %% test/octave.test/io/fwrite-2.m
-%!error <Invalid call to fwrite.*> fwrite (1, rand (10), "char", 1, "native", 2);
+%!error <Invalid call to fwrite> fwrite (1, rand (10), "char", 1, "native", 2);
 
 %% test/octave.test/io/fwrite-3.m
 %!error fwrite ("foo", 1);
 
 %% test/octave.test/io/feof-1.m
-%!error <Invalid call to feof.*> feof ();
+%!error <Invalid call to feof> feof ();
 
 %% test/octave.test/io/feof-2.m
-%!error <Invalid call to feof.*> feof (1, 2);
+%!error <Invalid call to feof> feof (1, 2);
 
 %% test/octave.test/io/feof-3.m
 %!error feof ("foo");
@@ -592,28 +592,28 @@
 %!error ferror ("foo");
 
 %% test/octave.test/io/ftell-1.m
-%!error <Invalid call to ftell.*> ftell ();
+%!error <Invalid call to ftell> ftell ();
 
 %% test/octave.test/io/ftell-2.m
-%!error <Invalid call to ftell.*> ftell (1, 2);
+%!error <Invalid call to ftell> ftell (1, 2);
 
 %% test/octave.test/io/ftell-3.m
 %!error ftell ("foo");
 
 %% test/octave.test/io/fseek-1.m
-%!error <Invalid call to fseek.*> fseek ();
+%!error <Invalid call to fseek> fseek ();
 
 %% test/octave.test/io/fseek-2.m
-%!error <Invalid call to fseek.*> fseek (1, 0, SEEK_SET, 1);
+%!error <Invalid call to fseek> fseek (1, 0, SEEK_SET, 1);
 
 %% test/octave.test/io/fseek-3.m
 %!error fseek ("foo", 0, SEEK_SET);
 
 %% test/octave.test/io/frewind-1.m
-%!error <Invalid call to frewind.*> frewind ();
+%!error <Invalid call to frewind> frewind ();
 
 %% test/octave.test/io/frewind-2.m
-%!error <Invalid call to frewind.*> frewind (1, 2);
+%!error <Invalid call to frewind> frewind (1, 2);
 
 %% test/octave.test/io/frewind-3.m
 %!error frewind ("foo");
--- a/test/test_struct.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/test/test_struct.m	Wed Dec 07 19:06:13 2011 -0500
@@ -29,7 +29,7 @@
 %! assert(iscell (c) && strcmp (c{1}, "b"));
 
 %% test/octave.test/struct/fieldnames-3.m
-%!error <Invalid call to fieldnames.*> fieldnames ();
+%!error <Invalid call to fieldnames> fieldnames ();
 
 %% test/octave.test/struct/fieldnames-4.m
 %!test
@@ -52,7 +52,7 @@
 %! assert(!(isfield (s, "b")));
 
 %% test/octave.test/struct/isfield-3.m
-%!error <Invalid call to isfield.*> isfield ();
+%!error <Invalid call to isfield> isfield ();
 
 %% test/octave.test/struct/isfield-4.m
 %!test
@@ -100,7 +100,7 @@
 %! assert(isstruct (s.a));
 
 %% test/octave.test/struct/isstruct-10.m
-%!error <Invalid call to isstruct.*> isstruct ();
+%!error <Invalid call to isstruct> isstruct ();
 
 %% test/octave.test/struct/isstruct-11.m
 %!test
--- a/test/test_system.m	Tue Nov 29 05:16:09 2011 +0000
+++ b/test/test_system.m	Wed Dec 07 19:06:13 2011 -0500
@@ -39,7 +39,7 @@
 %! assert(prog_output_assert("ok"));
 
 %% test/octave.test/system/pause-2.m
-%!error <Invalid call to pause.*> pause (1, 2);
+%!error <Invalid call to pause> pause (1, 2);
 
 %% test/octave.test/system/sleep-1.m
 %!test
@@ -48,10 +48,10 @@
 %! assert(prog_output_assert("ok"));
 
 %% test/octave.test/system/sleep-2.m
-%!error <Invalid call to sleep.*> sleep ();
+%!error <Invalid call to sleep> sleep ();
 
 %% test/octave.test/system/sleep-3.m
-%!error <Invalid call to sleep.*> sleep (1, 2);
+%!error <Invalid call to sleep> sleep (1, 2);
 
 %% test/octave.test/system/usleep-1.m
 %!test
@@ -60,10 +60,10 @@
 %! assert(prog_output_assert("ok"));
 
 %% test/octave.test/system/usleep-2.m
-%!error <Invalid call to usleep.*> usleep ();
+%!error <Invalid call to usleep> usleep ();
 
 %% test/octave.test/system/usleep-3.m
-%!error <Invalid call to usleep.*> usleep (1, 2);
+%!error <Invalid call to usleep> usleep (1, 2);
 
 %% test/octave.test/system/rename-1.m
 %!test
@@ -85,10 +85,10 @@
 %! endif
 
 %% test/octave.test/system/rename-2.m
-%!error <Invalid call to rename.*> rename ();
+%!error <Invalid call to rename> rename ();
 
 %% test/octave.test/system/rename-3.m
-%!error <Invalid call to rename.*> rename ("foo", "bar", 1);
+%!error <Invalid call to rename> rename ("foo", "bar", 1);
 
 %% test/octave.test/system/unlink-1.m
 %!test
@@ -102,10 +102,10 @@
 %! endif
 
 %% test/octave.test/system/unlink-2.m
-%!error <Invalid call to unlink.*> unlink ();
+%!error <Invalid call to unlink> unlink ();
 
 %% test/octave.test/system/unlink-3.m
-%!error <Invalid call to unlink.*> unlink ("foo", 1);
+%!error <Invalid call to unlink> unlink ("foo", 1);
 
 %% test/octave.test/system/readdir-1.m
 %!test
@@ -113,10 +113,10 @@
 %! assert(iscell (files) && status == 0 && strcmp (msg, ""));
 
 %% test/octave.test/system/readdir-2.m
-%!error <Invalid call to readdir.*> readdir ();
+%!error <Invalid call to readdir> readdir ();
 
 %% test/octave.test/system/readdir-3.m
-%!error <Invalid call to readdir.*> readdir ("foo", 1);
+%!error <Invalid call to readdir> readdir ("foo", 1);
 
 %% test/octave.test/system/mk-rm-dir-1.m
 %!test
@@ -128,13 +128,13 @@
 %! assert((e1 && strcmp (s2.modestr(1), "d") && e3 && e4 < 0));
 
 %% test/octave.test/system/mkdir-1.m
-%!error <Invalid call to mkdir.*> mkdir ();
+%!error <Invalid call to mkdir> mkdir ();
 
 %% test/octave.test/system/mkdir-2.m
-%!error <Invalid call to mkdir.*> mkdir ("foo", 1, 2);
+%!error <Invalid call to mkdir> mkdir ("foo", 1, 2);
 
 %% test/octave.test/system/rmdir-1.m
-%!error <Invalid call to rmdir.*> rmdir ();
+%!error <Invalid call to rmdir> rmdir ();
 
 %% test/octave.test/system/rmdir-2.m
 %!test
@@ -163,10 +163,10 @@
 %! assert(strcmp (s1.modestr, "-rw-rw-rw-") && strcmp (s2.modestr, "----------"));
 
 %% test/octave.test/system/umask-2.m
-%!error <Invalid call to umask.*> umask ();
+%!error <Invalid call to umask> umask ();
 
 %% test/octave.test/system/umask-3.m
-%!error <Invalid call to umask.*> umask (1, 2);
+%!error <Invalid call to umask> umask (1, 2);
 
 %% test/octave.test/system/stat-1.m
 %!test
@@ -186,10 +186,10 @@
 %! && ischar (msg)));
 
 %% test/octave.test/system/stat-2.m
-%!error <Invalid call to stat.*> stat ();
+%!error <Invalid call to stat> stat ();
 
 %% test/octave.test/system/stat-3.m
-%!error <Invalid call to stat.*> stat ("foo", 1);
+%!error <Invalid call to stat> stat ("foo", 1);
 
 %% test/octave.test/system/lstat-1.m
 %!test
@@ -209,10 +209,10 @@
 %! && ischar (msg)));
 
 %% test/octave.test/system/lstat-2.m
-%!error <Invalid call to lstat.*> lstat ();
+%!error <Invalid call to lstat> lstat ();
 
 %% test/octave.test/system/lstat-3.m
-%!error <Invalid call to lstat.*> lstat ("foo", 1);
+%!error <Invalid call to lstat> lstat ("foo", 1);
 
 %% test/octave.test/system/glob-1.m
 %!assert(iscell (glob ([filesep "*"])));
@@ -221,7 +221,7 @@
 %!error <Invalid call to glob*> glob ();
 
 %% test/octave.test/system/glob-3.m
-%!error <Invalid call to glob.*> glob ("foo", 1);
+%!error <Invalid call to glob> glob ("foo", 1);
 
 %% test/octave.test/system/fnmatch-1.m
 %!test
@@ -233,10 +233,10 @@
 %! && fnmatch ("x???y", {"xabcy"; "xy"}) == [1; 0]));
 
 %% test/octave.test/system/fnmatch-2.m
-%!error <Invalid call to fnmatch.*> fnmatch ();
+%!error <Invalid call to fnmatch> fnmatch ();
 
 %% test/octave.test/system/fnmatch-3.m
-%!error <Invalid call to fnmatch.*> fnmatch ("foo", "bar", 3);
+%!error <Invalid call to fnmatch> fnmatch ("foo", "bar", 3);
 
 %% test/octave.test/system/file_in_path-1.m
 %!assert(ischar (file_in_path (path (), "date.m")));
@@ -245,10 +245,10 @@
 %!error <invalid option> file_in_path ("foo", "bar", 1);
 
 %% test/octave.test/system/file_in_path-3.m
-%!error <Invalid call to file_in_path.*> file_in_path ();
+%!error <Invalid call to file_in_path> file_in_path ();
 
 %% test/octave.test/system/file_in_path-4.m
-%!error <Invalid call to file_in_path.*> file_in_path ("foo", "bar", "baz", "ooka");
+%!error <Invalid call to file_in_path> file_in_path ("foo", "bar", "baz", "ooka");
 
 %% test/octave.test/system/tilde_expand-1.m
 %!testif HAVE_GETPWUID
@@ -258,10 +258,10 @@
 %! && strcmp ("foobar", tilde_expand ("foobar"))));
 
 %% test/octave.test/system/tilde_expand-2.m
-%!error <Invalid call to tilde_expand.*> tilde_expand ();
+%!error <Invalid call to tilde_expand> tilde_expand ();
 
 %% test/octave.test/system/tilde_expand-3.m
-%!error <Invalid call to tilde_expand.*> tilde_expand ("str", 2);
+%!error <Invalid call to tilde_expand> tilde_expand ("str", 2);
 
 %% test/octave.test/system/getpgrp-1.m
 %!testif HAVE_GETPGRP
@@ -311,10 +311,10 @@
 %!assert(strcmp (getenv ("HOME"), tilde_expand ("~")));
 
 %% test/octave.test/system/getenv-2.m
-%!error <Invalid call to getenv.*> getenv ();
+%!error <Invalid call to getenv> getenv ();
 
 %% test/octave.test/system/getenv-3.m
-%!error <Invalid call to getenv.*> getenv ("foo", 1);
+%!error <Invalid call to getenv> getenv ("foo", 1);
 
 %% test/octave.test/system/getenv-4.m
 %!test
@@ -329,10 +329,10 @@
 %! assert(strcmp (getenv ("foobar"), "baz"));
 
 %% test/octave.test/system/putenv-2.m
-%!error <Invalid call to putenv.*> putenv ();
+%!error <Invalid call to putenv> putenv ();
 
 %% test/octave.test/system/putenv-3.m
-%!error <Invalid call to putenv.*> putenv ("foo", "bar", 1);
+%!error <Invalid call to putenv> putenv ("foo", "bar", 1);
 
 %% test/octave.test/system/putenv-4.m
 %!test
@@ -377,7 +377,7 @@
 %! && isfield (s, "shell")));
 
 %% test/octave.test/system/getpwent-2.m
-%!error <Invalid call to getpwent.*> getpwent (1);
+%!error <Invalid call to getpwent> getpwent (1);
 
 %% test/octave.test/system/getpwuid-1.m
 %!testif HAVE_GETPWUID
@@ -387,10 +387,10 @@
 %! assert(strcmp (x.name, y.name) && x.uid == y.uid && x.gid == y.gid);
 
 %% test/octave.test/system/getpwuid-2.m
-%!error <Invalid call to getpwuid.*> getpwuid ();
+%!error <Invalid call to getpwuid> getpwuid ();
 
 %% test/octave.test/system/getpwuid-3.m
-%!error <Invalid call to getpwuid.*> getpwuid (1, 2);
+%!error <Invalid call to getpwuid> getpwuid (1, 2);
 
 %% test/octave.test/system/getpwnam-1.m
 %!testif HAVE_GETPWNAM
@@ -400,10 +400,10 @@
 %! assert(strcmp (x.name, y.name) && x.uid == y.uid && x.gid == y.gid);
 
 %% test/octave.test/system/getpwnam-2.m
-%!error <Invalid call to getpwnam.*> getpwnam ();
+%!error <Invalid call to getpwnam> getpwnam ();
 
 %% test/octave.test/system/getpwnam-3.m
-%!error <Invalid call to getpwnam.*> getpwnam ("foo", 1);
+%!error <Invalid call to getpwnam> getpwnam ("foo", 1);
 
 %% test/octave.test/system/setpwent-1.m
 %!testif HAVE_SETPWENT
@@ -414,10 +414,10 @@
 %! assert(strcmp (x.name, y.name) && x.uid == y.uid && x.gid == y.gid);
 
 %% test/octave.test/system/setpwent-2.m
-%!error <Invalid call to setpwent.*> setpwent (1);
+%!error <Invalid call to setpwent> setpwent (1);
 
 %% test/octave.test/system/endpwent-1.m
-%!error <Invalid call to endpwent.*> endpwent (1);
+%!error <Invalid call to endpwent> endpwent (1);
 
 %% test/octave.test/system/getgrent-1.m
 %!testif HAVE_GETGRENT
@@ -430,7 +430,7 @@
 %! && isfield (x, "mem")));
 
 %% test/octave.test/system/getgrent-2.m
-%!error <Invalid call to getgrent.*> getgrent (1);
+%!error <Invalid call to getgrent> getgrent (1);
 
 %% test/octave.test/system/getgrgid-1.m
 %!testif HAVE_GETGRGID
@@ -440,10 +440,10 @@
 %! assert(strcmp (x.name, y.name) && x.gid == y.gid);
 
 %% test/octave.test/system/getgrgid-2.m
-%!error <Invalid call to getgrgid.*> getgrgid ();
+%!error <Invalid call to getgrgid> getgrgid ();
 
 %% test/octave.test/system/getgrgid-3.m
-%!error <Invalid call to getgrgid.*> getgrgid (1, 2);
+%!error <Invalid call to getgrgid> getgrgid (1, 2);
 
 %% test/octave.test/system/getgrnam-1.m
 %!testif HAVE_GETGRNAM
@@ -453,10 +453,10 @@
 %! assert(strcmp (x.name, y.name) && x.gid == y.gid);
 
 %% test/octave.test/system/getgrnam-2.m
-%!error <Invalid call to getgrnam.*> getgrnam ();
+%!error <Invalid call to getgrnam> getgrnam ();
 
 %% test/octave.test/system/getgrnam-3.m
-%!error <Invalid call to getgrnam.*> getgrnam ("foo", 1);
+%!error <Invalid call to getgrnam> getgrnam ("foo", 1);
 
 %% test/octave.test/system/setgrent-1.m
 %!testif HAVE_SETGRENT
@@ -467,10 +467,10 @@
 %! assert(strcmp (x.name, y.name) && x.gid == y.gid);
 
 %% test/octave.test/system/setgrent-2.m
-%!error <Invalid call to setgrent.*> setgrent (1);
+%!error <Invalid call to setgrent> setgrent (1);
 
 %% test/octave.test/system/endgrent-1.m
-%!error <Invalid call to endgrent.*> endgrent (1);
+%!error <Invalid call to endgrent> endgrent (1);
 
 %% test/octave.test/system/isieee-1.m
 %!assert(isieee () == 1 || isieee () == 0);