chiark / gitweb /
suppression
authorian <ian>
Wed, 14 Apr 2004 22:32:53 +0000 (22:32 +0000)
committerian <ian>
Wed, 14 Apr 2004 22:32:53 +0000 (22:32 +0000)
farnell/control.partlist [new file with mode: 0644]
farnell/farnell-find

diff --git a/farnell/control.partlist b/farnell/control.partlist
new file mode 100644 (file)
index 0000000..ecad651
--- /dev/null
@@ -0,0 +1,2 @@
+suppress std *
+suppress 432-9363
index f6edb3bef19100ec215c49a264e200eee9d1f803..07088df8733b56c5612fd17f2332dca3df2ed072 100755 (executable)
@@ -14,6 +14,8 @@
 #
 # Input format: lines, #-comments, blank lines ignored.
 # Indent level is relevant, but only 0, 1, >1 relevant.
+# Order of information in a file is not relevant unless explicitly
+# stated below.
 #
 #   <Circuit Name>
 #        Starts a circuit.
 #        no more specific description, and the constructed description
 #        is <desc prefix> with a space and the remainder of the part
 #        name appended.
+#
+#   suppress <item>
+#   suppress <part glob>
+#        Suppresses all processing for all parts matching the
+#        glob.
+#
 #   end
 #        Ends the file.  Optional.
 
@@ -92,6 +100,9 @@ our(%show);
 # $show{$item}{Info}      )  strings ready to print
 # $show{$item}{Price}     calculated value
 
+our(%suppress_item);
+our(@suppress_partre);
+
 our(@sorthow);
 # list of desc price avail
 
@@ -201,6 +212,14 @@ sub read_spec ($) {
            if (defined $3) {
                push @{ $itemdesc{$2} }, "$1: $3";
            }
+       } elsif (m/^suppress\s+($item_re)$/) {
+           $suppress_item{$1}= 1;
+       } elsif (m/^suppress\s+(\S.*)$/) {
+           $_= $1; s/\s+/ /g;
+           s/\W/ ($& eq '*' ? '.*' :
+                  $& eq '?' ? '.' :
+                  "\\$&") /ge;
+           push @suppress_partre, $_;
        } else {
            die "$_ ?";
        }
@@ -213,7 +232,10 @@ sub itemsortmap ($) {
     my ($o, $bi, $how, $title);
     $o= '';
     $bi= $iteminfo{$item};
-    if (!defined $bi) { return "? $item\n"; }
+    if (!defined $bi) {
+       $bi= { Avail => '?U' };
+       $bi->{Description} = $itemdesc{$item} ? $itemdesc{$item}[0] : '?U';
+    }
     foreach $how (@sorthow) {
        if ($how eq 'price') {
            $o .= sprintf "%030.20f ", 1.0 / ($show{$item}{Price} + 0.0001);
@@ -230,10 +252,28 @@ sub itemsortmap ($) {
     return $o;
 }
 
+sub hrule () { print '-'x79, "\n" or die $!; }
+
+sub iteminstanceprint ($) {
+    my ($ii) = @_;
+    my ($ql,$qr);
+
+    $ql= $ii->{Qty}; $qr= '';
+    if ($ql =~ s/\D\d+$//) { $qr= $&; }
+    if ($ql =~ s,(\d+)/[a-z]+$,,) { $qr= "$1/"; }
+    if ($ql =~ s/\=//) { $qr .= $&; }
+    return sprintf("%*s %5s%-2s %s\n",
+                  (4+1+4),'',
+                  $ql,$qr,
+                  $ii->{Use});
+}    
+
 sub analyse_spec () {
     my ($part,$pd,$try,@rhs,$sp,$circuit,$iteratable,$count,$pe,$use);
     my ($item,$totalqty,$ii,$bi,$toorder,$price,$total,$notechar,$desc);
-    my ($avail,%avail,$desclen,$why,$ql,$qr);
+    my ($avail,%avail,$desclen,$why,$suppress,%suppress,$pi);
+    my ($iteminstance);
+    $desclen= 42;
     foreach $part (sort keys %partdef) {
        $item= $partdef{$part};
        next if exists $itemdesc{$item};
@@ -266,24 +306,31 @@ sub analyse_spec () {
            $use= $pe->{Use};
            $use= defined $use ? "$circuit: $use" : $circuit;
            $part= $pe->{Part};
+           $suppress= 0;
            if ($part =~ m/^$item_re$/) {
                $item= $part;
            } elsif (exists $partdef{$part}) {
+               $suppress= 1 if grep { $part =~ m/^$_$/ } @suppress_partre;
                $item= $partdef{$part};
            } else {
                push @fault, "unknown part $part ($pe->{FileLine})";
                next;
            }
-           push @{ $iteminstances{$item} }, {
+           $suppress= 1 if exists $suppress_item{$item};
+           $iteminstance= {
                Use => $use,
                Qty => $pe->{Qty},
                Mult => $count,
-               FileLine => $pe->{FileLine}
-               };
+               FileLine => $pe->{FileLine},
+           };
+           if ($suppress) {
+               push @{ $suppress{$item} }, iteminstanceprint($iteminstance);
+           } else {
+               push @{ $iteminstances{$item} }, $iteminstance;
+           }
        }
     }
     $total= 0;
-    $desclen= 42;
     foreach $item (sort keys %iteminstances) {
        $why= defined $itemdesc{$item} ? $itemdesc{$item}[0].'; ' : '';
        $why .= join ",", map { $_->{FileLine} } @{ $iteminstances{$item} };
@@ -317,15 +364,7 @@ sub analyse_spec () {
                        $desc);
        }
        foreach $ii (@{ $iteminstances{$item} }) {
-           $ql= $ii->{Qty}; $qr= '';
-           if ($ql =~ s/\D\d+$//) { $qr= $&; }
-           if ($ql =~ s,(\d+)/[a-z]+$,,) { $qr= "$1/"; }
-           if ($ql =~ s/\=//) { $qr .= $&; }
-           $show{$item}{Info} .=
-               sprintf("%*s %5s%-2s %s\n",
-                       (4+1+4),'',
-                       $ql,$qr,
-                       $ii->{Use});
+           $show{$item}{Info} .= iteminstanceprint($ii);
        }
     }
     foreach $item (sort { itemsortmap($a) cmp itemsortmap($b); }
@@ -341,7 +380,25 @@ sub analyse_spec () {
        or die $!;
     print "\n" or die $!;
     dump_warnerrs();
-    print '-'x70, "\n" or die $!;
+    if (keys %suppress) {
+       print "---------- suppressed ----------\n" or die $!;
+       foreach $item (sort { itemsortmap($a) cmp itemsortmap($b); }
+                      keys %suppress) {
+           $pi= $item;
+           foreach $ii (@{ $itemdesc{$item} }) {
+               printf " %-10s %s\n", $pi, $ii
+                   or die $!;
+               $pi= '';
+           }
+           if (length $pi) {
+               print " $pi\n" or die $!;
+           }
+           foreach $ii (@{ $suppress{$item} }) {
+               print $ii or die $!;
+           }
+       }
+    }
+    hrule();
 }
 
 sub addqty ($$$$) {