Mercurial > hg > octave-terminal
changeset 12208:9611014e7cf1
Add function compare_versions to documentation.
Update docstrings for surrounding functions in manual.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 29 Jan 2011 16:54:14 -0800 |
parents | c37f167a816a |
children | 61a4171c057f |
files | doc/ChangeLog doc/interpreter/system.txi scripts/ChangeLog scripts/miscellaneous/compare_versions.m scripts/miscellaneous/ver.m scripts/miscellaneous/version.m scripts/path/matlabroot.m src/ChangeLog src/DLD-FUNCTIONS/getrusage.cc src/toplev.cc |
diffstat | 10 files changed, 78 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2011-01-29 Rik <octave@nomad.inbox5.com> + + * interpreter/system.txi: Add compare_versions function to + documentation. + 2011-01-27 Rik <octave@nomad.inbox5.com> * interpreter/numbers.txi: Add sizemax function to documentation.
--- a/doc/interpreter/system.txi +++ b/doc/interpreter/system.txi @@ -465,18 +465,20 @@ @DOCSTRING(isieee) -@DOCSTRING(matlabroot) - @DOCSTRING(OCTAVE_HOME) -@DOCSTRING(OCTAVE_VERSION) +@DOCSTRING(matlabroot) -@DOCSTRING(license) +@DOCSTRING(OCTAVE_VERSION) @DOCSTRING(version) @DOCSTRING(ver) +@DOCSTRING(compare_versions) + +@DOCSTRING(license) + @DOCSTRING(octave_config_info) @DOCSTRING(getrusage)
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,11 @@ +2011-01-29 Rik <octave@nomad.inbox5.com> + + * miscellaneous/compare_versions.m: Allow only "==" equality operator. + Add input validation tests. Improve docstring. + + * miscellaneous/ver.m, miscellaneous/version.m, path/matlabroot.m: + Improve docstring. + 2011-01-29 Ben Abbott <bpabbott@mac.com> * miscellaneous/edit.m: As most editors open their own window, change
--- a/scripts/miscellaneous/compare_versions.m +++ b/scripts/miscellaneous/compare_versions.m @@ -66,14 +66,12 @@ ## Note that version "1.1-test2" will compare as greater than ## "1.1-test10". Also, since the numeric part is compared first, "a" ## compares less than "1a" because the second string starts with a -## numeric part even though double("a") is greater than double("1"). +## numeric part even though @code{double("a")} is greater than +## @code{double("1").} ## @end deftypefn ## Author: Bill Denney <denney@seas.upenn.edu> -## FIXME?: This allows a single equal sign "=" to indicate equality, do -## we want to require a double equal since that is the boolean operator? - function out = compare_versions (v1, v2, operator) if (nargin != 3) @@ -83,7 +81,7 @@ ## Make sure that the version numbers are valid. if (! (ischar (v1) && ischar (v2))) error ("compare_versions: both version numbers must be strings"); - elseif (size (v1, 1) != 1 || size (v2, 1) != 1) + elseif (rows (v1) != 1 || rows (v2) != 1) error ("compare_versions: version numbers must be a single row"); endif @@ -91,7 +89,7 @@ if (! ischar (operator)) error ("compare_versions: OPERATOR must be a character string"); elseif (numel (operator) > 2) - error("compare_versions: OPERATOR cannot be more than 2 characters long"); + error("compare_versions: OPERATOR must be 1 or 2 characters long"); endif ## trim off any character data that is not part of a normal version @@ -169,6 +167,10 @@ error ("compare_versions: OPERATOR cannot contain both greater and less than symbols"); elseif ((gt_op || lt_op) && not_op) error ("compare_versions: OPERATOR cannot contain not and greater than or less than symbols"); + elseif (strcmp (operator, "=")) + error ("compare_versions: equality OPERATOR is \"==\", not \"=\""); + elseif (! (equal_op || not_op || lt_op || gt_op)) + error ("compare_versions: No valid OPERATOR specified"); endif ## Compare the versions (making sure that they're the same shape) @@ -187,19 +189,19 @@ ## They're correctly less than or greater than. out = (vcmp(firstdiff) > 0); else - ## They're not correctly less than or greater than, and they're not - ## equal. + ## They're not correctly less than or greater than, and they're not equal. out = false; endif ## Reverse the output if not is given. - out = xor (not_op, out); + if (not_op) + out = !out; + endif endfunction ## tests ## test both equality symbols -%!assert(compare_versions("1", "1", "="), true) ## test arbitrarily long equality %!assert(compare_versions("1.1.0.0.0", "1.1", "=="), true) %!assert(compare_versions("1", "1.1", "<"), true) @@ -224,7 +226,7 @@ %!assert(compare_versions("1.1.0test", "1.1.0test", "=="), true) ## make sure that it won't just give true output -%!assert(compare_versions("1", "0", "="), false) +%!assert(compare_versions("1", "0", "=="), false) ## test arbitrarily long equality %!assert(compare_versions("1.1.1.0.0", "1.1", "=="), false) %!assert(compare_versions("1.1", "1", "<"), false) @@ -238,5 +240,14 @@ %!assert(compare_versions("0.1", "0.1", "!="), false) %!assert(compare_versions("0.1", "0.1", "~="), false) -## FIXME: how do we check to make sure that it gives errors when it -## should +%% Test input validation +%!error(compare_versions(0.1, "0.1", "==")) +%!error(compare_versions("0.1", 0.1, "==")) +%!error(compare_versions(["0";".";"1"], "0.1", "==")) +%!error(compare_versions("0.1", ["0";".";"1"], "==")) +%!error(compare_versions("0.1", "0.1", "<>")) +%!error(compare_versions("0.1", "0.1", "!>")) +%!error(compare_versions("0.1", "0.1", "=")) +%!error(compare_versions("0.1", "0.1", "aa")) + +
--- a/scripts/miscellaneous/ver.m +++ b/scripts/miscellaneous/ver.m @@ -18,32 +18,35 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} ver () -## Display a header containing the current Octave version -## number, license string and operating system, followed by -## the installed package names, versions, and installation -## directories. +## Display a header containing the current Octave version number, license +## string and operating system, followed by the installed package names, +## versions, and installation directories. +## ## @deftypefnx {Function File} {v =} ver () ## Return a vector of structures, respecting Octave and each installed package. ## The structure includes the following fields. ## ## @table @code -## @item Name -## Package name. +## @item Name +## Package name. ## -## @item Version -## Version of the package. +## @item Version +## Version of the package. ## -## @item Revision -## Revision of the package. +## @item Revision +## Revision of the package. ## -## @item Date -## Date respecting the version/revision. +## @item Date +## Date respecting the version/revision. ## @end table +## ## @deftypefnx {Function File} {v =} ver (@code{"Octave"}) ## Return version information for Octave only. +## ## @deftypefnx {Function File} {v =} ver (@var{package}) ## Return version information for @var{package}. -## @seealso{license, version} +## +## @seealso{version, octave_config_info} ## @end deftypefn ## Author: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com>
--- a/scripts/miscellaneous/version.m +++ b/scripts/miscellaneous/version.m @@ -18,8 +18,11 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} version () -## Return Octave's version number as a string. This is also the value of -## the built-in variable @w{@env{OCTAVE_VERSION}}. +## Return the version number of Octave, as a string. +## +## This is an alias for the function @code{OCTAVE_VERSION} provided for +## compatability +## @seealso{OCTAVE_VERSION}. ## @end deftypefn ## Author: jwe
--- a/scripts/path/matlabroot.m +++ b/scripts/path/matlabroot.m @@ -17,8 +17,11 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{val} =} matlabroot () -## Return the location of Octave's home directory. +## @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 +## for compatability. ## @seealso{OCTAVE_HOME} ## @end deftypefn
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2011-01-29 Rik <octave@nomad.inbox5.com> + + * DLD-FUNCTIONS/getrusage.cc, toplev.cc: Improve docstring + 2011-01-29 John W. Eaton <jwe@octave.org> * DLD-FUNCTIONS/__fltk_uigetfile__.cc (__fltk_uigetfile__):
--- a/src/DLD-FUNCTIONS/getrusage.cc +++ b/src/DLD-FUNCTIONS/getrusage.cc @@ -65,9 +65,8 @@ Return a structure containing a number of statistics about the current\n\ Octave process. Not all fields are available on all systems. If it is\n\ not possible to get CPU time statistics, the CPU time slots are set to\n\ -zero. Other missing data are replaced by NaN@. Here is a list of all\n\ -the possible fields that can be present in the structure returned by\n\ -@code{getrusage}:\n\ +zero. Other missing data are replaced by NaN@. The list of possible\n\ +fields is:\n\ \n\ @table @code\n\ @item idrss\n\
--- a/src/toplev.cc +++ b/src/toplev.cc @@ -1168,11 +1168,12 @@ DEFUN (octave_config_info, args, , "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {} octave_config_info (@var{option})\n\ +@deftypefn {Built-in Function} {} octave_config_info ()\n\ +@deftypefnx {Built-in Function} {} octave_config_info (@var{option})\n\ Return a structure containing configuration and installation\n\ information for Octave.\n\ \n\ -if @var{option} is a string, return the configuration information for the\n\ +If @var{option} is a string, return the configuration information for the\n\ specified option.\n\ \n\ @end deftypefn")