chiark / gitweb /
quacks-ingredients: -counts: Fix a ws mistake nfc
[reprap-play.git] / quacks-ingredients-counts
index 101629598d265555c2e578f3344c11061ccf72c9..46d7f1bee8c294027a22e71bca1eeaa1627866b3 100755 (executable)
@@ -5,8 +5,11 @@ use strict;
 use Data::Dumper;
 use POSIX;
 
+our $which = shift @ARGV;
+
 sub xdata ($) {
     my ($cb) = @_;
+    return unless $which eq 'Base';
     foreach my $count (qw(1 2 3)) {
        foreach my $nspots (qw(1 2 3 4)) {
            $_ = $cb->($count,$nspots)."\t".$_;
@@ -27,31 +30,45 @@ foreach my $nspots (qw(1 2 3 4)) {
     $_=<DATA>; chomp or die;
     xdata sub {
        my ($xcount,$xnspots) = @_;
-       $xnspots == $nspots and $xcount;
+       $xnspots == $nspots and "$xcount+0";
     };
     my @l = split /\t/, $_;
-    foreach my $i (0..$#names) { $count{$names[$i]}{$nspots} = $l[$i] || 0; }
+    foreach my $i (0..$#names) {
+       $_ = $l[$i] || '0+0';
+       $_ ||= 0;
+       m/\+/;
+       
+       $count{$names[$i]}{$nspots} =
+           $which eq 'All'     ? $` + $' :
+           $which eq 'Base'    ? $`      :
+           $which eq 'Witches' ?      $' :
+           die "$which ?";
+    }
 }
 
 $_ = Dumper(\%count);
 s{^}{// }mg;
+#print STDERR;
 
 our $name;
 our $total_count;
+our $total_real_count;
 our $max_nrows=0;
 our $max_rowsz=0;
 
 sub wrtoplevel () {
-    print "module $name(){ ////toplevel\n";
+    print "module ${which}_$name(){ ////toplevel\n";
     my $cs = $count{$name};
     my $total = 0; $total += $_ foreach values %$cs;
     my $rowsz = ceil(sqrt($total));
     my $nrows = ceil($total / $rowsz);
     $total_count += $total;
+    $total_real_count += $total if $name =~ m/^[A-Z][a-z]+$/;
     $max_nrows = $nrows if $nrows > $max_nrows;
     $max_rowsz = $rowsz if $rowsz > $max_rowsz;
     my $ix = 0;
-    print "// total=$total, rowsz=$rowsz, nrows=$nrows\n";
+    printf "// %s  %-10s  total=%2d  rowsz=$rowsz  nrows=$nrows\n",
+       $which, "$name", $total;
     foreach my $nspots (sort keys %$cs) {
        my $c = $cs->{$nspots};
        print <<END;
@@ -78,15 +95,15 @@ foreach $name (sort keys %count) {
 }
 
 print <<END;
-// total_count=$total_count
-// max_rowsz=$max_rowsz max_nrows=$max_nrows
+// $which  total_count=$total_count   total_real_count=$total_real_count
+// $which  max_rowsz=$max_rowsz       max_nrows=$max_nrows
 END
 
 STDOUT->error and die $!;
 
 __DATA__
 White  Green   Blue    Red     Yellow  Purple  Black   Orange
-20     15      14      12      13      15      18      20
-8      10      10      8       6
-4
-       13      10      10      10
+20+6   15+10   14+8    12+6    13+6    15+8    18+8    20+12
+8+3    10+5    10+5    8+5     6+5
+4+2
+       13+5    10+5    10+5    10+5