From c07e33bec626da66e9fbede1943db586ae040d22 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 1 Jun 2014 10:35:27 -0300 Subject: [PATCH] rptflt/rptflt.pl: filter for KiCad DRC reports --- rptflt/rptflt.pl | 104 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 rptflt/rptflt.pl diff --git a/rptflt/rptflt.pl b/rptflt/rptflt.pl new file mode 100755 index 0000000..e141f8a --- /dev/null +++ b/rptflt/rptflt.pl @@ -0,0 +1,104 @@ +#!/usr/bin/perl +# +# rptflt.pl - Filter known issues from KiCad DRC reports +# +# Written 2014 by Werner Almesberger +# Copyright 2014 Werner Almesberger +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# + +# +# Usage: +# +# - generate a DRC report file with pcbnew, e.g., foo.rpt +# - review report file for any real issues +# - rename foo.rpt to foo.exceptions +# - to check for new errors, generate new report file, then run +# rptflt.pl foo.exceptions foo.rpt +# + + +sub compact +{ + local ($m); + + die if $#e != 2; + die unless $e[0] =~ /^ErrType\(\d+\):\s+(.*)\s*$/; + $m = $1; + die unless $e[1] =~ /^\s+@[^:]++:\s+(.*)\s*$/; + $m .= "; $1"; + die unless $e[2] =~ /^\s+@[^:]+:\s+(.*)\s*$/; + $m .= "; $1"; + return $m; +} + + +sub add +{ + local ($m); + + $m = &compact; + $exc{$m} = 1; + undef @e; +} + + +sub filter +{ + local ($m); + + $m = &compact; + if (defined $exc{$m}) { + $seen{$m} = 1; + } else { + print join("", @e); + } + undef @e; +} + + +sub process +{ + open(FILE, $_[0]) || die "$_[0]: $!"; + undef @e; + while () { + if (/^ErrType/) { + &flush if @e; + @e = ($_); + next; + } + if (/^\s+@/) { + die unless @e; + push(@e, $_); + next; + } + &flush if @e; + print unless $silent; + } + &flush if @e; + close FILE; +} + + +if ($#ARGV != 1) { + print stderr "usage: $0 name.exceptions name.rpt\n"; + exit(1); +} + + +*flush = *add; +$silent = 1; +&process($ARGV[0]); +*flush = *filter; +$silent = 0; +&process($ARGV[1]); + +for $m (keys %exc) { +#print STDERR "check $i\n"; + next if $seen{$m}; + print STDERR "Warning: exception \"$m\" not seen\n"; +}