Author: spadkins
Date: Sat Oct  2 13:57:03 2010
New Revision: 14457

Modified:
   p5ee/trunk/App-Repository/bin/dash
   p5ee/trunk/App-Repository/lib/App/RepositoryShell.pm

Log:
fix some autoformatting problems

Modified: p5ee/trunk/App-Repository/bin/dash
==============================================================================
--- p5ee/trunk/App-Repository/bin/dash  (original)
+++ p5ee/trunk/App-Repository/bin/dash  Sat Oct  2 13:57:03 2010
@@ -26,10 +26,10 @@
         #compact => {
         #    description => "Trim titles to make compact table",
         #},
-        #decimals => {
-        #    description => "Number of decimal places to print on floats",
-        #    default => "2",
-        #},
+        decimals => {
+            description => "Number of decimal places to print on floats",
+            default => "2",
+        },
         #subtotal_columns => {
         #    description => "Print sub-totals at the end",
         #},

Modified: p5ee/trunk/App-Repository/lib/App/RepositoryShell.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/RepositoryShell.pm        (original)
+++ p5ee/trunk/App-Repository/lib/App/RepositoryShell.pm        Sat Oct  2 
13:57:03 2010
@@ -716,6 +716,8 @@
     my ($row, $r, $c, $elem, $format, $len, $f, $heading);
     my (@autoformat);
     my $headings = $options->{headings};
+    my $decimals = $options->{decimals};
+    $decimals = 2 if (! defined $decimals);
 
     # compute the number of columns as the max columns of any row
     my $max_columns = 0;
@@ -732,7 +734,7 @@
         if (! defined $autoformat[$c]) {
             $autoformat[$c] = {
                 max_length => 0,
-                type => 0,        # 0=string, 1=float, 2=integer
+                type => 2,        # 0=string, 1=float, 2=integer
                 min => undef,
                 max => undef,
             };
@@ -765,31 +767,37 @@
                 else {
                     $len = length($elem);
                     if ($elem =~ /^-?[0-9]*\.[0-9]+$/) {  # float
-                        $len = 
length(sprintf("%.$App::options{decimals}f",$elem));
                         $f->{type} = 1 if ($f->{type} > 1);
                         if (!defined $f->{min} || $elem < $f->{min}) {
                             $f->{min} = $elem;
                         }
-                        if (!defined $f->{max} || $elem < $f->{max}) {
+                        if (!defined $f->{max} || $elem > $f->{max}) {
                             $f->{max} = $elem;
                         }
+                        $len = length(sprintf("%.${decimals}f",$elem));
+                        $f->{max_length} = $len if ($len > $f->{max_length});
                     }
                     elsif ($elem =~ /^-?[0-9]+$/) { # integer
+                        $f->{type} = 2 if ($f->{type} > 2);
                         if (!defined $f->{min} || $elem < $f->{min}) {
                             $f->{min} = $elem;
                         }
-                        if (!defined $f->{max} || $elem < $f->{max}) {
+                        if (!defined $f->{max} || $elem > $f->{max}) {
                             $f->{max} = $elem;
                         }
+                        $len = length($elem);
+                        $f->{max_length} = $len if ($len > $f->{max_length});
                     }
                     else {
                         $f->{type} = 0;
                     }
                     $f->{max_length} = $len if ($len > $f->{max_length});
+print "elem=[$elem] type=[$f->{type}]\n";
                 }
             }
         }
         $self->determine_sprintf_fmt($f);
+print "[$c] type=[$f->{type}] max_length=[$f->{max_length}] min=[$f->{min}] 
max=[$f->{max}] fmt=[$f->{fmt}] title_fmt=[$f->{title_fmt}]\n";
     }
     if (!$options->{silent} || $options->{silent} <= 1) {
         for ($c = 0; $c <= $#$columns; $c++) {
@@ -825,8 +833,10 @@
     my ($self, $f) = @_;
     my ($width, $int_len, $fract_len);
     if ($f->{type} == 1) {     # float
+        my $decimals = $App::options{decimals};
+        $decimals = 2 if (! defined $decimals);
         $f->{title_fmt} = "%$f->{max_length}.$f->{max_length}s";
-        $f->{fmt} = "%$f->{max_length}.$App::options{decimals}f";
+        $f->{fmt} = "%$f->{max_length}.${decimals}f";
     }
     elsif ($f->{type} == 2) {  # integer
         $f->{title_fmt} = "%$f->{max_length}.$f->{max_length}s";

Reply via email to