599
|
1 |
# Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
# All rights reserved.
|
|
3 |
# This component and the accompanying materials are made available
|
|
4 |
# under the terms of "Eclipse Public License v1.0"
|
|
5 |
# which accompanies this distribution, and is available
|
|
6 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
#
|
|
8 |
# Initial Contributors:
|
|
9 |
# Nokia Corporation - initial contribution.
|
|
10 |
#
|
|
11 |
# Contributors:
|
|
12 |
#
|
|
13 |
# Description:
|
|
14 |
# Contains utility subroutines for MAKMAKE and associated scripts
|
|
15 |
#
|
|
16 |
#
|
|
17 |
|
|
18 |
package Genutl;
|
|
19 |
|
|
20 |
require Exporter;
|
|
21 |
@ISA=qw(Exporter);
|
|
22 |
|
|
23 |
@EXPORT=qw(
|
|
24 |
Genutl_AnyToHex
|
|
25 |
Genutl_VersionToUserString
|
|
26 |
Genutl_VersionToHexString
|
|
27 |
Genutl_VersionToFileAugment
|
|
28 |
Genutl_StringToVersion
|
|
29 |
Genutl_ParseVersionedName
|
|
30 |
Genutl_NormaliseVersionedName
|
|
31 |
);
|
|
32 |
|
|
33 |
|
|
34 |
sub Genutl_AnyToHex ($) {
|
|
35 |
# changes decimal and hexadecimal numbers to the required hexadecimal format
|
|
36 |
my $Num=$_[0];
|
|
37 |
$Num=lc $Num; # lower casing the x specifying hexadecimal essential
|
|
38 |
if ($Num=~/^(\d{1,10}|0x[\dabcdef]{1,8})$/o) { # this isn't perfect
|
|
39 |
$Num=oct $Num if $Num=~/^0x/o;
|
|
40 |
return sprintf "0x%.8lx", $Num;
|
|
41 |
}
|
|
42 |
return undef;
|
|
43 |
}
|
|
44 |
|
|
45 |
sub Genutl_VersionToUserString(%) {
|
|
46 |
my (%ver) = @_;
|
|
47 |
return sprintf("%d\.%d", $ver{major}, $ver{minor});
|
|
48 |
}
|
|
49 |
|
|
50 |
sub Genutl_VersionToHexString(%) {
|
|
51 |
my (%ver) = @_;
|
|
52 |
return sprintf("%04x%04x", $ver{major}, $ver{minor});
|
|
53 |
}
|
|
54 |
|
|
55 |
sub Genutl_VersionToFileAugment(%) {
|
|
56 |
my (%ver) = @_;
|
|
57 |
return sprintf("{%04x%04x}", $ver{major}, $ver{minor});
|
|
58 |
}
|
|
59 |
|
|
60 |
sub Genutl_StringToVersion($) {
|
|
61 |
my ($s) = @_;
|
|
62 |
if ($s =~ /^(\d+)\.(\d+)$/) {
|
|
63 |
my %ver;
|
|
64 |
$ver{major} = $1;
|
|
65 |
$ver{minor} = $2;
|
|
66 |
if ($ver{major}<32768 and $ver{minor}<32768) {
|
|
67 |
return %ver;
|
|
68 |
}
|
|
69 |
}
|
|
70 |
return undef;
|
|
71 |
}
|
|
72 |
|
|
73 |
sub Genutl_ParseVersionedName($) {
|
|
74 |
my ($nref) = @_;
|
|
75 |
return 1 unless ($$nref =~ /\{|\}/);
|
|
76 |
my $a;
|
|
77 |
my $b;
|
|
78 |
if ($$nref =~ /(.*)\{((\d|a|b|c|d|e|f){8})\}(.*?)/i) {
|
|
79 |
$a = $1;
|
|
80 |
$b = $3;
|
|
81 |
} elsif ($$nref =~ /(.*)\{\s*(\d+)\s*\.\s*(\d+)\s*\}(.*?)$/i) {
|
|
82 |
$a = $1;
|
|
83 |
$b = $4;
|
|
84 |
my $major = $2;
|
|
85 |
my $minor = $3;
|
|
86 |
return 0 if ($major>=32768 or $minor>=32768);
|
|
87 |
$$nref = $a.sprintf("{%04x%04x}",$major,$minor).$b;
|
|
88 |
} else {
|
|
89 |
return 0;
|
|
90 |
}
|
|
91 |
if ($a=~/\{|\}/ or $b=~/\{|\}/) {
|
|
92 |
return 0;
|
|
93 |
}
|
|
94 |
return 1;
|
|
95 |
}
|
|
96 |
|
|
97 |
sub Genutl_NormaliseVersionedName($) {
|
|
98 |
my ($name) = @_;
|
|
99 |
if ($name =~ /(.*)\{\s*(\d+)\s*\.\s*(\d+)\s*\}(.*?)$/i) {
|
|
100 |
my $a = $1;
|
|
101 |
my $b = $4;
|
|
102 |
my $major = $2;
|
|
103 |
my $minor = $3;
|
|
104 |
return $a.sprintf("{%04x%04x}",$major,$minor).$b if ($major<32768 and $minor<32768);
|
|
105 |
}
|
|
106 |
return $name;
|
|
107 |
}
|