|
1 # |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 ###################################### |
|
17 # Run with -h to get help |
|
18 ###################################### |
|
19 use strict; |
|
20 use lib "."; |
|
21 use open OUT => ':raw'; |
|
22 use Win32::OLE qw(in with); |
|
23 use Win32::OLE::Const 'Microsoft Excel'; |
|
24 use Cwd; |
|
25 use Getopt::Long; |
|
26 use File::Copy; |
|
27 use Storable qw(fd_retrieve); |
|
28 use excel_support; # Own perl module that contains the reading of memory-sheets |
|
29 use cenrep_keys; # Own perl module that contains the reading of memory-sheets |
|
30 |
|
31 |
|
32 use Data::Dumper; |
|
33 |
|
34 # this is the bit mask that is put into the metadata in the ini-file, when |
|
35 # backup is set on. |
|
36 my $globalBackupValue = 0x01000000; |
|
37 |
|
38 ########################################################################### |
|
39 ########################################################################### |
|
40 sub printStr |
|
41 { |
|
42 my $to = shift; |
|
43 my $str = shift; |
|
44 |
|
45 for (my $i = 0; $i < length($str); $i++) |
|
46 { |
|
47 printf $to "%s\0", substr($str,$i, 1); |
|
48 } |
|
49 } |
|
50 |
|
51 ########################################################################### |
|
52 ########################################################################### |
|
53 sub printNewLine |
|
54 { |
|
55 my $to = shift; |
|
56 my $fileName = shift; |
|
57 |
|
58 print $to "\x0D\x00\x0A\x00"; |
|
59 |
|
60 return; |
|
61 } |
|
62 # # We need to close the file temporarely so that we can |
|
63 # # write a new line into it differently. It seems that |
|
64 # # unicode file name writing is somehow wrong in the |
|
65 # # used perl versio (ActivePerl 5.8.4) |
|
66 |
|
67 # close $to; |
|
68 # # Writing the new line into the end of the line |
|
69 # open $to,">>$fileName"; |
|
70 # binmode OUT; |
|
71 # print OUT chr(13); |
|
72 # print OUT chr(0); |
|
73 # print OUT chr(10); |
|
74 # print OUT chr(0); |
|
75 # close OUT; |
|
76 |
|
77 # # Opening the file again to |
|
78 # # open(OUT,">>:encoding(UTF-16LE)",$fileName) || die "unable to open $fileName"; |
|
79 # open(OUT,">>$fileName") || die "unable to open $fileName"; |
|
80 # } |
|
81 |
|
82 ########################################################################### |
|
83 # Function that gets a dir as parameter and reads the list of excel files from the |
|
84 # given directory. |
|
85 # |
|
86 # Params: a directory name |
|
87 # |
|
88 # Return value: a reference to a list of filenames. |
|
89 ########################################################################### |
|
90 sub getExcelFilesFromDir |
|
91 { |
|
92 my $dir = shift; |
|
93 |
|
94 # the given dir should be relative to the dir, where the script is executed. |
|
95 if($dir !~ /^[\\\/]/ && $dir !~ /^[A-Za-z]:/) |
|
96 { |
|
97 $dir = cwd . "\\$dir"; |
|
98 } |
|
99 my @files; |
|
100 @files = <$dir\\*.xls >; |
|
101 |
|
102 return \@files; |
|
103 } |
|
104 |
|
105 |
|
106 ################################################### |
|
107 # Function that reads the file names from the given file. |
|
108 # THe information is read from Column A and 1st empty row indicates |
|
109 # end of input. |
|
110 # |
|
111 # Params: fileNameRead, refToExcelApp |
|
112 ################################################### |
|
113 sub getExcelFilesFromFile |
|
114 { |
|
115 my $file = shift; |
|
116 |
|
117 my @fileList; |
|
118 # ---------------------------------------------------------------- |
|
119 # Open the file |
|
120 # ---------------------------------------------------------------- |
|
121 open(IN,$file) || die "Unable to open: $file"; |
|
122 |
|
123 #------------------------------------------------------------ |
|
124 # Read file line by line |
|
125 #------------------------------------------------------------ |
|
126 while(<IN>) |
|
127 { |
|
128 my $fileWithPath = $_; |
|
129 chomp($fileWithPath); |
|
130 |
|
131 if(! -f $fileWithPath) |
|
132 { |
|
133 print STDERR "Warning: input file not found: $fileWithPath\n"; |
|
134 } |
|
135 else |
|
136 { |
|
137 push(@fileList,$fileWithPath); |
|
138 } |
|
139 } |
|
140 |
|
141 return \@fileList; |
|
142 } |
|
143 |
|
144 ################################################### |
|
145 ################################################### |
|
146 sub isRemoved |
|
147 { |
|
148 my $platId = shift; |
|
149 my $platRel = shift; |
|
150 my $removed = shift; |
|
151 |
|
152 # If not defined => not removed |
|
153 if(! defined($removed)) |
|
154 { |
|
155 return 0; |
|
156 } |
|
157 |
|
158 if($removed =~ /$platId\s+([0-9]+\.[0-9]+)/i) |
|
159 { |
|
160 my $rel = $1; |
|
161 if($rel <= $platRel) |
|
162 { |
|
163 return 1; |
|
164 } |
|
165 } |
|
166 return 0; |
|
167 } |
|
168 ################################################### |
|
169 # returns the official capa name from internal name. |
|
170 # this is implemented since the capa names in cenrep keys |
|
171 # migth not be the same as official names in the ini-file. |
|
172 ################################################### |
|
173 sub getCapaValue |
|
174 { |
|
175 my $formatNbr = shift; # not used at the moment. |
|
176 my $refToCapaList = shift; |
|
177 |
|
178 ######################### |
|
179 # official way, caps as strings |
|
180 ######################### |
|
181 |
|
182 # my $retVal = ""; |
|
183 # my $isFirst = 1; |
|
184 # foreach my $capa (@$refToCapaList) |
|
185 # { |
|
186 # next if($capa =~ /^\s*$/); |
|
187 # if(!$isFirst) |
|
188 # { |
|
189 # $retVal .= ","; |
|
190 # } |
|
191 # $retVal .= $capa; |
|
192 |
|
193 # $isFirst = 0; |
|
194 # } |
|
195 |
|
196 ######################### |
|
197 # Caps as strings |
|
198 ######################### |
|
199 my $retVal = ""; |
|
200 my @capaList; |
|
201 foreach my $capa (@$refToCapaList) |
|
202 { |
|
203 next if($capa =~ /^\s*$/); |
|
204 |
|
205 if( $capa =~ /ReadUserData/) |
|
206 { |
|
207 push(@capaList,"ReadUserData"); |
|
208 } |
|
209 elsif($capa =~ /WriteUserData/) |
|
210 { |
|
211 push(@capaList,"WriteUserData"); |
|
212 } |
|
213 elsif( $capa =~ /ReadDeviceData/) |
|
214 { |
|
215 push(@capaList,"ReadDeviceData"); |
|
216 } |
|
217 elsif($capa =~ /WriteDeviceData/) |
|
218 { |
|
219 push(@capaList,"WriteDeviceData"); |
|
220 } |
|
221 elsif($capa =~ /NetworkControl/) |
|
222 { |
|
223 push(@capaList,"NetworkControl"); |
|
224 } |
|
225 elsif($capa =~ /NetworkServices/) |
|
226 { |
|
227 push(@capaList,"NetworkServices"); |
|
228 } |
|
229 elsif($capa =~ /Local Services/) |
|
230 { |
|
231 push(@capaList,"LocalServices"); |
|
232 } |
|
233 elsif($capa =~ /Location/) |
|
234 { |
|
235 push(@capaList,"Location"); |
|
236 } |
|
237 elsif($capa =~ /ProtServ/) |
|
238 { |
|
239 push(@capaList,"ProtServ"); |
|
240 } |
|
241 elsif($capa =~ /DRM/) |
|
242 { |
|
243 push(@capaList,"DRM"); |
|
244 } |
|
245 elsif($capa =~ /SwEvent/) |
|
246 { |
|
247 push(@capaList,"SwEvent"); |
|
248 } |
|
249 elsif($capa =~ /PowerMgmt/) |
|
250 { |
|
251 push(@capaList,"PowerMgmt"); |
|
252 } |
|
253 elsif($capa =~ /AllFiles/) |
|
254 { |
|
255 push(@capaList,"AllFiles"); |
|
256 } |
|
257 elsif($capa =~ /DiskAdmin/) |
|
258 { |
|
259 push(@capaList,"DiskAdmin"); |
|
260 } |
|
261 elsif($capa =~ /MultiMediaDD/) |
|
262 { |
|
263 push(@capaList,"MultimediaDD"); |
|
264 } |
|
265 elsif($capa =~ /CommDD/) |
|
266 { |
|
267 push(@capaList,"CommDD"); |
|
268 } |
|
269 elsif($capa =~ /TrustedUI/) |
|
270 { |
|
271 push(@capaList,"TrustedUI"); |
|
272 } |
|
273 elsif($capa =~ /TCB/) |
|
274 { |
|
275 push(@capaList,"TCB"); |
|
276 } |
|
277 elsif($capa =~ /AlwaysPass/ || $capa =~ /None/) |
|
278 { |
|
279 push(@capaList,"alwayspass"); |
|
280 } |
|
281 elsif($capa =~ /UserEnvironment/) |
|
282 { |
|
283 push(@capaList,"UserEnvironment"); |
|
284 } |
|
285 elsif($capa =~ /SurroundingsDD/) |
|
286 { |
|
287 push(@capaList,"SurroundingsDD"); |
|
288 } |
|
289 } |
|
290 |
|
291 return join(",",@capaList); |
|
292 |
|
293 } |
|
294 ################################################### |
|
295 # 3rd param syntax: |
|
296 # <release> |
|
297 # => { |
|
298 # "R" => (<capa1ForReading>,<capa2ForReading>) |
|
299 # "W" => (<capa1ForWriting>,<capa2ForWriting>) |
|
300 # "value" => <value> |
|
301 # "rfs" => <0/1> |
|
302 # "backup" => <0/1> |
|
303 # } |
|
304 # |
|
305 ################################################### |
|
306 sub getConfig |
|
307 { |
|
308 my $platId = shift; |
|
309 my $platRel = shift; |
|
310 my $refToHash = shift; |
|
311 |
|
312 my $currRel = "0"; |
|
313 my $currRef = undef; |
|
314 foreach my $plat (sort keys %$refToHash) |
|
315 { |
|
316 if($plat =~ /$platId\s+([0-9]+\.[0-9]+)/i) |
|
317 { |
|
318 my $tentativeRel = $1; |
|
319 if($tentativeRel > $currRel && $tentativeRel <= $platRel) |
|
320 { |
|
321 $currRel = $tentativeRel; |
|
322 $currRef = $$refToHash{$plat}; |
|
323 } |
|
324 } |
|
325 } |
|
326 # if($currRel > 0) |
|
327 # { |
|
328 # print $$refToHash{$currRel}, "a\n"; |
|
329 # return $$refToHash{$currRel}; |
|
330 # } |
|
331 return $currRef; |
|
332 } |
|
333 |
|
334 ########################################################################### |
|
335 # Main function, |
|
336 ########################################################################### |
|
337 sub readConfig |
|
338 { |
|
339 my $refToExcelFiles = shift; |
|
340 my $refToExcel = shift; |
|
341 |
|
342 my %reshHash; |
|
343 my $refToWorkSheet; |
|
344 |
|
345 # Loop through each found excel sheet. This will open one file after each other |
|
346 # and parse information into the hashes defined above. |
|
347 foreach my $file ( @{$refToExcelFiles} ) |
|
348 { |
|
349 print " Reading: $file\n"; |
|
350 |
|
351 # ---------------------------------------------------------------- |
|
352 # Open the file |
|
353 # ---------------------------------------------------------------- |
|
354 my $refToWb = openWorkbook( $file,$refToExcel); |
|
355 |
|
356 # ---------------------------------------------------------------- |
|
357 # Check, that the template version is the one we support. If not |
|
358 # the file is skipped and warning is written to user. |
|
359 # ---------------------------------------------------------------- |
|
360 # if( isSupported($refToWb) == 0) |
|
361 # { |
|
362 # # "delete" the workbooks, this closes the excel application |
|
363 # undef $$refToWb; |
|
364 # undef $refToWb; |
|
365 # print STDERR "Warning: Unsupported template version in file: $file\n"; |
|
366 # next; |
|
367 # } |
|
368 |
|
369 |
|
370 # ---------------------------------------------------------------- |
|
371 # Read the information from the worksheets |
|
372 # ---------------------------------------------------------------- |
|
373 for( my $i = 0; $i < $$refToWb->Worksheets->Count; $i++) |
|
374 { |
|
375 my $workSheet = $$refToWb->WorkSheets($i + 1); |
|
376 $refToWorkSheet = getWorkSheet( $refToWb,$workSheet->Name); |
|
377 readCentrepKeyInfo( $refToWorkSheet,\%reshHash); |
|
378 } |
|
379 # "delete" the workbooks, this closes the excel application |
|
380 $$refToWb->Close(0); |
|
381 undef $$refToWb; |
|
382 undef $refToWb; |
|
383 } |
|
384 return \%reshHash; |
|
385 } |
|
386 ########################################################################### |
|
387 ########################################################################### |
|
388 sub getKeyType |
|
389 { |
|
390 my $key = shift; |
|
391 |
|
392 return "string" if($key =~ /str/i); |
|
393 return "int" if($key =~ /int/i); |
|
394 return "real" if($key =~ /real/i); |
|
395 return "binary" if($key =~ /bin/i); |
|
396 |
|
397 return "unknown_type"; |
|
398 } |
|
399 |
|
400 |
|
401 ########################################################################### |
|
402 # Prints the Key and key type into the given output. |
|
403 # The format in which the key is printed is format specific. |
|
404 ########################################################################### |
|
405 sub printKey |
|
406 { |
|
407 my $to = shift; |
|
408 my $formatNbr = shift; |
|
409 my $key = shift; |
|
410 my $keyType = shift; |
|
411 |
|
412 $key =~ s/0x(0*)/0x/g; |
|
413 # Add 0 if the key value is "0x" (cases, where the id == 0) |
|
414 $key .= "0" if $key =~ /0x\s*$/; |
|
415 printStr $to, $key . " " . $keyType . " "; |
|
416 |
|
417 return; |
|
418 } |
|
419 |
|
420 ########################################################################### |
|
421 # Prints the capabilities into the given output. |
|
422 # The format in which the capabilities are printed is format specific. |
|
423 ########################################################################### |
|
424 sub printCapa |
|
425 { |
|
426 my $to = shift; |
|
427 my $formatNbr = shift; |
|
428 my $refToCapaList = shift; |
|
429 my $prefix = shift; |
|
430 my $alwaysFail = shift; |
|
431 |
|
432 if($formatNbr > 1) |
|
433 { |
|
434 if($alwaysFail && $formatNbr > 3) |
|
435 { |
|
436 printStr \*OUT, " $prefix=alwaysfail"; |
|
437 } |
|
438 elsif(defined($refToCapaList) && scalar(@$refToCapaList) > 0) |
|
439 { |
|
440 my $capaStr = getCapaValue($formatNbr,$refToCapaList); |
|
441 printStr \*OUT, " $prefix=$capaStr" if($capaStr); |
|
442 } |
|
443 } |
|
444 } |
|
445 |
|
446 ########################################################################### |
|
447 # Prints the Sid capabilities into the given output. |
|
448 # The format in which the capabilities are printed is format specific. |
|
449 ########################################################################### |
|
450 sub printSidCapa |
|
451 { |
|
452 my $to = shift; |
|
453 my $formatNbr = shift; |
|
454 my $refToCapaList = shift; |
|
455 my $prefix = shift; |
|
456 |
|
457 if($formatNbr > 1) |
|
458 { |
|
459 if(defined($refToCapaList) && scalar(@$refToCapaList) > 0) |
|
460 { |
|
461 # Only 1 SID is allowed |
|
462 printStr \*OUT, " $prefix=$$refToCapaList[0]"; |
|
463 } |
|
464 } |
|
465 } |
|
466 |
|
467 ########################################################################### |
|
468 # Prints the information about ranges |
|
469 ########################################################################### |
|
470 sub printPlatSec |
|
471 { |
|
472 my $to = shift; |
|
473 my $formatNbr = shift; |
|
474 my $refToUidSpecificHash = shift; |
|
475 my $refToRangesHash = shift; |
|
476 my $fileName = shift; |
|
477 my $addDefCaps = shift; |
|
478 |
|
479 #------------------------------- |
|
480 # UID specific (default capabilities) |
|
481 #------------------------------- |
|
482 # we need to know if write / read was specified. |
|
483 # if not and addDefCaps is defined => then be add the |
|
484 # default alwayspass to the file |
|
485 my $readSpecified = 0; |
|
486 my $writeSpecified = 0; |
|
487 |
|
488 ############################### |
|
489 # RSid-capa writing (format specific) |
|
490 ############################### |
|
491 my $refToCapaList = $$refToUidSpecificHash{"RSid"}; |
|
492 printSidCapa($to,$formatNbr,$refToCapaList,"sid_rd"); |
|
493 $readSpecified += scalar(@$refToCapaList) if defined($refToCapaList); |
|
494 |
|
495 ############################### |
|
496 # R-capa writing (format specific) |
|
497 ############################### |
|
498 $refToCapaList = $$refToUidSpecificHash{"R"}; |
|
499 printCapa($to,$formatNbr,$refToCapaList,"cap_rd",0); |
|
500 $readSpecified = scalar(@$refToCapaList) if defined($refToCapaList); |
|
501 |
|
502 # Add def caps if no caps were defined |
|
503 if($addDefCaps > 0 && $readSpecified < 1) |
|
504 { |
|
505 printStr \*OUT, " cap_rd=alwayspass"; |
|
506 |
|
507 } |
|
508 |
|
509 ############################### |
|
510 # WSid-capa writing (format specific) |
|
511 ############################### |
|
512 $refToCapaList = $$refToUidSpecificHash{"WSid"}; |
|
513 printSidCapa($to,$formatNbr,$refToCapaList,"sid_wr"); |
|
514 $writeSpecified += scalar(@$refToCapaList) if defined($refToCapaList); |
|
515 |
|
516 ############################### |
|
517 # W-capa writing (format specific) |
|
518 ############################### |
|
519 $refToCapaList = $$refToUidSpecificHash{"W"}; |
|
520 printCapa($to,$formatNbr,$refToCapaList,"cap_wr",0); |
|
521 $writeSpecified = scalar(@$refToCapaList) if defined($refToCapaList); |
|
522 |
|
523 # Add def caps if no caps were defined |
|
524 if($addDefCaps > 0 && $writeSpecified < 1) |
|
525 { |
|
526 printStr \*OUT, " cap_wr=alwayspass"; |
|
527 |
|
528 } |
|
529 |
|
530 printNewLine($to,$fileName); |
|
531 |
|
532 #------------------------------- |
|
533 # Ranges |
|
534 #------------------------------- |
|
535 foreach my $rangeFrom (keys %$refToRangesHash) |
|
536 { |
|
537 my $refToRangeFromHash = $$refToRangesHash{$rangeFrom}; |
|
538 |
|
539 foreach my $rangeTo (keys %$refToRangeFromHash) |
|
540 { |
|
541 my $refToRangeToHash = $$refToRangeFromHash{$rangeTo}; |
|
542 |
|
543 printStr $to, $rangeFrom . " " .$rangeTo; |
|
544 |
|
545 ############################### |
|
546 # RSid-capa writing (format specific) |
|
547 ############################### |
|
548 $refToCapaList = $$refToRangeToHash{"RSid"}; |
|
549 printSidCapa($to,$formatNbr,$refToCapaList,"sid_rd"); |
|
550 |
|
551 ############################### |
|
552 # R-capa writing (format specific) |
|
553 ############################### |
|
554 $refToCapaList = $$refToRangeToHash{"R"}; |
|
555 printCapa($to,$formatNbr,$refToCapaList,"cap_rd",0); |
|
556 |
|
557 ############################### |
|
558 # WSid-capa writing (format specific) |
|
559 ############################### |
|
560 $refToCapaList = $$refToRangeToHash{"WSid"}; |
|
561 printSidCapa($to,$formatNbr,$refToCapaList,"sid_wr"); |
|
562 |
|
563 ############################### |
|
564 # W-capa writing (format specific) |
|
565 ############################### |
|
566 $refToCapaList = $$refToRangeToHash{"W"}; |
|
567 printCapa($to,$formatNbr,$refToCapaList,"cap_wr",0); |
|
568 |
|
569 printNewLine($to,$fileName); |
|
570 } |
|
571 } |
|
572 } |
|
573 |
|
574 ########################################################################### |
|
575 # Prints the information about metadata |
|
576 ########################################################################### |
|
577 sub printMetadata |
|
578 { |
|
579 my $to = shift; |
|
580 my $formatNbr = shift; |
|
581 my $refToUidSpecificHash = shift; |
|
582 my $refToRangesHash = shift; |
|
583 my $fileName = shift; |
|
584 |
|
585 #------------------------------- |
|
586 # UID specific metadata |
|
587 #------------------------------- |
|
588 |
|
589 my $metaData = 0; |
|
590 if($$refToUidSpecificHash{"backup"}) |
|
591 { |
|
592 $metaData += $globalBackupValue; |
|
593 } |
|
594 printStr $to, " $metaData"; |
|
595 printNewLine($to,$fileName); |
|
596 |
|
597 |
|
598 #------------------------------- |
|
599 # Ranges |
|
600 #------------------------------- |
|
601 foreach my $rangeFrom (keys %$refToRangesHash) |
|
602 { |
|
603 my $refToRangeFromHash = $$refToRangesHash{$rangeFrom}; |
|
604 |
|
605 foreach my $rangeTo (keys %$refToRangeFromHash) |
|
606 { |
|
607 my $refToRangeToHash = $$refToRangeFromHash{$rangeTo}; |
|
608 |
|
609 printStr $to, $rangeFrom . " " .$rangeTo; |
|
610 |
|
611 my $metaData2 = 0; |
|
612 if($$refToRangeToHash{"backup"}) |
|
613 { |
|
614 $metaData2 += $globalBackupValue; |
|
615 } |
|
616 printStr $to, " $metaData2"; |
|
617 printNewLine($to,$fileName); |
|
618 } |
|
619 } |
|
620 } |
|
621 |
|
622 ########################################################################### |
|
623 # Function that generates a text file for the Restore factory settings. |
|
624 # This file |
|
625 ########################################################################### |
|
626 sub generateRfsFile |
|
627 { |
|
628 my $reshHash = shift; |
|
629 my $rfsFileWithPath = shift; |
|
630 |
|
631 open(OUT,">$rfsFileWithPath") || die "unable to open $rfsFileWithPath for writing"; |
|
632 print OUT "\xFF\xFE"; |
|
633 |
|
634 foreach my $uid (keys %$reshHash) |
|
635 { |
|
636 my $refToUidHash = $$reshHash{$uid}; |
|
637 $uid =~ s/^0x0*//g; |
|
638 $uid = 0 if $uid =~ /^$/; |
|
639 my $refToUidSpecificHash = $$refToUidHash{"uid_specific"}; |
|
640 |
|
641 # Uid specific rfs overwrites the key specific values |
|
642 # Thus if this is set to yes => we can skip key specific values |
|
643 if($$refToUidSpecificHash{"rfs"}) |
|
644 { |
|
645 printStr \*OUT, "CR $uid"; |
|
646 printNewLine(\*OUT,$rfsFileWithPath); |
|
647 next; |
|
648 } |
|
649 |
|
650 # If we get here => uid was not set to yes for RFS. |
|
651 # now we loop through each ke |
|
652 ######################## |
|
653 # print each key into the file. |
|
654 ######################## |
|
655 my $refToKeysHash = $$refToUidHash{"keys"}; |
|
656 my $isFirstInUid = 1; |
|
657 foreach my $key (sort keys %$refToKeysHash) |
|
658 { |
|
659 my $refToKeyHash = $$refToKeysHash{$key}; |
|
660 |
|
661 # Check, if the key was restored in RFS. |
|
662 if($$refToKeyHash{"rfs"}) |
|
663 { |
|
664 # If this is the 1st key for this UI, then |
|
665 # we print the keyword (CR) and the uid into the |
|
666 # file. |
|
667 if($isFirstInUid) |
|
668 { |
|
669 $isFirstInUid = 0; |
|
670 printStr \*OUT, "CR $uid"; |
|
671 |
|
672 } |
|
673 |
|
674 # print the key into the file (after some modifications) |
|
675 $key =~ s/^0x0*//g; |
|
676 $key = 0 if $key =~ /^$/; |
|
677 printStr \*OUT, " $key"; |
|
678 } |
|
679 } |
|
680 # Print a newline if (and only if) there was keys that had rfs-flag |
|
681 # on. |
|
682 if(! $isFirstInUid) |
|
683 { |
|
684 printNewLine(\*OUT,$rfsFileWithPath); |
|
685 } |
|
686 } |
|
687 close OUT; |
|
688 } |
|
689 |
|
690 ########################################################################### |
|
691 # Function that generates all the ini (txt)-files for the central repository. |
|
692 # There are multiple formats, which are supported at the moment, since the |
|
693 # development in ongoing and syntax is still a little but unknown. |
|
694 ########################################################################### |
|
695 sub generateIniFiles |
|
696 { |
|
697 my $reshHash = shift; |
|
698 my $dirname = shift; |
|
699 my $formatNbr = shift; |
|
700 my $addDefCaps = shift; |
|
701 |
|
702 my $iniFileCount = 0; |
|
703 my $keyCount = 0; |
|
704 |
|
705 foreach my $uid (keys %$reshHash) |
|
706 { |
|
707 my $refToHash = $$reshHash{$uid}; |
|
708 $refToHash = $$refToHash{"keys"}; |
|
709 my $refToRangeHash = $$refToHash{"ranges"}; |
|
710 if(scalar(keys %$refToHash) < 1 && scalar(keys %$refToRangeHash)) |
|
711 { |
|
712 # Skip uid, if no keys and ranges |
|
713 next; |
|
714 } |
|
715 $iniFileCount++; |
|
716 |
|
717 ################################## |
|
718 # Filename syntax is "uid.txt" without the 0x in the begining |
|
719 ################################## |
|
720 my $fileName = "$uid.txt"; |
|
721 $fileName =~ s/^0x//i; |
|
722 |
|
723 # Add dir name into the filename. |
|
724 if($dirname !~ /^\s*$/) |
|
725 { |
|
726 my $tmpFileName = $fileName; |
|
727 $fileName = $dirname; |
|
728 if($dirname !~ /[\\\/]$/) |
|
729 { |
|
730 $fileName .= "\\"; |
|
731 } |
|
732 $fileName .= $tmpFileName; |
|
733 } |
|
734 |
|
735 ######################## |
|
736 # Copy the start of the file into the new name |
|
737 # (note that this migth become format specific, |
|
738 # but is not at the moment). |
|
739 ######################## |
|
740 my $templateName = "cenrep_start.ini"; |
|
741 |
|
742 copy($templateName,$fileName) or die "Copy failed: $! : $fileName"; |
|
743 open(OUT,">>$fileName") || die "unable to open $fileName"; |
|
744 ######################## |
|
745 # Print the [owner] section |
|
746 ######################## |
|
747 if($formatNbr > 2) |
|
748 { |
|
749 my $refToUidHash = $$reshHash{$uid}; |
|
750 my $refToUidSpecificHash = $$refToUidHash{"uid_specific"}; |
|
751 |
|
752 if($$refToUidSpecificHash{"owner"} !~ /^\s*$/) |
|
753 { |
|
754 printStr \*OUT, "[owner]"; |
|
755 printNewLine(\*OUT,$fileName); |
|
756 printStr \*OUT, $$refToUidSpecificHash{"owner"}; |
|
757 printNewLine(\*OUT,$fileName); |
|
758 } |
|
759 } |
|
760 |
|
761 ######################## |
|
762 # Print the [defaultmeta] section |
|
763 # Note that depending on the format |
|
764 # nbr the metadata has to be before or after |
|
765 # platsec-section. |
|
766 ######################## |
|
767 if($formatNbr > 3 ) |
|
768 { |
|
769 printStr \*OUT, "[defaultmeta]"; |
|
770 printNewLine(\*OUT,$fileName); |
|
771 |
|
772 my $refToUidHash = $$reshHash{$uid}; |
|
773 printMetadata(\*OUT,$formatNbr,$$refToUidHash{"uid_specific"}, |
|
774 $$refToUidHash{"ranges"},$fileName); |
|
775 } |
|
776 |
|
777 ######################## |
|
778 # Print the [PlatSec] section |
|
779 ######################## |
|
780 if($formatNbr > 1) |
|
781 { |
|
782 printStr \*OUT, "[platsec]"; |
|
783 printNewLine(\*OUT,$fileName); |
|
784 |
|
785 my $refToUidHash = $$reshHash{$uid}; |
|
786 printPlatSec(\*OUT,$formatNbr,$$refToUidHash{"uid_specific"}, |
|
787 $$refToUidHash{"ranges"},$fileName,$addDefCaps); |
|
788 } |
|
789 ######################## |
|
790 # Print the [metadata] section |
|
791 ######################## |
|
792 if($formatNbr eq 3) |
|
793 { |
|
794 printStr \*OUT, "[metadata]"; |
|
795 printNewLine(\*OUT,$fileName); |
|
796 |
|
797 my $refToUidHash = $$reshHash{$uid}; |
|
798 printMetadata(\*OUT,$formatNbr,$$refToUidHash{"uid_specific"}, |
|
799 $$refToUidHash{"ranges"},$fileName); |
|
800 } |
|
801 |
|
802 ######################## |
|
803 # Print the [Main] section |
|
804 ######################## |
|
805 if($formatNbr > 0) |
|
806 { |
|
807 printStr \*OUT, "[Main]"; |
|
808 printNewLine(\*OUT,$fileName); |
|
809 } |
|
810 |
|
811 ######################## |
|
812 # print each key into the file. |
|
813 ######################## |
|
814 foreach my $key (sort keys %$refToHash) |
|
815 { |
|
816 $keyCount++; |
|
817 my $refToHash2 = $$refToHash{$key}; |
|
818 |
|
819 ############################### |
|
820 # Writing the key and key type. |
|
821 # This is format specific. |
|
822 ############################### |
|
823 printKey(\*OUT,$formatNbr,$key,getKeyType($$refToHash2{"key type"})); |
|
824 |
|
825 ############################### |
|
826 # Write the value into the file |
|
827 ############################### |
|
828 |
|
829 # Strings are always enclosed with \". Also empty binary value is also enclosed |
|
830 # such way |
|
831 if($$refToHash2{"key type"} =~ /str/i ) |
|
832 { |
|
833 printStr \*OUT, "\""; |
|
834 } |
|
835 printStr \*OUT, $$refToHash2{"value"}; |
|
836 if($$refToHash2{"key type"} =~ /str/i) |
|
837 { |
|
838 printStr \*OUT, "\""; |
|
839 } |
|
840 |
|
841 if ($$refToHash2{"key type"} =~ /bin/i && $$refToHash2{"value"} =~ /^\s*$/) |
|
842 { |
|
843 printStr \*OUT, "00"; |
|
844 } |
|
845 |
|
846 ############################### |
|
847 # Generating the metadata and adding it into the file |
|
848 ############################### |
|
849 my $metaData = 0; |
|
850 if($$refToHash2{"backup"}) |
|
851 { |
|
852 $metaData += $globalBackupValue; |
|
853 } |
|
854 printStr \*OUT, " $metaData"; |
|
855 |
|
856 # Note, according to the cenrep specification, then read access has to be |
|
857 # before the write access. |
|
858 |
|
859 ############################### |
|
860 # RSid-capa writing (format specific) |
|
861 ############################### |
|
862 my $refToCapaList = $$refToHash2{"RSid"}; |
|
863 printSidCapa(\*OUT,$formatNbr,$refToCapaList,"sid_rd"); |
|
864 |
|
865 ############################### |
|
866 # R-capa writing (format specific) |
|
867 ############################### |
|
868 $refToCapaList = $$refToHash2{"R"}; |
|
869 printCapa(\*OUT,$formatNbr,$refToCapaList,"cap_rd",0); |
|
870 |
|
871 ############################### |
|
872 # WSid-capa writing (format specific) |
|
873 ############################### |
|
874 $refToCapaList = $$refToHash2{"WSid"}; |
|
875 printSidCapa(\*OUT,$formatNbr,$refToCapaList,"sid_wr"); |
|
876 |
|
877 ############################### |
|
878 # W-capa writing (format specific) |
|
879 ############################### |
|
880 $refToCapaList = $$refToHash2{"W"}; |
|
881 printCapa(\*OUT,$formatNbr,$refToCapaList,"cap_wr",$$refToHash2{"read-only"}); |
|
882 |
|
883 ########################################## |
|
884 ########################################## |
|
885 ########################################## |
|
886 ########################################## |
|
887 printNewLine(\*OUT,$fileName); |
|
888 } |
|
889 close OUT; |
|
890 } |
|
891 |
|
892 print "Ini file count = $iniFileCount\n"; |
|
893 print "Key count = $keyCount\n"; |
|
894 } |
|
895 |
|
896 ########################################################################### |
|
897 # Shows help. |
|
898 # |
|
899 # Params: - |
|
900 # |
|
901 # Return: - |
|
902 # |
|
903 ########################################################################### |
|
904 sub usage |
|
905 { |
|
906 $0 =~ /([0-9a-zA-Z\_\.]+)$/; |
|
907 my $filename = $1; |
|
908 print "\n"; |
|
909 print "\n"; |
|
910 print "\n"; |
|
911 print "This script is intended to be used to generate ini-files for Central Repository\n"; |
|
912 print "based on the information in the cenrep key excel-sheet(s). These sheets define\n"; |
|
913 print "the content of the ini-files.\n"; |
|
914 print "\n"; |
|
915 print "Rough discruption on how the values for the ini-files are determinated:\n"; |
|
916 print "1) Content of sheets identified by -d or -s are read.\n"; |
|
917 print " (alternatively -b can be used a storable file, where the sheet info\n"; |
|
918 print " is already in binary format)\n"; |
|
919 print "2) From sheets read in step 1 the information is parsed based on the\n"; |
|
920 print " information specified by -p, -r and -v\n"; |
|
921 print "3) [optional] Default values specified by the steps 1 and 2 can be\n"; |
|
922 print " overriden by defining information in other sheets, specified by parameters\n"; |
|
923 print " -vd,-vs,-vb and -vv, \n"; |
|
924 print "\n"; |
|
925 print "\n"; |
|
926 print "Usage:\n"; |
|
927 print " $filename [-h|-help] [-fh]\n"; |
|
928 print " [-p <platId>] -r <platRel> [-v <variantName]\n"; |
|
929 print " (-d <dirName> | -s <sourceFilename> | -b <storableFilename>)\n"; |
|
930 print " [ -rd <resultDir>]\n"; |
|
931 print " [ (-vd <variantDirName> | -vs <sourceFilename> | -vb <storableFilename>)\n"; |
|
932 print " [-vv <variantsVariantName>]]\n"; |
|
933 print " [-f <formatNbr> ]\n"; |
|
934 print " [-dc ]\n"; |
|
935 print " [-rfs <dirName> [-noini]]\n"; |
|
936 print "\n"; |
|
937 print "Options:\n"; |
|
938 print " -h : Show this help\n"; |
|
939 print " -help : Show this help\n"; |
|
940 print " -fh : Show the help about supported formats.\n"; |
|
941 print " -p <platId> : The identifier specifying platform. Optional. Default value: S60\n"; |
|
942 print " to the directory where the mem-sheets exist.\n"; |
|
943 print " -r <platRel> : The platform number. For example: 3.0\n"; |
|
944 print " -rd <resultDir> : The path, where the generated ini-files are written.\n"; |
|
945 print " Default: current directory\n"; |
|
946 print " -v <variantName> : The variant name. Optional. Default value: \"\" == no variant.\n"; |
|
947 print " The names are not fixed in the script. The same names has to be\n"; |
|
948 print " used as supported by the excel sheet.\n"; |
|
949 print " -d <dirName> : The dir, which contains the sheets, which are read. Relative path to the\n"; |
|
950 print " current dir or absoluth path. NOTE: the dir name can't contain any spaces.\n"; |
|
951 print " -s <sourceFilename> : The text filename, which contains sheet name with absoluth\n"; |
|
952 print " path names (1/row)\n"; |
|
953 print " -b <storableFilename> : the storable file name, which contains the same information as the\n"; |
|
954 print " key sheets. ( this can be generated with gather_cenrep_to_storable.pl)\n"; |
|
955 print " -vd <variantDirName> : Same as -d, but for variant information\n"; |
|
956 print " (see rough description above) Optional.\n"; |
|
957 print " -vs <sourceFilename> : Same as -s, but for variant information\n"; |
|
958 print " (see rough description above) Optional.\n"; |
|
959 print " -vb <storableFilename> : the storable file name, which contains the same information as the\n"; |
|
960 print " variant key sheets.\n"; |
|
961 print " -vv <variantsVariantName> : Same as -v, but for variant information\n"; |
|
962 print " (see rough description above) Optional.\n"; |
|
963 print " -f <formatNbr> : the format type that is generated. (see list of formats with -fh)\n"; |
|
964 print " -dc : adds alwayspass as default capabilities for UID namespace if non \n"; |
|
965 print " specified (also applies to certain formats)\n"; |
|
966 print " -rfs <dirName> : The dir to which cenrep.txt-file is generated. This file\n"; |
|
967 print " contains info for Restore Factory Settings\n"; |
|
968 print " -noini : used only with -rfs-option. If specified, only RFS file generated,\n"; |
|
969 print " no ini-files.\n"; |
|
970 print "\n"; |
|
971 print "\n"; |
|
972 print "You have specify either -d or -s, but not both at the same time.\n"; |
|
973 print "You can specify either -vd or -vs, but not both at the same time.\n"; |
|
974 print "\n"; |
|
975 print "\n"; |
|
976 } |
|
977 |
|
978 |
|
979 ########################################################################### |
|
980 # Shows format help. |
|
981 # |
|
982 # Params: - |
|
983 # |
|
984 # Return: - |
|
985 # |
|
986 ########################################################################### |
|
987 sub formatHelp |
|
988 { |
|
989 $0 =~ /([0-9a-zA-Z\_\.]+)$/; |
|
990 my $filename = $1; |
|
991 print "\n"; |
|
992 print "\n"; |
|
993 print "Supported formats (default format is 4):\n"; |
|
994 print " 0 : Format, where there are no capabilities generated for the keys.\n"; |
|
995 print " Supported is key (as hex), type, value and metadata.\n"; |
|
996 print " No \"[Main]\"-tag is included into the ini-file.\n"; |
|
997 print " (a temporary fix so that testing can continue).\n"; |
|
998 print " 1 : Format 0 + \"[Main]\"-tag is included into the ini-file.\n"; |
|
999 print " (Symbian w48 and earlier builds).\n"; |
|
1000 print "\n"; |
|
1001 print " 2 : Format 1 + in addition capabilities are written in text format.\n"; |
|
1002 print " Supported is key (as hex), type, value, metadata and read/write capabilities in text format.\n"; |
|
1003 print " (Symbian w50 and later builds).\n"; |
|
1004 print "\n"; |
|
1005 print " 3 : Format 3 + in addition owner and metadata are written in text format.\n"; |
|
1006 print " Supported is key (as hex), type, value, metadata and read/write capabilities in text format.\n"; |
|
1007 print " (Symbian w?? and later builds).\n"; |
|
1008 print "\n"; |
|
1009 print " 4 : Format 4 + in addition alwaysfail-keyword used in ini-file.\n"; |
|
1010 print " (Symbian w10 and later builds).\n"; |
|
1011 print "\n"; |
|
1012 print "\n"; |
|
1013 print "\n"; |
|
1014 |
|
1015 } |
|
1016 ########################################################################### |
|
1017 # Parses the command line parameters from ARGV |
|
1018 # |
|
1019 # Params: - |
|
1020 # |
|
1021 # Return: - |
|
1022 # |
|
1023 ########################################################################### |
|
1024 sub parseCmdLine |
|
1025 { |
|
1026 my $platId = "S60"; |
|
1027 my $platRel = ""; |
|
1028 my $varName = ""; |
|
1029 my $sheetDirname = ""; |
|
1030 my $sheetFilename = ""; |
|
1031 my $storableFilename = ""; |
|
1032 my $resultDirname = ""; |
|
1033 my $varNameVariant = ""; |
|
1034 my $sheetDirnameVariant = ""; |
|
1035 my $sheetFilenameVariant = ""; |
|
1036 my $storableFilenameVariant = ""; |
|
1037 my $formatNbr = -1; |
|
1038 my $addDefCaps = 0; |
|
1039 my $rfsDir = ""; |
|
1040 my $noIni = 0; |
|
1041 my $showHelp = 0; |
|
1042 my $showFormatHelp = 0; |
|
1043 |
|
1044 if( ! GetOptions('p:s' => \$platId, |
|
1045 'r:s' => \$platRel, |
|
1046 'v:s' => \$varName, |
|
1047 'd:s' => \$sheetDirname, |
|
1048 's:s' => \$sheetFilename, |
|
1049 'b:s' => \$storableFilename, |
|
1050 'rd:s' => \$resultDirname, |
|
1051 'vv:s' => \$varNameVariant, |
|
1052 'vd:s' => \$sheetDirnameVariant, |
|
1053 'vs:s' => \$sheetFilenameVariant, |
|
1054 'vb:s' => \$storableFilenameVariant, |
|
1055 'f:i' => \$formatNbr, |
|
1056 'dc' => \$addDefCaps, |
|
1057 'rfs:s' => \$rfsDir, |
|
1058 'noini' => \$noIni, |
|
1059 'h' => \$showHelp, |
|
1060 'help' => \$showHelp, |
|
1061 'fh' => \$showFormatHelp, |
|
1062 '<>' => \&usage)) |
|
1063 { |
|
1064 usage(); |
|
1065 exit(1); |
|
1066 } |
|
1067 |
|
1068 |
|
1069 #################################### |
|
1070 # Format number handling. |
|
1071 #################################### |
|
1072 # Set default format number, if not specified. |
|
1073 if( $formatNbr < 0) |
|
1074 { |
|
1075 $formatNbr = 4; |
|
1076 } |
|
1077 elsif( $formatNbr > 4) |
|
1078 { |
|
1079 print "\nError: Invalid format number: $formatNbr.\n"; |
|
1080 $showFormatHelp = 1; |
|
1081 } |
|
1082 |
|
1083 if($showFormatHelp) |
|
1084 { |
|
1085 formatHelp(); |
|
1086 exit(1); |
|
1087 } |
|
1088 if($showHelp) |
|
1089 { |
|
1090 usage(); |
|
1091 exit(1); |
|
1092 } |
|
1093 |
|
1094 |
|
1095 |
|
1096 #################################### |
|
1097 # Checking other parameters |
|
1098 #################################### |
|
1099 my $error = 0; |
|
1100 if( ($sheetDirname ne "" and $sheetFilename ne "") |
|
1101 or ($sheetDirname ne "" and -b $storableFilename ne "") |
|
1102 or ($sheetFilename ne "" and -b $storableFilename ne "")) |
|
1103 { |
|
1104 print "\nError: The -s, -d and -b arguments can't be specified at the same time.\n"; |
|
1105 $error = 1; |
|
1106 } |
|
1107 elsif($sheetDirname eq "" and $sheetFilename eq "" and $storableFilename eq "") |
|
1108 { |
|
1109 print "\n\nError: You have to specify either the -d or -s or -b argument.\n"; |
|
1110 $error = 1; |
|
1111 } |
|
1112 |
|
1113 if( ($sheetDirnameVariant ne "" and $sheetFilenameVariant ne "") |
|
1114 or ($sheetDirnameVariant ne "" and $storableFilenameVariant ne "") |
|
1115 or ($storableFilenameVariant ne "" and $sheetFilenameVariant ne "") |
|
1116 ) |
|
1117 { |
|
1118 print "\nError: The -vs and -vd and -vb arguments can't be specified at the same time.\n"; |
|
1119 $error = 1; |
|
1120 } |
|
1121 |
|
1122 if($platRel eq "") |
|
1123 { |
|
1124 print "\nError: You have to specify -r parameter.\n"; |
|
1125 $error = 1; |
|
1126 } |
|
1127 |
|
1128 if($error) |
|
1129 { |
|
1130 usage(); |
|
1131 exit(1); |
|
1132 } |
|
1133 elsif($showHelp) |
|
1134 { |
|
1135 usage(); |
|
1136 } |
|
1137 |
|
1138 return ($platId,$platRel,$varName,$sheetDirname,$sheetFilename,$storableFilename, |
|
1139 $resultDirname,$varNameVariant, |
|
1140 $sheetDirnameVariant,$sheetFilenameVariant,$storableFilenameVariant,$formatNbr, |
|
1141 $addDefCaps,$rfsDir,$noIni); |
|
1142 } |
|
1143 |
|
1144 ########################################################################### |
|
1145 # |
|
1146 # The format of the returned hash is: |
|
1147 # NOTE: Still one bug, onge a range/key has been defined it can't be removed |
|
1148 # { |
|
1149 # <uid> => |
|
1150 # { |
|
1151 # "uid_specific" |
|
1152 # = > { |
|
1153 # "R" => (<capa1ForReading>,<capa2ForReading>) |
|
1154 # "W" => (<capa1ForWriting>,<capa2ForWriting>) |
|
1155 # "RSid" => (<sidForReading>) |
|
1156 # "WSid" => (<sidForWriting>) |
|
1157 # "owner" => <someHexValue> |
|
1158 # "rfs" => <0/1> |
|
1159 # "backup" => <0/1> |
|
1160 # } |
|
1161 # "ranges" |
|
1162 # = > { |
|
1163 # <fromRange> |
|
1164 # => { |
|
1165 # <toRange> |
|
1166 # => { |
|
1167 # "R" => (<capa1ForReading>,<capa2ForReading>) |
|
1168 # "W" => (<capa1ForWriting>,<capa2ForWriting>) |
|
1169 # "RSid" => (<sidForReading>) |
|
1170 # "WSid" => (<sidForWriting>) |
|
1171 # "rfs" => <0/1> |
|
1172 # "backup" => <0/1> |
|
1173 # } |
|
1174 # } |
|
1175 # } |
|
1176 # "keys" => { |
|
1177 # <keyInt> |
|
1178 # => { |
|
1179 # "read-only" => <0/1> |
|
1180 # "key type" => <bin/int/str/bool> |
|
1181 # "R" => (<capa1ForReading>,<capa2ForReading>) |
|
1182 # "W" => (<capa1ForWriting>,<capa2ForWriting>) |
|
1183 # "RSid" => (<sidForReading>) |
|
1184 # "WSid" => (<sidForWriting>) |
|
1185 # "value" => <value> |
|
1186 # "rfs" => <0/1> |
|
1187 # "backup" => <0/1> |
|
1188 # } |
|
1189 # } # keys |
|
1190 ########################################################################### |
|
1191 sub generateConfig |
|
1192 { |
|
1193 my $refToResHash = shift; # The generated configuration |
|
1194 my $reftoConfigHash = shift; # from where the configuration is generated from |
|
1195 my $platId = shift; |
|
1196 my $platRel = shift; |
|
1197 my $varName = shift; |
|
1198 |
|
1199 if($varName =~ /^\s*$/) |
|
1200 { |
|
1201 # same as in cenrep_keys.pm |
|
1202 $varName = "default"; |
|
1203 } |
|
1204 |
|
1205 # See syntax of reftoConfigHash from the documentation of |
|
1206 # readCentrepKeyInfo |
|
1207 my $refToHash; |
|
1208 foreach my $uid (keys %$reftoConfigHash) |
|
1209 { |
|
1210 my $tmpUidResHash = addHash($uid,$refToResHash); |
|
1211 my $refToUidConfigHash = $$reftoConfigHash{$uid}; |
|
1212 |
|
1213 ########################################## |
|
1214 # Adding UID information |
|
1215 ########################################## |
|
1216 my $refToUidSpecificResHash = addHash("uid_specific",$tmpUidResHash); |
|
1217 |
|
1218 my $refToUidSpecificConfigHash = $$refToUidConfigHash{"uid_specific"}; |
|
1219 my $refToUidSpecificVariantConfigHash = undef; |
|
1220 |
|
1221 #-------------------------------------------------- |
|
1222 # now check, if there is variant specific configuration |
|
1223 #-------------------------------------------------- |
|
1224 if(defined($$refToUidSpecificConfigHash{$varName})) |
|
1225 { |
|
1226 $refToUidSpecificVariantConfigHash |
|
1227 = getConfig($platId,$platRel, |
|
1228 $$refToUidSpecificConfigHash{$varName}); |
|
1229 } |
|
1230 #-------------------------------------------------- |
|
1231 # if not found, then try to get default configuration |
|
1232 #-------------------------------------------------- |
|
1233 if(!defined($refToUidSpecificVariantConfigHash) && $varName ne "default") |
|
1234 { |
|
1235 $refToUidSpecificVariantConfigHash |
|
1236 = getConfig($platId,$platRel, |
|
1237 $$refToUidSpecificConfigHash{"default"}); |
|
1238 } |
|
1239 #-------------------------------------------------- |
|
1240 # if we found configuration then add it to the hash |
|
1241 #-------------------------------------------------- |
|
1242 if(defined($refToUidSpecificVariantConfigHash)) |
|
1243 { |
|
1244 $$refToUidSpecificResHash{"rfs"} = $$refToUidSpecificVariantConfigHash{"rfs"}; |
|
1245 $$refToUidSpecificResHash{"backup"} = $$refToUidSpecificVariantConfigHash{"backup"}; |
|
1246 $$refToUidSpecificResHash{"R"} = $$refToUidSpecificVariantConfigHash{"R"}; |
|
1247 $$refToUidSpecificResHash{"W"} = $$refToUidSpecificVariantConfigHash{"W"}; |
|
1248 $$refToUidSpecificResHash{"RSid"} = $$refToUidSpecificVariantConfigHash{"RSid"}; |
|
1249 $$refToUidSpecificResHash{"WSid"} = $$refToUidSpecificVariantConfigHash{"WSid"}; |
|
1250 $$refToUidSpecificResHash{"owner"} = $$refToUidSpecificVariantConfigHash{"owner"}; |
|
1251 } |
|
1252 ########################################## |
|
1253 # Adding range information |
|
1254 ########################################## |
|
1255 my $refToRangesResHash = addHash("ranges",$tmpUidResHash); |
|
1256 |
|
1257 my $refToRangesConfigHash = $$refToUidConfigHash{"ranges"}; |
|
1258 foreach my $rangeFrom (keys %$refToRangesConfigHash) |
|
1259 { |
|
1260 my $refToRangeCommonConfigHash = ${$$refToRangesConfigHash{$rangeFrom}}{"common"}; |
|
1261 # 1st check, if the key belongs to this release |
|
1262 if(isRemoved($platId,$platRel,$$refToRangeCommonConfigHash{"removed"})) |
|
1263 { |
|
1264 next; |
|
1265 } |
|
1266 |
|
1267 my $refToRangesToConfigHash = ${$$refToRangesConfigHash{$rangeFrom}}{"to"}; |
|
1268 foreach my $rangeTo (keys %$refToRangesToConfigHash) |
|
1269 { |
|
1270 my $refToSingleRangeToConfigHash |
|
1271 = $$refToRangesToConfigHash{$rangeTo}; |
|
1272 my $refToRangeToVariantConfigHash = undef; |
|
1273 #-------------------------------------------------- |
|
1274 # now check, if there is variant specific configuration |
|
1275 #-------------------------------------------------- |
|
1276 if(defined($$refToSingleRangeToConfigHash{$varName})) |
|
1277 { |
|
1278 $refToRangeToVariantConfigHash |
|
1279 = getConfig($platId,$platRel, |
|
1280 $$refToSingleRangeToConfigHash{$varName}); |
|
1281 } |
|
1282 #-------------------------------------------------- |
|
1283 # if not found, then try to get default configuration |
|
1284 #-------------------------------------------------- |
|
1285 if(!defined($refToRangeToVariantConfigHash) && $varName ne "default") |
|
1286 { |
|
1287 $refToRangeToVariantConfigHash |
|
1288 = getConfig($platId,$platRel, |
|
1289 $$refToSingleRangeToConfigHash{"default"}); |
|
1290 } |
|
1291 #-------------------------------------------------- |
|
1292 # if we found configuration then add it to the hash |
|
1293 #-------------------------------------------------- |
|
1294 if(defined($refToRangeToVariantConfigHash)) |
|
1295 { |
|
1296 my $refRangeVariantResHash = addHash($rangeFrom,$refToRangesResHash); |
|
1297 $refRangeVariantResHash = addHash($rangeTo,$refRangeVariantResHash); |
|
1298 $$refRangeVariantResHash{"rfs"} = $$refToRangeToVariantConfigHash{"rfs"}; |
|
1299 $$refRangeVariantResHash{"backup"} = $$refToRangeToVariantConfigHash{"backup"}; |
|
1300 $$refRangeVariantResHash{"R"} = $$refToRangeToVariantConfigHash{"R"}; |
|
1301 $$refRangeVariantResHash{"W"} = $$refToRangeToVariantConfigHash{"W"}; |
|
1302 $$refRangeVariantResHash{"RSid"} = $$refToRangeToVariantConfigHash{"RSid"}; |
|
1303 $$refRangeVariantResHash{"WSid"} = $$refToRangeToVariantConfigHash{"WSid"}; |
|
1304 } |
|
1305 } |
|
1306 } |
|
1307 ########################################## |
|
1308 # Adding key values |
|
1309 ########################################## |
|
1310 my $tmpKeysResHash = addHash("keys",$tmpUidResHash); |
|
1311 |
|
1312 $refToHash = $$reftoConfigHash{$uid}; |
|
1313 $refToHash = $$refToHash{"keys"}; |
|
1314 foreach my $key (keys %$refToHash) |
|
1315 { |
|
1316 my $refToCommonHash = ${$$refToHash{$key}}{"common"}; |
|
1317 # 1st check, if the key belongs to this release |
|
1318 if(isRemoved($platId,$platRel,$$refToCommonHash{"removed"})) |
|
1319 { |
|
1320 next; |
|
1321 } |
|
1322 #-------------------------------------------------- |
|
1323 # now check, if there is variant specific configuration |
|
1324 #-------------------------------------------------- |
|
1325 my $refToRelHash = ${$$refToHash{$key}}{"release"}; |
|
1326 my $refToKeyConfigHash; |
|
1327 if(defined($$refToRelHash{$varName})) |
|
1328 { |
|
1329 $refToKeyConfigHash = getConfig($platId,$platRel, |
|
1330 $$refToRelHash{$varName}); |
|
1331 } |
|
1332 #-------------------------------------------------- |
|
1333 # if not found, then try to get default configuration |
|
1334 #-------------------------------------------------- |
|
1335 if(!defined($refToKeyConfigHash) && $varName ne "default") |
|
1336 { |
|
1337 $refToKeyConfigHash |
|
1338 = getConfig($platId,$platRel, |
|
1339 $$refToRelHash{"default"}); |
|
1340 } |
|
1341 #-------------------------------------------------- |
|
1342 # if we found configuration then add it to the hash |
|
1343 #-------------------------------------------------- |
|
1344 if(defined($refToKeyConfigHash)) |
|
1345 { |
|
1346 my $keyResHash = addHash($key,$tmpKeysResHash); |
|
1347 $$keyResHash{"read-only"} = $$refToCommonHash{"read-only"}; |
|
1348 $$keyResHash{"key type"} = $$refToCommonHash{"key type"}; |
|
1349 $$keyResHash{"value"} = $$refToKeyConfigHash{"value"}; |
|
1350 $$keyResHash{"rfs"} = $$refToKeyConfigHash{"rfs"}; |
|
1351 $$keyResHash{"backup"} = $$refToKeyConfigHash{"backup"}; |
|
1352 $$keyResHash{"R"} = $$refToKeyConfigHash{"R"}; |
|
1353 $$keyResHash{"W"} = $$refToKeyConfigHash{"W"}; |
|
1354 $$keyResHash{"RSid"} = $$refToKeyConfigHash{"RSid"}; |
|
1355 $$keyResHash{"WSid"} = $$refToKeyConfigHash{"WSid"}; |
|
1356 } |
|
1357 } |
|
1358 } |
|
1359 } |
|
1360 |
|
1361 ########################################################################### |
|
1362 # reads either default config or variant config into the result hash. |
|
1363 # Note that the variant hash can't delete any keys, just override them. |
|
1364 ########################################################################### |
|
1365 sub readSingleConfig |
|
1366 { |
|
1367 my $refToExcel = shift; |
|
1368 my $sheetDirname = shift; |
|
1369 my $sheetFilename = shift; |
|
1370 my $storableFilename = shift; |
|
1371 my $refToResultHash = shift; |
|
1372 my $platId = shift; |
|
1373 my $platRel = shift; |
|
1374 my $varName = shift; |
|
1375 |
|
1376 #----------------------------------------------------------------- |
|
1377 # There are 2 options how the user can give the if-sheet names handled: |
|
1378 # 1) He gives the directory where all files are located |
|
1379 # 2) He gives an excel sheet, which contains all the files in column A. |
|
1380 #----------------------------------------------------------------- |
|
1381 my $refToExcelFilesList; |
|
1382 |
|
1383 if($sheetDirname !~ /^\s*$/) |
|
1384 { |
|
1385 # Read the filenames from the directory given |
|
1386 $refToExcelFilesList = getExcelFilesFromDir $sheetDirname; |
|
1387 } |
|
1388 elsif($sheetFilename !~ /^\s*$/) |
|
1389 { |
|
1390 # Read the filenames from the excel file given |
|
1391 $refToExcelFilesList = getExcelFilesFromFile $sheetFilename; |
|
1392 } |
|
1393 elsif($storableFilename =~ /^\s*$/) |
|
1394 { |
|
1395 # nothing to do, just exit function |
|
1396 return; |
|
1397 } |
|
1398 #----------------------------------------------------------------- |
|
1399 # The main function that parses the information from sheets |
|
1400 #----------------------------------------------------------------- |
|
1401 my $refToDefHash; |
|
1402 if($storableFilename !~ /^\s*$/) |
|
1403 { |
|
1404 # read mem sheets info |
|
1405 open(STORABLE_IN ,$storableFilename) || die "Unable to open: $storableFilename"; |
|
1406 $refToDefHash = fd_retrieve(\*STORABLE_IN); |
|
1407 close STORABLE_IN; |
|
1408 } |
|
1409 else |
|
1410 { |
|
1411 $refToDefHash = readConfig($refToExcelFilesList,$refToExcel); |
|
1412 } |
|
1413 #For testing to get the generated config printed to terminal |
|
1414 # $Data::Dumper::Indent = 1; |
|
1415 # print Dumper($refToDefHash); |
|
1416 # exit 1; |
|
1417 |
|
1418 #----------------------------------------------------------------- |
|
1419 # Determinate the default configuration |
|
1420 #----------------------------------------------------------------- |
|
1421 generateConfig($refToResultHash,$refToDefHash,$platId,$platRel,$varName); |
|
1422 $refToDefHash = undef; |
|
1423 |
|
1424 # #For testing to get the generated config printed to terminal |
|
1425 # $Data::Dumper::Indent = 1; |
|
1426 # print Dumper($refToResultHash); |
|
1427 # exit 1; |
|
1428 |
|
1429 } |
|
1430 |
|
1431 ################################################### |
|
1432 # Actual program |
|
1433 ################################################### |
|
1434 my($platId,$platRel,$varName,$sheetDirname,$sheetFilename,$storableFilename,$resultDirname, |
|
1435 $varNameVariant,$sheetDirnameVariant,$storableFilenameVariant,$sheetFilenameVariant,$formatNbr, |
|
1436 $addDefCaps,$rfsDir,$noIni) = parseCmdLine; |
|
1437 |
|
1438 # ---------------------------------------------------------------- |
|
1439 # Get excel application |
|
1440 # ---------------------------------------------------------------- |
|
1441 my $refToExcel = getExcelApp(); |
|
1442 |
|
1443 #----------------------------------------------------------------- |
|
1444 # read the default configuration hash |
|
1445 #----------------------------------------------------------------- |
|
1446 my %resultHash; |
|
1447 readSingleConfig($refToExcel,$sheetDirname,$sheetFilename,$storableFilename,\%resultHash, |
|
1448 $platId,$platRel,$varName); |
|
1449 |
|
1450 #----------------------------------------------------------------- |
|
1451 # read the overriding variant configuration hash |
|
1452 #----------------------------------------------------------------- |
|
1453 readSingleConfig($refToExcel,$sheetDirnameVariant,$sheetFilenameVariant,$storableFilenameVariant, |
|
1454 \%resultHash,$platId,$platRel,$varNameVariant); |
|
1455 |
|
1456 #----------------------------------------------------------------- |
|
1457 # quit excel and "delete" the instances. |
|
1458 #----------------------------------------------------------------- |
|
1459 quitExcelApp($refToExcel); |
|
1460 |
|
1461 #----------------------------------------------------------------- |
|
1462 # Generate the ini-files |
|
1463 #----------------------------------------------------------------- |
|
1464 if(! $noIni) |
|
1465 { |
|
1466 generateIniFiles(\%resultHash,$resultDirname,$formatNbr,$addDefCaps); |
|
1467 } |
|
1468 |
|
1469 #----------------------------------------------------------------- |
|
1470 # Generate the RFS file (if wanted) |
|
1471 #----------------------------------------------------------------- |
|
1472 if($rfsDir !~ /^\s*$/) |
|
1473 { |
|
1474 $rfsDir =~ s/[\/\\]$//g; |
|
1475 $rfsDir .= "/cenrep_rfs.txt"; |
|
1476 generateRfsFile(\%resultHash,$rfsDir); |
|
1477 } |
|
1478 |