author | Brendan Donegan <brendand@symbian.org> |
Wed, 14 Apr 2010 14:11:02 +0100 | |
changeset 969 | 6cf4537e2fb5 |
parent 814 | 11c237c9ad00 |
child 1304 | 26a71d6a561e |
permissions | -rw-r--r-- |
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; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
29 |
my $help; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
30 |
GetOptions(( |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
31 |
'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
|
32 |
'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
|
33 |
'help!' => \$help, |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
34 |
)); |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
35 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
36 |
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
|
37 |
unless ($help) |
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 |
$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
|
40 |
$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
|
41 |
} |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
42 |
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
|
43 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
44 |
print <<"EOT"; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
45 |
|
588
1bdf644455fe
Added support for being passed wildcards in an XML file argument.
Simon Howkins <simonh@symbian.org>
parents:
570
diff
changeset
|
46 |
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
|
47 |
EOT |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
48 |
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
|
49 |
} |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
50 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
51 |
# 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
|
52 |
my $mergeTags; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
53 |
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
|
54 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
55 |
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
|
56 |
$tag ||= $term; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
57 |
$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
|
58 |
} |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
59 |
|
588
1bdf644455fe
Added support for being passed wildcards in an XML file argument.
Simon Howkins <simonh@symbian.org>
parents:
570
diff
changeset
|
60 |
# Expand wildcards |
1bdf644455fe
Added support for being passed wildcards in an XML file argument.
Simon Howkins <simonh@symbian.org>
parents:
570
diff
changeset
|
61 |
@ARGV = map { glob $_ } @ARGV; |
1bdf644455fe
Added support for being passed wildcards in an XML file argument.
Simon Howkins <simonh@symbian.org>
parents:
570
diff
changeset
|
62 |
|
570
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
63 |
# 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
|
64 |
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
|
65 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
66 |
# 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
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
print "\n"; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
71 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
72 |
exit(0); |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
73 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
74 |
sub mergeMultipleTrees |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
75 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
76 |
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
|
77 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
78 |
# 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
|
79 |
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
|
80 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
81 |
my $outTree; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
82 |
# 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
|
83 |
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
|
84 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
85 |
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
|
86 |
if (!$outTree) |
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 |
# 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
|
89 |
$outTree = $tree; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
90 |
} |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
91 |
else |
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 |
# 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
|
94 |
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
|
95 |
} |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
96 |
} |
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 |
return $outTree; |
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 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
101 |
sub mergeTwoTrees |
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 |
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
|
104 |
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
|
105 |
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
|
106 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
107 |
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
|
108 |
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
|
109 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
110 |
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
|
111 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
112 |
# 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
|
113 |
my $mergeIt; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
114 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
115 |
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
|
116 |
$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
|
117 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
118 |
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
|
119 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
120 |
# 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
|
121 |
# 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
|
122 |
$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
|
123 |
} |
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 ($mergeIt) |
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 |
# Merge children |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
128 |
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
|
129 |
} |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
130 |
else |
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 |
# 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
|
133 |
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
|
134 |
} |
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 |
} |
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 |
sub matchTag |
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 |
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
|
141 |
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
|
142 |
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
|
143 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
144 |
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
|
145 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
146 |
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
|
147 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
148 |
return $peer; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
149 |
} |
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 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
152 |
return undef; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
153 |
} |
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 |