changeset 65150:6d566cf5ad51

(version-list-<, version-list-<=, version-list-=) Renamed from integer-list-*. (version-list-not-zero): Likewise. Fix while loop. (version=): Use version-list-= instead of string-equal.
author Kim F. Storm <storm@cua.dk>
date Fri, 26 Aug 2005 12:31:55 +0000
parents 7dc655f04e1d
children 7ab3eb3e09b8
files lisp/subr.el
diffstat 1 files changed, 38 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/subr.el	Fri Aug 26 12:31:36 2005 +0000
+++ b/lisp/subr.el	Fri Aug 26 12:31:55 2005 +0000
@@ -2851,8 +2851,9 @@
 				   (setq ,(car spec) (1+ ,(car spec)))))
        (progress-reporter-done ,temp2)
        nil ,@(cdr (cdr spec)))))
+
 
-;;;; Integer list & Version funs.
+;;;; Compare Version Strings
 
 (defvar version-separator "."
   "*Specify the string used to separate the version elements.
@@ -2952,7 +2953,7 @@
 	(nreverse lst)))))
 
 
-(defun integer-list-< (l1 l2)
+(defun version-list-< (l1 l2)
   "Return t if integer list L1 is lesser than L2.
 
 Note that integer list (1) is equal to (1 0), (1 0 0), (1 0 0 0),
@@ -2968,12 +2969,12 @@
    ;; l1 null and l2 null         ==> l1 length = l2 length
    ((and (null l1) (null l2)) nil)
    ;; l1 not null and l2 null     ==> l1 length > l2 length
-   (l1 (< (integer-list-not-zero l1) 0))
+   (l1 (< (version-list-not-zero l1) 0))
    ;; l1 null and l2 not null     ==> l2 length > l1 length
-   (t  (< 0 (integer-list-not-zero l2)))))
-
-
-(defun integer-list-= (l1 l2)
+   (t  (< 0 (version-list-not-zero l2)))))
+
+
+(defun version-list-= (l1 l2)
   "Return t if integer list L1 is equal to L2.
 
 Note that integer list (1) is equal to (1 0), (1 0 0), (1 0 0 0),
@@ -2989,12 +2990,12 @@
    ;; l1 null and l2 null     ==> l1 length = l2 length
    ((and (null l1) (null l2)))
    ;; l1 not null and l2 null ==> l1 length > l2 length
-   (l1 (zerop (integer-list-not-zero l1)))
+   (l1 (zerop (version-list-not-zero l1)))
    ;; l1 null and l2 not null ==> l2 length > l1 length
-   (t  (zerop (integer-list-not-zero l2)))))
-
-
-(defun integer-list-<= (l1 l2)
+   (t  (zerop (version-list-not-zero l2)))))
+
+
+(defun version-list-<= (l1 l2)
   "Return t if integer list L1 is lesser than or equal to L2.
 
 Note that integer list (1) is equal to (1 0), (1 0 0), (1 0 0 0),
@@ -3010,15 +3011,20 @@
    ;; l1 null and l2 null     ==> l1 length = l2 length
    ((and (null l1) (null l2)))
    ;; l1 not null and l2 null ==> l1 length > l2 length
-   (l1 (<= (integer-list-not-zero l1) 0))
+   (l1 (<= (version-list-not-zero l1) 0))
    ;; l1 null and l2 not null ==> l2 length > l1 length
-   (t  (<= 0 (integer-list-not-zero l2)))))
-
-
-(defalias 'version= 'string-equal
-  "Return t if version V1 is equal to V2.
-
-Compare version string using `string-equal'.")
+   (t  (<= 0 (version-list-not-zero l2)))))
+
+(defun version-list-not-zero (lst)
+  "Return the first non-zero element of integer list LST.
+
+If all LST elements are zeroes or LST is nil, return zero."
+  (while (and lst (zerop (car lst)))
+    (setq lst (cdr lst)))
+  (if lst
+      (car lst)
+    ;; there is no element different of zero
+    0))
 
 
 (defun version< (v1 v2)
@@ -3028,7 +3034,7 @@
 etc.  That is, the trailing \".0\"s are irrelevant.  Also, version string \"1\"
 is greater than \"1pre\" which is greater than \"1beta\" which is greater than
 \"1alpha\"."
-  (integer-list-< (version-to-list v1) (version-to-list v2)))
+  (version-list-< (version-to-list v1) (version-to-list v2)))
 
 
 (defun version<= (v1 v2)
@@ -3038,19 +3044,17 @@
 etc.  That is, the trailing \".0\"s are irrelevant.  Also, version string \"1\"
 is greater than \"1pre\" which is greater than \"1beta\" which is greater than
 \"1alpha\"."
-  (integer-list-<= (version-to-list v1) (version-to-list v2)))
-
-
-(defun integer-list-not-zero (lst)
-  "Return the first non-zero element of integer list LST.
-
-If all LST elements are zeroes or LST is nil, return zero."
-  (while (zerop (car lst))
-    (setq lst (cdr lst)))
-  (if lst
-      (car lst)
-    ;; there is no element different of zero
-    0))
+  (version-list-<= (version-to-list v1) (version-to-list v2)))
+
+(defun version= (v1 v2)
+  "Return t if version V1 is equal to V2.
+
+Note that version string \"1\" is equal to \"1.0\", \"1.0.0\", \"1.0.0.0\",
+etc.  That is, the trailing \".0\"s are irrelevant.  Also, version string \"1\"
+is greater than \"1pre\" which is greater than \"1beta\" which is greater than
+\"1alpha\"."
+  (version-list-= (version-to-list v1) (version-to-list v2)))
+
 
 
 ;; arch-tag: f7e0e6e5-70aa-4897-ae72-7a3511ec40bc