From e0c789ddf7d0e06c91d0e025ebe55251a4976f97 Mon Sep 17 00:00:00 2001 From: ian Date: Wed, 14 Apr 2004 15:12:11 +0000 Subject: [PATCH] improved --- farnell/farnell-find | 150 +++++++++++++++++++++++++++---------------- 1 file changed, 94 insertions(+), 56 deletions(-) diff --git a/farnell/farnell-find b/farnell/farnell-find index 5087eac..5353b49 100755 --- a/farnell/farnell-find +++ b/farnell/farnell-find @@ -5,35 +5,73 @@ # run it on farnell-1 and you'll see # it seems very confused, particularly about defined parts +# Input format: lines, #-comments, blank lines ignored. +# Indent level is relevant, but only 0, 1, >1 relevant. +# +# +# Starts a circuit. +# Circuit names must start with an uppercase letter. +# per +# Starts an iteratable (ends at start of next cct). +# Iteratable name must start with uppercase letter, +# may contain any non-ws chars. +# [] +# [] +# Specifies that the circuit contains that part +# in the quantity specified. Quantity is scaled +# by the iteratable's count if we're in an iteratable. +# is any string starting with a non-ws char. +# = [ +# Defines . is a sequence of words each separated +# by one space. Each word consists of some non-ws chars. The +# first word may not consist entirely of digits and hyphens; no +# other words may consist entirely of digits, slashes and +# equals signs. is any string starting with non-ws. +# ? = +# Gives a default description of parts which have +# as an initial subsequence of words. has the +# syntax of a . The description is used only if there is +# no more specific description, and the constructed description +# is with a space and the remainder of the part +# name appended. +# end +# Ends the file. Mandatory. + use strict; use POSIX; our(@warn); our(@fault); -our(%pkinddesc); # $pkinddesc{'a b c'} => 'y' after `a b c ? = y' +# neither @warn nor @fault entries have trailing \n + +our(%pkinddesc); +# $pkinddesc{'a b c'} => 'y' after `a b c ? = y' our(%parts); -# $parts{"$sect/$sper"}[]{Part} -# $parts{"$sect/$sper"}[]{Qty} -# $parts{"$sect/$sper"}[]{Desc} +# $parts{"$circuit\n$sper"}[]{Part} or item +# $parts{"$circuit\n$sper"}[]{Qty} +# $parts{"$circuit\n$sper"}[]{Use} our(%partdef); -# $partdef{"part name"}{Item} -# $partdef{"part name"}{Desc} +# $partdef{"part name"}= $item; our(%count); # $count{"$sper"} is number of times sper is instantiated # (no syntax for specifying this atm) our(%iteminstances); -# @{ $iteminstances{$item} } one entry for every sect/sper which has it -# $iteminstances{$item}[]{Desc} +# @{ $iteminstances{$item} } one entry for every circuit/sper which has it +# $iteminstances{$item}[]{Use} includes circuit # $iteminstances{$item}[]{Qty} -# $iteminstances{$item}[]{SectPer} -# $iteminstances{$item}[]{Mult} number in this sect/sper +# $iteminstances{$item}[]{Mult} number in this circuit/sper our(%itemdesc); -# $itemdesc{$item}{$desc}= 1; +# $itemdesc{$item}[]= $desc; + +our($partword1_re)= '\S*[^ \t0-9-]\S*'; +our($partword_re)= '\S*[^ \t0-9/=]\S*'; +our($part_re)= "$partword1_re(?: $partword_re)*"; +our($item_re)= '\d{3}\-\d{3,7}'; sub by_item ($) { my ($itemcode) = @_; @@ -42,7 +80,7 @@ sub by_item ($) { local ($_); my ($chr,$shortcode,$sc2,$url,$price); $url= 'http://uk.farnell.com/jsp/catalog/viewproductdetails.jsp?prodId='; - $itemcode =~ m/^(\d\d\d)\-(\d{3,7})$/ or die; + $itemcode =~ m/^(\d\d\d)\-(\d{3,7})$/ or die "$itemcode ?"; $chr->{Item}= $itemcode; $chr->{Shortcode}= $1.$2; $url .= $chr->{Shortcode}; @@ -65,7 +103,12 @@ sub by_item ($) { return undef; } $chr->{Description}= snarf('Description'); + eval { + my ($partno)= snarf('Manufacturer Part Number'); + $chr->{Description}= "[$partno] $chr->{Description}"; + }; $chr->{Avail}= snarf('Stock Availability'); + $chr->{Avail} =~ s/^Awaiting Delivery$/Awaiting/; $chr->{MinOrder}= snarf('Minimum Order'); $chr->{Multiple}= snarf('Order Multiple'); $price= snarf('Unit Price', "\n\