Merge pull request #228 from DOCGroup/jwillemsen-patch-1
[MPC.git] / modules / WinVersionTranslator.pm
blobff82a7d2a3ed47b62860c1653996f293aa134b97
1 package WinVersionTranslator;
3 # ************************************************************
4 # Description : Translate the version value for Windows.
5 # Windows can not handle letters in the version
6 # and truncates anything after \d+\.\d+. We
7 # will convert letters to numbers, retain
8 # trailing numbers and everything else will be
9 # converted to a zero.
11 # ex. 1.4.3 => 1.403
12 # 1.4a.5 => 1.4005
13 # 1.4b.4 => 1.4104
15 # Author : Chad Elliott
16 # Create Date : 10/7/2004
17 # ************************************************************
19 # ************************************************************
20 # Pragmas
21 # ************************************************************
23 use strict;
25 # ************************************************************
26 # Subroutine Section
27 # ************************************************************
29 sub translate {
30 my $version = shift;
32 ## See if the version contains something other than numbers followed by
33 ## a decimal point and numbers.
34 if ($version =~ /^(\d+\.\d+)([^\d].*)$/) {
35 $version = $1;
36 my $post = $2;
37 my $length = length($post);
39 ## Convert the non-conforming value to all numbers
40 for(my $i = 0; $i < $length; ++$i) {
41 my $ch = substr($post, $i, 1);
42 if ($ch =~ /[a-z]/i) {
43 my $digit = ord(lc($ch)) - ord('a');
44 $version .= $digit;
46 elsif ($ch =~ /\d/) {
47 $version .= $ch;
49 else {
50 $version .= '0';
54 ## If we have a good version number we need to make sure that the
55 ## minor version number does not exceed the value of a short unsigned
56 ## integer.
57 if ($version =~ /(\d+)\.(\d+)/) {
58 my($major, $minor) = ($1, $2);
59 $minor =~ s/^\d+\.//;
60 while($minor > 65535) {
61 $minor = substr($minor, 0, length($minor) - 1);
63 $version = $major . '.' . $minor;
66 return $version;