Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f098aa8

Browse files
author
Werner Almesberger
committed
prettyord: added SMT fab type BOM output
- prettyord: new option -f to generate SMT fab output - prettyord: new option -c to generate CSV output - prettyord: new option -r to sort by component reference (instead of part number) - prettyord (usage): added description of options
1 parent e038585 commit f098aa8

File tree

1 file changed

+57
-9
lines changed

1 file changed

+57
-9
lines changed

‎eda/boom/prettyord‎

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,30 @@ require "misc.pl";
66

77
sub usage
88
{
9-
print STDERR "usage: 0ドル [-s/from/to/ ...] [-t] ...\n";
9+
print STDERR <<"END";
10+
usage: 0ドル [-c] [-f|-t] [-r] [-s/from/to/ ...] ...
11+
12+
-c generate CSV output (default: generate formatted text)
13+
-f generate SMT fab output (default: generate shopping list)
14+
-r sort by component reference (default: sort by part number)
15+
-s/from/to/ substitute description and treat result as reference
16+
-t print the total number of items and the total cost.
17+
-t cannot be combined with -c or -f.
18+
END
1019
exit(1);
1120
}
1221

22+
$shop = 1;
23+
$by_pn = 1;
1324
while ($ARGV[0] =~ /^-./) {
1425
if ($ARGV[0] =~ /^-s/) {
1526
&usage unless &dsc_xlat_arg($');
27+
} elsif ($ARGV[0] eq "-c") {
28+
$csv = 1;
29+
} elsif ($ARGV[0] eq "-f") {
30+
$shop = 0;
31+
} elsif ($ARGV[0] eq "-r") {
32+
$by_pn = 0;
1633
} elsif ($ARGV[0] eq "-t") {
1734
$total = 1;
1835
} else {
@@ -21,26 +38,57 @@ while ($ARGV[0] =~ /^-./) {
2138
shift @ARGV;
2239
}
2340

41+
&usage if $total && !$shop;
42+
&usage if $total && $csv;
43+
2444
&parse;
2545

2646
$out[0][0] = "Pos";
2747
$out[1][0] = "Qty";
2848
$out[2][0] = "P/N";
2949
$out[3][0] = "Description";
30-
$out[4][0] = "Value";
31-
$out[5][0] = "";
3250

33-
for (sort keys %order) {
51+
if ($shop) {
52+
$out[4][0] = "Value";
53+
$out[5][0] = "";
54+
} else {
55+
$out[4][0] = "Ref";
56+
}
57+
58+
for (sort { $by_pn ? $a cmp $b : $order{$a}[3] cmp $order{$b}[3] }
59+
keys %order) {
3460
push(@{ $out[0] }, ++$n);
35-
push(@{ $out[1] }, $order{$_}[0]);
61+
push(@{ $out[1] }, $shop ? $order{$_}[0] : @{ $order{$_} }-3);
3662
@f = split(/\s+/, $_);
37-
push(@{ $out[2] }, $f[1]);
63+
push(@{ $out[2] }, $shop ? $f[1] : "$f[0] $f[1]");
3864
my $dsc = &dsc_find($_);
3965
print STDERR "$_: no description\n" unless defined $dsc;
4066
push(@{ $out[3] }, defined $dsc ? $dsc : "???");
41-
push(@{ $out[4] }, $order{$_}[1]);
42-
push(@{ $out[5] }, sprintf("%.2f", $order{$_}[2]));
43-
$price{$order{$_}[1]} += $order{$_}[2];
67+
if ($shop) {
68+
push(@{ $out[4] }, $order{$_}[1]);
69+
push(@{ $out[5] }, sprintf("%.2f", $order{$_}[2]));
70+
$price{$order{$_}[1]} += $order{$_}[2];
71+
} else {
72+
my @r = @{ $order{$_} };
73+
push(@{ $out[4] }, join(", ", @r[3..$#r]));
74+
}
75+
}
76+
77+
if ($csv) {
78+
for ($i = 0; $i <= $#{ $out[0] }; $i++) {
79+
for ($j = 0; $j <= $#out; $j++) {
80+
print "," if $j;
81+
if ($i && $j < 2) {
82+
print $out[$j][$i];
83+
} else {
84+
my $s = $out[$j][$i];
85+
$s =~ s/"/''/g;
86+
print "\"$s\"";
87+
}
88+
}
89+
print "\n";
90+
}
91+
exit(0);
4492
}
4593

4694
for (@out) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /