OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [tools/] [bin/] [isemsg_filter] - Rev 12

Go to most recent revision | Compare with Previous | Blame | View Log

#!/usr/bin/perl -w
# $Id: isemsg_filter 406 2011-08-14 21:06:44Z mueller $
#
# Copyright 2011- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
#
# This program is free software; you may redistribute and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 2, or at your option any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for complete details.
#
#  Revision History:
# Date         Rev Version  Comment
# 2011-08-14   406   1.0    Initial version
#

use 5.005;                                  # require Perl 5.005 or higher
use strict;                                 # require strict checking
use FileHandle;

use Getopt::Long;

my %opts = ();

GetOptions(\%opts, "help", "pack") || exit 1;

sub print_help;
sub read_mfs;
sub read_log;

my $type   = shift @ARGV;
my $mfsnam = shift @ARGV;
my $lognam = shift @ARGV;
my @flist;
my @mlist;
my $nackcnt = 0;
my $ackcnt  = 0;
my $misscnt = 0;


autoflush STDOUT 1;             # autoflush, so noting lost on exec later

if (exists $opts{help}) {
  print_help;
  exit 0;
}

if (!defined $type || !defined $mfsnam || !defined $lognam) {
  print STDERR "%isemsg_filter-E: one of 'type mfs log' missing \n\n";
  print_help;
  exit 1;
}

if ($type !~ m{^(xst|tra|map|par|twr|bgn)$}) {
  print STDERR "%isemsg_filter-E: type must be  xst,tra,map,par,twr, or bgn\n";
  exit 1;
}

if (read_mfs()) {exit 1;}
if (read_log()) {exit 1;}

foreach (@mlist) {
  my $msgorig = $_->[0];
  my $msgflat = $_->[1];
  my $msgmatch = 0;
  foreach (@flist) {
    my $filt = $_->[0];
    if ($msgflat =~ m{$filt}) {
      $_->[1] += 1;
      $msgmatch = 1;
      last;
    }
  }
  if ($msgmatch) {
    $_->[2] += 1;
  } else {
    $nackcnt += 1;
  }
}

if ($nackcnt) {
  print "Non-acknowledged messages of type [$type] from $lognam:\n";
  foreach (@mlist) {
    next if $_->[2];
    print $_->[0] . "\n";
  }
  print "\n";
}

foreach (@flist) {
  if ($_->[1]) {
    $ackcnt  += 1;
  } else {
    $misscnt += 1;
  }
}

if ($ackcnt && exists $opts{pack}) {
  print "Acknowledged messages of type [$type] from $lognam:\n";
  foreach (@flist) {
    next if $_->[1] == 0;
    printf "%4d: %s\n", $_->[1], $_->[0];
  }
  print "\n";
}

if ($misscnt) {
  print "Missed acknowledged messages of type [$type] from $lognam:\n";
  foreach (@flist) {
    next if $_->[1] != 0;
    printf "%4d: %s\n", $_->[1], $_->[0];
  }
  print "\n";
}

#-------------------------------------------------------------------------------
sub read_mfs {
  if (not -r $mfsnam) {
    print STDERR "%isemsg_filter-E: \'$mfsnam\' not existing or readable\n";
    return 1;
  }

  open (FFILE, $mfsnam)    or die "can't open for read $mfsnam: $!";

  my $intyp = 0;

  while (<FFILE>) {
    chomp;
    next if /^\s*#/;                        # drop comments
    next if /^\s*$/;                        # drop empty lines

    if (m{^\[([a-z]{3})\]$}) {
      if ($1 eq $type) {
        $intyp = 1;
      } else {
        $intyp = 0;
      }
    } else {
      if ($intyp) {
        push @flist, [$_, 0];
      }
    }
  }

  close (FFILE);
  return 0;
}

#-------------------------------------------------------------------------------
sub read_log {
  if (not -r $lognam) {
    print STDERR "%isemsg_filter-E: \'$lognam\' not existing or readable\n";
    return 1;
  }

  open (LFILE, $lognam)    or die "can't open for read $lognam: $!";

  my $msgorig = "";
  my $msgflat = "";
  my $inmsg = 0;

  while (<LFILE>) {
    chomp;
    if (m{^(INFO|WARNING|ERROR):}) {
      if ($inmsg) {push @mlist, [$msgorig, $msgflat, 0];}
      $inmsg = 1;
      $msgorig = $_;
      $msgflat = $_;
    } elsif ($inmsg && m{^\s\s\s\S}) {
      $msgorig .= "\n" . $_;
      my $txt = $_;
      $txt =~ s{\s\s}{};                    # replace 3 leading blanks by one !
      $msgflat .= $txt;
    } else {
      if ($inmsg) {push @mlist, [$msgorig, $msgflat, 0];}
      $inmsg = 0;
    }
  }

  if ($inmsg) {push @mlist, [$msgorig, $msgflat, 0];}

  close (LFILE);

  return 0;
}

#-------------------------------------------------------------------------------

sub print_help {
  print "usage: isemsg_filter [options] type mfs log\n";
  print "  type  log file type: xst,tra,map,par,twr, or bgn\n";
  print "  mfs   message filter setup file\n";
  print "  log   log file\n";
  print "  Options:\n";
  print "    --pack           print summary of acknowledged messages\n";
  print "    --help           this message\n";
}

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.