602
|
1 |
#! /bin/perl
|
|
2 |
# Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
# readmrp - API to parse mrp files (but do no further processing)
|
|
16 |
#
|
|
17 |
#
|
|
18 |
|
|
19 |
package ReadMrp;
|
|
20 |
|
|
21 |
sub New($)
|
|
22 |
{
|
|
23 |
my $proto = shift;
|
|
24 |
my $class = ref($proto) || $proto;
|
|
25 |
my $self = {};
|
|
26 |
bless $self, $class;
|
|
27 |
|
|
28 |
my ($fileName) = @_;
|
|
29 |
$self->{filename} = $fileName;
|
|
30 |
$self->Read();
|
|
31 |
|
|
32 |
return $self;
|
|
33 |
}
|
|
34 |
|
|
35 |
sub Read()
|
|
36 |
{
|
|
37 |
my $self = shift;
|
|
38 |
my $fileName = $self->{filename};
|
|
39 |
|
|
40 |
die "ERROR: MRP file '$fileName' does not exist\n" unless (-e $fileName);
|
|
41 |
|
|
42 |
my $srcitems = [];
|
|
43 |
my $binexpitems = [];
|
|
44 |
my $component;
|
|
45 |
my $notes;
|
|
46 |
|
|
47 |
open MRP, "$fileName" or die "ERROR: Couldn't open '$fileName' for reading: $!\n";
|
|
48 |
|
|
49 |
while (my $line = <MRP>)
|
|
50 |
{
|
|
51 |
chomp $line;
|
|
52 |
|
|
53 |
$line =~ s/(?<!\\)#.*$//; # remove comments
|
|
54 |
$line =~ s/^\s+//;
|
|
55 |
next if (!$line); # blank lines
|
|
56 |
|
|
57 |
my @operands;
|
|
58 |
|
|
59 |
my $string = $line;
|
|
60 |
while ($string)
|
|
61 |
{
|
|
62 |
if ($string =~ s/^\"(.*?)\"// # Match and remove next quoted string
|
|
63 |
or $string =~ s/^(.*?)\s+// # or, match and remove next (but not last) unquoted string
|
|
64 |
or $string =~ s/^(.*)\s*$//) # or, match and remove last unquoted string.
|
|
65 |
{
|
|
66 |
push (@operands, $1);
|
|
67 |
$string =~ s/^\s+//; # Remove delimiter if present.
|
|
68 |
}
|
|
69 |
}
|
|
70 |
|
|
71 |
my $keyword = shift @operands;
|
|
72 |
|
|
73 |
my $minus = ($keyword =~ s/^-//);
|
|
74 |
|
|
75 |
if ($keyword eq "component")
|
|
76 |
{
|
|
77 |
die "-component is not a valid command in file '$fileName'\n" if $minus;
|
|
78 |
$component = shift @operands;
|
|
79 |
}
|
|
80 |
elsif ($keyword eq "notes_source")
|
|
81 |
{
|
|
82 |
die "-notes_source is not a valid command in file '$fileName'\n" if $minus;
|
|
83 |
$notes = shift @operands
|
|
84 |
# N.B. This may require source mapping, so we don't check for existence here
|
|
85 |
}
|
|
86 |
elsif ($keyword eq "source")
|
|
87 |
{
|
|
88 |
die "-source is not supported by this parser yet in file '$fileName'\n" if $minus;
|
|
89 |
my $srcItem = join ' ', @operands;
|
|
90 |
push @$srcitems, $srcItem;
|
|
91 |
}
|
|
92 |
elsif ($keyword eq "binary")
|
|
93 |
{
|
|
94 |
if (scalar @operands == 1)
|
|
95 |
{
|
|
96 |
push @$binexpitems, shift @operands;
|
|
97 |
}
|
|
98 |
else
|
|
99 |
{
|
|
100 |
# This release doesn't handle bld.inf binary lines; no parsing here
|
|
101 |
}
|
|
102 |
}
|
|
103 |
elsif ($keyword eq "testbinary")
|
|
104 |
{
|
|
105 |
if (scalar @operands == 1)
|
|
106 |
{
|
|
107 |
push @$binexpitems, shift @operands;
|
|
108 |
}
|
|
109 |
else
|
|
110 |
{
|
|
111 |
# This release doesn't handle bld.inf binary lines; no parsing here
|
|
112 |
}
|
|
113 |
}
|
|
114 |
elsif ($keyword eq "exports")
|
|
115 |
{
|
|
116 |
# This release doesn't handle bld.inf exports lines; no parsing here
|
|
117 |
}
|
|
118 |
elsif ($keyword eq "testexports")
|
|
119 |
{
|
|
120 |
# This release doesn't handle bld.inf exports lines; no parsing here
|
|
121 |
}
|
|
122 |
elsif ($keyword eq "export_file")
|
|
123 |
{
|
|
124 |
push @$binexpitems, $operands[1];
|
|
125 |
}
|
|
126 |
elsif ($keyword eq "ipr")
|
|
127 |
{
|
|
128 |
# This release doesn't handle ipr lines; no parsing here
|
|
129 |
}
|
|
130 |
else
|
|
131 |
{
|
|
132 |
die "ERROR: In file '$fileName', command not understood in line: $line\n";
|
|
133 |
}
|
|
134 |
}
|
|
135 |
die "ERROR: Component not specified in file '$fileName'\n" unless defined($component);
|
|
136 |
die "ERROR: Notes_source not specified in file '$fileName'\n" unless defined($notes);
|
|
137 |
$self->{srcitems} = $srcitems;
|
|
138 |
$self->{component} = $component;
|
|
139 |
$self->{binexpitems} = $binexpitems;
|
|
140 |
$self->{notes} = $notes;
|
|
141 |
}
|
|
142 |
|
|
143 |
sub GetComponent()
|
|
144 |
{
|
|
145 |
my $self = shift;
|
|
146 |
return $self->{component};
|
|
147 |
}
|
|
148 |
|
|
149 |
sub GetSrcItems()
|
|
150 |
{
|
|
151 |
my $self = shift;
|
|
152 |
return $self->{srcitems};
|
|
153 |
}
|
|
154 |
|
|
155 |
sub GetBinExpItems()
|
|
156 |
{
|
|
157 |
my $self = shift;
|
|
158 |
return $self->{binexpitems};
|
|
159 |
}
|
|
160 |
|
|
161 |
sub GetNotes()
|
|
162 |
{
|
|
163 |
my $self = shift;
|
|
164 |
return $self->{notes};
|
|
165 |
}
|
|
166 |
|
|
167 |
sub _SplitOnSpaces($)
|
|
168 |
{
|
|
169 |
my $self = shift;
|
|
170 |
my ($operands) = (@_);
|
|
171 |
|
|
172 |
# Break down operands
|
|
173 |
my @operands = ();
|
|
174 |
my $operand = "";
|
|
175 |
my $first;
|
|
176 |
while ($operands =~ /\S/)
|
|
177 |
{
|
|
178 |
$operands =~ /^(\s*\S+)(\s+.*)?$/ or die "Semantic error (broken regexp)";
|
|
179 |
|
|
180 |
($first, $operands) = ($1, $2);
|
|
181 |
$operand .= $first;
|
|
182 |
|
|
183 |
$operand =~ s/^\s*//; # Remove preceding whitespace
|
|
184 |
|
|
185 |
if (substr($operand,0,1) ne '"')
|
|
186 |
{
|
|
187 |
# Not quoted
|
|
188 |
push @operands, $operand;
|
|
189 |
$operand = "";
|
|
190 |
}
|
|
191 |
else
|
|
192 |
{
|
|
193 |
# Quoted
|
|
194 |
if (substr($operand,scalar($operand-1),1) eq '"')
|
|
195 |
{
|
|
196 |
# Complete quoted operand
|
|
197 |
$operand = substr ($operand, 1, scalar($operand-1));
|
|
198 |
push @operands, $operand;
|
|
199 |
$operand = "";
|
|
200 |
}
|
|
201 |
# Else leave the operand to have the next word added
|
|
202 |
}
|
|
203 |
}
|
|
204 |
|
|
205 |
if ($operand ne "")
|
|
206 |
{
|
|
207 |
die "ERROR: Missing end quote from '$operand'\n";
|
|
208 |
}
|
|
209 |
|
|
210 |
return @operands;
|
|
211 |
}
|
|
212 |
1;
|
|
213 |
|
|
214 |
__END__
|
|
215 |
|
|
216 |
=pod
|
|
217 |
|
|
218 |
=head1 NAME
|
|
219 |
|
|
220 |
readmrp - Simple parser for MRP fils
|
|
221 |
|
|
222 |
=head1 SYNOPSIS
|
|
223 |
|
|
224 |
use readmrp;
|
|
225 |
|
|
226 |
my $mrpFile = '\someFolder\anMrpFile.mrp';
|
|
227 |
|
|
228 |
# Create an instance of a readmrp object
|
|
229 |
my $mrp = new readmrp($mrpFile);
|
|
230 |
|
|
231 |
# Get data out
|
|
232 |
my $name = $mrp->GetComponent();
|
|
233 |
my @srcitems = @{$mrp->GetSrcItems()};
|
|
234 |
my @binexpitems = @{$mrp->GetBinExpItems()};
|
|
235 |
my $notessrc = $mrp->GetNotes();
|
|
236 |
|
|
237 |
=head1 DESCRIPTION
|
|
238 |
|
|
239 |
This module is used to parse MRP files and to store the basic data. It does not do any further processing of the data, and so it deliberately does not depend on the referenced files being present. It records source statements, as well as simple binary statements and the target of export_file statements. It ignores exports and complex binary statements, which refer to a group directory and would require further processing to determine their targets.
|
|
240 |
|
|
241 |
=head1 METHODS
|
|
242 |
|
|
243 |
=head2 New (mrpFile)
|
|
244 |
|
|
245 |
Constructor. Takes an MRP filename, and immediately parses it. Dies if there is a syntax error in the MRP file.
|
|
246 |
|
|
247 |
=head2 GetComponent ()
|
|
248 |
|
|
249 |
Returns the parsed component name.
|
|
250 |
|
|
251 |
=head2 GetSrcItems ()
|
|
252 |
|
|
253 |
Returns an array ref of the source paths of the 'source' statements in the MRP file.
|
|
254 |
|
|
255 |
=head2 GetBinExpItems ()
|
|
256 |
|
|
257 |
Returns an array ref of the target paths of the simple 'binary' and 'export_file' statements in the MRP file. It does not distringuish between binary files and exports.
|
|
258 |
|
|
259 |
=head2 GetNotes ()
|
|
260 |
|
|
261 |
Returns the path of the 'notes_source' file.
|
|
262 |
|
|
263 |
=head1 COPYRIGHT
|
|
264 |
|
|
265 |
Copyright (c) 2004-2007 Symbian Software Ltd. All Rights Reserved.
|
|
266 |
|
|
267 |
=cut
|