sort versions with major.minor.patch number, e.g.: 5.1.1 <> 5.2.2
This commit is contained in:
parent
5712cd7e23
commit
d2227d7bce
Notes:
svn2git
2020-12-08 03:00:23 +00:00
svn path=/head/; revision=53009
1 changed files with 40 additions and 5 deletions
|
@ -672,7 +672,7 @@ $manPathDefault = 'FreeBSD 12.0-RELEASE and Ports';
|
|||
'HP-UX 10.01', "$manLocalDir/HP-UX-10.01",
|
||||
'HP-UX 9.07', "$manLocalDir/HP-UX-9.07",
|
||||
|
||||
'IRIX-6.5.30', "$manLocalDir/IRIX-6.5.30/catman/a_man:$manLocalDir/IRIX-6.5.30/catman/p_man:$manLocalDir/IRIX-6.5.30/catman/u_man:$manLocalDir/IRIX-6.5.30/dt",
|
||||
'IRIX 6.5.30', "$manLocalDir/IRIX-6.5.30/catman/a_man:$manLocalDir/IRIX-6.5.30/catman/p_man:$manLocalDir/IRIX-6.5.30/catman/u_man:$manLocalDir/IRIX-6.5.30/dt",
|
||||
|
||||
'SunOS 5.10', "$manLocalDir/SunOS-5.10",
|
||||
'SunOS 5.9', "$manLocalDir/SunOS-5.9",
|
||||
|
@ -911,20 +911,55 @@ sub sort_versions {
|
|||
my @b = ( lc($b) =~ m,^(\D+)([\d\.]+)(\D*)$, );
|
||||
|
||||
if (@a and @b) {
|
||||
return $a[0] cmp $b[0] || (-1 * ($a[1] <=> $b[1])) || $a[2] cmp $a[2] || $a cmp $b;
|
||||
return $a[0] cmp $b[0] || # FreeBDS <=> IRIX
|
||||
&version($a[1], $b[1]) || # 6.5.30 <=> 6.5.31
|
||||
$a[2] cmp $a[2] || # RELEASE <=> ports
|
||||
$a cmp $b; # rest
|
||||
}
|
||||
|
||||
# 2.9.1 BSD
|
||||
@a = ( lc($a) =~ m,^(\d\.+)(.*)$, );
|
||||
@b = ( lc($b) =~ m,^(\d\.+)(.*)$, );
|
||||
@a = ( lc($a) =~ m,^([\d\.]+)(.*)$, );
|
||||
@b = ( lc($b) =~ m,^([\d\.]+)(.*)$, );
|
||||
if (@a and @b) {
|
||||
return (-1 * ( $a[0] <=> $b[0])) || $a[1] <=> $b[1] || $a cmp $b;
|
||||
return &version($a[0], $b[0]) || # 2.9.1BSD
|
||||
$a[1] <=> $b[1] || # BSD
|
||||
$a cmp $b; # rest
|
||||
}
|
||||
|
||||
# rest
|
||||
return $a cmp $b;
|
||||
}
|
||||
|
||||
sub version {
|
||||
return &version_compare(@_) * -1;
|
||||
}
|
||||
|
||||
# compare two versions, e.g.: 5.1.1 <> 5.2.2
|
||||
sub version_compare {
|
||||
my $a = shift;
|
||||
my $b = shift;
|
||||
|
||||
my @a = split( '\.', $a );
|
||||
my @b = split( '\.', $b );
|
||||
|
||||
my $max = @a >= @b ? @a : @b;
|
||||
|
||||
for ( my $i = 0 ; $i < $max ; $i++ ) {
|
||||
|
||||
# 5.1 <=> 5.1.1
|
||||
return -1 if !defined $a[$i];
|
||||
|
||||
# 5.1.1 <=> 5.1
|
||||
return +1 if !defined $b[$i];
|
||||
|
||||
if ( ( $a[$i] <=> $b[$i] ) != 0 ) {
|
||||
return $a[$i] <=> $b[$i];
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
# FreeBSD manual pages first before any other manual pages
|
||||
sub freebsd_first {
|
||||
my @list = @_;
|
||||
|
|
Loading…
Reference in a new issue