common/tools/mergeXML.pl
author Simon Howkins <simonh@symbian.org>
Mon, 05 Oct 2009 13:40:29 +0100
changeset 581 46df4556c7d9
parent 570 e5e6ae6bf38f
child 588 1bdf644455fe
permissions -rw-r--r--
New XSL rules to generate a diamonds compatible BRAG status, which can be posted into the database.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
570
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     1
#!perl -w
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     2
# Copyright (c) 2009 Symbian Foundation Ltd
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     3
# This component and the accompanying materials are made available
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     4
# under the terms of the License "Eclipse Public License v1.0"
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     5
# which accompanies this distribution, and is available
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     7
#
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     8
# Initial Contributors:
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     9
# Symbian Foundation Ltd - initial contribution.
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    10
# 
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    11
# Contributors:
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    12
#
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    13
# Description:
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    14
# Merge a set of XML files
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    15
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    16
use strict;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    17
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    18
use XML::Parser;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    19
use Getopt::Long;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    20
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    21
# Read option arguments
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    22
my $howtoString;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    23
my $xslLink;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    24
my $help;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    25
GetOptions((
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    26
	'xsl=s' => \$xslLink,
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    27
	'merge=s' => \$howtoString,
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    28
	'help!' => \$help,
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    29
));
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    30
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    31
my $wrongArgs = 0;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    32
unless ($help)
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    33
{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    34
	$wrongArgs += warn "No merge string specified to indicate how the files should be merged\n" unless defined $howtoString;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    35
	$wrongArgs += warn "No files to be merged\n" unless scalar @ARGV;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    36
}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    37
if ($help || $wrongArgs)
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    38
{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    39
	print <<"EOT";
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    40
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    41
mergeXML.pl --xsl=brag.xsl --merge=SystemDefinition,systemModel,layer(name),block(name),package(name) sysModel1.xml [model2.xml ...] > output.xml
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    42
EOT
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    43
	exit(0 + !$help);
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    44
}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    45
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    46
# Hash of tags that should be merged, with optional attribute consideration
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    47
my $mergeTags;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    48
foreach my $term (split m{\s*,\s*}, $howtoString)
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    49
{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    50
	my ($tag, $attribute) = $term =~ m{(\w+)\((\w+)\)};
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    51
	$tag ||= $term;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    52
	$mergeTags->{$tag} = $attribute;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    53
}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    54
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    55
# Merge all the trees together
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    56
my $outTree = mergeMultipleTrees($mergeTags, @ARGV);
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    57
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    58
# Output total tree
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    59
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    60
print "<?xml-stylesheet type=\"text/xsl\" href=\"$xslLink\"?>\n" if $xslLink;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    61
printTree($outTree->[0]);
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    62
print "\n";
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    63
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    64
exit(0);
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    65
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    66
sub mergeMultipleTrees
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    67
{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    68
	my $mergeTags = shift or die;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    69
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    70
	# Create an XML parser
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    71
	my $parser = new XML::Parser(Style => "Objects") or die;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    72
	
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    73
	my $outTree;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    74
	# For each XML file to merge...
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    75
	foreach my $xmlFile (@_)
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    76
	{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    77
		my $tree = eval { $parser->parsefile($xmlFile) } or die "Failed to parse $xmlFile : $@";
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    78
		if (!$outTree)
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    79
		{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    80
			# The first file is taken verbatim
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    81
			$outTree = $tree;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    82
		}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    83
		else
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    84
		{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    85
			# Merge into output Tree
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    86
			mergeTwoTrees($outTree->[0], $tree->[0], $mergeTags);
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    87
		}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    88
	}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    89
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    90
	return $outTree;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    91
}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    92
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    93
sub mergeTwoTrees
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    94
{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    95
	my $baseTree = shift or die;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    96
	my $extrasTree = shift or die;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    97
	my $mergeTags = shift or die;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    98
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    99
	die ("Trees do not match: ".(ref $baseTree)." vs ".(ref $extrasTree)) unless ref $baseTree eq ref $extrasTree;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   100
	return if ref $baseTree eq "main::Characters";
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   101
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   102
	foreach my $extraChild (@{$extrasTree->{Kids}})
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   103
	{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   104
		# Work out whether this child should be merged with a namesake, or appended
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   105
		my $mergeIt;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   106
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   107
		my $extraChildTag = ref $extraChild;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   108
		$extraChildTag =~ s{^main::}{};
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   109
		
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   110
		if (exists $mergeTags->{$extraChildTag})
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   111
		{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   112
			# Should be merged if there's already one there
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   113
			# Look for a namesake in the base
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   114
			$mergeIt = matchTag($baseTree->{Kids}, $extraChild, $mergeTags->{$extraChildTag});
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   115
		}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   116
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   117
		if ($mergeIt)
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   118
		{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   119
			# Merge children
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   120
			mergeTwoTrees($mergeIt, $extraChild, $mergeTags);
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   121
		}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   122
		else
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   123
		{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   124
			# Add this child
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   125
			push @{$baseTree->{Kids}}, $extraChild;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   126
		}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   127
	}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   128
}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   129
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   130
sub matchTag
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   131
{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   132
	my $peers = shift;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   133
	my $outsider = shift;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   134
	my $attr = shift;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   135
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   136
	foreach my $peer (@$peers)
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   137
	{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   138
		if (ref $peer eq ref $outsider && (!defined $attr || $peer->{$attr} eq $outsider->{$attr}))
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   139
		{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   140
			return $peer;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   141
		}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   142
	}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   143
	
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   144
	return undef;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   145
}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   146
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   147
sub printTree
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   148
{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   149
	my $tree = shift or die;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   150
	die unless ref $tree;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   151
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   152
	my $tagName = ref $tree;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   153
	$tagName =~ s{^main::}{};
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   154
	if ($tagName eq "Characters")
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   155
	{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   156
		print $tree->{Text};
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   157
		return;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   158
	}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   159
	
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   160
	print "<$tagName";
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   161
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   162
	foreach my $attr (
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   163
		sort
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   164
		grep {
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   165
			! ref $tree->{$_}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   166
		}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   167
		keys %$tree)
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   168
	{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   169
		print " $attr=\"$tree->{$attr}\"";
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   170
	}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   171
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   172
	my $children = $tree->{Kids};
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   173
	if (scalar @$children)
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   174
	{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   175
		print ">";
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   176
		foreach my $child (@$children)
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   177
		{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   178
			printTree($child);
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   179
		}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   180
		print "</$tagName";
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   181
	}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   182
	else
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   183
	{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   184
		print "/"
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   185
	}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   186
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   187
	print ">";
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   188
}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   189
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   190