comparison lisp/subr.el @ 107709:6db4a0b4404d

Merge from emacs-23 branch
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 30 Mar 2010 22:37:57 -0400
parents 954352cc49bd 1d43618b7e72
children 452f0cc5f879
comparison
equal deleted inserted replaced
107666:67420d9c4e00 107709:6db4a0b4404d
3593 '(("^[-_+ ]?a\\(lpha\\)?$" . -3) 3593 '(("^[-_+ ]?a\\(lpha\\)?$" . -3)
3594 ("^[-_+]$" . -3) ; treat "1.2.3-20050920" and "1.2-3" as alpha releases 3594 ("^[-_+]$" . -3) ; treat "1.2.3-20050920" and "1.2-3" as alpha releases
3595 ("^[-_+ ]cvs$" . -3) ; treat "1.2.3-CVS" as alpha release 3595 ("^[-_+ ]cvs$" . -3) ; treat "1.2.3-CVS" as alpha release
3596 ("^[-_+ ]?b\\(eta\\)?$" . -2) 3596 ("^[-_+ ]?b\\(eta\\)?$" . -2)
3597 ("^[-_+ ]?\\(pre\\|rc\\)$" . -1)) 3597 ("^[-_+ ]?\\(pre\\|rc\\)$" . -1))
3598 "*Specify association between non-numeric version part and a priority. 3598 "*Specify association between non-numeric version and its priority.
3599 3599
3600 This association is used to handle version string like \"1.0pre2\", 3600 This association is used to handle version string like \"1.0pre2\",
3601 \"0.9alpha1\", etc. It's used by `version-to-list' (which see) to convert the 3601 \"0.9alpha1\", etc. It's used by `version-to-list' (which see) to convert the
3602 non-numeric part to an integer. For example: 3602 non-numeric part of a version string to an integer. For example:
3603 3603
3604 String Version Integer List Version 3604 String Version Integer List Version
3605 \"1.0pre2\" (1 0 -1 2) 3605 \"1.0pre2\" (1 0 -1 2)
3606 \"1.0PRE2\" (1 0 -1 2) 3606 \"1.0PRE2\" (1 0 -1 2)
3607 \"22.8beta3\" (22 8 -2 3) 3607 \"22.8beta3\" (22 8 -2 3)
3615 (REGEXP . PRIORITY) 3615 (REGEXP . PRIORITY)
3616 3616
3617 Where: 3617 Where:
3618 3618
3619 REGEXP regexp used to match non-numeric part of a version string. 3619 REGEXP regexp used to match non-numeric part of a version string.
3620 It should begin with a `^' anchor and end with a `$' to 3620 It should begin with the `^' anchor and end with a `$' to
3621 prevent false hits. Letter-case is ignored while matching 3621 prevent false hits. Letter-case is ignored while matching
3622 REGEXP. 3622 REGEXP.
3623 3623
3624 PRIORITY negative integer which indicate the non-numeric priority.") 3624 PRIORITY a negative integer specifying non-numeric priority of REGEXP.")
3625 3625
3626 3626
3627 (defun version-to-list (ver) 3627 (defun version-to-list (ver)
3628 "Convert version string VER into an integer list. 3628 "Convert version string VER into a list of integers.
3629 3629
3630 The version syntax is given by the following EBNF: 3630 The version syntax is given by the following EBNF:
3631 3631
3632 VERSION ::= NUMBER ( SEPARATOR NUMBER )*. 3632 VERSION ::= NUMBER ( SEPARATOR NUMBER )*.
3633 3633
3637 | `version-regexp-alist' (which see). 3637 | `version-regexp-alist' (which see).
3638 3638
3639 The NUMBER part is optional if SEPARATOR is a match for an element 3639 The NUMBER part is optional if SEPARATOR is a match for an element
3640 in `version-regexp-alist'. 3640 in `version-regexp-alist'.
3641 3641
3642 As an example of valid version syntax: 3642 Examples of valid version syntax:
3643 3643
3644 1.0pre2 1.0.7.5 22.8beta3 0.9alpha1 6.9.30Beta 3644 1.0pre2 1.0.7.5 22.8beta3 0.9alpha1 6.9.30Beta
3645 3645
3646 As an example of invalid version syntax: 3646 Examples of invalid version syntax:
3647 3647
3648 1.0prepre2 1.0..7.5 22.8X3 alpha3.2 .5 3648 1.0prepre2 1.0..7.5 22.8X3 alpha3.2 .5
3649 3649
3650 As an example of version convertion: 3650 Examples of version conversion:
3651 3651
3652 String Version Integer List Version 3652 Version String Version as a List of Integers
3653 \"1.0.7.5\" (1 0 7 5) 3653 \"1.0.7.5\" (1 0 7 5)
3654 \"1.0pre2\" (1 0 -1 2) 3654 \"1.0pre2\" (1 0 -1 2)
3655 \"1.0PRE2\" (1 0 -1 2) 3655 \"1.0PRE2\" (1 0 -1 2)
3656 \"22.8beta3\" (22 8 -2 3) 3656 \"22.8beta3\" (22 8 -2 3)
3657 \"22.8Beta3\" (22 8 -2 3) 3657 \"22.8Beta3\" (22 8 -2 3)
3693 (error "Invalid version syntax: '%s'" ver) 3693 (error "Invalid version syntax: '%s'" ver)
3694 (nreverse lst))))) 3694 (nreverse lst)))))
3695 3695
3696 3696
3697 (defun version-list-< (l1 l2) 3697 (defun version-list-< (l1 l2)
3698 "Return t if integer list L1 is lesser than L2. 3698 "Return t if L1, a list specification of a version, is lower than L2.
3699 3699
3700 Note that integer list (1) is equal to (1 0), (1 0 0), (1 0 0 0), 3700 Note that a version specified by the list (1) is equal to (1 0),
3701 etc. That is, the trailing zeroes are irrelevant. Also, integer 3701 \(1 0 0), (1 0 0 0), etc. That is, the trailing zeros are insignificant.
3702 list (1) is greater than (1 -1) which is greater than (1 -2) 3702 Also, a version given by the list (1) is higher than (1 -1), which in
3703 which is greater than (1 -3)." 3703 turn is higher than (1 -2), which is higher than (1 -3)."
3704 (while (and l1 l2 (= (car l1) (car l2))) 3704 (while (and l1 l2 (= (car l1) (car l2)))
3705 (setq l1 (cdr l1) 3705 (setq l1 (cdr l1)
3706 l2 (cdr l2))) 3706 l2 (cdr l2)))
3707 (cond 3707 (cond
3708 ;; l1 not null and l2 not null 3708 ;; l1 not null and l2 not null
3714 ;; l1 null and l2 not null ==> l2 length > l1 length 3714 ;; l1 null and l2 not null ==> l2 length > l1 length
3715 (t (< 0 (version-list-not-zero l2))))) 3715 (t (< 0 (version-list-not-zero l2)))))
3716 3716
3717 3717
3718 (defun version-list-= (l1 l2) 3718 (defun version-list-= (l1 l2)
3719 "Return t if integer list L1 is equal to L2. 3719 "Return t if L1, a list specification of a version, is equal to L2.
3720 3720
3721 Note that integer list (1) is equal to (1 0), (1 0 0), (1 0 0 0), 3721 Note that a version specified by the list (1) is equal to (1 0),
3722 etc. That is, the trailing zeroes are irrelevant. Also, integer 3722 \(1 0 0), (1 0 0 0), etc. That is, the trailing zeros are insignificant.
3723 list (1) is greater than (1 -1) which is greater than (1 -2) 3723 Also, a version given by the list (1) is higher than (1 -1), which in
3724 which is greater than (1 -3)." 3724 turn is higher than (1 -2), which is higher than (1 -3)."
3725 (while (and l1 l2 (= (car l1) (car l2))) 3725 (while (and l1 l2 (= (car l1) (car l2)))
3726 (setq l1 (cdr l1) 3726 (setq l1 (cdr l1)
3727 l2 (cdr l2))) 3727 l2 (cdr l2)))
3728 (cond 3728 (cond
3729 ;; l1 not null and l2 not null 3729 ;; l1 not null and l2 not null
3735 ;; l1 null and l2 not null ==> l2 length > l1 length 3735 ;; l1 null and l2 not null ==> l2 length > l1 length
3736 (t (zerop (version-list-not-zero l2))))) 3736 (t (zerop (version-list-not-zero l2)))))
3737 3737
3738 3738
3739 (defun version-list-<= (l1 l2) 3739 (defun version-list-<= (l1 l2)
3740 "Return t if integer list L1 is lesser than or equal to L2. 3740 "Return t if L1, a list specification of a version, is lower or equal to L2.
3741 3741
3742 Note that integer list (1) is equal to (1 0), (1 0 0), (1 0 0 0), 3742 Note that integer list (1) is equal to (1 0), (1 0 0), (1 0 0 0),
3743 etc. That is, the trailing zeroes are irrelevant. Also, integer 3743 etc. That is, the trailing zeroes are irrelevant. Also, integer
3744 list (1) is greater than (1 -1) which is greater than (1 -2) 3744 list (1) is greater than (1 -1) which is greater than (1 -2)
3745 which is greater than (1 -3)." 3745 which is greater than (1 -3)."
3755 (l1 (<= (version-list-not-zero l1) 0)) 3755 (l1 (<= (version-list-not-zero l1) 0))
3756 ;; l1 null and l2 not null ==> l2 length > l1 length 3756 ;; l1 null and l2 not null ==> l2 length > l1 length
3757 (t (<= 0 (version-list-not-zero l2))))) 3757 (t (<= 0 (version-list-not-zero l2)))))
3758 3758
3759 (defun version-list-not-zero (lst) 3759 (defun version-list-not-zero (lst)
3760 "Return the first non-zero element of integer list LST. 3760 "Return the first non-zero element of LST, which is a list of integers.
3761 3761
3762 If all LST elements are zeroes or LST is nil, return zero." 3762 If all LST elements are zeros or LST is nil, return zero."
3763 (while (and lst (zerop (car lst))) 3763 (while (and lst (zerop (car lst)))
3764 (setq lst (cdr lst))) 3764 (setq lst (cdr lst)))
3765 (if lst 3765 (if lst
3766 (car lst) 3766 (car lst)
3767 ;; there is no element different of zero 3767 ;; there is no element different of zero
3768 0)) 3768 0))
3769 3769
3770 3770
3771 (defun version< (v1 v2) 3771 (defun version< (v1 v2)
3772 "Return t if version V1 is lesser than V2. 3772 "Return t if version V1 is lower (older) than V2.
3773 3773
3774 Note that version string \"1\" is equal to \"1.0\", \"1.0.0\", \"1.0.0.0\", 3774 Note that version string \"1\" is equal to \"1.0\", \"1.0.0\", \"1.0.0.0\",
3775 etc. That is, the trailing \".0\"s are irrelevant. Also, version string \"1\" 3775 etc. That is, the trailing \".0\"s are insignificant. Also, version
3776 is greater than \"1pre\" which is greater than \"1beta\" which is greater than 3776 string \"1\" is higher (newer) than \"1pre\", which is higher than \"1beta\",
3777 \"1alpha\"." 3777 which is higher than \"1alpha\"."
3778 (version-list-< (version-to-list v1) (version-to-list v2))) 3778 (version-list-< (version-to-list v1) (version-to-list v2)))
3779 3779
3780 3780
3781 (defun version<= (v1 v2) 3781 (defun version<= (v1 v2)
3782 "Return t if version V1 is lesser than or equal to V2. 3782 "Return t if version V1 is lower (older) than or equal to V2.
3783 3783
3784 Note that version string \"1\" is equal to \"1.0\", \"1.0.0\", \"1.0.0.0\", 3784 Note that version string \"1\" is equal to \"1.0\", \"1.0.0\", \"1.0.0.0\",
3785 etc. That is, the trailing \".0\"s are irrelevant. Also, version string \"1\" 3785 etc. That is, the trailing \".0\"s are insignificant.. Also, version
3786 is greater than \"1pre\" which is greater than \"1beta\" which is greater than 3786 string \"1\" is higher (newer) than \"1pre\", which is higher than \"1beta\",
3787 \"1alpha\"." 3787 which is higher than \"1alpha\"."
3788 (version-list-<= (version-to-list v1) (version-to-list v2))) 3788 (version-list-<= (version-to-list v1) (version-to-list v2)))
3789 3789
3790 (defun version= (v1 v2) 3790 (defun version= (v1 v2)
3791 "Return t if version V1 is equal to V2. 3791 "Return t if version V1 is equal to V2.
3792 3792
3793 Note that version string \"1\" is equal to \"1.0\", \"1.0.0\", \"1.0.0.0\", 3793 Note that version string \"1\" is equal to \"1.0\", \"1.0.0\", \"1.0.0.0\",
3794 etc. That is, the trailing \".0\"s are irrelevant. Also, version string \"1\" 3794 etc. That is, the trailing \".0\"s are insignificant.. Also, version
3795 is greater than \"1pre\" which is greater than \"1beta\" which is greater than 3795 string \"1\" is higher (newer) than \"1pre\", which is higher than \"1beta\",
3796 \"1alpha\"." 3796 which is higher than \"1alpha\"."
3797 (version-list-= (version-to-list v1) (version-to-list v2))) 3797 (version-list-= (version-to-list v1) (version-to-list v2)))
3798 3798
3799 3799
3800 ;;; Misc. 3800 ;;; Misc.
3801 (defconst menu-bar-separator '("--") 3801 (defconst menu-bar-separator '("--")