DLT_GenConverterData.pl
8.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/usr/bin/perl
#
# Filename:
# ---------
# DLT_GenConverterData.pl
#
# Description:
# ------------
# used to generate DLT converter data.
#
# Auther:
# -------
# mtk01542
#
# Note:
# -----
# none.
#
# Log:
# -----
# 2006/12/26 Create.
#
BEGIN { push @INC, '..\..\..\tools'} # add additional library path
#package XXX; # declare package library
use strict;
use Office;
#******************************************************************************
# Global Data
#******************************************************************************
my $dataFile = "DLT_ThemeTagMapping.xls";
my $outputFilename = "mmi_theme_converter_data.h";
my $outputPath = "..\\..\\Framework\\ThemeManager\\ThemeManagerInc";
my $mmiThemeFile = "CustThemesRes.h";
my $mmiThemePath = "..\\..\\mmi\\inc";
my $tagImageList = 'ImageList';
#******************************************************************************
# Export Function
#******************************************************************************
#******************************************************************************
# Internal Data
#******************************************************************************
#******************************************************************************
# Program Start
#******************************************************************************
my $filename = getCurrDir()."\\$dataFile";
# tag related
my $indexRow_tag = 1;
my %xmlHash = (); # tag data
my $idx_tagHdlr = 1;
my $idx_fieldName = 2;
my $str_tagName = "Tag Name";
my $str_tagHdlr = "Tag Handler";
#my $str_fieldName = "field name of MMI_theme";
my $str_fieldName = "in MMI_theme struct";
my @indexStrArray = ($str_tagName, $str_tagHdlr, $str_fieldName);
# image id related
my $indexRow_imgList = 2;
my %imgDataHash = ();
my $str_imgAttr = "Image Attribute Name";
my $str_imgId = "Image ID in target";
my $str_imgCmplOption = "Compile Option";
my @indexStrArrayImgList = ($str_imgAttr, $str_imgId, $str_imgCmplOption);
my %indexHash = ();
my $row = 2;
my $tagName = "";
my @oriDataHead = ();
my @oriDataTail = ();
my @fileData = ();
my $dataSection = 'head';
&Office::excelOpen($filename);
# read tag data
&Office::excelGetColIndex(\@indexStrArray, \%indexHash, $indexRow_tag);
$tagName = trim(&Office::excelRead($row, $indexHash{$str_tagName}));
while ($tagName ne "")
{
$xmlHash{$tagName}[$idx_tagHdlr] = trim(&Office::excelRead($row, $indexHash{$str_tagHdlr}));
$xmlHash{$tagName}[$idx_fieldName] = trim(&Office::excelRead($row, $indexHash{$str_fieldName}));
$row++;
$tagName = trim(&Office::excelRead($row, $indexHash{$str_tagName}));
}
# read image-id data
&Office::excelSetWorksheet($tagImageList);
&Office::excelGetColIndex(\@indexStrArrayImgList, \%indexHash, $indexRow_imgList);
$row = $indexRow_imgList + 1;
my $attrName = trim(&Office::excelRead($row, $indexHash{$str_imgAttr}));
while ($attrName ne "")
{
my $imgId = trim(&Office::excelRead($row, $indexHash{$str_imgId}));
my $cmplOption = trim(&Office::excelRead($row, $indexHash{$str_imgCmplOption}));
die "duplicate: $attrName-$imgId\n" if (exists $imgDataHash{$attrName}{$imgId});
$imgDataHash{$attrName}{$imgId} = $cmplOption;
$row++;
$attrName = trim(&Office::excelRead($row, $indexHash{$str_imgAttr}));
}
&Office::excelClose();
# sort tags and attrs
my @sortedTags = sort keys(%xmlHash);
my @sortedImgAttrs = sort keys(%imgDataHash);
my $outputFile = "$outputPath\\$outputFilename";
# read original data
open(hFile, "<$outputFile") or die "can't open $outputFile!\n";
@fileData = <hFile>;
close(hFile);
foreach my $line (@fileData)
{
if ($dataSection eq 'head')
{
push @oriDataHead, $line;
$dataSection = '' if ($line =~ /Converter Data Begins/);
}
elsif ($dataSection eq 'tail')
{
push @oriDataTail, $line;
}
else
{
if ($line =~/Converter Data Ends/)
{
$dataSection = 'tail';
push @oriDataTail, $line;
}
}
}
push @oriDataHead, "\n";
unshift @oriDataTail, "\n";
open(hFile, ">$outputFile") or die "can't open $outputFile to write!\n";
@fileData = ();
# parse MMI_theme structure
&parseMMIThemeStruct(\@fileData, "$mmiThemePath\\$mmiThemeFile");
push @fileData, "MMI_theme_buff_type buffer_DLT;\n\n";
push @fileData, "#define BASE_PTR(x)\t\t(&(buffer_DLT.x))\n\n";
# generate tag data
push @fileData, "/* tags should be sorted in ASCII code order */\n";
push @fileData, "const tc_all_tags_index_struct g_tc_xml_tags_map[] = {\n";
foreach my $tag (@sortedTags)
{
my $tagHdlr;
die "tag handler is empty for $tag!!\n" if ($xmlHash{$tag}[$idx_tagHdlr] eq "");
$tagHdlr = $xmlHash{$tag}[$idx_tagHdlr];
#print "$tag [ver] = $xmlHash{$tag}[$idx_ver]\n";
my $fieldName = $xmlHash{$tag}[$idx_fieldName];
my $dltPtr = "NULL";
my $basePtr = "NULL";
#if ($fieldName !~ /^[\s]*$/)
if ($fieldName =~ /^Y$/i)
{
$dltPtr = "DLT_PTR($tag)"; # tag name is same as MMI_theme field name
if ($tagHdlr !~ /(mmi_tc_pu8_tag_handler)|(mmi_tc_s32_tag_handler)/)
{
$basePtr = "BASE_PTR($tag)"; # tag name is same as MMI_theme field name
}
}
push @fileData, "\t{\"$tag\", $tagHdlr, (void *)$dltPtr, (void *)$basePtr},\n";
}
push @fileData, "};\n";
# generate image-id attribute data
push @fileData, "\n/* attributes should be sorted in ASCII code order */\n";
push @fileData, "const tc_image_tags_index_struct g_tc_image_tags_map[] = {\n";
foreach my $attr (@sortedImgAttrs)
{
while (my ($key, $value) = each(%{$imgDataHash{$attr}}))
{
push @fileData, "#if $value\n" if ($value ne "");
push @fileData, "\t{\"$attr\", $key},\n";
push @fileData, "#endif\n" if ($value ne "");
}
}
push @fileData, "};\n";
unshift @fileData, @oriDataHead;
push @fileData, @oriDataTail;
print hFile join('', @fileData);
close(hFile);
#******************************************************************************
# Internal Function
#******************************************************************************
#******************************************************************************
# FUNCTION
# xxx
# DESCRIPTION
# xxx
# PARAMETERS
# xxx
# RETURNS
# xxx
#******************************************************************************
#******************************************************************************
# FUNCTION
# parseMMIThemeStruct
# DESCRIPTION
# xxx
# PARAMETERS
# xxx
# RETURNS
# xxx
#******************************************************************************
sub parseMMIThemeStruct()
{
my $dataOut_ref;
my $sourceFile;
($dataOut_ref, $sourceFile) = @_;
my @fileData;
my %buffList = ("UI_filled_area" => 1, "color" => 1);
my $startParsing = 0;
my $hFile;
open($hFile, "<$sourceFile") or die "[ERROR] can't open $sourceFile!\n";
@fileData = <$hFile>;
close($hFile);
foreach my $line (@fileData)
{
if ($line =~ /^[\s]*}[\s]*MMI_theme;/)
{
push @{$dataOut_ref}, "} MMI_theme_buff_type;\n\n\n";
last;
}
if ($startParsing)
{
if ($line =~ /^[\s]*([\w]+)[\s]+([\w]+);/)
{
# special handle for UI_font_type -> stFontAttribute
if ($1 eq 'UI_font_type')
{
push @{$dataOut_ref}, "\tstFontAttribute\t$2;\n";
}
}
elsif ($line =~ /^[\s]*([\w]+)[\s]*\*[\s]*([\w]+);/)
{
push @{$dataOut_ref}, "\t$1\t$2;\n";
}
else
{
# skip continuous empty lines
if (!(($line =~ /^[\s]*$/) && ($$dataOut_ref[scalar(@{$dataOut_ref})-1] =~ /^[\s]*$/)))
{
push @{$dataOut_ref}, $line if ($line !~ /^[\s]*{/);
}
}
}
elsif ($line =~ /^[\s]*typedef[\s]+struct[\s]+_MMI_theme/)
{
push @{$dataOut_ref}, "typedef struct {\n";
$startParsing = 1;
}
}
}
#******************************************************************************
# FUNCTION
# getCurrDir
# DESCRIPTION
# get current directory
# PARAMETERS
# none
# RETURNS
# current directory
#******************************************************************************
sub getCurrDir()
{
use Cwd;
my $currDir;
$currDir = getcwd;
$currDir =~ s/\//\\/g;
return $currDir;
}
#******************************************************************************
# FUNCTION
# trim
# DESCRIPTION
# trim left and right spaces
# PARAMETERS
# $str [IN] - string to process
# RETURNS
# processed string
#******************************************************************************
sub trim()
{
my $str;
($str) = @_;
$str =~ s/(^\s*)|(\s*$)//g;
return $str;
}