# HG changeset patch # User Rik # Date 1296348854 28800 # Node ID f07e6b4d34c72f0707c978130359da2da6c20f5b # Parent 0566e6fef0c091dedd59439ba787210f61b1e669 Add function compare_versions to documentation. Update docstrings for surrounding functions in manual. diff -r 0566e6fef0c0 -r f07e6b4d34c7 doc/ChangeLog --- a/doc/ChangeLog Sat Jan 29 16:56:42 2011 -0500 +++ b/doc/ChangeLog Sat Jan 29 16:54:14 2011 -0800 @@ -1,3 +1,8 @@ +2011-01-29 Rik + + * interpreter/system.txi: Add compare_versions function to + documentation. + 2011-01-27 Rik * interpreter/numbers.txi: Add sizemax function to documentation. diff -r 0566e6fef0c0 -r f07e6b4d34c7 doc/interpreter/system.txi --- a/doc/interpreter/system.txi Sat Jan 29 16:56:42 2011 -0500 +++ b/doc/interpreter/system.txi Sat Jan 29 16:54:14 2011 -0800 @@ -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) diff -r 0566e6fef0c0 -r f07e6b4d34c7 scripts/ChangeLog --- a/scripts/ChangeLog Sat Jan 29 16:56:42 2011 -0500 +++ b/scripts/ChangeLog Sat Jan 29 16:54:14 2011 -0800 @@ -1,3 +1,11 @@ +2011-01-29 Rik + + * 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 * miscellaneous/edit.m: As most editors open their own window, change diff -r 0566e6fef0c0 -r f07e6b4d34c7 scripts/miscellaneous/compare_versions.m --- a/scripts/miscellaneous/compare_versions.m Sat Jan 29 16:56:42 2011 -0500 +++ b/scripts/miscellaneous/compare_versions.m Sat Jan 29 16:54:14 2011 -0800 @@ -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 -## 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")) + + diff -r 0566e6fef0c0 -r f07e6b4d34c7 scripts/miscellaneous/ver.m --- a/scripts/miscellaneous/ver.m Sat Jan 29 16:56:42 2011 -0500 +++ b/scripts/miscellaneous/ver.m Sat Jan 29 16:54:14 2011 -0800 @@ -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 diff -r 0566e6fef0c0 -r f07e6b4d34c7 scripts/miscellaneous/version.m --- a/scripts/miscellaneous/version.m Sat Jan 29 16:56:42 2011 -0500 +++ b/scripts/miscellaneous/version.m Sat Jan 29 16:54:14 2011 -0800 @@ -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 diff -r 0566e6fef0c0 -r f07e6b4d34c7 scripts/path/matlabroot.m --- a/scripts/path/matlabroot.m Sat Jan 29 16:56:42 2011 -0500 +++ b/scripts/path/matlabroot.m Sat Jan 29 16:54:14 2011 -0800 @@ -17,8 +17,11 @@ ## . ## -*- 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 diff -r 0566e6fef0c0 -r f07e6b4d34c7 src/ChangeLog --- a/src/ChangeLog Sat Jan 29 16:56:42 2011 -0500 +++ b/src/ChangeLog Sat Jan 29 16:54:14 2011 -0800 @@ -1,3 +1,7 @@ +2011-01-29 Rik + + * DLD-FUNCTIONS/getrusage.cc, toplev.cc: Improve docstring + 2011-01-29 John W. Eaton * DLD-FUNCTIONS/__fltk_uigetfile__.cc (__fltk_uigetfile__): diff -r 0566e6fef0c0 -r f07e6b4d34c7 src/DLD-FUNCTIONS/getrusage.cc --- a/src/DLD-FUNCTIONS/getrusage.cc Sat Jan 29 16:56:42 2011 -0500 +++ b/src/DLD-FUNCTIONS/getrusage.cc Sat Jan 29 16:54:14 2011 -0800 @@ -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\ diff -r 0566e6fef0c0 -r f07e6b4d34c7 src/toplev.cc --- a/src/toplev.cc Sat Jan 29 16:56:42 2011 -0500 +++ b/src/toplev.cc Sat Jan 29 16:54:14 2011 -0800 @@ -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")