Changeset 5706 for i2c-tools/trunk

Show
Ignore:
Timestamp:
03/20/09 15:40:59 (3 years ago)
Author:
khali
Message:

Automatically adjust the width of columns in text side-by-side mode.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • i2c-tools/trunk/eeprom/decode-dimms

    r5705 r5706  
    4242use Fcntl qw(:DEFAULT :seek); 
    4343use vars qw($opt_html $opt_bodyonly $opt_side_by_side $opt_merge 
    44             $opt_igncheck $use_sysfs $use_hexdump 
     44            $opt_igncheck $use_sysfs $use_hexdump $sbs_col_width 
    4545            @vendors %decode_callback $revision @dimm $current %hexdump_cache); 
    4646 
     
    393393                } 
    394394 
    395                 my $format = "%-47s".(" %-19s" x (scalar @values - 1))." %s\n"; 
     395                my $format = "%-47s".((" %-".$sbs_col_width."s") x (scalar @values - 1))." %s\n"; 
    396396                my $maxl = 0; # Keep track of the max number of lines 
    397397 
     
    18801880} 
    18811881 
     1882# Find out the longest value string to adjust the column width 
     1883# Note: this could be improved a bit by not taking into account strings 
     1884# which will end up being merged. 
     1885$sbs_col_width = 15; 
     1886if ($opt_side_by_side && !$opt_html) { 
     1887        for $current (0 .. $#dimm) { 
     1888                my @output = @{$dimm[$current]->{output}}; 
     1889                my $line; 
     1890                my @strings; 
     1891 
     1892                for ($line = 0; $line < @output; $line++) { 
     1893                        my ($func, $label, $value) = @{$output[$line]}; 
     1894                        push @strings, split("\n", $value) if defined $value; 
     1895                } 
     1896 
     1897                foreach $line (@strings) { 
     1898                        my $len = length($line); 
     1899                        $sbs_col_width = $len if $len > $sbs_col_width; 
     1900                } 
     1901        } 
     1902} 
     1903 
    18821904# Print the decoded information for all DIMMs 
    18831905for $current (0 .. $#dimm) {