author | Maciej Seroka <maciejs@symbian.org> |
Mon, 23 Nov 2009 09:08:01 +0000 | |
changeset 787 | bfafbde70ba1 |
parent 588 | 1bdf644455fe |
child 814 | 11c237c9ad00 |
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 |
|
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 |
|
588
1bdf644455fe
Added support for being passed wildcards in an XML file argument.
Simon Howkins <simonh@symbian.org>
parents:
570
diff
changeset
|
41 |
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
|
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 |
|
588
1bdf644455fe
Added support for being passed wildcards in an XML file argument.
Simon Howkins <simonh@symbian.org>
parents:
570
diff
changeset
|
55 |
# Expand wildcards |
1bdf644455fe
Added support for being passed wildcards in an XML file argument.
Simon Howkins <simonh@symbian.org>
parents:
570
diff
changeset
|
56 |
@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
|
57 |
|
570
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
58 |
# 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
|
59 |
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
|
60 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
61 |
# 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
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
print "\n"; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
66 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
67 |
exit(0); |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
68 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
69 |
sub mergeMultipleTrees |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
70 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
71 |
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
|
72 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
73 |
# 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
|
74 |
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
|
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 $outTree; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
77 |
# 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
|
78 |
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
|
79 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
80 |
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
|
81 |
if (!$outTree) |
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 |
# 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
|
84 |
$outTree = $tree; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
85 |
} |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
86 |
else |
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 |
# 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
|
89 |
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
|
90 |
} |
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 |
return $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 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
96 |
sub mergeTwoTrees |
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 |
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
|
99 |
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
|
100 |
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
|
101 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
102 |
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
|
103 |
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
|
104 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
105 |
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
|
106 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
107 |
# 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
|
108 |
my $mergeIt; |
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 $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
|
111 |
$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
|
112 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
113 |
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
|
114 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
115 |
# 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
|
116 |
# 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
|
117 |
$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
|
118 |
} |
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 |
if ($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 |
# Merge children |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
123 |
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
|
124 |
} |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
125 |
else |
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 |
# 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
|
128 |
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
|
129 |
} |
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 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
133 |
sub matchTag |
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 |
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
|
136 |
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
|
137 |
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
|
138 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
139 |
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
|
140 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
141 |
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
|
142 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
143 |
return $peer; |
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 |
} |
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 |
return undef; |
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 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
150 |
sub printTree |
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 $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
|
153 |
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
|
154 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
155 |
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
|
156 |
$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
|
157 |
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
|
158 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
159 |
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
|
160 |
return; |
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 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
163 |
print "<$tagName"; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
164 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
165 |
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
|
166 |
sort |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
167 |
grep { |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
168 |
! ref $tree->{$_} |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
169 |
} |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
170 |
keys %$tree) |
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 |
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
|
173 |
} |
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 |
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
|
176 |
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
|
177 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
178 |
print ">"; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
179 |
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
|
180 |
{ |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
181 |
printTree($child); |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
182 |
} |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
183 |
print "</$tagName"; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
184 |
} |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
185 |
else |
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 |
print ">"; |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
191 |
} |
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
192 |
|
e5e6ae6bf38f
Script to merge multiple MXL files together, according to a merge specification string
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
193 |