#!/usr/bin/perl -w
-# FIXME
-# this program is broken
-# 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.
#
+# Usages:
+# TBD
+#
# <Circuit Name>
# Starts a circuit.
# Circuit names must start with an uppercase letter.
# $show{$item}{Info} ) strings ready to print
# $show{$item}{Price} calculated value
-our($sorthow);
-# desc or price
+our(@sorthow);
+# list of desc price avail
our($partfrac_unique)= 'aaaa'; # increments
sub itemsortmap ($) {
my ($item) = @_;
- my ($z, $bi, $title);
- if ($sorthow eq 'price') {
- $z= sprintf "%030.20f ", 1.0 / ($show{$item}{Price} + 0.0001);
- } else {
- $z= '';
- }
+ my ($o, $bi, $how, $title);
+ $o= '';
$bi= $iteminfo{$item};
- return "? $z $item" if !defined $bi;
- $title= $bi->{Description};
- $title .= "\n".$1 if $title =~ s/^(\[[^][]+\]) //;
- return "$z $title";
+ if (!defined $bi) { return "? $item\n"; }
+ foreach $how (@sorthow) {
+ if ($how eq 'price') {
+ $o .= sprintf "%030.20f ", 1.0 / ($show{$item}{Price} + 0.0001);
+ } elsif ($how eq 'desc') {
+ $title= $bi->{Description};
+ $title .= "\n".$1 if $title =~ s/^(\[[^][]+\]) //;
+ $o .= "$title\n";
+ } elsif ($how eq 'avail') {
+ $o .= $bi->{Avail};
+ } else {
+ die "unknown sort option \`$o'\n";
+ }
+ }
+ return $o;
}
sub analyse_spec () {
$avail{$avail}= 1;
$avail= ' '.$stockmap{$avail} if exists $stockmap{$avail};
$show{$item}{Head}=
- sprintf("%5d%1s %-11s %-${desclen}.${desclen}s".
- " %6.3f %6.2f%1s %s\n",
+ sprintf("%4d%1s %-10s %-${desclen}.${desclen}s".
+ " %7.3f %7.2f%1s %s\n",
$toorder, $notechar, $item, $bi->{Description},
$bi->{Price}, $price, $notechar, $avail);
$show{$item}{Info}= '';
foreach $desc (@{ $itemdesc{$item} }) {
$show{$item}{Info} .=
sprintf("%*s %s\n",
- (5+1+1+11),'',
+ (4+1+1+10),'',
$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",
- (5+1+5),'',
+ (4+1+4),'',
$ql,$qr,
$ii->{Use});
}
foreach $k (sort keys %$chr) {
printf "%-20s %s\n", $k, $chr->{$k} or die $!;
}
-} elsif (@ARGV==1 || @ARGV==2) {
- open F, "< $ARGV[0]" or die $!;
- $sorthow= @ARGV>1 ? $ARGV[1] : 'price';
- die unless $sorthow !~ m/^(?:cost|desc)$/;
+} elsif (@ARGV>=1) {
+ my ($filename);
+ ($filename, @sorthow) = @ARGV;
+ @sorthow= qw(avail price) if !@sorthow;
+ open F, "< $filename" or die $!;
read_spec();
close F or die $!;
analyse_spec();