common/tools/raptor/preprocess_log.pl
changeset 923 5ccf9d5ab663
parent 922 996297fad800
parent 907 bab81256b297
child 924 a5ed0e6ca679
equal deleted inserted replaced
922:996297fad800 923:5ccf9d5ab663
     1 #!perl -w
       
     2 # Copyright (c) 2009 Symbian Foundation Ltd
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of the License "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 # Symbian Foundation Ltd - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # Preprocess a raptor log, trying to countermeasure a list of known anomalies
       
    15 
       
    16 use strict;
       
    17 
       
    18 use Getopt::Long;
       
    19 
       
    20 my $help = 0;
       
    21 GetOptions(
       
    22 	'help!' => \$help,
       
    23 );
       
    24 
       
    25 if ($help)
       
    26 {
       
    27 	warn <<"EOF";
       
    28 Preprocess a raptor log, trying to countermeasure a list of known anomalies
       
    29 
       
    30 Usage: perl preprocess_log.pl < INFILE > OUTFILE
       
    31 EOF
       
    32 	exit(0);
       
    33 }
       
    34 
       
    35 while (my $line = <>)
       
    36 {
       
    37 	if ($line =~ m{<[^<^>]+>.*&.*</[^<^>]+>})
       
    38 	{
       
    39 		$line = escape_ampersand($line);
       
    40 	}
       
    41 	elsif ($line =~ m{<\?xml\s.*encoding=.*\".*\?>})
       
    42 	{
       
    43 		$line = set_encoding_utf8($line);
       
    44 	}
       
    45 	elsif ($line =~ m{<archive.*?[^/]>})
       
    46 	{
       
    47 		$line = unterminated_archive_tag($line, scalar <>, $.)
       
    48 	}
       
    49 	elsif ($line =~ m{make.exe: Circular .* <- .* dependency dropped.})
       
    50 	{
       
    51 		$line = escape_left_angle_bracket($line);
       
    52 	}
       
    53 	
       
    54 	print $line;
       
    55 }
       
    56 
       
    57 sub escape_ampersand
       
    58 {
       
    59 	my ($line) = @_;
       
    60 	
       
    61 	warn "escape_ampersand\n";
       
    62 	warn "in: $line";
       
    63 	
       
    64 	$line =~ s,&,&amp;,g;
       
    65 	
       
    66 	warn "out: $line";
       
    67 	return $line;
       
    68 }
       
    69 
       
    70 sub set_encoding_utf8
       
    71 {
       
    72 	my ($line) = @_;
       
    73 	
       
    74 	warn "set_encoding_utf8\n";
       
    75 	warn "in: $line";
       
    76 	
       
    77 	$line =~ s,encoding=".*",encoding="utf-8",;
       
    78 	
       
    79 	warn "out: $line";
       
    80 	return $line;
       
    81 }
       
    82 
       
    83 sub unterminated_archive_tag
       
    84 {
       
    85 	my $line = shift;
       
    86 	my $nextLine = shift;
       
    87 	my $lineNum = shift;
       
    88 	
       
    89 	if ($nextLine !~ m{(<member>)|(</archive>)})
       
    90 	{
       
    91 		warn "unterminated_archive_tag\n";
       
    92 		warn "in: $line";
       
    93 		$line =~ s{>}{/>};
       
    94 		warn "out: $line";
       
    95 	}
       
    96 	
       
    97 	return $line . $nextLine;
       
    98 }
       
    99 
       
   100 sub escape_left_angle_bracket
       
   101 {
       
   102 	my ($line) = @_;
       
   103 	
       
   104 	warn "escape_left_angle_bracket\n";
       
   105 	warn "in: $line";
       
   106 	
       
   107 	$line =~ s,<,&lt;,g;
       
   108 	
       
   109 	warn "out: $line";
       
   110 	return $line;
       
   111 }