blob: 69c5f55896672818faaad13e4508cf9c6f996c67 [file] [log] [blame]
#
# All Rights Reserved
#
# MARVELL CONFIDENTIAL
# Copyright 2012 Marvell International Ltd All Rights Reserved.
# The source code contained or described herein and all documents related to
# the source code ("Material") are owned by Marvell International Ltd or its
# suppliers or licensors. Title to the Material remains with Marvell International Ltd
# or its suppliers and licensors. The Material contains trade secrets and
# proprietary and confidential information of Marvell or its suppliers and
# licensors. The Material is protected by worldwide copyright and trade secret
# laws and treaty provisions. No part of the Material may be used, copied,
# reproduced, modified, published, uploaded, posted, transmitted, distributed,
# or disclosed in any way without Marvell's prior express written permission.
#
# No license under any patent, copyright, trade secret or other intellectual
# property right is granted to or conferred upon you by disclosure or delivery
# of the Materials, either expressly, by implication, inducement, estoppel or
# otherwise. Any license under such intellectual property rights must be
# express and approved by Marvell in writing.
#
#!/usr/bin/perl -w
use strict;
use Spreadsheet::ParseExcel;
use XML::DOM;
use XML::Twig;
use IO::File;
my ($inputFile, $outputFile) = @ARGV;
my $file_type = substr($inputFile, -4, 5);
die "Input file type error $inputFile" unless $file_type eq ".xls";
die "Cen't open $inputFile" unless -r $inputFile;
# define node names
my %headline = ('Operation'=>0, 'ReferencePath'=>1, 'Component'=>2, 'ControlProtocol'=>3, 'Comment'=>4, 'Register'=>5, 'Value'=>6, 'Misc'=>7);
my %str_headline = (0=>'Operation', 1=>'ReferencePath', 2=>'Component', 3=>'ControlProtocol', 4=>'Comment', 5=>'Register', 6=>'Value', 7=>'Misc');
my %row_type = ('Operation'=>0, 'Component'=>1, 'Comment'=>2, 'Register'=>3);
#open input excel
my $parser_excel = Spreadsheet::ParseExcel->new();
my $workbook = $parser_excel ->parse($inputFile);
die $parser_excel->error() unless defined $workbook;
#open parser for output xml
my $xml = "<MarvellAudioPathConfiguration/>";
my $parser_xml = new XML::DOM::Parser;
my $dom = $parser_xml->parse($xml);
die $parser_xml->error() unless defined $dom;
# Write <?xml version="1.0"?> and <MarvellAudioPathConfiguration> element
my $Decl = $dom->createXMLDecl("1.0");
$dom->setXMLDecl($Decl);
for my $worksheet ( $workbook->worksheets() ) {
if ($worksheet->get_name() eq 'PathToAliasList') {
my ( $row_min, $row_max ) = $worksheet->row_range();
for my $row ( $row_min+1 .. $row_max ) {
my $AudioPath = $dom->createElement("AudioPath");
my $path_name = $worksheet->get_cell($row, 1)->value;
$AudioPath->setAttribute("identifier", $path_name);
my $alias_name = $worksheet->get_cell($row, 0)->value;
$AudioPath->setAttribute("alias", $alias_name);
$dom->getDocumentElement->appendChild($AudioPath);
}
next;
}
# Generate AudioPath node.
my $AudioPath = $dom->createElement("AudioPath");
# The first row is the audio path name.
my $path_name = $worksheet->get_cell(0, 0)->value;
$AudioPath->setAttribute("identifier", $path_name);
my $Operation;
my $Component;
my $Comment;
my $Register;
my $str_Component_cur;
my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();
#ingore second row since it is the headline
for my $row ( $row_min+2 .. $row_max ) {
my $str_Operation = undef;
my $str_Refpath = undef;
my $str_Component = undef;
my $str_CtlProtocol = undef;
my $str_Comment = undef;
my $str_Register = undef;
my $str_Value = undef;
my $str_Misc = undef;
my $row_type = undef;
#parse each row
for my $col ( $col_min .. $col_max ) {
my $cell = $worksheet->get_cell( $row, $col );
next unless $cell;
if ($str_headline{$col} eq 'Operation'){
#Operation
$row_type = $row_type{'Operation'};
$str_Operation = $cell->value();
}elsif($str_headline{$col} eq 'ReferencePath'){
#ReferencePath
$str_Refpath = $cell->value();
}elsif($str_headline{$col} eq 'Component'){
#Component
$row_type = $row_type{'Component'};
$str_Component = $cell->value();
}elsif($str_headline{$col} eq 'ControlProtocol'){
#ControlProtocol
$str_CtlProtocol = $cell->value();
}elsif($str_headline{$col} eq 'Comment'){
#Comment
$row_type = $row_type{'Comment'};
$str_Comment = $cell->value();
}elsif($str_headline{$col} eq 'Register'){
#Register
$row_type = $row_type{'Register'};
$str_Register = $cell->value();
}elsif($str_headline{$col} eq 'Value'){
#Value
$str_Value = $cell->value();
}elsif($str_headline{$col} eq 'Misc'){
#Misc
$str_Misc = $cell->value();
}
}
if ($row_type == $row_type{'Operation'}){
$Operation->appendChild($Component) if defined $Component && defined $Operation; #append the last Component Node
$Component = undef;
$AudioPath->appendChild($Operation) if defined $Operation; #append the old Operation Node
$Operation = $dom->createElement('Operation'); #create new Operation node
$Operation->setAttribute("identifier", $str_Operation) if $str_Operation;
$Operation->setAttribute("ref_path_identifier", $str_Refpath) if $str_Refpath;
}elsif($row_type == $row_type{'Component'}){
$Operation->appendChild($Component) if defined $Component; #append the old Component Node
$Component = $dom->createElement('AudioComponent'); #create new Component node
$Component->setAttribute("identifier", $str_Component) if $str_Component;
$str_Component_cur = $str_Component;
$Component->setAttribute("control_protocol", $str_CtlProtocol) if $str_CtlProtocol;
}elsif($row_type == $row_type{'Comment'}){
$Comment = $dom->createComment($str_Comment); #create new Comment node
$Component->appendChild($Comment) if defined $Component; #append the old Comment Node
}elsif($row_type == $row_type{'Register'}){
if($str_Component_cur eq 'DELAY'){
$Register = $dom->createElement('Delay'); #create new Delay node
$Register->setAttribute("value", $str_Register) if defined $str_Register;
}elsif($str_Component_cur eq 'GPIO_PORT'){
$Register = $dom->createElement('GPIO'); #create new GPIO node
$Register->setAttribute("name", $str_Register) if defined $str_Register;
$Register->setAttribute("port", $str_Value) if defined $str_Value;
$Register->setAttribute("value", $str_Misc) if defined $str_Misc;
}else{
$Register = $dom->createElement('Register'); #create new Register node
$Register->setAttribute("field", $str_Register) if defined $str_Register;
$Register->setAttribute("value", $str_Value) if defined $str_Value;
$Register->setAttribute("misc", $str_Misc) if defined $str_Misc;
}
$Component->appendChild($Register); #append the old Register Node
}
$row_type = undef;
}
#append the last Component Node
$Operation->appendChild($Component) if defined $Component && defined $Operation;
#append the last Operation Node
$AudioPath->appendChild($Operation) if defined $Operation;
#append AudioPath
$dom->getDocumentElement->appendChild($AudioPath);
}
# end of parsing, flush to output file
open OUTPUT, ">$outputFile";
select OUTPUT;
my $twig = new XML::Twig;
$twig->set_indent(" "x4);
$twig->parse($dom->toString);
$twig->set_pretty_print("indented");
print $twig->sprint;
select STDOUT;
close OUTPUT