# HG changeset patch # User Dremov Kirill (Nokia-D-MSW/Tampere) # Date 1263843357 -7200 # Node ID beb51793110d4a242f2f0cfc3718069ff86dd0b7 Revision: 201002 Kit: 201003 diff -r 000000000000 -r beb51793110d Symbian/SysDefToText/SysDefCollector.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian/SysDefToText/SysDefCollector.pm Mon Jan 18 21:35:57 2010 +0200 @@ -0,0 +1,610 @@ +# +# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# +#------------------------------------------------------------------------------- +# package: SysDefCollector +# +# usage: Interacts with the SysDefParser to obtain those parts of the system +# definition which are relevant to building a named configuration within the +# system definition. Contains a SysDefCollector::ParserClient instance which +# acts as the interface to the SysDefParser. This separation reduces the +# possibility of a method name clash due to the parser callback mechanism +# requiring the client to implement methods of the same name as the XML +# element tags of interest. +# +# public methods: +# +# new(configname, loghandle): constructs a new instance to collect system +# definition info relating to the configuration name 'configname'. +# +# parserClient(): returns a reference to the SysDefCollector::ParserClient +# instance - typically for passing to the parser. +# +# options(): returns a list of the abld options flags as specified in the +# 'option' elements. +# +# targets(): returns a list of the abld target flags as specified by the +# 'targetList' attributes for each 'buildLayer' element in the specified +# configuration. +# +# specialInstructionsFlag(): returns true/false accordingly as any relevant +# 'specialInstructions' elements are present/not present. Relevant means +# instructions which invoke SETUPPRJ.BAT. +# +# components(): returns a hash of component name and bldFile directories +# for each component to be built for the specified configuration. +# +# dump(): debug/development method to dump the internal data structures +# +# test(): debug/development method to dump the results of the methods +# 'options()', 'targets()', 'specialInstructionsFlag()', 'components()'. +# +#------------------------------------------------------------------------------- +package SysDefCollector; +use strict; + +my $debugFlag = 0; + +sub new +{ + my ($class, $configname, $loghandle) = @_; + my $self = { client => SysDefCollector::ParserClient->new($configname,$loghandle), loghandle => $loghandle }; + return bless $self, $class; +} + +sub parserClient +{ + my $self = shift; + return $self->{client}; +} + +#------------------------------------------------------------------------------- +# sub options() - returns the translated list of options for each 'option' element +#------------------------------------------------------------------------------- +sub options +{ + my $self = shift; + return $self->_collectedList('option'); +} + +#------------------------------------------------------------------------------- +# sub targets() - returns the translated list of targets for each 'buildLayer' +# in the named configuration. +#------------------------------------------------------------------------------- +sub targets +{ + my $self = shift; + + my @targets; + my @buildLayerTargetList = $self->_collectedList('buildLayerTargetList'); + + for my $layerTarget (@buildLayerTargetList) + { + my %targetListHash = $self->_collectedHash('targetList'); + my @targetList = @{ $targetListHash{$layerTarget} }; + push @targets, @targetList; + } + + # eliminate any duplicates by storing as hash keys + my %targetHash = map { $_, '' } @targets; + + # now translate via the target mapping + my %targetMap = $self->_collectedHash('target'); + @targets = map { $targetMap{$_} } keys %targetHash; + + return @targets; +} + +#------------------------------------------------------------------------------- +# sub specialInstructionsFlag() - returns true if 'specialInstructions' elements are present. +#------------------------------------------------------------------------------- +sub specialInstructionsFlag +{ + my $self = shift; + my $flag = 0; + $flag = $self->_collected()->{specialInstructions} + if exists $self->_collected()->{specialInstructions}; + return $flag; +} + +#------------------------------------------------------------------------------- +# sub components() - returns an array of components to be built for the named +# configuration. Each array element is a reference to a further array whose +# element[0] is the component name and element[1] is the directory location +# of that component's 'bld.inf' file. +#------------------------------------------------------------------------------- +sub components +{ + my $self = shift; + my $loghandle = $self->{loghandle}; + + my @unitNames; + my @unitListRef = $self->_collectedList('unitListRef'); + my %unitList = $self->_collectedHash('unitList'); + my %unitListNamesHash; # Used to detect duplicates and then discarded! + my %unitNamesHash; # Used to detect duplicates and then discarded! + my %unitMap = $self->_collectedHash('unit'); + + for my $unitListName (@unitListRef) + { + if (defined $unitListNamesHash{$unitListName}) + { # Duplicate unitListName! Ignore it! + print $loghandle "Ignoring duplicated unitList: $unitListName\n"; + next; + } + $unitListNamesHash{$unitListName} = 1; + unless (defined $unitList{$unitListName}) + { # No info for this unitList! + print $loghandle "No Unit info for unitList: $unitListName\n"; + next; + } + my @units = @{ $unitList{$unitListName} }; + foreach my $unit (@units) + { + if (defined $unitNamesHash{$unit}) + { # Duplicate unit name! Ignore it! + print $loghandle "Ignoring duplicated Unit: $unit\n"; + next; + } + $unitNamesHash{$unit} = 1; + unless (defined $unitMap{$unit}) + { # No bldFile (directory) info for this component! + print $loghandle "No bldFile info for Unit: $unit\n"; + next; + } + my @unitdef = ($unit, $unitMap{$unit}); + push @unitNames, \@unitdef; + } + } + + return @unitNames; +} + +#------------------------------------------------------------------------------- +# +#------------------------------------------------------------------------------- +sub dump +{ + my $self = shift; + my $fh = shift; + $self->parserClient($fh)->dump($fh); +} + +#------------------------------------------------------------------------------- +# +#------------------------------------------------------------------------------- +sub test +{ + my $self = shift; + my $fh = $self->{loghandle}; # Logfile handle + + my @options = $self->options(); + my @targets = $self->targets(); + my $special = $self->specialInstructionsFlag(); + my @components = $self->components($fh); + + print $fh "\nTest Collected System Definition Query Methods\n"; + print $fh "==============================================\n"; + + print $fh "options: ['", (join "', '", @options), "']\n"; + print $fh "targets: ['", (join "', '", @targets), "']\n"; + print $fh "special instructions: '", ($special ? "yes" : "no" ), "'\n"; + print $fh "components:\n{\n"; + for my $component (@components) + { + print $fh "\t'", $component->[0], "' => '", $component->[1], "'\n"; + } + print $fh "}\n"; + print $fh "==============================================\n"; +} + +#------------------------------------------------------------------------------- +# private methods: +#------------------------------------------------------------------------------- +sub _collected +{ + my $self = shift; + return $self->parserClient()->{collected}; +} + +sub _collectedHash +{ + my ($self, $slot) = @_; + my %hash = (); + %hash = %{ $self->_collected()->{$slot} } + if exists $self->_collected()->{$slot}; + return %hash; +} + +sub _collectedList +{ + my ($self, $slot) = @_; + my @list = (); + @list = @{ $self->_collected()->{$slot} } + if exists $self->_collected()->{$slot}; + return @list; +} + +#------------------------------------------------------------------------------- +# package: SysDefCollector::ParserClient +# +# usage: Interacts directly with the SysDefParser to obtain those parts of the system +# definition which are of interest. Implements the parser callback methods +# for the XML elements for which we collect information. Some elements are +# of interest only if they are enclosed within an outer element with certain +# properties. Other elements are always of interest. The latter style of +# element is always collected. The former is only collected when it is known +# that we are within an appropriate enclosing element. The 'context' property +# is used for testing this condition. +# +# methods: +# +# new(configname): constructs a new instance to collect system definition info +# relating to the configuration name 'configname'. +# +# parserClient(): returns a reference to the SysDefCollector::ParserClient +# instance - typically for passing to the parser. +# +#------------------------------------------------------------------------------- +package SysDefCollector::ParserClient; +use strict; + +sub new +{ + my ($class, $configname, $loghandle) = @_; + my $self = { configname => $configname, configfound => 0, context => {intask => 0}, collected => {}, loghandle => $loghandle }; + return bless $self, $class; +} + +#------------------------------------------------------------------------------- +# The following methods 'configuration()', 'configuration_()' initiate and +# terminate respectively the collection of element information found inside a +# 'configuration' element with 'name' attribute matching the objects 'configname' +# attribute. +#------------------------------------------------------------------------------- +sub configuration +{ + my ($self, $expat, $element, %attrs) = @_; + $self->_debugin(@_); + my $loghandle = $self->{loghandle}; + + # start of a 'configuration' element - if the name of the element matches our + # 'configname' attribute then we create contexts so that elements of interest + # nested within this 'configuration' element can be collected. + unless ($attrs{name} eq $self->{configname}) { return; } + + if ($self->{configfound}) + { + print $loghandle "Ignoring duplicated configuration: $attrs{name} ($attrs{description})\n"; + } + else + { + $self->{configfound} = 1; + $self->{context}->{unitListRef} = []; + $self->{context}->{buildLayerTargetList} = []; + } +} + +sub configuration_ +{ + my ($self, $expat, $element) = @_; + $self->_debugout(@_); + + # end of a 'configuration' element - save what we have collected within this + # 'configuration' element and delete the context so as to terminate collection + # of any subsequently encountered nested elements. + + if (exists $self->{context}->{unitListRef}) + { + $self->{collected}->{unitListRef} = $self->{context}->{unitListRef}; + delete $self->{context}->{unitListRef}; + } + + if (exists $self->{context}->{buildLayerTargetList}) + { + # eliminate duplicates + my %hash = map { $_, '' } @{$self->{context}->{buildLayerTargetList}}; + my @unique = keys %hash; + $self->{collected}->{buildLayerTargetList} = \@unique; + delete $self->{context}->{buildLayerTargetList}; + } +} + +#------------------------------------------------------------------------------- +# Method 'unitListRef()' accumulates 'unitListRef' unitList information found +# within a 'configuration element with matching name. +#------------------------------------------------------------------------------- +sub unitListRef +{ + my ($self, $expat, $element, %attrs) = @_; + $self->_debugin(@_); + + if($self->{context}->{intask}) + { return; } # Task-specific unitListRef not supported + + # if there is a previously created context for 'unitListRef's then store this one. + + if (exists $self->{context}->{unitListRef}) + { + push @{$self->{context}->{unitListRef}}, $attrs{unitList}; + } + my $x = 1; +} + +#------------------------------------------------------------------------------- +# Methods 'task()' and 'task_()' track context (i.e. inside a task or not) +# because task-specific activities are not supported. +#------------------------------------------------------------------------------- +sub task +{ + my ($self, $expat, $element, %attrs) = @_; + $self->_debugin(@_); + $self->{context}->{intask} = 1; +} + +sub task_ +{ + my ($self, $expat, $element, %attrs) = @_; + $self->_debugout(@_); + $self->{context}->{intask} = 0; +} + +#------------------------------------------------------------------------------- +# Method 'buildlayer()' accumulates 'buildlayer' targetList information found +# within a 'configuration element with matching name. +#------------------------------------------------------------------------------- +sub buildLayer +{ + my ($self, $expat, $element, %attrs) = @_; + $self->_debugin(@_); + + if (exists $self->{context}->{buildLayerTargetList}) + { + push @{$self->{context}->{buildLayerTargetList}}, (split /\s+/, $attrs{targetList}); + } +} + +#------------------------------------------------------------------------------- +# The following three methods 'unitList()', 'unitList_()' and 'unitRef()' +# accumulate 'unitList' and 'unitRef' information found within the 'build' elements. +#------------------------------------------------------------------------------- +sub unitList +{ + my ($self, $expat, $element, %attrs) = @_; + $self->_debugin(@_); + + # start of a 'unitList' element - create a context so that collection of all + # 'unitRef's elements found within this 'unitList' element can be collected. + + die "Fatal: context already has unitList\n" if exists $self->{context}->{unitList}; + $self->{context}->{unitList} = { name => $attrs{name}, list => [] }; +} + +sub unitList_ +{ + my ($self, $expat, $element, %attrs) = @_; + $self->_debugout(@_); + + # end of the current 'unitList' element - save what we have collected + # and delete the context + + $self->{collected}->{unitList} = {} if ! exists $self->{collected}->{unitList}; + + my $unitList = delete $self->{context}->{unitList}; + $self->{collected}->{unitList}->{$unitList->{name}} = $unitList->{list}; + +} + +sub unitRef +{ + my ($self, $expat, $element, %attrs) = @_; + $self->_debugin(@_); + + # unitRef found - save unitRef data to current context + + die "Fatal: context requires unitList\n" if ! exists $self->{context}->{unitList}; + push @{$self->{context}->{unitList}->{list}}, $attrs{unit}; +} + +#------------------------------------------------------------------------------- +# The method 'unit()' accumulates 'unit' information found within the 'systemModel' +# elements. +#------------------------------------------------------------------------------- +sub unit +{ + my ($self, $expat, $element, %attrs) = @_; + $self->_debugin(@_); + + # no need to set up a temporary context to collect these since they have global scope + $self->{collected}->{unit} = {} if ! exists $self->{collected}->{unit}; + $self->{collected}->{unit}->{$attrs{unitID}} = $attrs{bldFile}; +} + +#------------------------------------------------------------------------------- +# sub option() - accumulates 'option' element information found within the +# 'build' element. +#------------------------------------------------------------------------------- +sub option +{ + my ($self, $expat, $element, %attrs) = @_; + $self->_debugin(@_); + + if ($attrs{enable} =~ /[Yy]/) + { + # no need to set up a temporary context to collect these since they have global scope + $self->{collected}->{option} = [] if ! exists $self->{collected}->{option}; + push @{$self->{collected}->{option}}, $attrs{abldOption}; + } +} + +#------------------------------------------------------------------------------- +# sub target() - accumulates 'target' element information found within the +# 'build' element. +#------------------------------------------------------------------------------- +sub target +{ + my ($self, $expat, $element, %attrs) = @_; + $self->_debugin(@_); + + $self->{collected}->{target} = {} if ! exists $self->{collected}->{target}; + $self->{collected}->{target}->{$attrs{name}} = $attrs{abldTarget}; +} + +#------------------------------------------------------------------------------- +# sub targetList() - accumulates 'targetList' element information found within the +# 'build' element. +#------------------------------------------------------------------------------- +sub targetList +{ + my ($self, $expat, $element, %attrs) = @_; + $self->_debugin(@_); + + $self->{collected}->{targetList} = {} if ! exists $self->{collected}->{targetList}; + my @list = split /\s+/, $attrs{target}; + $self->{collected}->{targetList}->{$attrs{name}} = \@list; +} + +#------------------------------------------------------------------------------- +# sub specialInstructions() - sets the 'specialInstructions' flag if a +# 'specialInstructions' element is encountered. In practice, we are only +# interested in instructions which invoke SETUPPRJ.BAT as this will require +# the inclusion of the "bootstrap" line in the output text file. +#------------------------------------------------------------------------------- +sub specialInstructions +{ + my ($self, $expat, $element, %attrs) = @_; + $self->_debugin(@_); + if ($attrs{command} =~ /^setupprj.bat/i) + { + $self->{collected}->{specialInstructions} = 1; + } +} + +#------------------------------------------------------------------------------- +# utility routines for development/debug purposes. +#------------------------------------------------------------------------------- + +sub _debugin +{ +## return; ## Suppress this debugging! + my $self = shift; + my ($ignore0, $ignore2, $element, @args) = @_; + my $loghandle = $self->{loghandle}; + if ($debugFlag) { print $loghandle "Enter: $element (", (join ' ', @args), ")\n"; } +} + +sub _debugout +{ +## return; ## Suppress this debugging! + my $self = shift; + my $loghandle = $self->{loghandle}; + if ($debugFlag) { print $loghandle "Leave: $_[2]\n"; } +} + +sub dump +{ + my $self = shift; + my $fh = shift; + + print $fh "\nDump Collected System Definition\n\n"; + print $fh "================================\n"; + + if (keys %{$self->{collected}} > 0) + { + if (exists $self->{collected}->{option}) + { + my @option = @{$self->{collected}->{option}}; + print $fh "option :[", (join ',', @option), "]\n"; + } + + if (exists $self->{collected}->{specialInstructions}) + { + my $flag = $self->{collected}->{specialInstructions}; + print $fh "specialInstructions : '", ($flag ? "yes" : "no"), "'\n"; + } + else + { + print $fh "specialInstructions : 'no'\n"; + } + + if (exists $self->{collected}->{buildLayerTargetList}) + { + my @buildLayerTargetList = @{$self->{collected}->{buildLayerTargetList}}; + print $fh "buildLayerTargetList :[", (join ',', @buildLayerTargetList), "]\n"; + } + + if (exists $self->{collected}->{unitListRef}) + { + my @unitListRef = @{$self->{collected}->{unitListRef}}; + print $fh "unitListRef :[", (join ',', @unitListRef), "]\n"; + } + + if (exists $self->{collected}->{unitList}) + { + print $fh "unitList:\n{\n"; + my %unitList = %{$self->{collected}->{unitList}}; + for my $key (keys %unitList) + { + my @list = @{$unitList{$key}}; + print $fh "\t'$key' has units:[", (join ',', @list), "]\n"; + } + print $fh "}\n"; + } + + if (exists $self->{collected}->{target}) + { + print $fh "target:\n{\n"; + my %target = %{$self->{collected}->{target}}; + for my $key (keys %target) + { + print $fh "\t'$key' => '", $target{$key} , "'\n"; + } + print $fh "}\n"; + } + + if (exists $self->{collected}->{targetList}) + { + print $fh "targetList:\n{\n"; + my %targetList = %{$self->{collected}->{targetList}}; + for my $key (keys %targetList) + { + my @list = @{$targetList{$key}}; + print $fh "\t'$key' has targets:[", (join ',', @list), "]\n"; + } + print $fh "}\n"; + } + + if (exists $self->{collected}->{unit}) + { + print $fh "unit:\n{\n"; + my %unit = %{$self->{collected}->{unit}}; + for my $key (keys %unit) + { + print $fh "\t'$key' => '", $unit{$key} , "'\n"; + } + print $fh "}\n"; + } + } + else + { + print $fh "Nothing collected\n"; + } + print $fh "================================\n"; +} + +#------------------------------------------------------------------------------- +# -EOF- +#------------------------------------------------------------------------------- +1; diff -r 000000000000 -r beb51793110d Symbian/SysDefToText/SysDefParser.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian/SysDefToText/SysDefParser.pm Mon Jan 18 21:35:57 2010 +0200 @@ -0,0 +1,131 @@ +# +# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# +#------------------------------------------------------------------------------- +# package: SysDefParser +# +# usage: Wrapper for an XML parser to dispatch callbacks to a client object which +# analyses the parsed XML data. The auxiliary package SysDefParser::Dispatcher +# acts as an intermediary between the parser and the client to convert function +# callbacks to method callbacks using perl's AUTOLOAD mechanism. +# +# public methods: +# +# new(-client => , [-parser => ]) : creates a +# instance. is the instance to which the parser callbacks +# are dispatched. is an optional alternative parser client +# package to use instead of the default XML::Parser class. +# +# parse(): parse the XML data from filehandle dispatching +# callbacks to the client object. +# +#------------------------------------------------------------------------------- + +package SysDefParser; +use strict; + +sub new +{ + my ($class, %args) = @_; + my $self = bless {}, $class; + $self->{client} = delete $args{-client}; + + if (exists $args{-parser}) + { + $args{Pkg} = 'SysDefParser::Dispatcher'; + require $args{-parser}; + $self->{parser} = $args{-parser}->createParser(%args); + } + else + { + $self->{parser} = $class->_createParser(%args); + } + + return $self; +} + +sub _createParser +{ + my ($class, %args) = @_; + require XML::Parser; + return XML::Parser->new + ( + Style => 'Subs', + Pkg => 'SysDefParser::Dispatcher', + ErrorContext => 2 + ); +} + +my $PARSERCLIENT = undef; + +sub _client { return $PARSERCLIENT; } + +sub parse +{ + my ($self, $fileh) = @_; + + # we can't pass any context down to the underlying parser so that we can work out which + # object any callbacks from the parser are associated with so, assuming that the parser will + # not be called in a re-entrant fashion, we store the context at this point, so that we can + # then dispatch the callbacks from the parsers 'parse' method to those methods of the saved + # $PARSERCLIENT instance. + + die "Fatal: client object not set\n" if ! defined $self->{client}; + die "Fatal: parser client object already set\n" if defined $PARSERCLIENT; + $PARSERCLIENT = $self->{client}; + + # call the parser, callbacks will be dispatched to sub AUTOLOAD in SysDefParser::Dispatcher + + my $rv =$self->{parser}->parse($fileh); + + # finished parsing, unset the context + + $PARSERCLIENT = undef; + + return $rv; +} + +#------------------------------------------------------------------------------- +# package SysDefParser::Dispatcher +# +# usage: Internal package. Uses AUTOLOAD mechanism to receive parser callbacks and +# convert them to object method calls on teh client object. +# +#------------------------------------------------------------------------------- +package SysDefParser::Dispatcher; +use strict; + +sub AUTOLOAD +{ + my @ARGS = @_; + + my $client = SysDefParser::_client(); + + die "Fatal: parser client object not set\n" if ! defined $client; + + # translate the called back function name to the client method name + my $clientpkg = ref($client); + my $method = $SysDefParser::Dispatcher::AUTOLOAD; + + $method =~ s/^SysDefParser::Dispatcher/$clientpkg/; + + # dispatch the parser's callback to the client object (if implemented by client) + $client->$method(@ARGS) if $client->can($method); +} + +#------------------------------------------------------------------------------- +# -EOF- +#------------------------------------------------------------------------------- +1; \ No newline at end of file diff -r 000000000000 -r beb51793110d Symbian/SysDefToText/SysDefToText.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian/SysDefToText/SysDefToText.pl Mon Jan 18 21:35:57 2010 +0200 @@ -0,0 +1,116 @@ +# +# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# +#!perl +# This script converts new-style System Definition XML files to the older +# .TXT file format (i.e. files of the type GT.TXT, Techview.TXT etc.) + +# +# Modified by S60 to get two xml input file +# Can use cases when system model and system build located in different files +# + +use strict; +use FindBin; # for FindBin::Bin +use lib $FindBin::Bin; +use Getopt::Long; +use SysDefToText; + +my $debug; + +my ($config, $XMLfile, $outfile, $logfile) = ProcessCommandLine(); + +print STDERR "Configuration: $config\n"; +print STDERR "Input .XML file: @$XMLfile\n"; +print STDERR "Output .TXT file: $outfile\n"; +if (defined $logfile) + { + print STDERR "Logfile: $logfile\n"; + } + +SysDefToText::ConvertFile($config, $XMLfile, $outfile, $logfile); + +exit(0); + +# ProcessCommandLine +# +# Inputs +# @ARGV +# +# Outputs +# Returns Configuration Nmae and filenames. +# +# Description +# This function processes the command line +# On error, exits via Usage(); + +sub ProcessCommandLine +{ + my ($help, $config, @XMLfile, $XMLfile1, $outfile, $logfile); + my $args = @ARGV; + + my $ret = GetOptions('h' => \$help, 'n=s' => \$config, 'x=s' => \@XMLfile, 'o=s' => \$outfile, 'l=s' => \$logfile); + + if (($help) || (!$args) || (!$ret) || (!@XMLfile) || (!defined $config) || (!defined $outfile)) + { + Usage(); + } + if (@ARGV) + { + Usage ("Redundant information on command line: @ARGV"); + } + return($config, \@XMLfile, $outfile, $logfile); +} + +# Usage +# +# Input: Error message, if any +# +# Output: Usage information. +# + +sub Usage +{ + if (@_) + { + print "\n****@_\n"; + } + + print <>@_"; } +} + +__END__ diff -r 000000000000 -r beb51793110d Symbian/SysDefToText/SysDefToText.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian/SysDefToText/SysDefToText.pm Mon Jan 18 21:35:57 2010 +0200 @@ -0,0 +1,219 @@ +# +# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# +# This module converts new-style System Definition XML files to the older +# .TXT file format (i.e. files of the type GT.TXT, Techview.TXT etc.) + +package SysDefToText; +use strict; +use SysDefCollector; +use SysDefParser; + +# ConvertFile +# +# Inputs +# Name of XML file to read +# Configuration name +# +# Outputs +# Writes data to Text File +# Writes to log file, if filename defined. +# +# Description +# This is the "top level" subroutine for the conversion of a "SysDef" .XML file to an old format "Text" file. +# +sub ConvertFile +{ + my ($configname, $XMLfile, $outfile, $logfile) = @_; + +# my $XMLhandle = \*XMLFILE; + my $outhandle = \*OUTFILE; + my $loghandle = \*LOGFILE; + +# open $XMLhandle, "<$XMLfile" or die "Cannot open input file: $XMLfile"; + open $outhandle, ">$outfile" or die "Cannot open output file: $outfile"; + if (defined $logfile) + { + open $loghandle, ">$logfile" or die "Cannot open logfile: $logfile"; + print $loghandle "Processing: $XMLfile Output to: $outfile\n"; + print $loghandle "==================================================\n"; + } + else + { + $loghandle = \*STDERR; + } + + my $sysdef = SysDefCollector->new($configname,$loghandle); + my $parser = SysDefParser->new(-client => $sysdef->parserClient()); + + foreach my $file (@$XMLfile) { + my $XMLhandle = \*file; + open $XMLhandle, "<$file" or die "Cannot open input file: $file"; + $parser->parse($XMLhandle); + close $XMLhandle; + } + + ## Suppress this debugging! + ##{ # FTB just call dump() and test() routines. + #$sysdef->dump($loghandle); + #$sysdef->test($loghandle); + ##} + + WriteHeader($outhandle,$configname,$XMLfile); + + my @list0 = $sysdef->options(); # ABLD options + my @list1 = $sysdef->targets(); + WriteOptionList($outhandle,\@list0,\@list1); + + my @list2 = $sysdef->components(); + my $bootflag = $sysdef->specialInstructionsFlag(); + WriteComponentList($outhandle,\@list2,$bootflag); + +# close XMLFILE; + close OUTFILE; + if (defined $logfile) { close LOGFILE; } +} + +# WriteHeader +# +# Inputs +# Handle of Text file to which to write +# Configuration name +# +# Outputs +# Writes data to Text File +# +# Description +# This subroutine initiates the old format "Text" file. +# +sub WriteHeader +{ + my $fh = shift; + my $config = shift; + my $XMLfile = shift; + print $fh < $column2pos) { $column2pos += 8; } + printf $fh "%-*s\t# use abld %s\n", $column2pos, $name, $option; + } + + foreach my $target (@$targets) + { + # abld targets are only one word + next if ($target =~ /\w+\s+\w+/); + my $name; + if ($target =~ /(misa|mint|mcot|mtemplate|meig)/i) + { + $name = "