|
1 # Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # Script to renumber the XML command file |
|
15 # |
|
16 # |
|
17 |
|
18 use strict; |
|
19 use Getopt::Long; |
|
20 use File::Copy; |
|
21 |
|
22 # Process the commandline |
|
23 my ($iDataSource) = ProcessCommandLine(); |
|
24 |
|
25 &Renumber($iDataSource); |
|
26 |
|
27 |
|
28 # ProcessCommandLine |
|
29 # |
|
30 # Inputs |
|
31 # |
|
32 # Outputs |
|
33 # $iDataSource (XML file to process) |
|
34 # |
|
35 # Description |
|
36 # This function processes the commandline |
|
37 |
|
38 sub ProcessCommandLine { |
|
39 my ($iHelp, $iPort, $iDataSource, $iLogFile); |
|
40 GetOptions('h' => \$iHelp, 'd=s' =>\$iDataSource ); |
|
41 |
|
42 if (($iHelp) || (!defined $iDataSource)) |
|
43 { |
|
44 Usage(); |
|
45 } elsif (! -e $iDataSource) { |
|
46 die "Cannot open $iDataSource"; |
|
47 } else { |
|
48 return($iDataSource); |
|
49 } |
|
50 } |
|
51 |
|
52 # Usage |
|
53 # |
|
54 # Description |
|
55 # Output Usage Information. |
|
56 # |
|
57 |
|
58 sub Usage { |
|
59 print <<USAGE_EOF; |
|
60 |
|
61 Usage: Renumber.pl [options] |
|
62 |
|
63 options: |
|
64 |
|
65 -h help |
|
66 -d Data Source (xml file) |
|
67 USAGE_EOF |
|
68 exit 1; |
|
69 } |
|
70 |
|
71 # Renumber |
|
72 # |
|
73 # Inputs |
|
74 # $iDataSource (XML file to process) |
|
75 # |
|
76 # Outputs |
|
77 # A renumber XML File |
|
78 # |
|
79 # Description |
|
80 # Renumber the XML file. |
|
81 sub Renumber |
|
82 { |
|
83 my ($iDataSource) = @_; |
|
84 |
|
85 my ($iLine, $iNum, $iOrder); |
|
86 $iNum = 1; |
|
87 $iOrder = 1; |
|
88 move($iDataSource,$iDataSource.".bak"); |
|
89 |
|
90 open XML, "<$iDataSource.bak" or die "Can't read $iDataSource.bak"; |
|
91 open XMLOUT, ">$iDataSource" or die "Can't read $iDataSource"; |
|
92 |
|
93 while ($iLine=<XML>) |
|
94 { |
|
95 if ($iLine =~ /ID=\"\d+\"/) |
|
96 { |
|
97 $iLine =~ s/ID="\d+"\s+Stage="\d+"/ID="$iNum" Stage="$iNum"/; |
|
98 $iNum++; |
|
99 } |
|
100 elsif ($iLine =~ /Order="\d+"/) |
|
101 { |
|
102 $iLine =~ s/Order="\d+"/Order="$iOrder"/; |
|
103 $iOrder++; |
|
104 } |
|
105 print XMLOUT $iLine; |
|
106 |
|
107 } |
|
108 |
|
109 close XML; |
|
110 } |