|
1 # |
|
2 # Copyright (c) 1997-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 "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 # |
|
16 |
|
17 use strict; |
|
18 use integer; |
|
19 |
|
20 package PARSER; |
|
21 require Exporter; |
|
22 @PARSER::ISA=qw(Exporter); |
|
23 @PARSER::EXPORT=qw(nextNonEmptyStrippedDownLine ungetNonEmptyStrippedDownLine); |
|
24 |
|
25 # @PARSER::nextNonEmptyStrippedDownLine is a global variable in this package |
|
26 |
|
27 sub strippedDownLine |
|
28 { |
|
29 my $strippedDownLine=shift; |
|
30 $strippedDownLine=~s/#.*$//; |
|
31 $strippedDownLine=~s/^\s+//; |
|
32 $strippedDownLine=~s/\s+$//; |
|
33 return $strippedDownLine; |
|
34 } |
|
35 |
|
36 sub nextNonEmptyStrippedDownLine |
|
37 { |
|
38 my $fileHandle=shift; |
|
39 if (defined(@PARSER::nextNonEmptyStrippedDownLine) && (@PARSER::nextNonEmptyStrippedDownLine>0)) |
|
40 { |
|
41 if (@{$PARSER::nextNonEmptyStrippedDownLine[0]}!=2) |
|
42 { |
|
43 close($fileHandle); |
|
44 die("Error: internal error in \"PARSER.PM\"\n"); |
|
45 } |
|
46 return @{shift(@PARSER::nextNonEmptyStrippedDownLine)}; |
|
47 } |
|
48 my $buffer=''; |
|
49 my $line; |
|
50 while ($line=<$fileHandle>) |
|
51 { |
|
52 $buffer.=$line; |
|
53 my $strippedDownBuffer=&strippedDownLine($buffer); |
|
54 if ($strippedDownBuffer!~/\\$/) |
|
55 { |
|
56 $strippedDownBuffer=~s/\\\n/ /g; |
|
57 if ($strippedDownBuffer ne '') |
|
58 { |
|
59 return ($buffer, $strippedDownBuffer); |
|
60 } |
|
61 $buffer=''; |
|
62 } |
|
63 } |
|
64 if ($buffer ne '') |
|
65 { |
|
66 close($fileHandle); |
|
67 die("Error: file ends with a \"\\\"\n"); |
|
68 } |
|
69 return ('', ''); |
|
70 } |
|
71 |
|
72 sub ungetNonEmptyStrippedDownLine |
|
73 { |
|
74 my $arrayCopy; |
|
75 @$arrayCopy=@_; |
|
76 unshift(@PARSER::nextNonEmptyStrippedDownLine, $arrayCopy); |
|
77 } |
|
78 |