chiark / gitweb /
labels in -m%.ps
[trains.git] / farnell / farnell-resistor-convert.pl
1 #!/usr/bin/perl
2 # ways to invoke:
3 #  1. Get a search list from farnell and feed HTML source to
4 #     this script with no args.  Will produce part number list.
5 #  2. Feed one or more outputs from farnell-find describe <item> to
6 #     this script with args  <mfprefix> <valueprefix>...
7 #     where <mfprefix> is the re for the first part of the mfr
8 #     code and <valueprefix> is the words of the part name prefix.
9 if (@ARGV>=2) {
10     ($kind,@prefix)= @ARGV;
11     sub insdot ($) {
12         my ($x)= @_;
13         $x =~ s/[mkr]/./;
14         return $x;
15     }   
16     while (<STDIN>) {
17         if (m/^Avail\s/) {
18             undef $value;
19         } elsif (
20  m/^Description\s+\[$kind (\d[0-9MKR]+)(?:\s[0-9.]+\%)?\]\s+RESISTOR/) {
21             $value= lc $1;
22         } elsif (m/^Description\s+(\S.*)/) {
23             print "#  $1\n";
24             $value= '';
25         } elsif (m/^Item\s+([-0-9]+)$/) {
26             die unless defined $value;
27             next unless length $value;
28             $item= $1;
29             die if exists $v2i{$value} and $v2i{$value} ne $1;
30             $v2i{$value}= $item;
31             undef $value;
32         }
33     }
34     foreach $v (sort {
35         foreach $mkr (qw(m k r)) {
36             $z= ($a =~ m/$mkr/) <=> ($b =~ m/$mkr/);
37             return $z if $z;
38         }
39         return insdot($a) <=> insdot($b);
40     }
41                 keys %v2i) {
42         printf "%s =\t%s\n", join(' ',@prefix,$v), $v2i{$v};
43     }    
44 } elsif (!@ARGV) {
45     while (<STDIN>) {
46         if (m/viewproductdetails.*\?prodId\=(\d{3})(\d{3,7})\"/) {
47             print "$1-$2\n" or die $!;
48         }
49     }
50 } else {
51     die;
52 }