Symbian/SysDefToText/SysDefToText.pm
branchRCL_3
changeset 18 ea3e26ea6629
parent 6 c8ecf89eb77f
equal deleted inserted replaced
6:c8ecf89eb77f 18:ea3e26ea6629
     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 # This module converts new-style System Definition XML files to the older
       
    17 # .TXT file format (i.e. files of the type GT.TXT, Techview.TXT etc.)
       
    18 
       
    19 package SysDefToText;
       
    20 use strict;
       
    21 use SysDefCollector;
       
    22 use SysDefParser;
       
    23 
       
    24 # ConvertFile
       
    25 #
       
    26 # Inputs
       
    27 #   Name of XML file to read
       
    28 #   Configuration name
       
    29 #
       
    30 # Outputs
       
    31 #   Writes data to Text File
       
    32 #   Writes to log file, if filename defined.
       
    33 #
       
    34 # Description
       
    35 #   This is the "top level" subroutine for the conversion of a "SysDef" .XML file to an old format "Text" file.
       
    36 #
       
    37 sub ConvertFile
       
    38 {
       
    39     my ($configname, $XMLfile, $outfile, $logfile) = @_;
       
    40 
       
    41 #    my $XMLhandle = \*XMLFILE;
       
    42     my $outhandle = \*OUTFILE;
       
    43     my $loghandle = \*LOGFILE;
       
    44 
       
    45 #    open $XMLhandle, "<$XMLfile" or die "Cannot open input file: $XMLfile";
       
    46     open $outhandle, ">$outfile" or die "Cannot open output file: $outfile";
       
    47     if (defined $logfile)
       
    48     {
       
    49         open $loghandle, ">$logfile" or die "Cannot open logfile: $logfile";
       
    50         print $loghandle "Processing: $XMLfile    Output to: $outfile\n";
       
    51         print $loghandle "==================================================\n";
       
    52     }
       
    53     else
       
    54     {
       
    55         $loghandle = \*STDERR;
       
    56     }
       
    57     
       
    58     my $sysdef = SysDefCollector->new($configname,$loghandle);
       
    59     my $parser = SysDefParser->new(-client => $sysdef->parserClient());
       
    60 
       
    61 		foreach my $file (@$XMLfile) {
       
    62 	    my $XMLhandle = \*file;
       
    63 	    open $XMLhandle, "<$file" or die "Cannot open input file: $file";
       
    64 	    $parser->parse($XMLhandle);
       
    65 	    close $XMLhandle;
       
    66 		}
       
    67 
       
    68     ## Suppress this debugging!
       
    69     ##{   # FTB just call dump() and test() routines.
       
    70         #$sysdef->dump($loghandle);
       
    71         #$sysdef->test($loghandle);
       
    72     ##}
       
    73     
       
    74     WriteHeader($outhandle,$configname,$XMLfile);
       
    75 
       
    76     my @list0 = $sysdef->options();          # ABLD options
       
    77     my @list1 = $sysdef->targets();
       
    78     WriteOptionList($outhandle,\@list0,\@list1);
       
    79 
       
    80     my @list2 = $sysdef->components();
       
    81     my $bootflag = $sysdef->specialInstructionsFlag();
       
    82     WriteComponentList($outhandle,\@list2,$bootflag);
       
    83     
       
    84 #    close XMLFILE;
       
    85     close OUTFILE;
       
    86     if (defined $logfile) { close LOGFILE; }
       
    87 }
       
    88 
       
    89 # WriteHeader
       
    90 #
       
    91 # Inputs
       
    92 #   Handle of Text file to which to write
       
    93 #   Configuration name
       
    94 #
       
    95 # Outputs
       
    96 #   Writes data to Text File
       
    97 #
       
    98 # Description
       
    99 #   This subroutine initiates the old format "Text" file.
       
   100 #
       
   101 sub WriteHeader
       
   102 {
       
   103     my $fh = shift;
       
   104     my $config = shift;
       
   105     my $XMLfile = shift;
       
   106     print $fh <<HEADER_TXT;
       
   107 #
       
   108 # ****************************** IMPORTANT NOTE ************************************
       
   109 #
       
   110 # This file was generated using information read from: @$XMLfile.
       
   111 # The configuration was specified as: $config
       
   112 #
       
   113 # **********************************************************************************
       
   114 #
       
   115 
       
   116 HEADER_TXT
       
   117 }
       
   118 
       
   119 # WriteOptionList
       
   120 #
       
   121 # Inputs
       
   122 #   Handle of Text file to which to write
       
   123 #   Array reference for list of ABLD Options
       
   124 #   Array reference for list of targets
       
   125 #
       
   126 # Outputs
       
   127 #   Writes data to Text File
       
   128 #
       
   129 # Description
       
   130 #   This subroutine writes out options and targets (one per line) to the old format "Text" file.
       
   131 #   Note that option lines and target lines have the same format! 
       
   132 #
       
   133 sub WriteOptionList
       
   134 {
       
   135     my $fh = shift;
       
   136     my $abldoptions = shift;      # Array ref.
       
   137     my $targets = shift;          # Array ref.
       
   138   
       
   139     print $fh "# Optional variations in the generated scripts\n\n";
       
   140 
       
   141     my $column2pos = 8;
       
   142     foreach my $option (@$abldoptions)
       
   143     {
       
   144         my $name = '<option ????>';
       
   145         if ($option =~ /^-(.+)/) {$name = "<option $1>"}
       
   146         my $len = length $name;
       
   147         while ($len > $column2pos) { $column2pos += 8; }
       
   148         printf $fh "%-*s\t# use abld %s\n", $column2pos, $name, $option;
       
   149     }
       
   150 
       
   151     foreach my $target (@$targets)
       
   152     {
       
   153         # abld targets are only one word
       
   154         next if ($target =~ /\w+\s+\w+/);
       
   155         my $name;
       
   156         if ($target =~ /(misa|mint|mcot|mtemplate|meig)/i)
       
   157         {
       
   158             $name = "<option arm_assp $target>";
       
   159         } else {
       
   160             $name = "<option $target>";
       
   161         }
       
   162         my $len = length $name;
       
   163         while ($len > $column2pos) { $column2pos += 8; }
       
   164         printf $fh "%-*s\t#\n", $column2pos, $name;
       
   165     }
       
   166 
       
   167     print $fh "\n";
       
   168 }
       
   169 
       
   170 # WriteComponentList
       
   171 #
       
   172 # Inputs
       
   173 #   Handle of Text file to which to write
       
   174 #   Hash reference for hash of Components
       
   175 #
       
   176 # Outputs
       
   177 #   Writes data to Text File
       
   178 #
       
   179 # Description
       
   180 #   This subroutine writes out the Name and filepath (abld_directory) for each component,
       
   181 #   one component per line, to the old format "Text" file.
       
   182 #
       
   183 sub WriteComponentList
       
   184 {
       
   185     my $fh = shift;
       
   186     my $listref = shift;    # Ordered array of array refs -> "Name" and "abld_directory" pairs
       
   187     my $bootflag = shift;   # Boolean flag indicates whether default bootstrap "component" required
       
   188     
       
   189     print $fh "# List of components required \n";
       
   190     print $fh "#\n# Name		abld_directory\n";
       
   191 
       
   192     if($bootflag)
       
   193         {
       
   194         print $fh "#\n# Bootstrapping....\n\n";
       
   195         print $fh "<special bldfiles E32Toolp group>			# Special installation for E32ToolP\n\n";
       
   196         print $fh "# Components:\n";
       
   197         }
       
   198     print $fh "#\n";
       
   199 
       
   200     ##print $fh "# Things which generate include files used by later components, e.g. .RSG, .MBG or .h files\n\n";
       
   201     ##print $fh "# Everything else\n\n";
       
   202 
       
   203     my $column2pos = 8;
       
   204     foreach my $component (@$listref)
       
   205     {
       
   206         my $len = length $component->[0];
       
   207         while ($len > $column2pos) { $column2pos += 8; }
       
   208         my $bldfile = $component->[1];
       
   209         if ($bldfile =~ /^\\/) {
       
   210           $bldfile =~ s/^\\//i;
       
   211         }
       
   212         printf $fh "%-*s\t%s\n", $column2pos, $component->[0], $bldfile;
       
   213     }
       
   214 }
       
   215 
       
   216 1;
       
   217 
       
   218 __END__
       
   219