brandingserver/tools/xml/mbg2xml.pl
changeset 0 e6b17d312c8b
child 21 cfd5c2994f10
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     1 #
       
     2 # Copyright (c) 2006-2006 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:  Converts mbg file into branding xml file
       
    15 #
       
    16 
       
    17 # SETUP
       
    18 #
       
    19 my $skinidconstants   = 'epoc32\include\middleware\aknsconstants.h';
       
    20 my $skiniddefinitions = 'epoc32\include\middleware\aknsconstants.hrh';
       
    21 my $version =           'v0.1';
       
    22 
       
    23 # GLOBALS
       
    24 #
       
    25 
       
    26 # these hashes store the data for each bitmap.
       
    27 # each data can be accessed with same key value.
       
    28 my %bitmaps = ();       # bitmapname => bitmap id
       
    29 my %masks = ();         # bitmapname => mask id
       
    30 my %skinidmajor = ();   # bitmapname => major skin id
       
    31 my %skinidminor = ();   # bitmapname => minor skin id
       
    32 
       
    33 my $commonpart;         # common part of every mbg
       
    34 
       
    35 #------------------------------------------------------------------------------
       
    36 # Trim string
       
    37 #------------------------------------------------------------------------------
       
    38 #
       
    39 sub trim($)
       
    40 {
       
    41 	my $string = shift;
       
    42 	$string =~ s/^[ ]+//;
       
    43 	$string =~ s/[ ]+$//;
       
    44 	return $string;
       
    45 }
       
    46 
       
    47 #------------------------------------------------------------------------------
       
    48 # Determines, validates, and returns EPOCROOT.
       
    49 #------------------------------------------------------------------------------
       
    50 #
       
    51 sub getEpocroot
       
    52 {
       
    53     my $epocroot = $ENV{EPOCROOT};
       
    54     die "ERROR: Must set the EPOCROOT environment variable.\n"
       
    55 	if (!defined($epocroot));
       
    56     $epocroot =~ s-/-\\-go;	# for those working with UNIX shells
       
    57     die "ERROR: EPOCROOT must be an absolute path, " .
       
    58 	"not containing a drive letter.\n" if ($epocroot !~ /^\\/);
       
    59     die "ERROR: EPOCROOT must not be a UNC path.\n" if ($epocroot =~ /^\\\\/);
       
    60     die "ERROR: EPOCROOT must end with a backslash.\n" if ($epocroot !~ /\\$/);
       
    61     die "ERROR: EPOCROOT must specify an existing directory.\n"
       
    62 	if (!-d $epocroot);
       
    63     return $epocroot;
       
    64 }
       
    65 
       
    66 #------------------------------------------------------------------------------
       
    67 # Prints usage information
       
    68 #------------------------------------------------------------------------------
       
    69 #
       
    70 sub UsageInformation
       
    71 {
       
    72     print <<EOF;
       
    73 MBG2XML.PL $version
       
    74 ------------------------
       
    75 converts mbg file into branding xml file. Seeks skin ids for all the
       
    76 found bitmaps. Script needs to be executed on the same drive as the
       
    77 development platform.
       
    78 
       
    79 NOTE! XML file is overwritten!
       
    80 
       
    81 Usage:
       
    82 mbg2xml.pl [in file:mbg] [out file:xml] [brand_id] [application_id]
       
    83            [language id] [version] [bitmap file extension (MBM, MIF..)]
       
    84 
       
    85 EOF
       
    86 
       
    87     exit;
       
    88 }
       
    89 
       
    90 #------------------------------------------------------------------------------
       
    91 # Parse Avkon skin id file and find ids
       
    92 #------------------------------------------------------------------------------
       
    93 #
       
    94 sub ParseAvkonSkinFile
       
    95 {
       
    96 # read file
       
    97 print "\nParsing file: ".&getEpocroot.$skinidconstants;
       
    98 open( F, &getEpocroot.$skinidconstants ) || die "Can't open avkon skin file!";
       
    99 my @readbuffer = <F>;
       
   100 close( F );
       
   101 my $longbuf = join( "", @readbuffer );
       
   102 
       
   103 # try to find each bitmap from file
       
   104 foreach $item( keys( %bitmaps ) )
       
   105     {
       
   106     $searchitem = $item;
       
   107     $searchitem =~ s/$commonpart//;
       
   108     $searchitem =~ s/_//g;
       
   109     $_ = $longbuf;
       
   110     #print "\n - Seaching: ".$searchitem." = \t";
       
   111     if( /static\s+const\s+TAknsItemID\s+KAknsIID($searchitem)\s*=\s*{\s*(\w+)\s*,\s*(\w+)\s*}\s*;/i )
       
   112         {
       
   113         #print $2." - ".$3;
       
   114         $skinidmajor{$item} = $2;
       
   115         $skinidminor{$item} = $3;
       
   116         }
       
   117     else
       
   118         {
       
   119         #print "not found";
       
   120         }
       
   121     }
       
   122 }
       
   123 
       
   124 #------------------------------------------------------------------------------
       
   125 # Parse Avkon skin id definition file and find values for ids
       
   126 #------------------------------------------------------------------------------
       
   127 #
       
   128 sub ParseAvkonSkinDefFile
       
   129 {
       
   130 # read file
       
   131 print "\nParsing file: ".&getEpocroot.$skiniddefinitions;
       
   132 open( F, &getEpocroot.$skiniddefinitions ) || die "Can't open avkon skin def file!";
       
   133 my @readbuffer = <F>;
       
   134 close( F );
       
   135 
       
   136 my $longbuf = join( "", @readbuffer );
       
   137 
       
   138 # Parse major ids
       
   139 print "\nParsing major skin ids";
       
   140 while( ( $key, $id ) = each( %skinidmajor ) )
       
   141     {
       
   142     $searchitem = $id;
       
   143     $_ = $longbuf;
       
   144     #print "\n - Seaching: ".$searchitem." = \t";
       
   145     if( /\s+$searchitem\s*=\s*([a-fx0-9]+)/i )
       
   146         {
       
   147         #print $1;
       
   148         $skinidmajor{$key} = hex($1);
       
   149         }
       
   150     else
       
   151         {
       
   152         #print "not found";
       
   153         }
       
   154     }
       
   155 
       
   156 # Parse minor ids
       
   157 print "\nParsing minor skin ids";
       
   158 while( ( $key, $id ) = each( %skinidminor ) )
       
   159     {
       
   160     $searchitem = $id;
       
   161     $_ = $longbuf;
       
   162     #print "\n - Seaching: ".$searchitem." = \t";
       
   163     if( /\s+$searchitem\s*=\s*([a-fx0-9]+)/i )
       
   164         {
       
   165         #print $1;
       
   166         $skinidminor{$key} = hex($1);
       
   167         }
       
   168     else
       
   169         {
       
   170         #print "not found";
       
   171         }
       
   172     }
       
   173 
       
   174 }
       
   175 
       
   176 #------------------------------------------------------------------------------
       
   177 # Reads MBG file and constructs associative array
       
   178 #------------------------------------------------------------------------------
       
   179 #
       
   180 sub ReadMbgFile
       
   181 {
       
   182 # Parse LOC file
       
   183 my $infile = shift;
       
   184 open(INPUT, $infile) || die "Can't open file: '$infile'";   # Open the file
       
   185 
       
   186 
       
   187 while( <INPUT> )
       
   188     {
       
   189     $_ = trim( $_ );
       
   190     if( /^\s*(E[\w_]*) [=] ([0-9]+),/i )
       
   191         {
       
   192         $_ = $1;
       
   193         $value = $2;
       
   194         if( /(E[\w_]*)_mask/ )
       
   195             {
       
   196             $masks{$1} = $value;
       
   197             }
       
   198         else
       
   199             {
       
   200             $bitmaps{$1} = $value;
       
   201             }
       
   202         #$id =~ s/_//g;      # remove all '_' chars
       
   203         }
       
   204     elsif( /^\s*(E[\w]*)LastElement\s*/ )
       
   205         {
       
   206         print "\nCommon part for bitmaps: '$1'\n";
       
   207         $commonpart = $1;
       
   208         }
       
   209     }
       
   210 close(INPUT);			    # Close the file
       
   211 }
       
   212 
       
   213 #------------------------------------------------------------------------------
       
   214 # Write branding XML file
       
   215 #------------------------------------------------------------------------------
       
   216 #
       
   217 sub WriteXmlFile
       
   218 {
       
   219 my %strings = @_;
       
   220 $len = length $ARGV[0];
       
   221 $bitmap_file_id = substr($ARGV[0], 0,  $len - 4);
       
   222 $bitmap_file = $bitmap_file_id . "." . $ARGV[6];
       
   223 $bitmap_file_id = $bitmap_file_id . "_" . $ARGV[6];
       
   224 
       
   225 open( OUTPUT, ">$ARGV[1]" ) || die "Can't open file: '$ARGV[1]'";
       
   226 
       
   227 print OUTPUT <<EOF;
       
   228 <?xml version="1.0" encoding="ISO-8859-1"?>
       
   229 <branding>
       
   230     <brand>
       
   231         <application_id>    $ARGV[3]</application_id>
       
   232         <brand_id>          $ARGV[2]</brand_id>
       
   233         <brand_language_id> $ARGV[4]</brand_language_id>
       
   234         <brand_version>     $ARGV[5]</brand_version>
       
   235         <element type="file" id=\"$bitmap_file_id\">
       
   236         	<element_value>
       
   237                 <file_name>c:\\private\\102828DD\\import\\$bitmap_file</file_name>
       
   238         	</element_value>
       
   239         </element>
       
   240 
       
   241 EOF
       
   242 
       
   243 
       
   244 while( ($key, $value) = each(%bitmaps) )
       
   245     {
       
   246     # strip underscores
       
   247     $modifkey = $key;
       
   248     $modifkey =~ s/_//g;
       
   249 
       
   250     print OUTPUT <<EOF;
       
   251         <element id="$modifkey" type="bitmap">
       
   252         	<element_value>
       
   253         		<bitmap_file_id> $bitmap_file_id</bitmap_file_id>
       
   254         		<bitmap_id>      $value </bitmap_id>
       
   255         		<mask_id>        $masks{$key} </mask_id>
       
   256         		<skin_id_major> $skinidmajor{$key} </skin_id_major>
       
   257         		<skin_id_minor>   $skinidminor{$key} </skin_id_minor>
       
   258          	</element_value>
       
   259         </element>
       
   260 
       
   261 EOF
       
   262     }
       
   263 
       
   264 print OUTPUT "    </brand>\n";
       
   265 print OUTPUT "</branding>\n";
       
   266 
       
   267 close( OUTPUT );
       
   268 }
       
   269 
       
   270 #------------------------------------------------------------------------------
       
   271 # Main function
       
   272 #------------------------------------------------------------------------------
       
   273 #
       
   274 
       
   275 # Check parameters
       
   276 my $count = @ARGV;
       
   277 if( $count != 7 )
       
   278     {
       
   279     UsageInformation();
       
   280     }
       
   281 
       
   282 # Parse MBG file for bitmaps
       
   283 print "\nParsing input file: $ARGV[0]";
       
   284 ReadMbgFile( $ARGV[0] );
       
   285 
       
   286 # Parse avkon skin files and find skin id's for all the found bitmaps
       
   287 ParseAvkonSkinFile();
       
   288 ParseAvkonSkinDefFile();
       
   289 
       
   290 # Write XML file
       
   291 WriteXmlFile();
       
   292 
       
   293 # Done!
       
   294 my @list = %bitmaps;
       
   295 $count = @list / 2;
       
   296 print "\n\nProcessed succesfully $count bitmaps.\nDone!\n"
       
   297 
       
   298 # end of file