octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New Function: verlessthan.m


From: Bill Denney
Subject: New Function: verlessthan.m
Date: Sun, 16 Mar 2008 21:59:27 -0400
User-agent: Thunderbird 2.0.0.12 (Windows/20080213)

Hi,

Attached is the new function verlessthan.m.

Have a good day,

Bill
# HG changeset patch
# User address@hidden
# Date 1205719035 14400
# Node ID cc77c260aa291b1009be3deaa2085697feb5088c
# Parent  c2fd7b04ccd25494fea13e188fc688b0ce674400
verlessthan.m: new function

diff -r c2fd7b04ccd2 -r cc77c260aa29 scripts/ChangeLog
--- a/scripts/ChangeLog Sun Mar 16 20:55:44 2008 -0400
+++ b/scripts/ChangeLog Sun Mar 16 21:57:15 2008 -0400
@@ -1,7 +1,14 @@ 2008-03-16  Bill Denney  <address@hidden
+2008-03-16  Bill Denney  <address@hidden>
+
+       * miscellaneous/verlessthan.m: new function
+       * miscellaneous/compare_versions.m: updated doc, minor code 
+       changes
+
 2008-03-16  Bill Denney  <address@hidden>
 
        * strings/validatestring.m, general/nargoutchk.m, 
        time/addtodate.m: new functions
+       * general/nargchk.m: updated docs
 
 2008-03-15  Bill Denney  <address@hidden>
 
diff -r c2fd7b04ccd2 -r cc77c260aa29 scripts/miscellaneous/Makefile.in
--- a/scripts/miscellaneous/Makefile.in Sun Mar 16 20:55:44 2008 -0400
+++ b/scripts/miscellaneous/Makefile.in Sun Mar 16 21:57:15 2008 -0400
@@ -1,6 +1,6 @@
 # Makefile for octave's scripts/miscellaneous directory
 #
-# Copyright (C) 1994, 1995, 1996, 1997, 2002, 2005, 2006, 2007
+# Copyright (C) 1994, 1995, 1996, 1997, 2002, 2005, 2006, 2007, 2008
 #               John W. Eaton
 #
 # This file is part of Octave.
@@ -42,7 +42,7 @@ SOURCES = ans.m bincoeff.m bug_report.m 
   news.m orderfields.m pack.m paren.m parseparams.m \
   run.m semicolon.m setfield.m single.m substruct.m swapbytes.m tar.m \
   tempdir.m tempname.m texas_lotto.m unix.m unpack.m untar.m \
-  unzip.m ver.m version.m warning_ids.m what.m xor.m zip.m
+  unzip.m ver.m version.m verlessthan.m warning_ids.m what.m xor.m zip.m
 
 DISTFILES = $(addprefix $(srcdir)/, Makefile.in $(SOURCES))
 
diff -r c2fd7b04ccd2 -r cc77c260aa29 scripts/miscellaneous/compare_versions.m
--- a/scripts/miscellaneous/compare_versions.m  Sun Mar 16 20:55:44 2008 -0400
+++ b/scripts/miscellaneous/compare_versions.m  Sun Mar 16 21:57:15 2008 -0400
@@ -1,4 +1,4 @@
-## Copyright (C) 2006, 2007 Bill Denney
+## Copyright (C) 2006, 2007, 2008 Bill Denney
 ##
 ## This file is part of Octave.
 ##
@@ -61,9 +61,10 @@
 ## "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").
+## @seealso{verlessthan,pkg,version,ver}
 ## @end deftypefn
 
-## Author: Bill Denney <address@hidden>
+## Author: Bill Denney <address@hidden>
 
 ## TODO?: This allows a single equal sign "=" to indicate equality, do
 ## we want to require a double equal since that is the boolean operator?
@@ -77,7 +78,7 @@ function out = compare_versions (v1, v2,
   ## 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
 
diff -r c2fd7b04ccd2 -r cc77c260aa29 scripts/miscellaneous/verlessthan.m
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/verlessthan.m       Sun Mar 16 21:57:15 2008 -0400
@@ -0,0 +1,61 @@
+## Copyright (C) 2008 Bill Denney
+##
+## 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} {} verlessthan (@var{package}, @var{version})
+## Determine if the installed version of @var{package} is less than
+## @var{version}.
+## @seealso{compare_versions,pkg,ver,version}
+## @end deftypefn
+
+## Author: Bill Denney <address@hidden>
+
+function out = verlessthan (package, v)
+
+  if (nargin != 2)
+    print_usage ();
+  endif
+
+  if strcmpi (package, "octave")
+    ## special handling for octave
+    v_installed = version ();
+  else
+    info = pkg ("list");
+    found = false ();
+    idx = 0;
+    while ((! found) && (idx < numel (info)))
+      ## assuming that package names are unique without case sensitivity
+      if strcmpi (info{++idx}.name, package)
+        found = true();
+      endif
+    endwhile
+    
+    if (! found)
+      error ("verlessthan: %s is not installed", package);
+    endif
+    v_installed = info{idx}.version;
+  endif
+
+  out = compare_versions (v_installed, v, "<");
+
+endfunction
+
+## Tests
+%!assert (verlessthan ("octave", "1"), 0)
+%!assert (verlessthan ("octave", "1.1"), 0)
+%!assert (verlessthan ("octave", "100000"), 1)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]