blob: 5a42c8874e49aced52ac05dab42ef46e9be203d4 [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::WriteExcel;
use XML::Parser;
my ($inputFile, $outputFile) = @ARGV;
my $file_type = substr($inputFile, -4, 4);
die "Input file type error $inputFile" unless $file_type eq ".xml";
die "Cen't open $inputFile" unless -r $inputFile;
my $workbook;
my $worksheet;
# Define columns
my %headline = ('Operation'=>0, 'ReferencePath'=>1, 'Component'=>2, 'ControlProtocol'=>3, 'Comment'=>4, 'Register'=>5, 'Value'=>6, 'misc'=>7);
my $row_num;
# Define Format
my $fmt_head;
my $fmt_op;
my $fmt_com;
my $fmt_path;
my @alias_list;
my $parse = new XML::Parser();
$parse->setHandlers(Start=>\&handler_start, End=>\&handler_end, Comment=>\&handler_comment,);
$parse->parsefile($inputFile);
sub handler_start
{
my($parser,$element,%attr)=@_;
my $attr;
my $value;
if (!defined $element){
print "element is not defined.\n";
}elsif($element eq 'MarvellAudioPathConfiguration'){
# Create a new Excel workbook
$workbook = Spreadsheet::WriteExcel->new($outputFile);
# Create font formats
$fmt_head = $workbook->add_format(); # headline
$fmt_head->set_bold();
$fmt_head->set_color('black');
$fmt_head->set_align('center');
$fmt_op = $workbook->add_format(); # operation
$fmt_op->set_bold();
$fmt_op->set_color('blue');
$fmt_op->set_align('center');
$fmt_com = $workbook->add_format(); # component
$fmt_com->set_bold();
$fmt_com->set_color('green');
$fmt_com->set_align('center');
$fmt_path = $workbook->add_format(); # component
$fmt_path->set_bold();
$fmt_path->set_color('red');
$fmt_path->set_align('center');
}elsif($element eq 'AudioPath'){
# Add a new worksheet
my $name;
my $col_num;
my $alias_name;
if (defined $attr{'alias'}){
push(@alias_list, join ':',$attr{'alias'},$attr{'identifier'});
}else{
# The WriteExcel component has a limitation that the worksheet name length
# should be less than 30, we need shrink the AudioPath name to 30 bytes,
# and just write the whole audio path name to the head of each excel worksheet.
my $path_name_trunk = substr($attr{'identifier'}, 0, 30);
$worksheet = $workbook->add_worksheet($path_name_trunk);
# Write audio path to head of each worksheet
# Write a headline
$worksheet->write(0, 0, $attr{'identifier'}, $fmt_path);
while (($name,$col_num) = each %headline){
$worksheet->write(1, $col_num, $name, $fmt_head);
}
}
$row_num = 1;
}elsif($element eq 'Operation'){
my $operation = $attr{'identifier'};
my $ref_path = $attr{'ref_path_identifier'};
# Write Operation = 'enable' or 'disable'
$worksheet->write(++$row_num, $headline{'Operation'}, $operation, $fmt_op);
# Write Reference path
$worksheet->write($row_num, $headline{'ReferencePath'}, $ref_path, $fmt_op);
}elsif($element eq 'AudioComponent'){
my $Componet = $attr{'identifier'};
my $ControlProtocol = $attr{'control_protocol'};
# Write Component name
$worksheet->write(++$row_num, $headline{'Component'}, $Componet, $fmt_com);
# Write ControlProtocol
$worksheet->write($row_num, $headline{'ControlProtocol'}, $ControlProtocol, $fmt_com);
}elsif($element eq 'Register'){
my $field = $attr{'field'};
my $value = $attr{'value'};
my $misc = $attr{'misc'};
# Write Register name
$worksheet->write(++$row_num, $headline{'Register'}, $field);
# Write value
$worksheet->write($row_num, $headline{'Value'}, $value);
$worksheet->write($row_num, $headline{'misc'}, $misc) if defined $misc;
}elsif($element eq 'Delay'){
my $value = $attr{'value'};
# Write value
$worksheet->write(++$row_num, $headline{'Register'}, $value);
}elsif($element eq 'GPIO'){
my $name = $attr{'name'};
my $port = $attr{'port'};
my $value = $attr{'value'};
$worksheet->write(++$row_num, $headline{'Register'}, $name);
$worksheet->write($row_num, $headline{'Value'}, $port);
$worksheet->write($row_num, $headline{'misc'}, $value);
}
}
sub handler_end
{
my($parser,$element)=@_;
if (!defined $element){
print "element is not defined.\n";
}elsif($element eq 'MarvellAudioPathConfiguration'){
# Create a new Excel workbook
my $row_num = 0;
my $worksheet = $workbook->add_worksheet('PathToAliasList');
$worksheet->write($row_num, 0, 'alias_name', $fmt_head);
$worksheet->write($row_num, 1, 'path_name', $fmt_head);
++$row_num;
foreach my $alias_line (@alias_list){
my ($alias_name, $path_name) = split /:/, $alias_line;
$worksheet->write($row_num, 0, $alias_name, $fmt_path);
$worksheet->write($row_num, 1, $path_name, $fmt_com);
++$row_num;
}
$workbook->close();
}
}
sub handler_comment
{
my($parser,$data)=@_;
# Write Comment
my $format = $workbook->add_format(); # Add a format
$format->set_bold();
$format->set_color('red');
$format->set_align('center');
$worksheet->write(++$row_num, $headline{'Comment'}, $data, $format);
}