brandingserver/tools/xml/loc2xml.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 loc file into branding xml file
       
    15 #
       
    16 
       
    17 #------------------------------------------------------------------------------
       
    18 # Trim string
       
    19 #------------------------------------------------------------------------------
       
    20 #
       
    21 sub trim($)
       
    22 {
       
    23 	my $string = shift;
       
    24 	$string =~ s/^[ ]+//;
       
    25 	$string =~ s/[ ]+$//;
       
    26 	return $string;
       
    27 }
       
    28 
       
    29 
       
    30 #------------------------------------------------------------------------------
       
    31 # Prints usage information
       
    32 #------------------------------------------------------------------------------
       
    33 #
       
    34 sub UsageInformation
       
    35 {
       
    36     print <<EOF;
       
    37 LOC2XML.PL
       
    38 converts loc file into branding xml file. XML file is overwritten!
       
    39 
       
    40 Usage:
       
    41 loc2xml.pl [in file:loc] [out file:xml] [brand_id] [application_id]
       
    42            [language id] [version]
       
    43 EOF
       
    44 
       
    45     exit;
       
    46 }
       
    47 
       
    48 #------------------------------------------------------------------------------
       
    49 # Reads LOC file and constructs associative array
       
    50 #------------------------------------------------------------------------------
       
    51 #
       
    52 sub ReadLocFile
       
    53 {
       
    54 # Parse LOC file
       
    55 my $infile = shift;
       
    56 open(INPUT, $infile) || die "Can't open file: '$infile'";   # Open the file
       
    57 my %array = ();
       
    58 
       
    59 while( <INPUT> )
       
    60     {
       
    61     $_ = trim( $_ );
       
    62     if( /^\#define\s+qtn.+\s+\".+\"/i )
       
    63         {
       
    64         # find ID
       
    65         /(qtn[\w\d_]+)/i;
       
    66         $id = $1;
       
    67         $id =~ s/_//g;      # remove all '_' chars
       
    68 
       
    69         #find value
       
    70         /\"(.+)\"/i;
       
    71         $value = $1;
       
    72 
       
    73         $array{$id} = $value;
       
    74 #        print "$id \t: \'$value\'\n\r"
       
    75         }
       
    76     }
       
    77 close(INPUT);			    # Close the file
       
    78 
       
    79 return %array;
       
    80 }
       
    81 
       
    82 #------------------------------------------------------------------------------
       
    83 # Write XML file from given array
       
    84 #------------------------------------------------------------------------------
       
    85 #
       
    86 sub WriteXmlFile
       
    87 {
       
    88 my %strings = @_;
       
    89 open( OUTPUT, ">$ARGV[1]" ) || die "Can't open file: '$ARGV[1]'";
       
    90 
       
    91 
       
    92 print OUTPUT <<EOF;
       
    93 <?xml version="1.0" encoding="ISO-8859-1"?>
       
    94 <branding>
       
    95     <brand>
       
    96         <application_id>$ARGV[3]</application_id>
       
    97         <brand_id>$ARGV[2]</brand_id>
       
    98         <brand_language_id>$ARGV[4]</brand_language_id>
       
    99         <brand_version>$ARGV[5]</brand_version>
       
   100 
       
   101 EOF
       
   102 
       
   103 while( ($key, $value) = each(%strings) )
       
   104     {
       
   105     print OUTPUT <<EOF;
       
   106         <element id="$key" type="text">
       
   107          <element_value>$value</element_value>
       
   108         </element>
       
   109 
       
   110 EOF
       
   111     }
       
   112 
       
   113 print OUTPUT "    </brand>\n";
       
   114 print OUTPUT "</branding>\n";
       
   115 
       
   116 close( OUTPUT );
       
   117 }
       
   118 
       
   119 #------------------------------------------------------------------------------
       
   120 # Main function
       
   121 #------------------------------------------------------------------------------
       
   122 #
       
   123 
       
   124 # Check parameters
       
   125 my $count = @ARGV;
       
   126 if( $count != 6 )
       
   127     {
       
   128     UsageInformation();
       
   129     }
       
   130 
       
   131 # Parse LOC file
       
   132 my %strings = &ReadLocFile( $ARGV[0] );
       
   133 
       
   134 # Write XML file
       
   135 WriteXmlFile( %strings );
       
   136 
       
   137 # Done!
       
   138 my @list = %strings;
       
   139 $count = @list / 2;
       
   140 print "Processed succesfully $count strings."
       
   141 
       
   142 # end of file