common/tools/raptor/preprocess_log.pl
changeset 243 71d24b4fa162
parent 222 1d9c60a4e308
child 843 c32873117195
--- a/common/tools/raptor/preprocess_log.pl	Mon Jul 13 11:38:30 2009 +0100
+++ b/common/tools/raptor/preprocess_log.pl	Mon Jul 13 17:43:50 2009 +0100
@@ -1,3 +1,4 @@
+#!perl -w
 # Copyright (c) 2009 Symbian Foundation Ltd
 # This component and the accompanying materials are made available
 # under the terms of the License "Eclipse Public License v1.0"
@@ -16,56 +17,49 @@
 
 use Getopt::Long;
 
-my $infile = '';
-my $outfile = '';
-my $basedir = '';
 my $help = 0;
-GetOptions((
-	'in:s' => \$infile,
-	'out:s' => \$outfile,
-	'help!' => \$help
-));
-
-$help = 1 if (!$infile);
+GetOptions(
+	'help!' => \$help,
+);
 
 if ($help)
 {
-	print "Preprocess a raptor log, trying to countermeasure a list of known anomalies\n";
-	print "Usage: perl preprocess_log.pl --in=INFILE --out=OUTFILE\n";
+	warn <<"EOF";
+Preprocess a raptor log, trying to countermeasure a list of known anomalies
+
+Usage: perl preprocess_log.pl < INFILE > OUTFILE
+EOF
 	exit(0);
 }
 
-open(INFILE, $infile);
-open(OUTFILE, ">$outfile");
-
-for my $line (<INFILE>)
+while (my $line = <>)
 {
-	if ($line =~ m,<[^<^>]+>.*&.*</[^<^>]+>,)
+	if ($line =~ m{<[^<^>]+>.*&.*</[^<^>]+>})
 	{
 		$line = escape_ampersand($line);
 	}
-	elsif ($line =~ m,<\?xml\s.*encoding=.*\".*\?>,)
+	elsif ($line =~ m{<\?xml\s.*encoding=.*\".*\?>})
 	{
 		$line = set_encoding_utf8($line);
 	}
+	elsif ($line =~ m{<archive.*?[^/]>})
+	{
+		$line = unterminated_archive_tag($line, scalar <>, $.)
+	}
 	
-	print OUTFILE $line;
+	print $line;
 }
 
-close(OUTFILE);
-close(INFILE);
-
-
 sub escape_ampersand
 {
 	my ($line) = @_;
 	
-	print "escape_ampersand\n";
-	print "in: $line";
+	warn "escape_ampersand\n";
+	warn "in: $line";
 	
 	$line =~ s,&,&amp;,g;
 	
-	print "out: $line";
+	warn "out: $line";
 	return $line;
 }
 
@@ -73,11 +67,28 @@
 {
 	my ($line) = @_;
 	
-	print "set_encoding_utf8\n";
-	print "in: $line";
+	warn "set_encoding_utf8\n";
+	warn "in: $line";
 	
 	$line =~ s,encoding=".*",encoding="utf-8",;
 	
-	print "out: $line";
+	warn "out: $line";
 	return $line;
-}
\ No newline at end of file
+}
+
+sub unterminated_archive_tag
+{
+	my $line = shift;
+	my $nextLine = shift;
+	my $lineNum = shift;
+	
+	if ($nextLine !~ m{(<member>)|(</archive>)})
+	{
+		warn "unterminated_archive_tag\n";
+		warn "in: $line";
+		$line =~ s{>}{/>};
+		warn "out: $line";
+	}
+	
+	return $line . $nextLine;
+}