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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [tools/] [bin/] [isemsg_filter] - Blame information for rev 12

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

Line No. Rev Author Line
1 12 wfjm
#!/usr/bin/perl -w
2
# $Id: isemsg_filter 406 2011-08-14 21:06:44Z mueller $
3
#
4
# Copyright 2011- by Walter F.J. Mueller 
5
#
6
# This program is free software; you may redistribute and/or modify it under
7
# the terms of the GNU General Public License as published by the Free
8
# Software Foundation, either version 2, or at your option any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
12
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13
# for complete details.
14
#
15
#  Revision History:
16
# Date         Rev Version  Comment
17
# 2011-08-14   406   1.0    Initial version
18
#
19
 
20
use 5.005;                                  # require Perl 5.005 or higher
21
use strict;                                 # require strict checking
22
use FileHandle;
23
 
24
use Getopt::Long;
25
 
26
my %opts = ();
27
 
28
GetOptions(\%opts, "help", "pack") || exit 1;
29
 
30
sub print_help;
31
sub read_mfs;
32
sub read_log;
33
 
34
my $type   = shift @ARGV;
35
my $mfsnam = shift @ARGV;
36
my $lognam = shift @ARGV;
37
my @flist;
38
my @mlist;
39
my $nackcnt = 0;
40
my $ackcnt  = 0;
41
my $misscnt = 0;
42
 
43
 
44
autoflush STDOUT 1;             # autoflush, so noting lost on exec later
45
 
46
if (exists $opts{help}) {
47
  print_help;
48
  exit 0;
49
}
50
 
51
if (!defined $type || !defined $mfsnam || !defined $lognam) {
52
  print STDERR "%isemsg_filter-E: one of 'type mfs log' missing \n\n";
53
  print_help;
54
  exit 1;
55
}
56
 
57
if ($type !~ m{^(xst|tra|map|par|twr|bgn)$}) {
58
  print STDERR "%isemsg_filter-E: type must be  xst,tra,map,par,twr, or bgn\n";
59
  exit 1;
60
}
61
 
62
if (read_mfs()) {exit 1;}
63
if (read_log()) {exit 1;}
64
 
65
foreach (@mlist) {
66
  my $msgorig = $_->[0];
67
  my $msgflat = $_->[1];
68
  my $msgmatch = 0;
69
  foreach (@flist) {
70
    my $filt = $_->[0];
71
    if ($msgflat =~ m{$filt}) {
72
      $_->[1] += 1;
73
      $msgmatch = 1;
74
      last;
75
    }
76
  }
77
  if ($msgmatch) {
78
    $_->[2] += 1;
79
  } else {
80
    $nackcnt += 1;
81
  }
82
}
83
 
84
if ($nackcnt) {
85
  print "Non-acknowledged messages of type [$type] from $lognam:\n";
86
  foreach (@mlist) {
87
    next if $_->[2];
88
    print $_->[0] . "\n";
89
  }
90
  print "\n";
91
}
92
 
93
foreach (@flist) {
94
  if ($_->[1]) {
95
    $ackcnt  += 1;
96
  } else {
97
    $misscnt += 1;
98
  }
99
}
100
 
101
if ($ackcnt && exists $opts{pack}) {
102
  print "Acknowledged messages of type [$type] from $lognam:\n";
103
  foreach (@flist) {
104
    next if $_->[1] == 0;
105
    printf "%4d: %s\n", $_->[1], $_->[0];
106
  }
107
  print "\n";
108
}
109
 
110
if ($misscnt) {
111
  print "Missed acknowledged messages of type [$type] from $lognam:\n";
112
  foreach (@flist) {
113
    next if $_->[1] != 0;
114
    printf "%4d: %s\n", $_->[1], $_->[0];
115
  }
116
  print "\n";
117
}
118
 
119
#-------------------------------------------------------------------------------
120
sub read_mfs {
121
  if (not -r $mfsnam) {
122
    print STDERR "%isemsg_filter-E: \'$mfsnam\' not existing or readable\n";
123
    return 1;
124
  }
125
 
126
  open (FFILE, $mfsnam)    or die "can't open for read $mfsnam: $!";
127
 
128
  my $intyp = 0;
129
 
130
  while () {
131
    chomp;
132
    next if /^\s*#/;                        # drop comments
133
    next if /^\s*$/;                        # drop empty lines
134
 
135
    if (m{^\[([a-z]{3})\]$}) {
136
      if ($1 eq $type) {
137
        $intyp = 1;
138
      } else {
139
        $intyp = 0;
140
      }
141
    } else {
142
      if ($intyp) {
143
        push @flist, [$_, 0];
144
      }
145
    }
146
  }
147
 
148
  close (FFILE);
149
  return 0;
150
}
151
 
152
#-------------------------------------------------------------------------------
153
sub read_log {
154
  if (not -r $lognam) {
155
    print STDERR "%isemsg_filter-E: \'$lognam\' not existing or readable\n";
156
    return 1;
157
  }
158
 
159
  open (LFILE, $lognam)    or die "can't open for read $lognam: $!";
160
 
161
  my $msgorig = "";
162
  my $msgflat = "";
163
  my $inmsg = 0;
164
 
165
  while () {
166
    chomp;
167
    if (m{^(INFO|WARNING|ERROR):}) {
168
      if ($inmsg) {push @mlist, [$msgorig, $msgflat, 0];}
169
      $inmsg = 1;
170
      $msgorig = $_;
171
      $msgflat = $_;
172
    } elsif ($inmsg && m{^\s\s\s\S}) {
173
      $msgorig .= "\n" . $_;
174
      my $txt = $_;
175
      $txt =~ s{\s\s}{};                    # replace 3 leading blanks by one !
176
      $msgflat .= $txt;
177
    } else {
178
      if ($inmsg) {push @mlist, [$msgorig, $msgflat, 0];}
179
      $inmsg = 0;
180
    }
181
  }
182
 
183
  if ($inmsg) {push @mlist, [$msgorig, $msgflat, 0];}
184
 
185
  close (LFILE);
186
 
187
  return 0;
188
}
189
 
190
#-------------------------------------------------------------------------------
191
 
192
sub print_help {
193
  print "usage: isemsg_filter [options] type mfs log\n";
194
  print "  type  log file type: xst,tra,map,par,twr, or bgn\n";
195
  print "  mfs   message filter setup file\n";
196
  print "  log   log file\n";
197
  print "  Options:\n";
198
  print "    --pack           print summary of acknowledged messages\n";
199
  print "    --help           this message\n";
200
}

powered by: WebSVN 2.1.0

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