brandingserver/tools/xml/xml2h.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:  Writes a header file based on brand xml file
       
    15 #
       
    16 
       
    17 #------------------------------------------------------------------------------
       
    18 # Prints usage information
       
    19 #------------------------------------------------------------------------------
       
    20 #
       
    21 sub UsageInformation
       
    22 {
       
    23     print <<EOF;
       
    24 XML2h.PL
       
    25 Finds all element id's in brand XML file and writes a C++ header file based on
       
    26 them. Destination file is overwritten!
       
    27 
       
    28 Usage:
       
    29 xml2h.pl [in file:xml] [out file:h]
       
    30 EOF
       
    31 
       
    32     exit;
       
    33 }
       
    34 
       
    35 #------------------------------------------------------------------------------
       
    36 # Reads XML file and finds element id's
       
    37 #------------------------------------------------------------------------------
       
    38 #
       
    39 sub ReadXMLFile
       
    40 {
       
    41     # Parse XML file
       
    42     open( INPUT, $ARGV[0] ) || die "ERROR: Can't open file: '$ARGV[0]'";
       
    43 
       
    44     # join lines
       
    45     my $xmlcontent = join( "", <INPUT> );
       
    46     close(INPUT);
       
    47 
       
    48     # remove all comments
       
    49     $xmlcontent =~ s/<!--[.\s]*-->//g;
       
    50 
       
    51     # find elements id's
       
    52     $_ = $xmlcontent;
       
    53     my @elements = /<.*element[. ]* id="([\w\d_]+)".*>/g;
       
    54 
       
    55     #debug print
       
    56 #   foreach $item (@elements) print "$item\n";
       
    57     return @elements;
       
    58 }
       
    59 
       
    60 #------------------------------------------------------------------------------
       
    61 # Write Header file
       
    62 #------------------------------------------------------------------------------
       
    63 #
       
    64 sub WriteHeaderFile
       
    65 {
       
    66     my @ids = @_;
       
    67     open( OUTPUT, ">$ARGV[1]" ) || die "Can't open file: '$ARGV[1]'";
       
    68 
       
    69     # Write header
       
    70     print OUTPUT <<EOF;
       
    71 // Branding item header file created with XML2H. DO NOT MODIFY!
       
    72 
       
    73 EOF
       
    74 
       
    75     # Write items
       
    76     foreach $item (@ids)
       
    77         {
       
    78         $const = $item;
       
    79         substr( $const, 0, 1 ) =~ tr/[a-z]/[A-Z]/;
       
    80         print OUTPUT <<EOF;
       
    81 _LIT8( K$const, \t"$item");
       
    82 EOF
       
    83         }
       
    84 
       
    85     print OUTPUT "\n//End of file\n";
       
    86     close( OUTPUT );
       
    87 }
       
    88 
       
    89 #------------------------------------------------------------------------------
       
    90 # Main function
       
    91 #------------------------------------------------------------------------------
       
    92 #
       
    93 
       
    94 # Check parameters
       
    95 my $count = @ARGV;
       
    96 if( $count != 2 )
       
    97     {
       
    98     UsageInformation();
       
    99     }
       
   100 
       
   101 # Parse XML file
       
   102 my @ids = ReadXMLFile();
       
   103 
       
   104 # Write XML file
       
   105 WriteHeaderFile( @ids );
       
   106 
       
   107 # Done!
       
   108 $count = @ids;
       
   109 print "Processed succesfully $count elements."
       
   110 
       
   111 # end of file