/[scripts]/trunk/sum.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/sum.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 75 by dpavlin, Tue Apr 8 20:46:20 2008 UTC revision 76 by dpavlin, Tue Apr 8 21:05:42 2008 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4  use Term::ReadKey qw(GetTerminalSize);  use Term::ReadKey qw(GetTerminalSize);
5    use Getopt::Long;
6    
7    my $human = 0;
8    GetOptions(
9            'human!' => \$human,
10    );
11    
12  my @lines;  my @lines;
13    
# Line 10  my $max_sum = 0; Line 16  my $max_sum = 0;
16  my $rest_len = 0;  my $rest_len = 0;
17  my $sum = 0;  my $sum = 0;
18    
19    my @units = qw/b k M G/;
20    sub unit {
21            my $v = shift;
22    
23            return $v unless $human;
24    
25            my $o = 0;
26    
27            while ( ( $v / 10000 ) >= 1 ) {
28                    $o++;
29                    $v /= 1024;
30            }
31    
32            if ( $v >= 1 ) {
33                    return sprintf("%d%s", $v, $units[$o]);
34            } elsif ( $v == 0 ) {
35                    return 0;
36            } else {
37                    return sprintf("%.1f%s", $v, $units[$o]);
38            }
39    }
40    
41  while(<>) {  while(<>) {
42          chomp;          chomp;
43          if (/\s*([\d\.]+)\s+(.+)/) {          if (/\s*([\d\.]+)\s+(.+)/) {
# Line 60  sub bar { Line 88  sub bar {
88  foreach my $l (@lines) {  foreach my $l (@lines) {
89          my ($size,$r,$tmpsum) = @{$l};          my ($size,$r,$tmpsum) = @{$l};
90  #       printf "%-50s\t[ + %-8d= %-8d ]\n",$r,$size,$tmpsum;  #       printf "%-50s\t[ + %-8d= %-8d ]\n",$r,$size,$tmpsum;
91          printf "%-${rest_len}s %${size_len}d %-${bar_size}s %${sum_len}d\n",          printf "%-${rest_len}s %${size_len}s %-${bar_size}s %${sum_len}s\n",
92                  $r, $size, bar($size, $sum, $tmpsum, $sum), $tmpsum;                  $r, unit($size), bar($size, $sum, $tmpsum, $sum), unit($tmpsum);
93  }  }

Legend:
Removed from v.75  
changed lines
  Added in v.76

  ViewVC Help
Powered by ViewVC 1.1.26