|
Lines 57-92
Link Here
|
| 57 |
# This function returns -1, 0, or 1, in the same manner as <=> or cmp. |
57 |
# This function returns -1, 0, or 1, in the same manner as <=> or cmp. |
| 58 |
# |
58 |
# |
| 59 |
sub CompareVersions { |
59 |
sub CompareVersions { |
| 60 |
local($v1, $v2); |
60 |
my($v1, $v2); |
| 61 |
$v1 = $_[0]; |
61 |
$v1 = $_[0]; |
| 62 |
$v2 = $_[1]; |
62 |
$v2 = $_[1]; |
| 63 |
|
63 |
|
| 64 |
# Short-cut in case of equality |
64 |
# Short-cut in case of equality |
| 65 |
if ($v1 eq $v2) { |
65 |
if ($v1 eq $v2) { |
| 66 |
return 0; |
66 |
return 0; |
| 67 |
} |
67 |
} |
| 68 |
|
68 |
|
| 69 |
# Loop over different components (the parts separated by dots). |
69 |
# Loop over different components (the parts separated by dots). |
| 70 |
# If any component differs, we have the basis for an inequality. |
70 |
# If any component differs, we have the basis for an inequality. |
| 71 |
while (1) { |
71 |
while (1) { |
| 72 |
($p1, $v1) = split(/\./, $v1, 2); |
72 |
($p1, $v1) = split(/\./, $v1, 2); |
| 73 |
($p2, $v2) = split(/\./, $v2, 2); |
73 |
($p2, $v2) = split(/\./, $v2, 2); |
| 74 |
|
74 |
|
| 75 |
# If we\'re out of components, they\'re equal (this probably won\'t |
75 |
# If we\'re out of components, they\'re equal (this probably won\'t |
| 76 |
# happen, since the short-cut case above should get this). |
76 |
# happen, since the short-cut case above should get this). |
| 77 |
if (($p1 eq "") && ($p2 eq "")) { |
77 |
if (($p1 eq "") && ($p2 eq "")) { |
| 78 |
return 0; |
78 |
return 0; |
| 79 |
} |
79 |
} |
| 80 |
# Check for numeric inequality. We assume here that (for example) |
80 |
# Check for numeric inequality. We assume here that (for example) |
| 81 |
# 3.09 < 3.10. |
81 |
# 3.09 < 3.10. We force a . on the front of $p1 and $p2 so that |
| 82 |
elsif ($p1 != $p2) { |
82 |
# 4.1 > 4.04 |
| 83 |
return $p1 <=> $p2; |
83 |
elsif ($p1 != $p2) { |
| 84 |
} |
84 |
$p1 = '.' . $p1; |
| 85 |
# Check for string inequality, given numeric equality. This |
85 |
$p2 = '.' . $p2; |
| 86 |
# handles version numbers of the form 3.4j < 3.4k. |
86 |
return $p1 <=> $p2; |
| 87 |
elsif ($p1 ne $p2) { |
87 |
} |
| 88 |
return $p1 cmp $p2; |
88 |
# Check for string inequality, given numeric equality. This |
| 89 |
} |
89 |
# handles version numbers of the form 3.4j < 3.4k. |
|
|
90 |
elsif ($p1 ne $p2) { |
| 91 |
return $p1 cmp $p2; |
| 92 |
} |
| 90 |
} |
93 |
} |
| 91 |
|
94 |
|
| 92 |
} |
95 |
} |