# HG changeset patch # User Andrew Janke # Date 1548111140 18000 # Node ID 0f187a956d47b23067690340551118c5a0d6f0ba # Parent 884fdd6c92104aea33c3193d2449974736cf4ca6 Add verLessThan function (bug #55525) * verLessThan.m: New function. * scripts/miscellaneous/module.mk: Add new function to the list. * system.txi: Add verLessThan doc string to the manual. * NEWS: Add verLessThan to the list of new functions. diff -r 884fdd6c9210 -r 0f187a956d47 NEWS --- a/NEWS Tue Jan 22 23:46:33 2019 -0800 +++ b/NEWS Mon Jan 21 17:52:20 2019 -0500 @@ -4,6 +4,7 @@ ** New functions added in 6.0: lightangle + verLessThan ** Deprecated functions. diff -r 884fdd6c9210 -r 0f187a956d47 doc/interpreter/system.txi --- a/doc/interpreter/system.txi Tue Jan 22 23:46:33 2019 -0800 +++ b/doc/interpreter/system.txi Mon Jan 21 17:52:20 2019 -0500 @@ -533,6 +533,8 @@ @DOCSTRING(compare_versions) +@DOCSTRING(verLessThan) + @DOCSTRING(license) @DOCSTRING(getrusage) diff -r 884fdd6c9210 -r 0f187a956d47 scripts/miscellaneous/module.mk --- a/scripts/miscellaneous/module.mk Tue Jan 22 23:46:33 2019 -0800 +++ b/scripts/miscellaneous/module.mk Mon Jan 21 17:52:20 2019 -0500 @@ -78,6 +78,7 @@ %reldir%/unzip.m \ %reldir%/validateattributes.m \ %reldir%/ver.m \ + %reldir%/verLessThan.m \ %reldir%/version.m \ %reldir%/what.m \ %reldir%/zip.m diff -r 884fdd6c9210 -r 0f187a956d47 scripts/miscellaneous/verLessThan.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/miscellaneous/verLessThan.m Mon Jan 21 17:52:20 2019 -0500 @@ -0,0 +1,67 @@ +## Copyright (C) 2019 Andrew Janke +## +## 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 +## . + +## -*- texinfo -*- +## @deftypefn {} {@var{out} =} verLessThan (@var{package}, @var{version}) +## True if the installed version of the package is less than @var{version}. +## +## @var{package} is the name of the package to check the version of. Use +## @code{"Octave"} as the @var{package} to check the version of Octave itself. +## +## @var{version} is the version to compare it to. A version is a string in the +## format accepted by @ref{XREFcompare_versions, ,compare_versions function}: +## an arbitrarily long string made of numeric and period characters possibly +## followed by an arbitrary string (e.g., @code{"1.2.3"}, @code{"0.3"}, +## @code{"0.1.2+"}, or @code{"1.2.3.4-test1"}). +## +## @example +## @group +## tf = verLessThan ("Octave", "5.0.0") +## tf = verLessThan ("io", "2.4.12") +## +## if (! verLessThan ("Octave", "5.0.0")) +## ## ... use new Octave 5.0 features ... +## endif +## @end group +## @end example +## +## @seealso{compare_versions, version, ver, pkg} +## @end deftypefn + +function out = verLessThan(package, version) + + if (! ischar (package) || size (package, 1) > 1) + error ("verLessThan: package must be a char vector"); + endif + + v = ver (); + idx = find (strcmpi (package, {v.Name})); + if (isempty (idx)) + error ("verLessThan: Package ""%s"" is not installed.", package); + endif + + out = compare_versions (v(idx).Version, version, "<"); + +endfunction + +%!assert (! verLessThan ("Octave", "3.0.0")) +%!assert (verLessThan ("Octave", "99.9.9")) +%!error +%! verLessThan ("no-such-package", "1.1.1") +%!error +%! verLessThan ("Octave", 4.1)