equal
deleted
inserted
replaced
|
1 # Copyright (c) 2009 Symbian Foundation Ltd |
|
2 # This component and the accompanying materials are made available |
|
3 # under the terms of the License "Eclipse Public License v1.0" |
|
4 # which accompanies this distribution, and is available |
|
5 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
6 # |
|
7 # Initial Contributors: |
|
8 # Symbian Foundation Ltd - initial contribution. |
|
9 # |
|
10 # Contributors: |
|
11 # |
|
12 # Description: |
|
13 # Preprocess a raptor log, trying to countermeasure a list of known anomalies |
|
14 |
|
15 use strict; |
|
16 |
|
17 use Getopt::Long; |
|
18 |
|
19 my $infile = ''; |
|
20 my $outfile = ''; |
|
21 my $basedir = ''; |
|
22 my $help = 0; |
|
23 GetOptions(( |
|
24 'in:s' => \$infile, |
|
25 'out:s' => \$outfile, |
|
26 'help!' => \$help |
|
27 )); |
|
28 |
|
29 $help = 1 if (!$infile); |
|
30 |
|
31 if ($help) |
|
32 { |
|
33 print "Preprocess a raptor log, trying to countermeasure a list of known anomalies\n"; |
|
34 print "Usage: perl preprocess_log.pl --in=INFILE --out=OUTFILE\n"; |
|
35 exit(0); |
|
36 } |
|
37 |
|
38 open(INFILE, $infile); |
|
39 open(OUTFILE, ">$outfile"); |
|
40 |
|
41 for my $line (<INFILE>) |
|
42 { |
|
43 if ($line =~ m,<[^<^>]+>.*&.*</[^<^>]+>,) |
|
44 { |
|
45 $line = escape_ampersand($line); |
|
46 } |
|
47 elsif ($line =~ m,<\?xml\s.*encoding=.*\".*\?>,) |
|
48 { |
|
49 $line = set_encoding_utf8($line); |
|
50 } |
|
51 |
|
52 print OUTFILE $line; |
|
53 } |
|
54 |
|
55 close(OUTFILE); |
|
56 close(INFILE); |
|
57 |
|
58 |
|
59 sub escape_ampersand |
|
60 { |
|
61 my ($line) = @_; |
|
62 |
|
63 print "escape_ampersand\n"; |
|
64 print "in: $line"; |
|
65 |
|
66 $line =~ s,&,&,g; |
|
67 |
|
68 print "out: $line"; |
|
69 return $line; |
|
70 } |
|
71 |
|
72 sub set_encoding_utf8 |
|
73 { |
|
74 my ($line) = @_; |
|
75 |
|
76 print "set_encoding_utf8\n"; |
|
77 print "in: $line"; |
|
78 |
|
79 $line =~ s,encoding=".*",encoding="utf-8",; |
|
80 |
|
81 print "out: $line"; |
|
82 return $line; |
|
83 } |