X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fparse_warn.pl;h=74379968be20e5231d247c5dcc2c923fdfa5fe62;hb=45e51047c2df703229843193e49fb9829489170f;hp=53a224c45bf6d2881b92cb5bb69f4933e02e91cb;hpb=1c0a2202fe58159dd4d4197c4ff8b21f9387685e;p=infobot.git diff --git a/scripts/parse_warn.pl b/scripts/parse_warn.pl index 53a224c..7437996 100755 --- a/scripts/parse_warn.pl +++ b/scripts/parse_warn.pl @@ -1,13 +1,13 @@ #!/usr/bin/perl -w # leading and trailing context lines. -my $contextspread = 2; +my $contextspread = 2; use strict; $| = 1; -if (!scalar @ARGV) { +if ( !scalar @ARGV ) { print "Usage: parse_warn.pl \n"; print "Example: parse_warn.pl log/*\n"; exit 0; @@ -17,75 +17,85 @@ my %done; my $file; foreach $file (@ARGV) { - if (! -f $file) { - print "warning: $file does not exist.\n"; - next; + if ( !-f $file ) { + print "warning: $file does not exist.\n"; + next; } my $str = ' at .* line '; print "Opening $file... "; - if ($file =~ /bz2$/) { # bz2 - open(FILE, "bzcat $file | egrep '$str' |"); - } elsif ($file =~ /gz$/) { # gz - open(FILE, "zegrep '$str' $file |"); - } else { # raw - open(FILE, "egrep '$str' $file |"); + if ( $file =~ /bz2$/ ) { # bz2 + open( FILE, "bzcat $file | egrep '$str' |" ); + } + elsif ( $file =~ /gz$/ ) { # gz + open( FILE, "zegrep '$str' $file |" ); + } + else { # raw + open( FILE, "egrep '$str' $file |" ); } print "Parsing... "; while () { - if (/ at (\S+) line (\d+)/) { - my ($file,$lineno) = ($1,$2+1); - $done{$file}{$lineno}++; - } + if (/ at (\S+) line (\d+)/) { + my ( $file, $lineno ) = ( $1, $2 + 1 ); + $done{$file}{$lineno}++; + } } close FILE; print "Done.\n"; } -foreach $file (keys %done) { - my $count = scalar(keys %{$done{$file}}); +foreach $file ( keys %done ) { + my $count = scalar( keys %{ $done{$file} } ); print "warn $file: $count unique warnings.\n"; - if (! -f $file) { - print "=> error: does not exist.\n\n"; - next; + if ( !-f $file ) { + print "=> error: does not exist.\n\n"; + next; } - if (open(IN,$file)) { - my @lines = ; - close IN; - - my $total = scalar @lines; - my $spread = 0; - my $done = 0; - for(my $i=0; $i<=$total; $i++) { - next unless (exists $done{$file}{$i+$contextspread} or $spread); - - if (exists $done{$file}{$i+$contextspread}) { - print "@@ $i @@\n" unless ($spread); - # max lines between offending lines should be 2*context-1. - # coincidence that it is! - $spread = 2*$contextspread; - } else { - $spread--; - } - - if (exists $done{$file}{$i}) { - print "*** "; - } else { - print "--- "; - } - - if ($i >= $total) { - print "EOF\n"; - } else { - print $lines[$i]; - } - } - print "\n"; - } else { - print "=> error: could not open file.\n"; + if ( open( IN, $file ) ) { + my @lines = ; + close IN; + + my $total = scalar @lines; + my $spread = 0; + my $done = 0; + for ( my $i = 0 ; $i <= $total ; $i++ ) { + next + unless ( exists $done{$file}{ $i + $contextspread } or $spread ); + + if ( exists $done{$file}{ $i + $contextspread } ) { + print "@@ $i @@\n" unless ($spread); + + # max lines between offending lines should be 2*context-1. + # coincidence that it is! + $spread = 2 * $contextspread; + } + else { + $spread--; + } + + if ( exists $done{$file}{$i} ) { + print "*** "; + } + else { + print "--- "; + } + + if ( $i >= $total ) { + print "EOF\n"; + } + else { + print $lines[$i]; + } + } + print "\n"; + } + else { + print "=> error: could not open file.\n"; } } + +# vim:ts=4:sw=4:expandtab:tw=80