Author: gotar                        Date: Tue Feb 22 10:20:35 2005 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- translate classid to text (via tccs.rc file),
- sort by classid by default,
- sort by speed with head functionality,
- commented out BPS warning (AFAICanSee there's no difference in numbers,
  only in naming convention),
- classid can contain non-digits - it's hex (TODO: limit to 0-9a-f).

---- Files affected:
SOURCES:
   tccs (1.1 -> 1.2) 

---- Diffs:

================================================================
Index: SOURCES/tccs
diff -u SOURCES/tccs:1.1 SOURCES/tccs:1.2
--- SOURCES/tccs:1.1    Sun Oct 31 23:24:17 2004
+++ SOURCES/tccs        Tue Feb 22 11:20:30 2005
@@ -15,8 +15,13 @@
 my $range;
 my %tree;
 my $recurse=10;
+my $speedlevel=0;
+my %translate;
 
-GetOptions('recurse=s'=>\$recurse);
+eval `cat tccs.rc`;
+
+GetOptions('recurse=s'=>\$recurse,
+               'fastest=s'=>\$speedlevel);
 
 while(<STDIN>) {
        if(/^ lended: / and $crate) {
@@ -39,14 +44,14 @@
                next;
        }
        if(/^ rate (\S+)(bit|bps) /) {
-               print "BPS rate!\n" if $2 eq "bps";
+               # print "BPS rate!\n" if $2 eq "bps";
                ($crate=$1)=~s/K/*1024/;
                $crate=~s/M/*1024*1024/;
                $crate=eval $crate;
                $crate*=8/1000;
                next;
        }
-       if(/^class (\S+) (\d+:\d+) (root|parent (\d+:\d+)) .*rate (\S+) ceil 
(\S+)/) {
+       if(/^class (\S+) (\S+:\S+) (root|parent (\S+:\S+)) .*rate (\S+) ceil 
(\S+)/) {
                $class=$1;
                $classid=$2;
                $rate=$5;
@@ -58,15 +63,35 @@
 
 my $level='';
 
+sub my_sort {
+       return 0 unless $_[0];
+       return $_[0] cmp $_[1] unless $speedlevel;
+       return -1 if($a=~/^\(/);
+       $tree{$_[0]}[0]=~m|\(\S+\)\ \S+ \s*([\d\.]+) kb/s       \(|;
+       my $a=$1;
+       $tree{$_[1]}[0]=~m|\(\S+\)\ \S+ \s*([\d\.]+) kb/s       \(|;
+       my $b=$1;
+       return $b <=> $a;
+}
+
 sub list {
        return if length($level)/2==$recurse;
-       printf "$level%-4s",$_[0] if $_[0];
+       if($_[0]) {
+               if(exists $translate{$_[0]}) {
+                       printf "$level%-4s",$translate{$_[0]};
+               } else {
+                       printf "$level%-4s",$_[0];
+               }
+       } else { return; }
        $level.='  ';
-       foreach my $id (@{$tree{$_[0]}}) {
+       my $rank=0;
+       foreach my $id (sort {my_sort($a,$b)} (@{$tree{$_[0]}})) {
                if($id=~/^\(/) {
                        print " $id\n";
                        next;
                } else {
+                       $rank++;
+                       next if $rank>$speedlevel and $speedlevel;
                        list($id);
                }
        }
@@ -75,6 +100,6 @@
 
 [EMAIL PROTECTED]'root'}}[0]="\n";
 #list('root');
-foreach (@{$tree{'root'}}) {
+foreach (sort {my_sort($a,$b)} (@{$tree{'root'}})) {
        list($_);
 }
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/SOURCES/tccs?r1=1.1&r2=1.2&f=u


_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to