common/tools/mergeXML.pl
author Simon Howkins <simonh@symbian.org>
Wed, 27 Oct 2010 16:22:14 +0100
changeset 1316 0b4a09013baf
parent 1304 26a71d6a561e
permissions -rw-r--r--
Added copyright messages
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
814
11c237c9ad00 Changed mergeXML.pl to use a better version of the XML printing algorithm, so it can generate well-formed content if the input includes some rogue &s or <>s.
Simon Howkins <simonh@symbian.org>
parents: 588
diff changeset
    21
use FindBin;
11c237c9ad00 Changed mergeXML.pl to use a better version of the XML printing algorithm, so it can generate well-formed content if the input includes some rogue &s or <>s.
Simon Howkins <simonh@symbian.org>
parents: 588
diff changeset
    22
use lib "$FindBin::Bin/lib";
11c237c9ad00 Changed mergeXML.pl to use a better version of the XML printing algorithm, so it can generate well-formed content if the input includes some rogue &s or <>s.
Simon Howkins <simonh@symbian.org>
parents: 588
diff changeset
    23
11c237c9ad00 Changed mergeXML.pl to use a better version of the XML printing algorithm, so it can generate well-formed content if the input includes some rogue &s or <>s.
Simon Howkins <simonh@symbian.org>
parents: 588
diff changeset
    24
use XML::Printer;
11c237c9ad00 Changed mergeXML.pl to use a better version of the XML printing algorithm, so it can generate well-formed content if the input includes some rogue &s or <>s.
Simon Howkins <simonh@symbian.org>
parents: 588
diff changeset
    25
570
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    26
# 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
    27
my $howtoString;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    28
my $xslLink;
1304
26a71d6a561e Fixed merging of BRAG elements so that the collated results should appear in time order, and hence in phase/step order as well.
Simon Howkins <simonh@symbian.org>
parents: 814
diff changeset
    29
my $sortByTime;
570
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    30
my $help;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    31
GetOptions((
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    32
	'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
    33
	'merge=s' => \$howtoString,
1304
26a71d6a561e Fixed merging of BRAG elements so that the collated results should appear in time order, and hence in phase/step order as well.
Simon Howkins <simonh@symbian.org>
parents: 814
diff changeset
    34
	'sortByTime!' => \$sortByTime,
570
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    35
	'help!' => \$help,
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
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    38
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
    39
unless ($help)
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
	$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
    42
	$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
    43
}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    44
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
    45
{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    46
	print <<"EOT";
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    47
588
1bdf644455fe Added support for being passed wildcards in an XML file argument.
Simon Howkins <simonh@symbian.org>
parents: 570
diff changeset
    48
mergeXML.pl --xsl=brag.xsl --merge=SystemDefinition,systemModel,layer(name),block(name),package(name) sysModel1.xml [model*.xml ...] > output.xml
570
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    49
EOT
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    50
	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
    51
}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    52
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    53
# 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
    54
my $mergeTags;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    55
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
    56
{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    57
	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
    58
	$tag ||= $term;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    59
	$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
    60
}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    61
588
1bdf644455fe Added support for being passed wildcards in an XML file argument.
Simon Howkins <simonh@symbian.org>
parents: 570
diff changeset
    62
# Expand wildcards
1bdf644455fe Added support for being passed wildcards in an XML file argument.
Simon Howkins <simonh@symbian.org>
parents: 570
diff changeset
    63
@ARGV = map { glob $_ } @ARGV;
1304
26a71d6a561e Fixed merging of BRAG elements so that the collated results should appear in time order, and hence in phase/step order as well.
Simon Howkins <simonh@symbian.org>
parents: 814
diff changeset
    64
if ($sortByTime)
26a71d6a561e Fixed merging of BRAG elements so that the collated results should appear in time order, and hence in phase/step order as well.
Simon Howkins <simonh@symbian.org>
parents: 814
diff changeset
    65
{
26a71d6a561e Fixed merging of BRAG elements so that the collated results should appear in time order, and hence in phase/step order as well.
Simon Howkins <simonh@symbian.org>
parents: 814
diff changeset
    66
	# Sort by creation time (this helps the BRAG merging put the phases & steps in the right build sequence)
26a71d6a561e Fixed merging of BRAG elements so that the collated results should appear in time order, and hence in phase/step order as well.
Simon Howkins <simonh@symbian.org>
parents: 814
diff changeset
    67
	@ARGV = sort { (stat($a))[10] <=> (stat($b))[10] } @ARGV;
26a71d6a561e Fixed merging of BRAG elements so that the collated results should appear in time order, and hence in phase/step order as well.
Simon Howkins <simonh@symbian.org>
parents: 814
diff changeset
    68
}
588
1bdf644455fe Added support for being passed wildcards in an XML file argument.
Simon Howkins <simonh@symbian.org>
parents: 570
diff changeset
    69
570
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    70
# 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
    71
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
    72
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    73
# 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
    74
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
    75
print "<?xml-stylesheet type=\"text/xsl\" href=\"$xslLink\"?>\n" if $xslLink;
814
11c237c9ad00 Changed mergeXML.pl to use a better version of the XML printing algorithm, so it can generate well-formed content if the input includes some rogue &s or <>s.
Simon Howkins <simonh@symbian.org>
parents: 588
diff changeset
    76
XML::Printer::printTree($outTree->[0]);
570
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    77
print "\n";
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    78
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    79
exit(0);
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    80
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    81
sub mergeMultipleTrees
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
	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
    84
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    85
	# 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
    86
	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
    87
	
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    88
	my $outTree;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    89
	# 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
    90
	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
    91
	{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    92
		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
    93
		if (!$outTree)
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
			# 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
    96
			$outTree = $tree;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    97
		}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    98
		else
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    99
		{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   100
			# 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
   101
			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
   102
		}
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
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   105
	return $outTree;
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
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   108
sub mergeTwoTrees
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
	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
   111
	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
   112
	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
   113
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   114
	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
   115
	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
   116
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   117
	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
   118
	{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   119
		# 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
   120
		my $mergeIt;
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
		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
   123
		$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
   124
		
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   125
		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
   126
		{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   127
			# 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
   128
			# 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
   129
			$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
   130
		}
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
		if ($mergeIt)
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   133
		{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   134
			# Merge children
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   135
			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
   136
		}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   137
		else
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   138
		{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   139
			# 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
   140
			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
   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
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   145
sub matchTag
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
	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
   148
	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
   149
	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
   150
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   151
	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
   152
	{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   153
		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
   154
		{
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   155
			return $peer;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   156
		}
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   157
	}
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
	return undef;
e5e6ae6bf38f Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
   160
}
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