IBM Prerequisite Scanner User Manual page 65

Table of Contents

Advertisement

'
-1 version1 < version2
'
0 version1 = version2
'
' Special cases:
' RESULT
version 1
'
0
empty
'
1
validString
' -1
empty
'
' NOTE: This function should eventually move to common_functions.vbs
function versionCompare(ver1, ver2)
WScript.echo "Comparing [" & ver1 & "] to [" & ver2 & "]"
Const UNASSIGNED = "*UNASSIGNED*"
Dim v1Default, v2Default
' Handle special cases:
if (IsEmpty(ver1) and IsEmpty(ver2)) Then
versionCompare = 0
exit function
end if
if (IsEmpty(ver1) and not IsEmpty(ver2)) Then
versionCompare = -1
exit function
end if
if (not IsEmpty(ver1) and IsEmpty(ver2)) Then
versionCompare = 1
exit function
end if
Dim ver1Parts, ver2Parts
' Versions are not empty. Break into parts and compare numbers
ver1Parts = Split(ver1,".")
ver2Parts = Split(ver2,".")
Dim v1Size, v2Size
v1Size = ubound(ver1Parts)
v2Size = ubound(ver2Parts)
' If last version part is "*", treat all missing parts as "*"
'(so 2.* matches 2.1.3, for example)
if (v1Size > v2Size) Then
Redim Preserve ver2Parts(v1Size)
if (ver2Parts(v2Size)="*") Then
for i = v2Size to v1Size
ver2Parts(i) = "*"
next
end if
elseif (v2Size > v1Size) Then
Redim Preserve ver1Parts(v2Size)
if (ver1Parts(v1Size)="*") Then
for i = v1Size to v2Size
ver1Parts(i) = "*"
next
end if
end if
Dim i
i = 0
Do While (i<=ubound(ver1Parts) or i<=ubound(ver2Parts))
Dim v1, v2, v1Str, v2Str
v1Str = UNASSIGNED
v2Str = UNASSIGNED
version 2
empty
empty
validString
Chapter 3. Extending Prerequisite Scanner
55

Advertisement

Table of Contents
loading

Table of Contents